Skip to content
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

[extension][ecsobserver] Init ECS service discovery using docker label #2734

Closed
wants to merge 9 commits into from

Conversation

pingleig
Copy link
Contributor

@pingleig pingleig commented Mar 18, 2021

Description:

This is the first (divided) implementation PR for #1395. In order to reduce the size of the pr, the feature is incomplete.

  • mock api client is used, no actual aws api calls
  • Only docker label based filter (matcher) is included (others are just place holders)
  • Extension impl under ecsobserver is excluded, it's a thin wrapper.

Those excluded logic are tested in other branches, so it works with real API end to end (eventually).

The package is located under internal/aws/ecssd (relocated to extension because currently there is no other aws related component reusing it)

Link to tracking Issue:

Testing:

unit test

Documentation:

No new doc, see #2377 for existing doc

Known issues

@pingleig pingleig requested a review from a team March 18, 2021 00:40
@linux-foundation-easycla
Copy link

linux-foundation-easycla bot commented Mar 18, 2021

CLA Signed

The committers are authorized under a signed CLA.

This is the first (divided) implementation PR for #1395.
In order to reduce the size of the pr, the feature is incomplete.

- mock api client is used, no actual aws api calls
- Only docker label based filter/matcher is included
- Extension impl under `ecsobserver` is excluded

Those excluded logic are tested in other branches, so it works with real
API end to end (eventually).

The package is located under internal/aws/ecssd because

- it can be used by other aws specific packages
- we may extract it out to a standalone repo in the future
  as it can run as a binary and support other prometheus
  compatiable collectors as a sidecar
@pingleig pingleig force-pushed the ext-ecssd-docker-label branch from cf211b3 to b70159f Compare March 18, 2021 00:42
@pingleig
Copy link
Contributor Author

pingleig commented Mar 18, 2021

I guess the bot should have assigned it to @jrcamp

The lint error is strange

make[1]: Entering directory '/home/circleci/project'
golangci-lint run --allow-parallel-runners
ERRO Running error: context loading failed: no go files to analyze 
make[1]: *** [Makefile.Common:93: lint] Error 5
make[1]: Leaving directory '/home/circleci/project'

@codecov
Copy link

codecov bot commented Mar 18, 2021

Codecov Report

Merging #2734 (5d200bd) into main (f8c550f) will increase coverage by 0.88%.
The diff coverage is 81.28%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #2734      +/-   ##
==========================================
+ Coverage   90.53%   91.42%   +0.88%     
==========================================
  Files         444      457      +13     
  Lines       21984    22450     +466     
==========================================
+ Hits        19904    20525     +621     
+ Misses       1618     1434     -184     
- Partials      462      491      +29     
Flag Coverage Δ
integration 69.18% <ø> (?)
unit 90.37% <81.28%> (-0.17%) ⬇️

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

Impacted Files Coverage Δ
extension/observer/ecsobserver/factory.go 46.66% <46.66%> (ø)
extension/observer/ecsobserver/fetcher.go 50.00% <50.00%> (ø)
extension/observer/ecsobserver/task.go 68.00% <68.00%> (ø)
extension/observer/ecsobserver/matcher.go 74.07% <74.07%> (ø)
extension/observer/ecsobserver/extension.go 80.00% <80.00%> (ø)
extension/observer/ecsobserver/filter.go 82.14% <82.14%> (ø)
extension/observer/ecsobserver/sd.go 82.14% <82.14%> (ø)
extension/observer/ecsobserver/target.go 82.35% <82.35%> (ø)
extension/observer/ecsobserver/exporter.go 84.90% <84.90%> (ø)
extension/observer/ecsobserver/config.go 100.00% <100.00%> (ø)
... and 25 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 f8c550f...5d200bd. Read the comment docs.

- ignore *.actual.yaml and only check in *.expected.yaml
@jrcamp jrcamp assigned jrcamp and unassigned jpkrohling Mar 18, 2021
@jrcamp
Copy link
Contributor

jrcamp commented Mar 19, 2021

@pingleig overall looks good. Can somebody at AWS review first? Quite a lot of code.

@pingleig
Copy link
Contributor Author

pingleig commented Mar 19, 2021

@jrcamp thanks! I just asked in internal channel for review. There should be some follow up PRs, those should be smaller because most interface and large struct definitions are in this PR.

internal/aws/ecssd/config.go Outdated Show resolved Hide resolved
internal/aws/ecssd/config.go Outdated Show resolved Hide resolved
func (d *DockerLabelConfig) Init() error {
// It's possible to support it in the future, but for now just fail at config,
// so user don't need to wonder which port is used in the exported target.
if len(d.MetricsPorts) != 0 {
Copy link
Member

Choose a reason for hiding this comment

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

if it is not supported now, can we remove CommonExporterConfig it in DockerLabelConfig? will it misleading customers by just looking Config structure?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't want to split the shared config because docker label is just one of three matchers, though its behaviour is pretty different from service and task based matcher so we could give it another struct like ExportConfigWithoutPorts. I plan to delay the change for next pr when service & task are added.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually I think since we are going to have open-telemetry/opentelemetry-collector#2802 it's better to put the validate logic here instead of removing it from struct. Because if user use metrics_ports for docker label and it's not in the struct, it will throw unmarshal error without telling why it is not there while it is supported for other filters. Though in the long term I think docker label should become part of common export config as well, you can discover based on service name and pick port based on docker label in task definition, we are just trying to be consistent with cloudwatch agent's behaviour here at this moment.

internal/aws/ecssd/filter.go Outdated Show resolved Hide resolved
@pingleig pingleig requested a review from jrcamp as a code owner March 23, 2021 23:45
@pingleig
Copy link
Contributor Author

pingleig commented Mar 24, 2021

oops, windows test failed because of \r\n and \n when comparing generated file https://app.circleci.com/pipelines/github/open-telemetry/opentelemetry-collector-contrib/11473/workflows/8898ac3b-3231-431e-a457-625ca5ca6442/jobs/97574 I will grab a windows pc and test it (if I don't end up playing games)

It seems when git checkout, the file \n is replaced with \r\n https://circleci.com/blog/circleci-config-teardown-how-we-write-our-circleci-config-at-circleci/#main:~:text=Line%20endings

The expected file is converted to \r\n during git checkout, however the
generated file is still using \n. This only happens on circle ci's
windows environemnt. See https://circleci.com/blog/circleci-config-teardown-how-we-write-our-circleci-config-at-circleci/#main:~:text=Line%20endings
Copy link
Member

@mxiamxia mxiamxia left a comment

Choose a reason for hiding this comment

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

LGTM in general. pls address the comments. Thanks!

extension/observer/ecsobserver/config.go Show resolved Hide resolved
extension/observer/ecsobserver/config.go Outdated Show resolved Hide resolved
extension/observer/ecsobserver/fetcher.go Outdated Show resolved Hide resolved
extension/observer/ecsobserver/matcher.go Outdated Show resolved Hide resolved
extension/observer/ecsobserver/matcher.go Outdated Show resolved Hide resolved
extension/observer/ecsobserver/filter.go Show resolved Hide resolved
- Fix typo
- Add more comment on how the matcher merge logic works
@pingleig
Copy link
Contributor Author

@mxiamxia addressed comments in 5d200bd and @jrcamp PTAL (btw: the code grows a bit bigger because the extension interface is implemented compared w/ last time you look at it)

Copy link
Member

@mxiamxia mxiamxia left a comment

Choose a reason for hiding this comment

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

LGTM! Thanks!

@jrcamp
Copy link
Contributor

jrcamp commented Mar 29, 2021

@pingleig Can we find a way to split this up more? I just don't have the cycles to digest such a large PR all in one.

@pingleig
Copy link
Contributor Author

@jrcamp it's doable, but in that case I don't think I can meet the requirement for test coverage because they will not work end to end (even in unit test). If that's ok I can create a new pr for just structs.

@pingleig
Copy link
Contributor Author

@jrcamp created #2939

@github-actions
Copy link
Contributor

github-actions bot commented Apr 6, 2021

This PR was marked stale due to lack of activity. It will be closed in 7 days.

@github-actions github-actions bot added the Stale label Apr 6, 2021
@pingleig
Copy link
Contributor Author

pingleig commented Apr 6, 2021

Close it since half of the PR is split into #2939 and I plan create a new PR for the remaining stuff instead of rebasing on this branch.

@pingleig pingleig closed this Apr 6, 2021
pingleig added a commit to pingleig/opentelemetry-collector-contrib that referenced this pull request May 11, 2021
Split from open-telemetry#2734

- Get port number from label value
- Check if the port number exists in container definition
bogdandrutu pushed a commit that referenced this pull request May 11, 2021
Split from #2734

- Get port number from label value
- Check if the port number exists in container definition
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants