jenkinsci / prometheus-plugin

Jenkins Prometheus Plugin
https://plugins.jenkins.io/prometheus/
Apache License 2.0
181 stars 151 forks source link

Delay initialization of Prometheus Plugin to fix startup issues in certain environments #648

Closed Waschndolos closed 5 months ago

Waschndolos commented 5 months ago

Fixes #647

Changes proposed

Changing Initialization logic

jonesbusy commented 5 months ago

On 2.5.1 I don't have issue with metrics collection

2024-03-28T05:00:33.493Z [DEBUG] [Thread=Metrics.afterExtensionsAugmented] - org.jenkinsci.plugins.prometheus.JobCollector # Collecting metrics for prometheus 

On 2.5.2 I see all the time and it's preventing the plugin to load

Caused by: java.lang.IllegalArgumentException: Failed to register Collector of type JenkinsStatusCollector: default_jenkins_version_info is already in use by another Collector of type JenkinsStatusCollector
        at io.prometheus.client.CollectorRegistry.register(CollectorRegistry.java:57)

Using the hpi 2.5.3-SNAPSHOT by rebuilding this PR I get now after a controller restart. The first initialization work

2024-03-28T05:02:48.905Z [INFO] [Thread=pool-182-thread-2] - jenkins.InitReactorRunner # Started initialization 
2024-03-28T05:02:48.908Z [DEBUG] [Thread=Initializers.initializePrometheusMetrics] - org.jenkinsci.plugins.prometheus.init.Initializers # Initializing Prometheus Plugin 
2024-03-28T05:02:48.908Z [ERROR] [Thread=Initializers.initializePrometheusMetrics] - org.jenkinsci.plugins.prometheus.init.Initializers # Unable to load Prometheus Plugin. Collecting Metrics won't work 
java.lang.IllegalStateException: Found no instances of org.jenkinsci.plugins.prometheus.service.PrometheusMetrics registered (possible annotation processor issue); try using `mvn clean test -Dtest=…` rather than an IDE test runner
        at hudson.ExtensionList.lookupSingleton(ExtensionList.java:454)

But doesn't prevent the plugin to load.

Cannot we keep the behavior of 2.5.1 that was working all the time ?

Thanks

Waschndolos commented 5 months ago

Closing. Will provide new attempt with reverting commits