Skip to content

Comments

feat: dynamic SDK version retrieval#45

Merged
mfiedorowicz merged 1 commit intodevelopfrom
feat-sdk-release-version
Sep 3, 2025
Merged

feat: dynamic SDK version retrieval#45
mfiedorowicz merged 1 commit intodevelopfrom
feat-sdk-release-version

Conversation

@mfiedorowicz
Copy link
Member

This pull request refactors how the SDK version is determined and propagated throughout the codebase, replacing the previous hardcoded SDKVersion constant with a dynamic value retrieved at runtime. The SDK name and version are now cached in both gRPC and DryRun clients, ensuring consistency and easier maintainability. Additional tests were added to verify correct SDK version detection and caching behavior.

SDK Version Detection and Propagation:

  • Introduced getSDKVersion() to dynamically determine the SDK version using Go build info, with a fallback to "dev" if unavailable. The function checks module dependencies for the SDK version. (diode/client.go, diode/client.goR182-R198)
  • Removed the hardcoded SDKVersion constant and updated all references to use the new dynamic value. (diode/client.go, [1]; diode/dryrun.go, [2]

Client Initialization and Metadata:

  • Updated GRPCClient and DryRunClient structs to include sdkName and sdkVersion fields, which are set during client initialization and used in metadata and requests. (diode/client.go, [1] [2]; diode/dryrun.go, [3] [4]
  • Changed user agent string and request metadata to use the cached SDK name and version from the client structs. (diode/client.go, [1] [2]; diode/dryrun.go, [3]
  • Removed the now-unnecessary userAgent() helper function. (diode/client.go, diode/client.goL566-L570)

Testing Enhancements:

  • Added tests to verify SDK version detection in various build environments and to ensure that SDK name and version are cached and consistent across multiple client instances for both gRPC and DryRun clients. (diode/client_test.go, [1]; diode/dryrun_test.go, [2]

Signed-off-by: Michal Fiedorowicz <mfiedorowicz@netboxlabs.com>
@github-actions
Copy link

github-actions bot commented Sep 3, 2025

Go test coverage

STATUS ELAPSED PACKAGE COVER PASS FAIL SKIP
🟢 PASS 0.49s github.com/netboxlabs/diode-sdk-go/cmd/diode-replay-dryrun 0.0% 0 0 0
🟢 PASS 1.33s github.com/netboxlabs/diode-sdk-go/diode 19.2% 256 0 0

Total coverage: 78.7%

Copy link
Contributor

@leoparente leoparente left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@mfiedorowicz mfiedorowicz merged commit 7000d5a into develop Sep 3, 2025
6 checks passed
@mfiedorowicz mfiedorowicz deleted the feat-sdk-release-version branch September 3, 2025 11:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants