Skip to content

[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

Merged
merged 3 commits into from
Sep 30, 2020

Conversation

hossain-rayhan
Copy link
Contributor

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.

@hossain-rayhan hossain-rayhan requested a review from a team September 28, 2020 19:42
@codecov
Copy link

codecov bot commented Sep 28, 2020

Codecov Report

Merging #1148 into master will increase coverage by 0.05%.
The diff coverage is 96.55%.

Impacted file tree graph

@@            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              
Flag Coverage Δ
#integration 73.57% <ø> (ø)
#unit 88.78% <96.55%> (+0.06%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
...eceiver/awsecscontainermetricsreceiver/receiver.go 93.75% <92.85%> (+2.84%) ⬆️
...ermetricsreceiver/awsecscontainermetrics/client.go 94.44% <94.44%> (ø)
...rmetricsreceiver/awsecscontainermetrics/metrics.go 100.00% <100.00%> (ø)
...ricsreceiver/awsecscontainermetrics/rest_client.go 100.00% <100.00%> (ø)
...sreceiver/awsecscontainermetrics/stats_provider.go 100.00% <100.00%> (ø)
receiver/awsecscontainermetricsreceiver/factory.go 100.00% <100.00%> (ø)
...eiver/awsxrayreceiver/internal/udppoller/poller.go 97.61% <0.00%> (-2.39%) ⬇️
... and 3 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update cd5dacb...482f1f2. Read the comment docs.

}

if resp.StatusCode != http.StatusOK {
return nil, fmt.Errorf("task metadata endpoint request GET %s failed - %q, response: %q",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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

Copy link
Contributor Author

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")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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

Copy link
Contributor Author

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) {
Copy link
Contributor

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)

Copy link
Contributor Author

@hossain-rayhan hossain-rayhan Sep 29, 2020

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"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Avoid errors throughout

Copy link
Contributor Author

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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// 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

Copy link
Contributor

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?

Copy link
Contributor Author

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"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

EndpointEnvKey

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated.

@hossain-rayhan
Copy link
Contributor Author

Hi @anuraaga thanks for your fast review. I pushed an update to address your feedbacks.

@hossain-rayhan
Copy link
Contributor Author

Hi @asuresh4 , will appreciate a fast review on this.

tr := defaultTransport()
return &clientImpl{
baseURL: endpoint,
httpClient: http.Client{Transport: tr},
Copy link
Member

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.

Copy link
Contributor Author

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",
Copy link
Member

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?

Copy link
Contributor Author

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)
Copy link
Member

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.

Copy link
Contributor Author

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
Copy link
Member

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.

Copy link
Contributor Author

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 {
Copy link
Member

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.

Copy link
Contributor Author

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
Copy link
Member

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.

Copy link
Contributor Author

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)
Copy link
Member

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.

Copy link
Contributor Author

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)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change

Copy link
Contributor Author

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)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated.

@hossain-rayhan
Copy link
Contributor Author

Hi @asuresh4 , thanks for your review. I pushed an update based on your review. Expecting another look.

@hossain-rayhan
Copy link
Contributor Author

Hi @tigrannajaryan can we get this merged, please.

@tigrannajaryan tigrannajaryan merged commit 7721b29 into open-telemetry:master Sep 30, 2020
dyladan referenced this pull request in dynatrace-oss-contrib/opentelemetry-collector-contrib Jan 29, 2021
* 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
ljmsc referenced this pull request in ljmsc/opentelemetry-collector-contrib Feb 21, 2022
#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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants