-
Notifications
You must be signed in to change notification settings - Fork 893
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
Allow one observer to observe multiple metrics #549
Comments
From Gitter:
|
the proposal -> this is how I implemented it in JS |
OTEP 72 does say that multiple observations are permitted per callback, but the intention at that point was to support multiple (value, label set) observations for a single metric. The language is unclear, but the pseudocode in the OTEP is somewhat clear. In getting to OTEP 72 we discussed several related issues. We removed "bound" observer instruments, justifying this because LabelSets were still part of the API and support caching the label encoding used in an exporter. Now that we have removed LabelSets from the API, the notion of a bound observer starts to look like a real optimization. What would an API look like to support multiple metrics to be observed from one callback? We would register callbacks with the SDK directly, since they are not associated with metrics directly. We could have three analogous calling patterns to the synchronous instruments: direct calls, bound calls, and batch calls. Callbacks would be executed sequentially in the order they were registered. For example:
This sort of change requires us to mention that callbacks are executed in order, whereas we didn't have to before. Last-value wins was previously applied to the result from one callback, but now it has to be applied to the result from all callbacks. Thoughts? @bogdandrutu this is a significant problem, please have a look. |
I like the idea of adding a callback interface to the Meter. Java pseudocode: meter.addObserver(Callback<Meter> meterCallback) where interface Callback<R> {
void update(R input);
} |
What if instead of function as a callback it would be an observable object. This way the problem with sync / async would be solved.
so every time you call The main problem when the callback is a function is that you have no easy way of getting data which requires async calls. And also you will have problem with blocking the sync call for longer than it is needed. |
@obecny What you've written looks like a synchronous instrument through and through. There are reasons for Observers to be asynchronous, they're supposed to be a solution. The reasons:
We had made the Observer callback support a single metric merely out of a desire to keep things as simple as possible. I believe this example demonstrates that we have oversimplified. The proposal I made above for bound observers surfaced in early in the 0.3 conversation IIRC, and we dropped it. |
I think it should be possible to have the "batch-callback" similar to batch record. Probably not one per meter, but allow batching-callback is indeed something that we can support. |
@jmacd I would rely on a combination of the BatchRecorder and ObserverResult to achieve the performance you mentioned:
|
I like this. There are a few details to work out, like:
As we have removed LabelSets, the BatchRecorder pattern that you bring up stands in as a replacement for LabelSet. I wonder if you would allow this pattern:
I have the same question for synchronous usage, e.g.:
Note the only difference between Sync- and Async- BatchRecorders is that Sync- recorders take Context, while Async- recorders take ObserverBatchResult. |
I would like to think of a solution where we can ensure only one callback is register at a time for every instrument, what do you think? |
I can't immediately think of how I'd do that. Do you have an API in mind? |
Possible OTel-Go APIs are being discussed here: open-telemetry/opentelemetry-go#634 |
This API review is underway: open-telemetry/opentelemetry-go#634 |
Summary
In opentelemetry-go, one metric == one observer.
This proposal stresses the need for one observer to observe multiple metrics.
The best use case is for reading various system metrics in one call such as:
This operation (and others) can be expensive. This one in particular can populates ~30 variables where each one is fit to be in its own metric/measure. Therefore, the current way it would work would have to be the following:
I hope you can see that this becomes inefficient fairly quickly.
Workaround
As a workaround, it was suggested on Gitter that we can just use Labels to substitute for multiple metrics. This has two issues:
Proposal
I propose that users should be able to register one call back that will populate multiple metrics as such:
If metric names must be passed ahead of time, then you'd probably need to pass the metric names in the
RegisterBatch<T>Observer
function.Otherwise, I'm happy to hear any other suggestions.
Thanks
The text was updated successfully, but these errors were encountered: