[PR #6719] fix: last_seen api peers #26798

Open
opened 2026-08-05 07:07:49 -04:00 by saavagebueno · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/netbirdio/netbird/pull/6719
Author: @nicovak
Created: 7/10/2026
Status: 🔄 Open

Base: mainHead: fix/last_seen-api-peers


📝 Commits (1)

📊 Changes

4 files changed (+152 additions, -8 deletions)

View changed files

📝 management/server/http/handlers/peers/peers_handler.go (+17 -3)
📝 management/server/http/handlers/peers/peers_handler_test.go (+123 -0)
📝 shared/management/http/api/openapi.yml (+6 -2)
📝 shared/management/http/api/types.gen.go (+6 -3)

📄 Description

Describe your changes

Fixes the /api/peers last_seen field so it reflects the current request time for connected peers, instead of freezing at the peer's connection-start timestamp.

Since commit 97bc1eebd introduced session-token fencing for peer status updates, peer_status.last_seen is written by the database only on connect/disconnect. While a peer stays connected on a long-lived gRPC Sync stream, the stored last_seen no longer gets refreshed. This change restores the expected API behavior at the HTTP presentation layer without altering the underlying fencing logic or adding database writes on the hot sync-stream path.

Changes:

  • Added peerLastSeen() helper in management/server/http/handlers/peers/peers_handler.go that returns time.Now().UTC() for connected peers and the stored LastSeen for disconnected peers.
  • Applied the helper to toSinglePeerResponse, toPeerListItemResponse, and peerToAccessiblePeer.
  • Updated the last_seen descriptions in shared/management/http/api/openapi.yml for Peer, PeerBatch (via Peer), and AccessiblePeer.
  • Regenerated shared/management/http/api/types.gen.go with oapi-codegen@v2.7.1.
  • Added TestPeerLastSeenInResponse covering list, single-peer, and accessible-peers endpoints.

Fixes https://github.com/netbirdio/netbird/issues/5139

Stack

Checklist

  • Is it a bug fix
  • Is a typo/documentation fix
  • Is a feature enhancement
  • It is a refactor
  • Created tests that fail without the change (if possible)
  • This change does not modify the public API, gRPC protocols, functionality behavior, CLI / service flags, or introduce a new feature — OR I have discussed it with the NetBird team beforehand (link the issue / Slack thread in the description). See CONTRIBUTING.md.

By submitting this pull request, you confirm that you have read and agree to the terms of the Contributor License Agreement.

Documentation

Select exactly one:

  • I added/updated documentation for this change
  • Documentation is not needed for this change (explain why)

Summary by CodeRabbit

  • Bug Fixes

    • Peer responses now report the current time as last_seen for connected peers.
    • Disconnected peers continue to show their most recently recorded timestamp.
    • Updated behavior consistently across peer list, detail, and accessible-peer views.
  • Documentation

    • Clarified last_seen behavior in the API documentation.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/netbirdio/netbird/pull/6719 **Author:** [@nicovak](https://github.com/nicovak) **Created:** 7/10/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `fix/last_seen-api-peers` --- ### 📝 Commits (1) - [`766501b`](https://github.com/netbirdio/netbird/commit/766501bdea8443fcad7a249604828018d8a0f656) fix: last_seen api peers ### 📊 Changes **4 files changed** (+152 additions, -8 deletions) <details> <summary>View changed files</summary> 📝 `management/server/http/handlers/peers/peers_handler.go` (+17 -3) 📝 `management/server/http/handlers/peers/peers_handler_test.go` (+123 -0) 📝 `shared/management/http/api/openapi.yml` (+6 -2) 📝 `shared/management/http/api/types.gen.go` (+6 -3) </details> ### 📄 Description ## Describe your changes Fixes the `/api/peers` `last_seen` field so it reflects the current request time for connected peers, instead of freezing at the peer's connection-start timestamp. Since commit `97bc1eebd` introduced session-token fencing for peer status updates, `peer_status.last_seen` is written by the database only on connect/disconnect. While a peer stays connected on a long-lived gRPC Sync stream, the stored `last_seen` no longer gets refreshed. This change restores the expected API behavior at the HTTP presentation layer without altering the underlying fencing logic or adding database writes on the hot sync-stream path. Changes: - Added `peerLastSeen()` helper in `management/server/http/handlers/peers/peers_handler.go` that returns `time.Now().UTC()` for connected peers and the stored `LastSeen` for disconnected peers. - Applied the helper to `toSinglePeerResponse`, `toPeerListItemResponse`, and `peerToAccessiblePeer`. - Updated the `last_seen` descriptions in `shared/management/http/api/openapi.yml` for `Peer`, `PeerBatch` (via `Peer`), and `AccessiblePeer`. - Regenerated `shared/management/http/api/types.gen.go` with `oapi-codegen@v2.7.1`. - Added `TestPeerLastSeenInResponse` covering list, single-peer, and accessible-peers endpoints. ## Issue ticket number and link Fixes https://github.com/netbirdio/netbird/issues/5139 ## Stack <!-- branch-stack --> ### Checklist - [x] Is it a bug fix - [ ] Is a typo/documentation fix - [ ] Is a feature enhancement - [ ] It is a refactor - [x] Created tests that fail without the change (if possible) - [ ] This change does **not** modify the public API, gRPC protocols, functionality behavior, CLI / service flags, or introduce a new feature — **OR** I have discussed it with the NetBird team beforehand (link the issue / Slack thread in the description). See [CONTRIBUTING.md](https://github.com/netbirdio/netbird/blob/main/CONTRIBUTING.md#discuss-changes-with-the-netbird-team-first). > By submitting this pull request, you confirm that you have read and agree to the terms of the [Contributor License Agreement](https://github.com/netbirdio/netbird/blob/main/CONTRIBUTOR_LICENSE_AGREEMENT.md). ## Documentation Select exactly one: - [x] I added/updated documentation for this change - [ ] Documentation is **not needed** for this change (explain why) <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Bug Fixes** * Peer responses now report the current time as `last_seen` for connected peers. * Disconnected peers continue to show their most recently recorded timestamp. * Updated behavior consistently across peer list, detail, and accessible-peer views. * **Documentation** * Clarified `last_seen` behavior in the API documentation. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
saavagebueno added the pull-request label 2026-08-05 07:07:49 -04:00
Sign in to join this conversation.
No Label pull-request
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: DYNR/netbird#26798