Skip to content

[cmd/mdatagen]: Improve loading errors for clarity #13206

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

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

jeffalder
Copy link

Description

Expose go list -f stderr if the command fails.

Link to tracking issue

Fixes #13205

Testing

Manual, unit tests

Documentation

No new docs required

@jeffalder jeffalder requested review from dmitryax and a team as code owners June 14, 2025 15:42
@jeffalder
Copy link
Author

The first problem is that I was using t.Chdir() which is new to 1.24. It all worked locally because I was mistakenly running it with go 1.24. I fixed that.

In order to avoid t.ChDir(), I moved the files into the tempdir. But when my test "failed to fail", I realized there was a disconnect about whether or not mdatagen expected to run in the module directory or not. I think the answer is no, because the command specifically grabs the abspath and uses that for all file manipulation. But the package name (from go list) is determined from the directory in which mdatagen is running, so some of the tests fail.

Because running the go list command is part of this PR, I'm going to fix this up. In theory it could be done separately but I'm in the same place in the code.

Copy link

codecov bot commented Jun 18, 2025

Codecov Report

Attention: Patch coverage is 87.50000% with 1 line in your changes missing coverage. Please review.

Project coverage is 91.54%. Comparing base (8cc2954) to head (a39f5c3).

Files with missing lines Patch % Lines
cmd/mdatagen/internal/loader.go 87.50% 1 Missing ⚠️

❌ Your patch check has failed because the patch coverage (87.50%) is below the target coverage (95.00%). You can increase the patch coverage or adjust the target coverage.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #13206      +/-   ##
==========================================
+ Coverage   91.52%   91.54%   +0.01%     
==========================================
  Files         522      522              
  Lines       29028    29032       +4     
==========================================
+ Hits        26569    26578       +9     
+ Misses       1939     1936       -3     
+ Partials      520      518       -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.

@jeffalder
Copy link
Author

jeffalder commented Jun 18, 2025

Coverage: The uncovered line requires that the go list -f '{{.ImportPath}}' command fail in some other way than a non-zero status code. For example, it'd have to fail to start or collapse on close. The coverage report marks these lines as completely uncovered in the default branch so I think this should be OK. If we want to be specific I can simply return "", err, but not being able to identify the source of the error was the reason I got into this PR to begin with.

Coverage report from HEAD: https://app.codecov.io/gh/open-telemetry/opentelemetry-collector/blob/main/cmd%2Fmdatagen%2Finternal%2Floader.go
Screenshot 2025-06-18 at 4 12 14 PM

Copy link
Member

Choose a reason for hiding this comment

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

Why this file and cmd/mdatagen/internal/testdata/empty.go are needed? Cannot see how they are being used

Copy link
Author

Choose a reason for hiding this comment

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

go list will fail if there are no source files in the directory containing metadata.yaml. The tests were passing because go list was being run in the internal directory, not in the directory where test yaml file was.

It goes back to my previous question

whether or not mdatagen expected to be run in the module directory itself or not. I think the answer is no, because the command specifically grabs the abspath and uses that for all file manipulation. But the package name (from go list) is determined from the directory in which mdatagen is running, so some of the tests fail.

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.

[cmd/mdatagen]: go list output missing
2 participants