-
Notifications
You must be signed in to change notification settings - Fork 848
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
Add batch callback API #4376
Add batch callback API #4376
Conversation
Codecov Report
@@ Coverage Diff @@
## main #4376 +/- ##
============================================
- Coverage 90.12% 90.02% -0.10%
- Complexity 5003 5029 +26
============================================
Files 569 578 +9
Lines 15435 15522 +87
Branches 1487 1493 +6
============================================
+ Hits 13911 13974 +63
- Misses 1061 1084 +23
- Partials 463 464 +1
Continue to review full report at Codecov.
|
We had earlier brainstormed about using the sync versions of the instruments themselves within callbacks since the usage seems very sync. Did you have any thoughts on that? |
Also for this I suggest pushing back on the |
We could potentially use the the API of the synchronous instruments (e.g.
Do you disagree with having any registration requirement of the instruments that will be involved in the batch callback? Or that there are different methods for registering long instruments and double instruments? I'm currently convinced that requiring registration of involved instruments is a good thing (see this comment). Doing so:
|
I disagree with any registration requirement - it's just really tedious to pass in an instrument, to only then effectively pass it in again when using in the callback. I've seen similar in React Hooks, where it's unfortunately required for the semantics themselves, and most people find it pretty annoying. Luckily there are compiler plugins to automatically add the registration command in that world.
Is this if a view configures a metric to be dropped? I don't know if this happens common enough in practice to require the stuttering in the API usage.
I haven't heard of this before, could you describe the use case and what it would look like? We would have the callbacks not exported as part of the SDK's collection interval?
This is the corner case I was aware of, it seems like a small point to require tedium in the API IMO. |
I opened a spec #2120 (also related to #2200 and #1432) a bit back related to this. My example was: Suppose you were interested in getting JVM runtime metrics every 10 seconds, but a 60 second interval was sufficient for potentially higher cardinality metrics capturing http server usage. This would be possible if:
Without knowing which instruments a batch callback can record to, the SDK has to evaluate all the batch callbacks each collection. FYI, the declarative association of instruments at registration time of the batch callback is currently proposed as a MUST in the spec. I'm in favor because it allows the SDK to be more correct, and the API it produces isn't that bad. |
We talked about a few different options for the API in the 4/14 Java Office Hours. Multiple add methods, and buildExplicit registration of instruments via two
An alternative version of this has An alternative version of this defines a single We also discussed a version of this where we introduce a method called something like a Single methodA single method accepts the runnable and the instruments
This code demonstrates the method signature as An alternative version of this accepts a set of instruments (i.e. Yet another alternative version of this accepts a set of instruments, and switches the argument order so the I believe by the end we were agreeing on keeping the instrument registration explicit, justified by it being unlikely that end users will have to register many of these. And after all, the batch callback concept is a performance optimization for users who care about multiple invocations of their callback. It seems unlikely the extra instrument argument will be a big imposition on performance minded folks. My preference at the moment is a single method: |
How does the Set version make it harder to omit? Edit: If we want a required argument with vararg it can look like |
+2 cents for
with required arg before the varargs like @anuraaga mentioned |
With the varargs version you could call it with no observables it would compile. You might not look at the javadoc close enough to understand that you need to include observables.
If forced to provide a set, you can't ignore including the observables without a compilation error. Of course you can still provide an empty set, but that feels more intentionally negligent. I do like the varargs version too though, just slightly easier to stumble. |
Yes, if we're going to varargs, this is the way to do it, since you have to include at least one Observable or nothing will do anything. |
Got it. Didn't think about that strategy, but that's a nice solution. |
Multi instrument callbacks have been merged into the spec, so I've marked this PR as "ready for review". I'm not in a rush to get it in before the next release, but I'd be happy if it were included assuming folks are comfortable with the additions to the API. |
As discussed in the SIG meeting last evening, we need to hold off on merging this until the spec has been officially released containing this functionality. |
FYI, the spec has released this feature in v1.11.0. If we're happy with the API, we can safely include it. |
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 believe we're all OK with the current API (single Observable required, multiple possible).
api/all/src/main/java/io/opentelemetry/api/metrics/DefaultMeter.java
Outdated
Show resolved
Hide resolved
I think it's fine, as long as instrumentation folks are happy with it, since they are the main driver of the feature. |
@jack-berg This LGTM given the current spec. I do wish we had spent some additional time thinking through type-system level enforcement we could provide to prevent "bad" usage at compile time, but what you propose here is likely good enough. |
Implementation of spec issue #2363.
Allows a single callback to record measurements for multiple instruments.
ObservableLongMeasurement
andObservableLongMeasurement
) for async instruments, i.e.ObservableDoubleMeasurement DoubleCounterBuilder#buildObserver()
.Resolves #3761.
Replaces earlier prototype #4024.
Updated 04/30/2022