Skip to content
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

Is it possible to be able to add custom labels to the metrics already being emitted #3040

Closed
vpareek1308 opened this issue Jan 24, 2024 · 2 comments
Assignees
Labels
for/stackoverflow Questions are best asked on SO or Gitter

Comments

@vpareek1308
Copy link

vpareek1308 commented Jan 24, 2024

I could not find a way to add custom static labels to the metrics that are emitted out-of-the-box. I want to differentiate the metrics if I have multiple beans of ConnectionProvider and want to analyse them seperately.

Motivation

I am working on a project where multiple tenants are able to access my service and I do some data aggregator for them by making HTTP calls to some other services. Now if the traffic from one tenant spikes, I do not want the other tenants to be affected so I decided to make multiple beans as the number of tenants for me is always going to be less than 5 (worst case scenario). I want to see the metrics for these tenants separately, but I could not find a way to add a custom label to the out-of-the-box provided metrics by the library.

Desired solution

Maybe there could be a way to add a custom label, with static values if not dynamic, that I can add at the time of bean creation, to the already emitted metrics.

Additional context

Here is the code for the bean that I was creating to use the ConnectionProvider that I later used to create a bean of Webclient for my reactive application.

@Bean
fun connectionProvider(): ConnectionProvider {
    return ConnectionProvider
        // Other properties
        .metrics(true)
        // Other properties
        .build()
}
@vpareek1308 vpareek1308 added status/need-triage A new issue that still need to be evaluated as a whole type/enhancement A general enhancement labels Jan 24, 2024
@violetagg violetagg self-assigned this Jan 24, 2024
@violetagg violetagg removed the status/need-triage A new issue that still need to be evaluated as a whole label Jan 24, 2024
@violetagg
Copy link
Member

@vpareek1308 Why don't you create every ConnectionProvider with a different name?

For example if you have this code, you will be able to distinguish them using the name tag.

ConnectionProvider provider1 = ConnectionProvider.builder("provider1").metrics(true).build();
ConnectionProvider provider2 = ConnectionProvider.builder("provider2").metrics(true).build();

WebClient.builder()
		.clientConnector(new ReactorClientHttpConnector(HttpClient.create(provider1)))
		.build()
		.get()
		.uri("https://httpbin.org/get")
		.retrieve()
		.bodyToMono(String.class)
		.block();

WebClient.builder()
		.clientConnector(new ReactorClientHttpConnector(HttpClient.create(provider2)))
		.build()
		.get()
		.uri("https://httpbin.org/get")
		.retrieve()
		.bodyToMono(String.class)
		.block();

More about the ConnectionProvider metrics you can find here
https://projectreactor.io/docs/netty/release/reference/index.html#_metrics_6
https://projectreactor.io/docs/netty/release/reference/index.html#observability-metrics-total-connections

@violetagg violetagg added for/stackoverflow Questions are best asked on SO or Gitter for/user-attention This issue needs user attention (feedback, rework, etc...) and removed type/enhancement A general enhancement labels Jan 24, 2024
@vpareek1308
Copy link
Author

@violetagg Thanks for the quick reply.

This fix makes sense, and I have added in my service for now. Maybe this can be added in the future if required. Let's close this issue for now.

@violetagg violetagg removed the for/user-attention This issue needs user attention (feedback, rework, etc...) label Jan 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
for/stackoverflow Questions are best asked on SO or Gitter
Projects
None yet
Development

No branches or pull requests

2 participants