Azure Multi-Cloud Metadata substitution#1996
Closed
Paramadon wants to merge 15 commits intofeature-multi-cloudfrom
Closed
Azure Multi-Cloud Metadata substitution#1996Paramadon wants to merge 15 commits intofeature-multi-cloudfrom
Paramadon wants to merge 15 commits intofeature-multi-cloudfrom
Conversation
Co-authored-by: Adnan Khan <AdnaneKhan@users.noreply.github.com>
Rename unused 'r' parameter to '_' in TestProvider_Refresh_Timeout to satisfy revive linter.
The return statement in InitGlobalProvider was reading globalErr without holding the lock, causing a race with concurrent readers.
sync.Once cannot be safely reset while concurrent Do() calls may be in progress. Replace with atomic uint32 flag and double-checked locking pattern, which allows safe reset from tests without racing.
- Reset global provider in TestTranslator to ensure test uses mock metadata - Update placeholderUtil tests to use SetGlobalProviderForTest instead of relying on legacy fallback path which doesn't work on Azure - Skip TestGetMetadataInfo_FallbackToLegacy on Azure since azure.IsAzure() takes precedence over the legacy fallback path
The test was resetting the global provider but then calling GetMetadataInfo which falls through to the Azure path on Azure CI runners. Now we set the mock provider first so GetMetadataInfo uses it instead of Azure IMDS.
Contributor
|
This PR was marked stale due to lack of activity. |
1a4b2ce to
620362c
Compare
Contributor
|
This PR was marked stale due to lack of activity. |
Contributor
|
Closing in favor of #2032 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add Cloud Metadata Placeholder Substitution
Problem
CloudWatch Agent configuration files require instance-specific values (instance ID, region, account ID, etc.) that vary across deployments. Currently, users must manually configure these values or use separate placeholder systems for AWS (
${aws:...}) and Azure (${azure:...}), leading to:Solution
Introduce universal
{cloud:...}placeholders that work across all cloud providers, while maintaining backward compatibility with existing${aws:...}and${azure:...}placeholders. The system automatically resolves placeholders using the cloud metadata provider at config translation time.Architecture
Key Design Decisions:
{cloud:...}syntax${aws:...}and${azure:...}still work"/logs/{cloud:InstanceId}/app"Changes
Placeholder Resolution (
translator/translate/util/placeholderUtil.go)New Functions:
ResolveCloudMetadataPlaceholders()- Resolves all placeholder typesresolveCloudPlaceholder()- Handles{cloud:...}syntaxresolveAzurePlaceholder()- Handles${azure:...}syntax (enhanced)resolveAWSPlaceholder()- Handles${aws:...}syntax (enhanced)Features:
{"instance": "{cloud:InstanceId}"}{"path": "/logs/{cloud:InstanceId}/app"}{"name": "{cloud:Region}-{cloud:InstanceType}"}{"aws": "${aws:InstanceId}", "azure": "${azure:VmId}"}Supported Placeholders
Universal Cloud Placeholders
Azure-Specific Placeholders (Enhanced)
AWS-Specific Placeholders (Existing)
Integration with Cloud Metadata Provider
The placeholder resolution system integrates with the cloud metadata provider (introduced in the IMDS PR):
Example Configurations
Before (AWS-specific):
{ "logs": { "logs_collected": { "files": { "collect_list": [ { "file_path": "/var/log/app.log", "log_group_name": "/aws/ec2/${aws:InstanceId}", "log_stream_name": "${aws:InstanceId}-app" } ] } } } }After (Cloud-agnostic):
{ "logs": { "logs_collected": { "files": { "collect_list": [ { "file_path": "/var/log/app.log", "log_group_name": "/aws/ec2/{cloud:InstanceId}", "log_stream_name": "{cloud:InstanceId}-app" } ] } } } }Mixed placeholders (Azure-specific + universal):
{ "metrics": { "append_dimensions": { "InstanceId": "{cloud:InstanceId}", "Region": "{cloud:Region}", "ResourceGroup": "${azure:ResourceGroupName}", "Environment": "production" } } }Testing
Unit Tests
New Tests (
translator/translate/util/placeholderUtil_test.go):TestResolveCloudMetadataPlaceholders_*- Universal placeholder resolutionTestResolveAzureMetadataPlaceholders_EmbeddedPlaceholders- Azure embedded placeholdersTestResolveAWSMetadataPlaceholders_EmbeddedPlaceholders- AWS embedded placeholdersCoverage:
Manual Verification
AWS EC2 (us-west-2):
{cloud:InstanceId}resolves to EC2 instance ID{cloud:Region}resolves tous-west-2/logs/{cloud:InstanceId}/appAzure VM (eastus2):
{cloud:InstanceId}resolves to Azure VM ID{cloud:Region}resolves toeastus2${azure:ResourceGroupName}resolves correctlyLocal (no cloud):
Backward Compatibility
✅ Existing configurations unchanged
${aws:...}placeholders continue to work${azure:...}placeholders continue to work✅ Graceful degradation
✅ No changes to existing behavior
{cloud:...}syntaxMigration Path
Users can migrate gradually:
${aws:...}or${azure:...}(no changes needed){cloud:...}for new configs (cloud-agnostic){cloud:...}(optional)No forced migration required - all syntaxes work simultaneously.
Dependencies
This PR depends on the cloud metadata provider infrastructure introduced in the Azure IMDS support PR. It should be merged after that PR is approved.
Verification Commands
Related PRs