[cmd/mdatagen] only import "slices" when a required reagg attribute exists#15145
Open
alliasgher wants to merge 1 commit intoopen-telemetry:mainfrom
Open
[cmd/mdatagen] only import "slices" when a required reagg attribute exists#15145alliasgher wants to merge 1 commit intoopen-telemetry:mainfrom
alliasgher wants to merge 1 commit intoopen-telemetry:mainfrom
Conversation
…xists The config.go.tmpl unconditionally imports "slices" whenever reaggregation is enabled and there are aggregatable (recommended/opt_in) attributes. However, slices.Contains is only emitted for *required* attributes. When a receiver has reaggregation enabled but carries no required attributes, the generated file fails to compile with "slices imported and not used". Add a second template variable $hasRequiredReagAttr and gate the "slices" import on it. Signed-off-by: Ali <alliasgher123@gmail.com>
nicknikolakakis
added a commit
to nicknikolakakis/opentelemetry-collector-contrib
that referenced
this pull request
Apr 18, 2026
Set reaggregation_enabled: true in metadata.yaml and mark all attributes (class, direction, disk_state, packet.type) as recommended. Removed unused slices import from generated code (upstream mdatagen template bug open-telemetry/opentelemetry-collector#15145). Fixes open-telemetry#46369 Part of open-telemetry#45396 Signed-off-by: Nick Nikolakakis <nonicked@protonmail.com>
Open
4 tasks
atoulme
pushed a commit
to open-telemetry/opentelemetry-collector-contrib
that referenced
this pull request
Apr 23, 2026
Part of #45396. ## Summary Sets `reaggregation_enabled: true` in `metadata.yaml` and assigns requirement levels to the three x.509 certificate attributes: | Attribute | Level | Rationale | |-----------|-------|-----------| | `tlscheck.x509.cn` | `recommended` | Enabled by default; identifies the cert subject | | `tlscheck.x509.issuer` | `recommended` | Enabled by default; identifies the cert authority | | `tlscheck.x509.san` | `opt_in` | Disabled by default; SANs can be many/verbose | The `tlscheck.target` is already a resource attribute so no metric attribute needs `required` level. Generated metadata files with mdatagen. ## Note When running `mdatagen` with `recommended`/`opt_in` attributes but no `required` attribute, the generated `generated_config.go` imports `"slices"` unconditionally but never calls any `slices.*` function, causing a compile error. A fix has been submitted to the upstream mdatagen template: open-telemetry/opentelemetry-collector#15145. The files in this PR were generated with that fix applied. ## Testing All existing `receiver/tlscheckreceiver` tests pass with the changes applied: \`\`\` ok github.com/open-telemetry/opentelemetry-collector-contrib/receiver/tlscheckreceiver ok github.com/open-telemetry/opentelemetry-collector-contrib/receiver/tlscheckreceiver/internal/metadata \`\`\` --------- Signed-off-by: Ali <alliasgher123@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
config.go.tmplunconditionally imports"slices"wheneverreaggregation_enabled: trueand there are aggregatable (recommended/opt_in) attributes ($hasReagMetrics = true). However,slices.Containsis only emitted for attributes withrequirement_level: required. When a receiver has reaggregation enabled but carries norequiredattributes, the generated file fails to compile:```
imported and not used: "slices"
```
This was discovered while enabling re-aggregation in the
tlscheckreceiver (open-telemetry/opentelemetry-collector-contrib), which has onlyrecommended/opt_inmetric attributes (the endpoint is already a resource attribute so no metric attribute needs to be required).Fix: add a second template variable
$hasRequiredReagAttrand gate the"slices"import on it, so the import is only emitted whenslices.Containswill actually be called.Testing
mdatagengenerates compilable output for receivers with norequiredreagg attributes.requiredattributes (e.g.tcpcheck) still compile correctly with the fix applied.