jhipster / generator-jhipster

JHipster is a development platform to quickly generate, develop, & deploy modern web applications & microservice architectures.
https://www.jhipster.tech
Apache License 2.0
21.54k stars 4.02k forks source link

Prometheus tags are not included in exported metrics #24101

Closed sbouchex closed 11 months ago

sbouchex commented 11 months ago
Overview of the issue

I have generated a simple JWT + angular + JDK17 monolytic app and tried to pull the prometheus metrics

Output looks like: [...] jvm_threads_states_threads{state="runnable",} 23.0 jvm_threads_states_threads{state="blocked",} 0.0 [...]

Whereas, it should be: [...] jvm_threads_states_threads{state="runnable",},application=jh80prom 23.0 jvm_threads_states_threads{state="blocked",},application=jh80prom 0.0 [...]

According to the application.yml: spring: application: name: jh80prom

management: prometheus: metrics: export: enabled: true tags: application: ${spring.application.name}

Motivation for or Use Case

tag must be included and it was included in the JH7 app

Reproduce the error

Generate the app, start it and curl

JHipster Version(s)

8.0 and yes, it's a regression

JHipster configuration

See attachment

sbouchex commented 11 months ago

.yo-rc.json

atomfrede commented 11 months ago

As a workaround, you may add common tag via MeterRegistryCustomizer

@Value("${spring.application.name}")
String applicationName;
@Bean
MeterRegistryCustomizer<MeterRegistry> metricsCommonTags() {
    return registry -> registry.config().commonTags("application", applicationName);
}

EDIT: Does setting a static tag via application.properties works?

sbouchex commented 11 months ago

@atomfrede Editing application.yml does not change anything

sbouchex commented 11 months ago

@atomfrede the tag is exported if I add [...] management: metrics: tags: application: ${spring.application.name} [...]

Sounds like the default yaml is wrong...

atomfrede commented 11 months ago

Thanks, I obviously misread your original snippet. Yes the generated one is wrong (see official documentation https://docs.spring.io/spring-boot/docs/3.1.5/reference/htmlsingle/#application-properties.actuator.management.metrics.tags)

mshima commented 11 months ago

@sbouchex can you contribute with a PR?