-
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
change feature registry as a prototype to make test friendly #4969
change feature registry as a prototype to make test friendly #4969
Conversation
service/telemetry.go
Outdated
func init() { | ||
//nolint:staticcheck | ||
featuregate.Register(featuregate.Gate{ | ||
featuregate.GetRegistry().Register(featuregate.Gate{ |
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.
To see the benefit of this change, we should split init into something like:
func init() {
initWithRegistry(featuregate.GetRegistry())
}
func initWithRegistry(registry *featuregate.Registry) {
registry.Register(featuregate.Gate{
ID: useOtelForInternalMetricsfeatureGateID,
Description: "controls whether the collector to uses open telemetry for internal metrics",
Enabled: configtelemetry.UseOpenTelemetryForInternalMetrics,
})
}
Then change all the tests to run initWithRegistry
and test using a custom "Registry" per test. Does it make sense?
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.
HI @bogdandrutu
We add a new func 'newRegistry()' to create object in test.
and add the func 'initWithRegistry' with unit test.
Would you please review it?
75bc21e
to
3c315f8
Compare
Signed-off-by: Kay Yan <[email protected]>
3c315f8
to
0c300b6
Compare
This PR was marked stale due to lack of activity. It will be closed in 14 days. |
Please rebase. @open-telemetry/collector-approvers please review |
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.
Does this actually provide any advantage? If the Registry
is to be exposed and the package-global accessor and mutator removed, then consumers should be provided with a Registry
to use rather than using the global Registry
. Setting the global Registry
in tests is no different than setting and testing flags on the global Registry
as was previously done.
If we are to provide a Registry
for consumers to use we need to be very careful to ensure that it is available to all consumers that may need to test flag status at all points where flag status may need to be checked. It might make sense to expose it through the Host
interface, but I don't believe that is available to factory instances when creating components. Putting it in *CreateSettings
structs might make it available to component factories, but not to the factory initializers.
@Aneurysm9 consider please to read the PR and the issue associated. This is mostly to help func init() {
initWithRegistry(featuregate.GetRegistry())
}
func initWithRegistry(registry *featuregate.Registry) {
// ... do work
} With this you can write unittests for |
I have read the PR and associated issue. Why would you assume that I hadn't done so before commenting on the implementation in the PR?
How does this help with testing? At most it allows testing of the |
Codecov Report
@@ Coverage Diff @@
## main #4969 +/- ##
==========================================
- Coverage 90.99% 90.78% -0.22%
==========================================
Files 178 182 +4
Lines 10632 10678 +46
==========================================
+ Hits 9675 9694 +19
- Misses 739 768 +29
+ Partials 218 216 -2
Continue to review full report at Codecov.
|
All these are making a wrong assumption that we need to "provide" the registry. I trust that engineers can design/refactor their code (similarly to the init example) in a way that the interesting functionality that use the "Gate"/"calls the registry" can be extracted into a separate func that accepts a registry as an argument. So then they can write unit tests. Same pattern by the way is used in the "go sdk for TracerProvider vs global", idea being you write the instrumentation plugins (code that uses the gates) to accept a "Registry" but if not provided then use the global. |
@Aneurysm9 here is actually the continuation of this PR and how tests can be improved f1b821c (part of a cloned PR #5160) |
Closing this, since we have the continuation #5160 |
change feature registry as a prototype to make test friendly.
Link to tracking Issue: #4917
Signed-off-by: Kay Yan [email protected]