beyla
beyla copied to clipboard
Add service name template
This PR is a proof of concept and not ready to be merged.
feature #1811
Adds a new configuration for a template under attributes.kubernetes.service_name_template
Adds ability to define the service.name based the ObjectMeta and ContainerName.
An example template that's possible:
{{- .Meta.Namespace }}/{{ index .Meta.Labels "app.kubernetes.io/name" }}/{{ index .Meta.Labels "app.kubernetes.io/component" -}}{{ if .ContainerName }}/{{ .ContainerName -}}{{ end -}}
I'm not sure about the implication in store.go:150 (cacheResourceMetadata) and store.go:405 (ServiceNameNamespaceForIP).
ServiceNameNamespaceForIP: figuring out the container name is probably hard / impossible cacheResourceMetadata: I think the ServiceName and ServiceNamespace is wrongly written into the cache anyways, so probably it doesn't matter, and it's overwritten in k8s.go:129 (appendMetadata). Specifically it reads the service name from the env var for each container, but overrides each of them, and in the end anyways loads it from the ServiceNameNamespace function.
Codecov Report
Attention: Patch coverage is 35.55556% with 29 lines in your changes missing coverage. Please review.
Project coverage is 65.73%. Comparing base (
8c40607) to head (c128493). Report is 16 commits behind head on main.
| Files with missing lines | Patch % | Lines |
|---|---|---|
| pkg/internal/kube/store.go | 34.37% | 20 Missing and 1 partial :warning: |
| pkg/components/beyla.go | 27.27% | 7 Missing and 1 partial :warning: |
Additional details and impacted files
@@ Coverage Diff @@
## main #1813 +/- ##
==========================================
- Coverage 67.84% 65.73% -2.12%
==========================================
Files 224 208 -16
Lines 22930 21235 -1695
==========================================
- Hits 15556 13958 -1598
+ Misses 6594 6389 -205
- Partials 780 888 +108
| Flag | Coverage Δ | |
|---|---|---|
| integration-test | 55.16% <6.66%> (-0.06%) |
:arrow_down: |
| k8s-integration-test | 53.50% <35.55%> (-0.10%) |
:arrow_down: |
| oats-test | 34.61% <6.66%> (-0.28%) |
:arrow_down: |
| unittests | ? |
Flags with carried forward coverage won't be shown. Click here to find out more.
:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.
:rocket: New features to boost your workflow:
- :snowflake: Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
- :package: JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.
This pull request sets up GitHub code scanning for this repository. Once the scans have completed and the checks have passed, the analysis results for this pull request branch will appear on this overview. Once you merge this pull request, the 'Security' tab will show more code scanning analysis results (for example, for the default branch). Depending on your configuration and choice of analysis tool, future pull requests will be annotated with code scanning analysis results. For more information about GitHub code scanning, check out the documentation.
This is an excellent addition for more control and totally makes sense as long as the default behavior is still the way the is right now - else we would get a breaking change for users that are selecting things based on service names.
It seems like this is only active when either service_name_template in the YAML or BEYLA_SERVICE_NAME_TEMPLATE env variable is set, if so I think we are good.
Yes, it's the intention to not cause any difference in behaviour. Default value is empty, and empty value is ignored.
The latest commit will introduce a change though - but I rather see it as a bugfix. Previously service name was the same for all containers, now each container can have it's own dedicated service name.
@thoro Before this PR is merged, there is no way to alter the "service.name" ? I have java processed and all have "app.kubernetes.io/name" pod label as service.name :(
@jcdauchy-moodys You can use the env variable OTEL_SERVICE_NAME, if it's the first container in the pod it will work. Add it to the service you want to change the service name for.
Ok thanks @thoro, will try that while waiting for this PR to be merged hopefully.
Hi @thoro, do you mind merging with main and moving this PR to ready for review so we can kick off the tests and continue with the process of merging this change? Thanks in advance.
@grcevski I have rebased and moved Ready to Review
I still have not gotten to actually implementing any unit or integration tests, I was having troubles with the integration test not running at all on my machine.
@grcevski I fixed the test cases, and added a specific test case for the ServiceNameTemplate
Thanks @thoro! It seems that the go linter is complaining about some code formatting. Just run 'make fmt' to fix them.
Codecov Report
Attention: Patch coverage is 54.40000% with 57 lines in your changes missing coverage. Please review.
Project coverage is 73.84%. Comparing base (
1641d37) to head (2b967be).
Additional details and impacted files
@@ Coverage Diff @@
## main #1813 +/- ##
==========================================
+ Coverage 68.84% 73.84% +4.99%
==========================================
Files 179 180 +1
Lines 19671 19764 +93
==========================================
+ Hits 13543 14594 +1051
+ Misses 5382 4415 -967
- Partials 746 755 +9
| Flag | Coverage Δ | |
|---|---|---|
| integration-test | 57.41% <12.00%> (-0.09%) |
:arrow_down: |
| k8s-integration-test | 54.68% <28.00%> (?) |
|
| oats-test | 34.34% <12.00%> (?) |
|
| unittests | 45.75% <44.80%> (-0.85%) |
:arrow_down: |
Flags with carried forward coverage won't be shown. Click here to find out more.
:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.
:rocket: New features to boost your workflow:
- :snowflake: Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
- :package: JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.
@grcevski Fixed the fmt error - It's unclear to me why codecov shows the new code uncovered, I ran go tool cover locally and verified if most of the new parts are covered, and they were.
@grafsean Thanks, incorporated the suggestions.
@grcevski Sorry I had a wrong import in the linux-only test, which wasn't executed!
Hi @thoro, I guess we have some lint errors:
Error: pkg/components/beyla_test_linux.go:17:6: var-naming: don't use underscores in Go names; func TestRun_DontPanic should be TestRunDontPanic (revive)
func TestRun_DontPanic(t *testing.T) {
^
You can use make lint to check for all of them.
@grcevski Fixed them, even though two were not mine, seems they were already in the code before??
https://github.com/grafana/beyla/blob/main/pkg/components/beyla_test.go#L17
I see the integration tests are still failing, I do not know why. Could you give me a pointer?
I see the integration tests are still failing, I do not know why. Could you give me a pointer?
Only zizmor was failing now. Probably unrelated. Let me run tests again.
@rafaelroquetto rebased again, removed the CanRun function