[PR #2144] [MERGED] Context creation and logging in management #16520

Open
opened 2026-08-05 04:06:13 -04:00 by saavagebueno · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/netbirdio/netbird/pull/2144
Author: @pascal-fischer
Created: 6/18/2024
Status: Merged
Merged: 6/27/2024
Merged by: @pascal-fischer

Base: feature/add-context-throughout-managementHead: develop/context-creation-and-logging


📝 Commits (10+)

  • 7738f63 add context creation and logging
  • c282ea6 fix test
  • 8abe453 remove comment
  • d978b2f add linter exceptions
  • 94e5eb4 set proper accountID to grpc calls
  • a466a43 exclude middleware from linter
  • bd1bd25 split request middleware into metrics and auth middleware
  • fcfeb06 better error handling for accountID from grpc
  • 2e2a656 fix linter
  • b92726c remove custom logger and merge with old logging code

📊 Changes

13 files changed (+220 additions, -39 deletions)

View changed files

📝 formatter/hook.go (+72 -0)
📝 formatter/set.go (+10 -1)
📝 management/cmd/management.go (+39 -4)
📝 management/server/account.go (+10 -4)
management/server/context/keys.go (+8 -0)
📝 management/server/grpcserver.go (+24 -1)
📝 management/server/http/handler.go (+6 -0)
📝 management/server/http/middleware/auth_middleware.go (+7 -2)
📝 management/server/http/middleware/auth_middleware_test.go (+10 -9)
📝 management/server/mock_server/account_mock.go (+9 -0)
📝 management/server/store.go (+3 -2)
📝 management/server/telemetry/http_api_metrics.go (+16 -15)
📝 util/log.go (+6 -1)

📄 Description

Describe your changes

This PR creates 3 root contexts. It adds a logSource parameter to each context:

  • GRPC: For all requests coming via grpc api. For this case, the context will be extended with a requestID, the deviceID of the peer, and the accountID the peer belongs to
  • HTTP: For all requests coming from REST api. For this case, the context will be extended with a requestID, the userID of the user querying the api, and the accountID the user is accessing (needs updating once we implement multitenancy).
  • SYSTEM: which logs general system logs that occur during management operation e.g. startup, expiration trigger...

The PR updates the logger with a custom implementation that logs the additional fields.

Caution

This PR will cause both management and client logger to lose their formatting. The formatting will be created in a separate PR before merging the feature branch.

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)
  • Extended the README / documentation, if necessary

🔄 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/2144 **Author:** [@pascal-fischer](https://github.com/pascal-fischer) **Created:** 6/18/2024 **Status:** ✅ Merged **Merged:** 6/27/2024 **Merged by:** [@pascal-fischer](https://github.com/pascal-fischer) **Base:** `feature/add-context-throughout-management` ← **Head:** `develop/context-creation-and-logging` --- ### 📝 Commits (10+) - [`7738f63`](https://github.com/netbirdio/netbird/commit/7738f63929c48d588880f72ab342d12e81acfeb3) add context creation and logging - [`c282ea6`](https://github.com/netbirdio/netbird/commit/c282ea64ab2ec8ad678325836a2ba6c342a37391) fix test - [`8abe453`](https://github.com/netbirdio/netbird/commit/8abe45394d1a6d37263253fc9b72f5331203d235) remove comment - [`d978b2f`](https://github.com/netbirdio/netbird/commit/d978b2fe2d511858d45708310e983fa1fd6cbc33) add linter exceptions - [`94e5eb4`](https://github.com/netbirdio/netbird/commit/94e5eb4d864c6d1de6921e781222b7486184d61d) set proper accountID to grpc calls - [`a466a43`](https://github.com/netbirdio/netbird/commit/a466a431250ddceac9c923d78b24faaf43605df8) exclude middleware from linter - [`bd1bd25`](https://github.com/netbirdio/netbird/commit/bd1bd2505eaab9de11731b82843f63337e907e70) split request middleware into metrics and auth middleware - [`fcfeb06`](https://github.com/netbirdio/netbird/commit/fcfeb067e2fa4859a98465ad203c2238b69ac5a9) better error handling for accountID from grpc - [`2e2a656`](https://github.com/netbirdio/netbird/commit/2e2a65662964e11ed5787c0af35d36f8816da8ce) fix linter - [`b92726c`](https://github.com/netbirdio/netbird/commit/b92726cadd49f93e6f86112ccaabc648b4bf095f) remove custom logger and merge with old logging code ### 📊 Changes **13 files changed** (+220 additions, -39 deletions) <details> <summary>View changed files</summary> 📝 `formatter/hook.go` (+72 -0) 📝 `formatter/set.go` (+10 -1) 📝 `management/cmd/management.go` (+39 -4) 📝 `management/server/account.go` (+10 -4) ➕ `management/server/context/keys.go` (+8 -0) 📝 `management/server/grpcserver.go` (+24 -1) 📝 `management/server/http/handler.go` (+6 -0) 📝 `management/server/http/middleware/auth_middleware.go` (+7 -2) 📝 `management/server/http/middleware/auth_middleware_test.go` (+10 -9) 📝 `management/server/mock_server/account_mock.go` (+9 -0) 📝 `management/server/store.go` (+3 -2) 📝 `management/server/telemetry/http_api_metrics.go` (+16 -15) 📝 `util/log.go` (+6 -1) </details> ### 📄 Description ## Describe your changes This PR creates 3 root contexts. It adds a logSource parameter to each context: - GRPC: For all requests coming via grpc api. For this case, the context will be extended with a requestID, the deviceID of the peer, and the accountID the peer belongs to - HTTP: For all requests coming from REST api. For this case, the context will be extended with a requestID, the userID of the user querying the api, and the accountID the user is accessing (needs updating once we implement multitenancy). - SYSTEM: which logs general system logs that occur during management operation e.g. startup, expiration trigger... The PR updates the logger with a custom implementation that logs the additional fields. > [!CAUTION] > This PR will cause both management and client logger to lose their formatting. The formatting will be created in a separate PR before merging the feature branch. ## Issue ticket number and link ### Checklist - [ ] Is it a bug fix - [ ] Is a typo/documentation fix - [x] Is a feature enhancement - [ ] It is a refactor - [ ] Created tests that fail without the change (if possible) - [ ] Extended the README / documentation, if necessary --- <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 04:06:13 -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#16520