fix(inputs.ecs): Test for v4 metadata endpoint (#14194)

This commit is contained in:
Joshua Powers 2023-10-30 02:15:47 -06:00 committed by GitHub
parent 920a49c846
commit 27b20d17ae
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 0 deletions

View File

@ -122,6 +122,15 @@ func resolveEndpoint(ecs *Ecs) {
// Auto-detect metadata endpoint version.
// Use metadata v4 if available.
// https://docs.aws.amazon.com/AmazonECS/latest/developerguide/task-metadata-endpoint-v4.html
v4Endpoint := os.Getenv("ECS_CONTAINER_METADATA_URI_V4")
if v4Endpoint != "" {
ecs.EndpointURL = v4Endpoint
ecs.metadataVersion = 4
return
}
// Use metadata v3 if available.
// https://docs.aws.amazon.com/AmazonECS/latest/developerguide/task-metadata-endpoint-v3.html
v3Endpoint := os.Getenv("ECS_CONTAINER_METADATA_URI")

View File

@ -808,6 +808,19 @@ func TestResolveEndpoint(t *testing.T) {
metadataVersion: 3,
},
},
{
name: "Endpoint is not set, ECS_CONTAINER_METADATA_URI_V4 is set => use v4 metadata",
setEnv: func(t *testing.T) {
t.Setenv("ECS_CONTAINER_METADATA_URI_V4", "v4-endpoint.local")
},
given: Ecs{
EndpointURL: "",
},
exp: Ecs{
EndpointURL: "v4-endpoint.local",
metadataVersion: 4,
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {