-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
[chore][mdatagen] Add telemetry metric test #11067
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #11067 +/- ##
==========================================
- Coverage 91.56% 91.48% -0.09%
==========================================
Files 430 430
Lines 20242 20260 +18
==========================================
Hits 18535 18535
- Misses 1331 1349 +18
Partials 376 376 ☔ View full report in Codecov by Sentry. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
cmd/mdatagen/internal/samplereceiver/internal/metadata/telemetry_test.go
Outdated
Show resolved
Hide resolved
// This is not a comprehensive test of the sample receiver's telemetry metrics, but should cover each of its cases. | ||
|
||
// Component telemetry setup should be uniform across components | ||
tt, err := componenttest.SetupTelemetry(component.MustNewID(Type.String())) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is it necessary to test these using componenttest
or can they be tested using the code in generated_component_telemetry_test.go
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like it's possible to use that functionality, but there would be some level of impact.
A couple of things to call out:
- The generated telemetry test from this PR would need to be moved up to each component's main directory, rather than
internal/metadata
. We could potentially append this testing to to thegenerated_component_telemetry_test.go
file, but that may just make the logic there more confusing. - The current interface of passing in expected metrics would result in pretty verbose generated tests. We may need to add more helper functions that can aid in generating expected metrics, or just deal with verbose tests.
Question out of ignorance: Why do we need generated_component_telemetry_test.go
for all of these different components? If it's always the same helper methods, why do we want to generate so much identical code rather than a central re-usable package?
Maybe another part of this is simply that we don't want to have to rely on componenttest
for v1.0
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Question out of ignorance: Why do we need generated_component_telemetry_test.go for all of these different components?
Totally valid question, I added it there as it would reduce the need for test package dependencies across component types. I didn't a processor to end up pulling in a dependency on receivers just to bring in a common test package. it would be possible to have these test separated per component type, but putting it in generated code seemed like a cheaper dependency.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The generated telemetry test from this PR would need to be moved up to each component's main directory, rather than internal/metadata
Would it be possible to move the tests code in generated_component_telemetry_test down into the internal package instead?
The current interface of passing in expected metrics would result in pretty verbose generated tests.
I would expect that we will eventually move to a similar model that we use for scrapers for "golden" metric files (i.e. https://github.com/open-telemetry/opentelemetry-collector-contrib/blob/main/receiver/mongodbatlasreceiver/testdata/alerts/golden/metric-threshold-closed.yaml)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't a processor to end up pulling in a dependency on receivers just to bring in a common test package. it would be possible to have these test separated per component type, but putting it in generated code seemed like a cheaper dependency.
Was there a reason that this was needed in the first place though, rather than depending on componenttest
? From my understanding it doesn't seem to have the issue of pulling in different component type dependencies. It has caller methods that specific component types wouldn't use (CheckExporterMetrics
wouldn't be used by a receiver
), but that doesn't seem to be the issue you're referencing here.
I realize this question is out of scope for these changes, just trying to understand context here.
Would it be possible to move the tests code in generated_component_telemetry_test down into the internal package instead?
Yes, I like that solution much better, just wasn't sure if it would be too big of a breaking change 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I like that solution much better, just wasn't sure if it would be too big of a breaking change 👍
I don't think that's a huge change, would just require to make the funcs that are used by components public in the internal package, and update the references
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I gave the move an attempt, but we need to make a decision around the tradeoffs. I've filed #11163 to discuss.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's move this forward and figure out if there's optimization around how the code should be generated later
@crobert-1 please rebase and we can get this merged |
da83a8f
to
05c43c6
Compare
Done. However, this PR was originally depending on functionality that has since been deleted in #11172. Please review the newly exposed methods in |
41b1250
to
29a1418
Compare
30c584f
to
d51eb5c
Compare
@codeboten I've updated this PR, it should be ready to merge if it still looks good to you. |
This PR was marked stale due to lack of activity. It will be closed in 14 days. |
Closed as inactive. Feel free to reopen if this PR is still being worked on. |
Description
As described in #10801, we're working on moving the collector's internal telemetry metric functionality to be generated by
mdatagen
, and handled by the generated code.This is generally meant to be equivalent to the
generated_metrics_test.go
file which tests components' metrics in a unit test format. This is not meant to be an integration test that can confirm a component's telemetry metric matches whatever data it's consuming/processing/exporting. That work is being tracked in #10856.Most (if not all) of the comments in
telemetry_test.go
will be removed once it's generated bymdatagen
. The intention is also to simply append this added test to the existinggenerated_telemetry_test.go
file rather than having its own file.Link to tracking issue
Part of #10801. This is step 1 of the proposed break down of the issue.
Testing
This is a test only change. I assume adding the new public function
GetMetric
incomponent/componenttest/obsreporttest.go
does not require a changelog.