Skip to content

[mdatagen] Fix semconv URL validation for metrics with underscores#14584

Open
osullivandonal wants to merge 3 commits intoopen-telemetry:mainfrom
osullivandonal:fix-mdatagen-underscore-in-semconv-bug
Open

[mdatagen] Fix semconv URL validation for metrics with underscores#14584
osullivandonal wants to merge 3 commits intoopen-telemetry:mainfrom
osullivandonal:fix-mdatagen-underscore-in-semconv-bug

Conversation

@osullivandonal
Copy link
Contributor

Description

Currently in mdatagen if you use a url for the semantic_convention: ref: key with a underscore in the anchor tag, mdatagen generate fails. Underscores in the anchor tag of the url is valid for exmaple in system.disk.io_time the anchor tag has: metric-systemdiskio_time. The underscore causes an error at generation time.

Example, in otel-collector-contrib hostmetricsreceiver metadata.yaml with semantic_convention key:

  system.disk.io_time:
    enabled: true
    description: Time disk spent activated. On Windows, this is calculated as the inverse of disk idle time.
    unit: s
    stability: development
    sum:
      value_type: double
      aggregation_temporality: cumulative
      monotonic: true
    attributes: [device]
    semantic_convention:
      ref: https://github.com/open-telemetry/semantic-conventions/blob/v1.38.0/docs/system/system-metrics.md#metric-systemdiskio_time

When running make generate we see this error:

…/receiver/hostmetricsreceiver main  ❯ make generate
cd /home/dos/Documents/opentelemetry-collector-contrib/internal/tools && GOOS="" GOARCH="" go build -o /home/dos/Documents/opentelemetry-collector-contrib/.tools/genqlient -trimpath github.com/Khan/genqlient
PATH="/home/dos/Documents/opentelemetry-collector-contrib/.tools:$PATH" go generate ./...
make[1]: Entering directory '/home/dos/Documents/opentelemetry-collector-contrib/receiver/hostmetricsreceiver'
make[1]: Leaving directory '/home/dos/Documents/opentelemetry-collector-contrib/receiver/hostmetricsreceiver'
make[1]: Entering directory '/home/dos/Documents/opentelemetry-collector-contrib/receiver/hostmetricsreceiver/internal/scraper/cpuscraper'
make[1]: Leaving directory '/home/dos/Documents/opentelemetry-collector-contrib/receiver/hostmetricsreceiver/internal/scraper/cpuscraper'
make[1]: Entering directory '/home/dos/Documents/opentelemetry-collector-contrib/receiver/hostmetricsreceiver/internal/scraper/diskscraper'
Error: failed loading /home/dos/Documents/opentelemetry-collector-contrib/receiver/hostmetricsreceiver/internal/scraper/diskscraper/metadata.yaml: metric "system.disk.io_time": invalid semantic-conventions URL: want https://github.com/open-telemetry/semantic-conventions/blob/v1.38.0/*#metric-systemdiskiotime, got "https://github.com/open-telemetry/semantic-conventions/blob/v1.38.0/docs/system/system-metrics.md#metric-systemdiskio_time"
Error: failed loading /home/dos/Documents/opentelemetry-collector-contrib/receiver/hostmetricsreceiver/internal/scraper/diskscraper/metadata.yaml: metric "system.disk.io_time": invalid semantic-conventions URL: want https://github.com/open-telemetry/semantic-conventions/blob/v1.38.0/*#metric-systemdiskiotime, got "https://github.com/open-telemetry/semantic-conventions/blob/v1.38.0/docs/system/system-metrics.md#metric-systemdiskio_time"
make[1]: *** [../../../../../Makefile.Common:264: mdatagen] Error 1
make[1]: Leaving directory '/home/dos/Documents/opentelemetry-collector-contrib/receiver/hostmetricsreceiver/internal/scraper/diskscraper'
internal/scraper/diskscraper/doc.go:4: running "make": exit status 2

Link to tracking issue

Fixes #14583

Testing

  • We can test this out in otel-collector-contrib via updating the tools to use this branch locally, for example:

  • In opentelemetry-collector-contrib/internal/tools/go.mod:

replace go.opentelemetry.io/collector/cmd/mdatagen => /home/dos/Documents/opentelemetry-collector/cmd/mdatagen
  system.disk.io_time:
    enabled: true
    description: Time disk spent activated. On Windows, this is calculated as the inverse of disk idle time.
    unit: s
    stability: development
    sum:
      value_type: double
      aggregation_temporality: cumulative
      monotonic: true
    attributes: [device]
    semantic_convention:
      ref: https://github.com/open-telemetry/semantic-conventions/blob/v1.38.0/docs/system/system-metrics.md#metric-systemdiskio_time
Unit-Tests

A unit test has been added to loader_test.go that uses the test file: with_underscore_in_semconv_ref_anchor_tag.yaml.

This test has the underscore in the anchor tag and will fail if the regex filters out the underscore.

Currently in mdatagen if you use a url for the semantic_convention: ref:
key with a underscore in the anchor tag, mdatagen generate fails.
Underscores in the anchor tag of the url is valid for exmaple in
system.disk.io_time the anchor tag has: metric-systemdiskio_time
The underscore causes an error at generation time. This commit fixes
that issue
@codecov
Copy link

codecov bot commented Feb 13, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.83%. Comparing base (292ea8f) to head (13ef03f).

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #14584      +/-   ##
==========================================
+ Coverage   91.81%   91.83%   +0.01%     
==========================================
  Files         679      679              
  Lines       42902    42902              
==========================================
+ Hits        39390    39397       +7     
+ Misses       2442     2437       -5     
+ Partials     1070     1068       -2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[mdatagen] Underscores in anchor tag in metadata key semantic_convention: ref: url causes generation error

2 participants