-
Notifications
You must be signed in to change notification settings - Fork 2.8k
[AwsEcsMetricsReceiver] Add codes to read data from ECS endpoint #1148
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
[AwsEcsMetricsReceiver] Add codes to read data from ECS endpoint #1148
Conversation
Codecov Report
@@ Coverage Diff @@
## master #1148 +/- ##
==========================================
+ Coverage 89.59% 89.65% +0.05%
==========================================
Files 272 276 +4
Lines 13240 13321 +81
==========================================
+ Hits 11863 11943 +80
- Misses 1011 1012 +1
Partials 366 366
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
} | ||
|
||
if resp.StatusCode != http.StatusOK { | ||
return nil, fmt.Errorf("task metadata endpoint request GET %s failed - %q, response: %q", |
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.
return nil, fmt.Errorf("task metadata endpoint request GET %s failed - %q, response: %q", | |
return nil, fmt.Errorf("request GET %s failed - %q, response: %q", |
Don't think this class is specific to task metadata
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.
Updated.
}() | ||
body, err := ioutil.ReadAll(resp.Body) | ||
if err != nil { | ||
return nil, errors.WithMessage(err, "failed to read response body") |
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.
return nil, errors.WithMessage(err, "failed to read response body") | |
return nil, fmt.Errorf("failed to read response body %w", err) |
Use native wrapping instead of errors
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.
Updated.
} | ||
|
||
// GetStats calls the ecs task metadata endpoint and unmarshals the data | ||
func (p *StatsProvider) GetStats() (map[string]ContainerStats, TaskMetadata, error) { |
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 in #1044 we agreed that container metadata needs to be in the receiver, but task metadata I still think we want in a processor that adds to Resource
, so it can be used for this, traces, and other metrics. Was it not the case that for task attributes that would be ok? Currently we're not planning on adding these to every SDK since we get more bang-for-buck with a collector-first implementation (this was just decided today though)
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.
Hi @anuraaga , I believe that discussion was more related to setting labels/dimensions/metadata
to task level metrics, and later we agreed to add them in the receiver for now. We also know that, if you implement a process later, we will do some redundant works. However, regardless of the label settings, I need to parse this TaskMetadata
for calculating some task level metrics value. We cannot skip it. For example, for calculating the value for MemoryReserved
, first we check the task level memory which comes from this TaskMetadata
. If that is not defined, we get the sum for all containers.
"io/ioutil" | ||
"testing" | ||
|
||
"github.com/pkg/errors" |
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.
Avoid errors
throughout
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.
Updated.
typeStr = "awsecscontainermetrics" | ||
|
||
// Default collection interval | ||
// Default collection interval. In every 20s the receiver will collect metrics from Amazon ECS Task Metadata Endpoint |
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.
// Default collection interval. In every 20s the receiver will collect metrics from Amazon ECS Task Metadata Endpoint | |
// Default collection interval. Every 20s the receiver will collect metrics from Amazon ECS Task Metadata Endpoint |
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.
Is it task metadata endpoint or container metrics endpoint?
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.
Amazon ECS Task Metadata Endpoint
@@ -30,6 +30,10 @@ const ( | |||
ContainerPrefix = "container." | |||
MetricResourceType = "aoc.ecs" | |||
|
|||
ENDPOINT = "ECS_CONTAINER_METADATA_URI_V4" |
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.
EndpointEnvKey
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.
Updated.
Hi @anuraaga thanks for your fast review. I pushed an update to address your feedbacks. |
Hi @asuresh4 , will appreciate a fast review on this. |
tr := defaultTransport() | ||
return &clientImpl{ | ||
baseURL: endpoint, | ||
httpClient: http.Client{Transport: tr}, |
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.
Can you take a look at config.HTTPClientSettings
? Looks like right now, there are no config options for the HTTP client but in the future when you add them, it'll be easier to extend if you have use the helpers on the struct. There's a method on HTTPClientSettings
, ToClient
which returns a HTTP client.
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.
Added a TODO for now.
} | ||
|
||
if resp.StatusCode != http.StatusOK { | ||
return nil, fmt.Errorf("request GET %s failed - %q, response: %q", |
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.
Would logging out the response body make this error too verbose?
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.
Removed.
) (component.MetricsReceiver, error) { | ||
rCfg := cfg.(*Config) | ||
return newAwsEcsContainerMetricsReceiver(params.Logger, rCfg, nextConsumer) | ||
ecsTaskMetadataEndpointV4 := os.Getenv(awsecscontainermetrics.EndpointEnvKey) |
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.
Would collect the env into a variable of type url.URL
, thought should help validate the URL as well, I think.
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.
Updated.
var _ Client = (*clientImpl)(nil) | ||
|
||
type clientImpl struct { | ||
baseURL 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.
Would consider making this of type, url.URL.
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.
Updated.
"go.opentelemetry.io/collector/consumer/consumerdata" | ||
) | ||
|
||
func MetricsData(containerStatsMap map[string]ContainerStats, metadata TaskMetadata, typeStr string) []*consumerdata.MetricsData { |
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.
Is the last parameter here required? Doesn't seem to be used.
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.
Removed.
|
||
taskStats, taskMetadata, err := p.rc.EndpointResponse() | ||
if err != nil { | ||
return stats, metadata, err |
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.
Do you think providing the context of the error here would help? Same with the below error.
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.
Updated.
return err | ||
} | ||
|
||
mds := awsecscontainermetrics.MetricsData(stats, metadata, typeStr) |
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.
Please add a TODO to add self metrics about the receiver that needs to be collected using obsreport
.
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.
Updated.
@@ -40,6 +55,7 @@ func TestCreateMetricsReceiver(t *testing.T) { | |||
) | |||
require.NoError(t, err) | |||
require.NotNil(t, metricsReceiver) | |||
|
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.
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.
Updated.
require.Nil(t, metricsReceiver) | ||
require.Equal(t, err, componenterror.ErrNilNextConsumer) | ||
|
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.
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.
Updated.
Hi @asuresh4 , thanks for your review. I pushed an update based on your review. Expecting another look. |
Hi @tigrannajaryan can we get this merged, please. |
* Enable "new-metrics" by default This change switches the defaults between "new-metrics" and "legacy-metrics". Now the defaults are: - "new-metrics" ON by default - "legacy-metrics" OFF by default - "add-instance-id" ON by default * Use Prometheus parser in tests
#1148) * Bump google.golang.org/grpc from 1.31.1 to 1.32.0 in /exporters/stdout Bumps [google.golang.org/grpc](https://github.com/grpc/grpc-go) from 1.31.1 to 1.32.0. - [Release notes](https://github.com/grpc/grpc-go/releases) - [Commits](grpc/grpc-go@v1.31.1...v1.32.0) Signed-off-by: dependabot[bot] <[email protected]> * Auto-fix go.sum changes in dependent modules Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: dependabot[bot] <dependabot[bot]@users.noreply.github.com> Co-authored-by: Anthony Mirabella <[email protected]>
Description:
This change adds codes to read actual metrics data from Amazon ECS task metadata endpoint.
Link to tracking Issue:
#457
Testing:
Unit tests added.
Documentation:
README added.