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

Add metrics support to k8s processor #358

Conversation

dmitryax
Copy link
Member

Description:
Kubernetes processor can be used to enrich not only spans but metrics with k8s metadata. In order to find a source of the metrics we take a different approach then for spans. The processor looks at "host.hostname" resource attribute which is set by prometheus receiver and some metrics instrumentation libraries to an originated IP address. That IP address is used by k8s processor to lookup for a k8s pod and fetch its metadata.

The processor uses the old-style metrics data model since the new metric model is not available in contrib yet. But it must be easy to switch over later once we wave it the new metrics model support.

Testing:

  • Added unit tests
  • Tested on a local k8s cluster

Documentation:
Added details about metrics to existing docs.

Kubernetes processor can be used to enrich not only spans but metrics with k8s metadata. In order to find a source of the metrics we take a different approach then for spans. The processor looks at "host.hostname" resource attribute which is set by prometheus receiver and some metrics instrumentation libraries to an originated IP address. That IP address is used by k8s processor to lookup for a k8s pod and fetch its metadata.

The processor uses the old-style metrics data model since the new metric model is not available in contrib yet. But it must be easy to switch over later once we wave it the new metrics model support.
@dmitryax dmitryax requested a review from owais June 24, 2020 18:52
@dmitryax dmitryax requested a review from a team as a code owner June 24, 2020 18:52
@project-bot project-bot bot added this to In progress in Collector Jun 24, 2020
@codecov
Copy link

codecov bot commented Jun 24, 2020

Codecov Report

Merging #358 into master will increase coverage by 0.07%.
The diff coverage is 92.15%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #358      +/-   ##
==========================================
+ Coverage   83.15%   83.22%   +0.07%     
==========================================
  Files         170      170              
  Lines        9116     9160      +44     
==========================================
+ Hits         7580     7623      +43     
  Misses       1217     1217              
- Partials      319      320       +1     
Flag Coverage Δ
#integration 0.00% <ø> (ø)
#unit 83.22% <92.15%> (+0.07%) ⬆️
Impacted Files Coverage Δ
processor/k8sprocessor/processor.go 92.52% <90.90%> (-1.51%) ⬇️
processor/k8sprocessor/factory.go 100.00% <100.00%> (ø)
receiver/carbonreceiver/transport/tcp_server.go 68.57% <0.00%> (+2.85%) ⬆️

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 c2c6e22...1412776. Read the comment docs.

Collector automation moved this from In progress to Reviewer approved Jun 24, 2020
Copy link
Contributor

@owais owais left a comment

Choose a reason for hiding this comment

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

LGTM. Feel free to fix the nits or leave as is. Not a blocker for me.

for _, opt := range options {
if err := opt(kp); err != nil {
return nil, err
}
}
err := kp.initKubeClient(logger, kubeClient)
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: I feel it is slightly better if the function creates a client instance and returns it leaving it to the called to set it to a field. Not a big deal though in this case.

Copy link
Member Author

Choose a reason for hiding this comment

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

I tried this way, but it seems adding more unnecessary complexity making this code reuse case not very useful.


// Don't invoke any k8s client functionality in passthrough mode.
// Just tag the IP and forward the batch.
if kp.passthroughMode || podIP == "" {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: this is a very simple and obvious case but I still feel we should separate out these two condition in their own if statements. I feel that reads better especially with the comment above the line.

Copy link
Member Author

Choose a reason for hiding this comment

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

Agreed. Pushed as another PR

Copy link
Member

@tigrannajaryan tigrannajaryan left a comment

Choose a reason for hiding this comment

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

LGTM

}
}

return kp.nextMetricsConsumer.ConsumeMetrics(ctx, metrics)
Copy link
Member

Choose a reason for hiding this comment

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

The loop above modifies mds and here we pass metrics. It is not apparent that modifying mds changes metrics (does it?). I am not sure if anything can be done to make it clear. We probably just need to wait until internal metric data type is available and get rid of the conversion.

Copy link
Member Author

Choose a reason for hiding this comment

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

@tigrannajaryan tigrannajaryan merged commit a834563 into open-telemetry:master Jun 24, 2020
Collector automation moved this from Reviewer approved to Done Jun 24, 2020
@dmitryax
Copy link
Member Author

I was just about to push few tests to get to 95% coverage and address nits :)

dmitryax added a commit to dmitryax/opentelemetry-collector-contrib that referenced this pull request Jun 24, 2020
@dmitryax
Copy link
Member Author

dmitryax commented Jun 24, 2020

Pushed the changes as different PRs eventually. Don't want to remove still useful code
#361
#362

tigrannajaryan pushed a commit that referenced this pull request Jun 29, 2020
It's the tests part missed to get 95% percent coverage in #358.
wyTrivail referenced this pull request in mxiamxia/opentelemetry-collector-contrib Jul 13, 2020
Kubernetes processor can be used to enrich not only spans but metrics with k8s metadata. In order to find a source of the metrics we take a different approach then for spans. The processor looks at "host.hostname" resource attribute which is set by prometheus receiver and some metrics instrumentation libraries to an originated IP address. That IP address is used by k8s processor to lookup for a k8s pod and fetch its metadata.

The processor uses the old-style metrics data model since the new metric model is not available in contrib yet. But it must be easy to switch over later once we wave it the new metrics model support.
wyTrivail pushed a commit to mxiamxia/opentelemetry-collector-contrib that referenced this pull request Jul 13, 2020
wyTrivail pushed a commit to mxiamxia/opentelemetry-collector-contrib that referenced this pull request Jul 13, 2020
It's the tests part missed to get 95% percent coverage in open-telemetry#358.
ljmsc referenced this pull request in ljmsc/opentelemetry-collector-contrib Feb 21, 2022
bogdandrutu pushed a commit that referenced this pull request May 12, 2022
Bumps [k8s.io/client-go](https://github.com/kubernetes/client-go) from 0.23.2 to 0.23.3.
- [Release notes](https://github.com/kubernetes/client-go/releases)
- [Changelog](https://github.com/kubernetes/client-go/blob/master/CHANGELOG.md)
- [Commits](kubernetes/client-go@v0.23.2...v0.23.3)

---
updated-dependencies:
- dependency-name: k8s.io/client-go
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <[email protected]>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
codeboten pushed a commit that referenced this pull request Nov 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
Collector
  
Done
Development

Successfully merging this pull request may close these issues.

None yet

3 participants