Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Having datasource name in metrics #58

Open
stefano-salmaso opened this issue Jan 22, 2025 · 4 comments
Open

Having datasource name in metrics #58

stefano-salmaso opened this issue Jan 22, 2025 · 4 comments

Comments

@stefano-salmaso
Copy link

Hello!
I noticed that in the metrics produced there is no tag with the name of the datasource.
In case there are more datasources it becomes impossible to use the metrics correctly.

Is this a desired behavior?
If so... is there a way to have the name of the datasource in the metrics produced?

Thanks

@stefano-salmaso stefano-salmaso marked this as a duplicate of #59 Jan 22, 2025
@stefano-salmaso stefano-salmaso marked this as a duplicate of #60 Jan 22, 2025
@ttddyy
Copy link
Member

ttddyy commented Jan 29, 2025

Hi @stefano-salmaso

Initially, I thought this could be achieved using a custom ObservationFilter to add the database name as a low-cardinality key-value.

However, the database name is not currently available in the context.

I'll think about adding the database name into the contexts.

@stefano-salmaso
Copy link
Author

HI @ttddyy
I looked at the code and I think that adding the datasource name in the context is relatively easy. If I can I could propose you a PR... 😄
But I have some doubts....
Once you add the datasource name in the context it is possible to have it as a metric tag using an ObservationFilter.
But this is not true for all the metrics produced.
For example I have the datasource name for jdbc.query but it is not there for jdbc.query.active, see below:

jdbc_query_active_seconds_active_count{app="my-app"} 0.0 # Missing!!!
jdbc_query_active_seconds_duration_sum{app="my-app"} 0.0 # Missing!!!
jdbc_query_active_seconds_max{app="my-app"} 0.0 # Missing!!!
jdbc_query_seconds_max{app="my-app",name="my-ds"} 0.0 # ok, added with ObservationFilter
jdbc_query_seconds_count{app="my-app",name="my-ds"} 1.0 # ok, added with ObservationFilter
jdbc_query_seconds_sum{app="my-app",name="my-ds",} 0.018519208 # ok, added with ObservationFilter

For jdbc.connection the same thing happens, but here I do not have the name for the managed metrics ObservationHandler also

jdbc_connection_commit_total{app="my-app",} 1.0 # Missing!!!
jdbc_connection_acquired_total{app="my-app",} 3.0 # Missing!!!
jdbc_connection_active_seconds_max{app="my-app",} 0.0 # Missing!!!
jdbc_connection_active_seconds_active_count{app="my-app",} 0.0 # Missing!!!
jdbc_connection_active_seconds_duration_sum{app="my-app",} 0.0 # Missing!!!
jdbc_connection_seconds_count{app="my-app",error="none",name="my-ds",} 2.0 # ok, added with ObservationFilter
jdbc_connection_seconds_sum{app="my-app",error="none",name="my-ds",} 82.99373225 # ok, added with ObservationFilter
jdbc_connection_seconds_max{app="my-app",error="none",name="my-ds",} 0.0 # ok, added with ObservationFilter

I think that having at least the name of the datasource is mandatory to have good metrics.
Do you know if and how to fix this thing?

Stefano.

@ttddyy
Copy link
Member

ttddyy commented Feb 1, 2025

Hi @stefano-salmaso

Did you add the datasource name to low-cardinality key-values?

Those _active_* metrics should be LongTaskTimer instances created by DefaultMeterObservationHandler.
They are tagged using low-cardinality key-values. So, if an ObservationFilter adds the datasource name to low-cardinality key-values, it should automatically be included in LongTaskTimer metrics.
The same applies to observation events for connection commit/acquired counters as well.

Is it not happening?

@stefano-salmaso
Copy link
Author

HI @ttddyy
Yes I added the datasource name in the low-cardinality key-values.
I did a little investigation and seems that an ObservationFilter doesn't have effects on metrics created and registered like the LongTaskTimer and observation events.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants