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

Custom micrometer tags are not displayer on actuator/prometheus page. #3070

Closed
tbarabanov opened this issue Feb 25, 2024 · 6 comments
Closed

Comments

@tbarabanov
Copy link
Contributor

spring-kafka version
org.springframework.kafka:spring-kafka:jar:3.0.10

micrometer version
io.micrometer:micrometer-core:jar:1.11.3
io.micrometer:micrometer-registry-prometheus:jar:1.11.3
io.micrometer:micrometer-observation:jar:1.11.3

Custom micrometer tags are not displayer on actuator/prometheus page.

I'm using autoconfigured kafka with a simple listener:

spring:
  kafka:
    bootstrap-servers: localhost:29092
    consumer:
      group-id: 'some.value'
      enable-auto-commit: false
      auto-offset-reset: latest
      max-poll-records: 1
      key-deserializer: org.apache.kafka.common.serialization.StringDeserializer
      value-deserializer: org.apache.kafka.common.serialization.StringDeserializer
    producer:
      bootstrap-servers: localhost:29092
      key-serializer: org.apache.kafka.common.serialization.StringSerializer
      value-serializer: org.apache.kafka.common.serialization.StringSerializer
@KafkaListener(topics = "pike")
public void listen(ConsumerRecord<String, String> record) {
    System.out.println(record.topic());
}
@Bean
DefaultKafkaConsumerFactoryCustomizer kafkaConsumerFactoryCustomizer(MeterRegistry meterRegistry) {
    return consumerFactory -> consumerFactory.addListener(
        new MicrometerConsumerListener<>(meterRegistry));
}
@Component
class ConcurrentKafkaListenerContainerFactoryCustomizer {

    // autoconfigured kafkaListenerContainerFactory customizer
    public ConcurrentKafkaListenerContainerFactoryCustomizer(
        ConcurrentKafkaListenerContainerFactory<?, ?> kafkaListenerContainerFactory,
        Function<ConsumerRecord<?, ?>, Map<String, String>> micrometerTagsProvider) {
      kafkaListenerContainerFactory.setContainerCustomizer(
          container -> {
            container.getContainerProperties().setMicrometerTagsProvider(micrometerTagsProvider);
          });
    }
  }

In IDE debug I see that my micrometerTagsProvider gets called (tags are generated) as well as the code in MicrometerHolder.java

private Timer buildTimer(String exception, @Nullable Object record) {
		Builder builder = Timer.builder(this.timerName)
			.description(this.timerDesc)
			.tag("name", this.name)
			.tag("result", exception.equals(NONE_EXCEPTION_METERS_KEY) ? "success" : "failure")
			.tag("exception", exception);
		Map<String, String> extra = this.tagsProvider.apply(record);
		if (extra != null && !extra.isEmpty()) {
			extra.forEach(builder::tag);
		}
		Timer registeredTimer = builder.register(this.registry);
		if (record == null) {
			this.meters.put(exception, registeredTimer);
		}
		return registeredTimer;
	}

I see that custom tags are added to builder, I see spring.kafka.listener metrics on actuator/prometheus page but no custom tags are displayed.

expected result
custom tags must be displayed on actuator/prometheus page along with their metrics

@tbarabanov
Copy link
Contributor Author

tbarabanov commented Feb 25, 2024

I've just noticed that meter timers doesn't change (always 0) then I do set container.getContainerProperties().setMicrometerTagsProvider(micrometerTagsProvider); despite the fact that registry has metrics and tags.

Снимок экрана 2024-02-25 в 22 08 44

@sobychacko
Copy link
Contributor

@tbarabanov Could you provide us with a small sample application where we can reproduce this issue? Please include some instructions to run the app as well.

@tbarabanov
Copy link
Contributor Author

tbarabanov commented Feb 27, 2024

@sobychacko I believe that it is micrometer+prometheus issue, but anyway here is the project link

@artembilan
Copy link
Member

If problem is not on Spring for Apache Kafka side, consider to close this issue and open a new one in Micormeter or Prometheus .

@tbarabanov
Copy link
Contributor Author

tbarabanov commented Feb 27, 2024

@artembilan sure, but just to let the spring-kafka team to know, that there is the issue

that made me (and probably others) mad =)

@artembilan
Copy link
Member

Thanks.

So, closed as Invalid.

@artembilan artembilan closed this as not planned Won't fix, can't repro, duplicate, stale Feb 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants