fix(inputs.ecs): Test for v4 metadata endpoint (#14194)
This commit is contained in:
parent
920a49c846
commit
27b20d17ae
|
|
@ -122,6 +122,15 @@ func resolveEndpoint(ecs *Ecs) {
|
||||||
|
|
||||||
// Auto-detect metadata endpoint version.
|
// 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.
|
// Use metadata v3 if available.
|
||||||
// https://docs.aws.amazon.com/AmazonECS/latest/developerguide/task-metadata-endpoint-v3.html
|
// https://docs.aws.amazon.com/AmazonECS/latest/developerguide/task-metadata-endpoint-v3.html
|
||||||
v3Endpoint := os.Getenv("ECS_CONTAINER_METADATA_URI")
|
v3Endpoint := os.Getenv("ECS_CONTAINER_METADATA_URI")
|
||||||
|
|
|
||||||
|
|
@ -808,6 +808,19 @@ func TestResolveEndpoint(t *testing.T) {
|
||||||
metadataVersion: 3,
|
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 {
|
for _, tt := range tests {
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue