-
Notifications
You must be signed in to change notification settings - Fork 2.2k
[cosmos] Fix ClientTelemetry static-init NPE when IMDS access is disabled #48887
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -47,15 +47,18 @@ private static ImplementationBridgeHelpers.CosmosClientTelemetryConfigHelper.Cos | |
| private static final Logger logger = LoggerFactory.getLogger(ClientTelemetry.class); | ||
| private static final String USER_AGENT = Utils.getUserAgent(); | ||
|
|
||
| // Sentinel for "not on Azure VM" or "IMDS unreachable". | ||
| // Must be declared before CACHED_METADATA so that fetchAzureVmMetadata() | ||
| // never reads a null value during class initialization (e.g. when IMDS | ||
| // access is disabled via COSMOS_DISABLE_IMDS_ACCESS). | ||
| private static final AzureVMMetadata METADATA_NOT_AVAILABLE = new AzureVMMetadata(); | ||
|
|
||
| // Cached IMDS metadata Mono. Reactor's cache() ensures: | ||
| // - The fetch executes at most once | ||
| // - All concurrent subscribers share the single result | ||
| // - The HTTP client is created and disposed within the fetch | ||
| private static final Mono<AzureVMMetadata> CACHED_METADATA = fetchAzureVmMetadata().cache(); | ||
|
||
|
|
||
| // Sentinel for "not on Azure VM" or "IMDS unreachable" | ||
| private static final AzureVMMetadata METADATA_NOT_AVAILABLE = new AzureVMMetadata(); | ||
|
|
||
| // IMDS Constants | ||
| private static final String IMDS_AZURE_VM_METADATA = "http://169.254.169.254:80/metadata/instance?api-version=2020-06-01"; | ||
| private static final Duration IMDS_DEFAULT_NETWORK_REQUEST_TIMEOUT = Duration.ofSeconds(5); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Like you mentioned in the PR description - moving to static initialization block to also fix the fragile IMDS_DEFAULT_* fields - would be my preference. I can take the additional changes (adding test coverage and making this change form here if you don't wnat to spend more time on this - perfectly understandable). If you want to finish/merge the PR please let me know when these changes are added and I will quickly re-review and approve.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks a lot, @FabianMeiswinkel, for your quick review!
You have a much better overall understanding of the SDK, so I’m perfectly happy to let you take over and apply the remaining changes. I hope this initial work was helpful to you. 👌
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It was and thanks for providing such detailed repro-info - really appreciated!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @lfavreli-betclic - i have published a PR #48888 for this and will get it merged asap.