From 004f81651b61b922fcf574d4597ea5f3b501a4d7 Mon Sep 17 00:00:00 2001 From: Joshua Powers Date: Wed, 15 Nov 2023 02:10:21 -0700 Subject: [PATCH] fix(inputs.ecs): Correct v4 metadata URLs (#14294) --- plugins/inputs/ecs/client.go | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/plugins/inputs/ecs/client.go b/plugins/inputs/ecs/client.go index b5521c5ea..067fc3b75 100644 --- a/plugins/inputs/ecs/client.go +++ b/plugins/inputs/ecs/client.go @@ -12,12 +12,13 @@ import ( var ( // https://docs.aws.amazon.com/AmazonECS/latest/developerguide/task-metadata-endpoint-v2.html - ecsMetadataPath = "/v2/metadata" - ecsMetaStatsPath = "/v2/stats" + ecsMetadataPathV2 = "/v2/metadata" + ecsMetaStatsPathV2 = "/v2/stats" // https://docs.aws.amazon.com/AmazonECS/latest/developerguide/task-metadata-endpoint-v3.html - ecsMetadataPathV3 = "/task" - ecsMetaStatsPathV3 = "/task/stats" + // https://docs.aws.amazon.com/AmazonECS/latest/developerguide/task-metadata-endpoint-v4.html + ecsMetadataPath = "/task" + ecsMetaStatsPath = "/task/stats" ) // Client is the ECS client contract @@ -32,8 +33,8 @@ type httpClient interface { // NewClient constructs an ECS client with the passed configuration params func NewClient(timeout time.Duration, endpoint string, version int) (*EcsClient, error) { - if version != 2 && version != 3 { - const msg = "expected metadata version 2 or 3, got %d" + if version < 2 || version > 4 { + const msg = "expected metadata version 2, 3 or 4, got %d" return nil, fmt.Errorf(msg, version) } @@ -59,11 +60,12 @@ func resolveTaskURL(base *url.URL, version int) string { var path string switch version { case 2: - path = ecsMetadataPath + path = ecsMetadataPathV2 case 3: - path = ecsMetadataPathV3 + path = ecsMetadataPath + case 4: + path = ecsMetadataPath default: - // Should never happen. const msg = "resolveTaskURL: unexpected version %d" panic(fmt.Errorf(msg, version)) } @@ -74,9 +76,11 @@ func resolveStatsURL(base *url.URL, version int) string { var path string switch version { case 2: - path = ecsMetaStatsPath + path = ecsMetaStatsPathV2 case 3: - path = ecsMetaStatsPathV3 + path = ecsMetaStatsPath + case 4: + path = ecsMetaStatsPath default: // Should never happen. const msg = "resolveStatsURL: unexpected version %d"