-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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
inputs.ecs: add v3 metadata support. #7154
Conversation
Could you take a look, @danielnelson? |
Maybe you could peek, @ssoroka? |
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.
Looks reasonable. 👍
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.
I think having both endpoint_url
and metadata_version
options introduce option combinations that you wouldn't normally want and would make the plugin more difficult to setup. For example, during normal use you would never want to set metadata_version = 3
and leave the endpoint_url
as the default value. Likewise setting an empty endpoint_url = ""
and metadata_version = 2
wouldn't work either.
What if we removed the metadata_version
and on startup we try to read the ECS_CONTAINER_METADATA_URI
envvar, if this is set we use v3 and if not we try with v2 and the endpoint_url
. We should update the endpoint_url
option to mention that it is only for use with v2.
With this approach most users will be bumped forward to v3, so the idea requires that v3 needs to show the same results as v2. I believe this is the case. If one wanted to force v2, it would always be possible to unset the environment variable.
plugins/inputs/ecs/client.go
Outdated
path := getMetaStatsPath(c.version) | ||
c.statsURL = c.BaseURL.String() + path |
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.
Nitpick but I prefer the old style:
c.statsURL = c.BaseURL.ResolveReference(getMetaStatsPath(c.version)).String()
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.
Unfortunately this doesn't work with v3 metadata endpoint.
The url for v3 looks something like http://1.1.1.1/v3/metadata
(I do not recall exact path, but the important part is that the path is present. IP is not relevant). When you use ResolveReference
on such base URL, the path you provide will override the the original path. I faced this issue when I was testing the code in ECS.
A small demo:
package main
import (
"fmt"
"log"
"net/url"
)
func main() {
examples := []struct{
base string
path string
} {
{
base: "http://1.1.1.1/v3/metadata",
path: "/stats",
},
{
base: "http://1.1.1.1/v3/metadata",
path: "stats",
},
}
for i, e := range examples {
u, err := url.Parse(e.path)
if err != nil {
log.Fatal(err)
}
base, err := url.Parse(e.base)
if err != nil {
log.Fatal(err)
}
fmt.Println("Example ", i)
fmt.Println(" base: ", e.base)
fmt.Println(" path: ", e.path)
fmt.Println(" result: ", base.ResolveReference(u))
fmt.Println()
}
}
Result:
Example 0
base: http://1.1.1.1/v3/metadata
path: /stats
result: http://1.1.1.1/stats
Example 1
base: http://1.1.1.1/v3/metadata
path: stats
result: http://1.1.1.1/v3/stats
Just noticed the change request. Will fix it. This is not abandoned. |
There is also metadata v4 now with a new variable name. |
@snemetz Thanks for the heads up, and I sure hope these version changes settle down. It would be good to support all available versions if we can. Could you open a feature request issue for v4 metadata? |
v4 feature request created |
@danielnelson, pushed requested changes. Please take a look. |
@danielnelson did you have a chance to peek again? |
Thank you! |
Justification: v2
metadata and Docker stats are available to tasks that use the awsvpc network mode ...
only [v2]. v3 metadata is available regardless of the network mode and provides the same statistics as the v2 metadata.[v2] https://docs.aws.amazon.com/AmazonECS/latest/developerguide/task-metadata-endpoint-v2.html
Required for all PRs: