prometheus / prometheus/client_java
Code quality improvements
Personne n'a encore pris cette issue.
- Langage dominant
- Java
- Étoiles
- 2.3k
- Forks
- 833
- Merge moyen
- 2 j 16 h
- PR mergées (30 j)
- 86
Description
Code Quality Improvement Plan
This document tracks code quality improvements for the Prometheus Java Client library. Work through these items incrementally across sessions.
High Priority
1. Add Missing Test Coverage for Exporter Modules
-
prometheus-metrics-exporter-common- base module, no tests -
prometheus-metrics-exporter-servlet-jakarta- no tests -
prometheus-metrics-exporter-servlet-javax- no tests -
prometheus-metrics-exporter-opentelemetry-otel-agent-resources- no tests
2. Eliminate Dropwizard Module Duplication
- Create shared base class or use generics for
prometheus-metrics-instrumentation-dropwizardandprometheus-metrics-instrumentation-dropwizard5(~297 lines each, nearly identical)
3. Address Technical Debt (TODOs)
-
prometheus-metrics-core/src/main/java/io/prometheus/metrics/core/metrics/Histogram.java:965- "reset interval isn't tested yet" -
prometheus-metrics-core/src/main/java/io/prometheus/metrics/core/metrics/Summary.java:205- "Exemplars (are hard-coded as empty)" -
prometheus-metrics-core/src/main/java/io/prometheus/metrics/core/metrics/SlidingWindow.java:18- "synchronized implementation, room for optimization" -
prometheus-metrics-config/src/main/java/io/prometheus/metrics/config/PrometheusPropertiesLoader.java:105- "Add environment variables like EXEMPLARS_ENABLED" -
prometheus-metrics-exporter-opentelemetry/src/main/java/io/prometheus/metrics/exporter/opentelemetry/PrometheusMetricProducer.java:44- "filter configuration for OpenTelemetry exporter" -
prometheus-metrics-config/src/main/java/io/prometheus/metrics/config/ExporterOpenTelemetryProperties.java:7- "JavaDoc missing"
4. Improve Exception Handling
Replace broad catch (Exception e) with specific exception types:
-
prometheus-metrics-instrumentation-dropwizard5/src/main/java/.../DropwizardExports.java:237 -
prometheus-metrics-instrumentation-caffeine/src/main/java/.../CacheMetricsCollector.java:229 -
prometheus-metrics-exporter-opentelemetry/src/main/java/.../PrometheusInstrumentationScope.java:47 -
prometheus-metrics-exporter-opentelemetry/src/main/java/.../OtelAutoConfig.java:115 -
prometheus-metrics-instrumentation-jvm/src/main/java/.../JvmNativeMemoryMetrics.java:166 -
prometheus-metrics-exporter-httpserver/src/main/java/.../HttpExchangeAdapter.java:115
Medium Priority
5. Add Branch Coverage to JaCoCo
- Update
pom.xmlto add branch coverage requirement (~50% minimum)
<limit>
<counter>BRANCH</counter>
<value>COVEREDRATIO</value>
<minimum>0.50</minimum>
</limit>
6. Raise Minimum Coverage Thresholds
Current thresholds to review:
-
prometheus-metrics-exporter-httpserver- 45% (raise to 60%) -
prometheus-metrics-instrumentation-dropwizard5- 50% (raise to 60%) -
prometheus-metrics-exposition-textformats- 50% (raise to 60%) -
prometheus-metrics-instrumentation-jvm- 55% (raise to 60%)
7. Add SpotBugs
- Add
spotbugs-maven-plugintopom.xml - Configure with appropriate rule set
8. Narrow Checkstyle Suppressions
- Review
checkstyle-suppressions.xml- currently suppresses ALL Javadoc checks globally - Narrow to specific packages/classes that need exceptions
Lower Priority
9. Refactor Large Classes
-
prometheus-metrics-core/src/main/java/.../Histogram.java(978 lines) - consider extracting native histogram logic
10. Document Configuration Classes
-
PrometheusPropertiesLoader- add JavaDoc -
ExporterPropertiesand related classes - add JavaDoc -
ExporterOpenTelemetryProperties- add JavaDoc (noted in TODO)
11. Consolidate Servlet Exporter Duplication
- Extract common logic from
servlet-jakartaandservlet-javaxintoexporter-common
12. Add Mutation Testing
- Add Pitest (
pitest-maven) for critical modules - Start with
prometheus-metrics-coreandprometheus-metrics-model
Progress Notes
Add notes here as items are completed:
| Date | Item | Notes |
|---|---|---|
| 2026-01-24 | Missing Test Coverage for Exporter Modules | Added 55 tests across 4 modules: exporter-common (22 tests), servlet-jakarta (14 tests), servlet-javax (14 tests), otel-agent-resources (5 tests). All tests passing. |
| 2026-01-24 | Eliminate Dropwizard Module Duplication | Created AbstractDropwizardExports base class (267 lines) with generic type parameters. Reduced dropwizard module from 297 to 209 lines (-88 lines, -30%), dropwizard5 module from 297 to 212 lines (-85 lines, -29%). All tests passing (32 tests dropwizard5, 13 tests dropwizard). |
Guide de contribution
Ouvrir le guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Piste de recherche
Considérez ceci comme un plan de suivi plutôt que comme une modification unique. Commencez par sélectionner un élément non coché et lire l’entrée indiquée dans le fichier, pom.xml ou checkstyle-suppressions.xml ; définissez les critères d’achèvement de cet élément avant d’apporter des modifications. Exécutez les tests du module ou les vérifications de build pertinentes et ne mettez à jour la liste de contrôle qu’une fois le travail sélectionné vérifié.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Évaluation
- Stack technique
- java
- Domaine
- build-system, testing, tooling
- Type d'issue
- Refactorisation
- Difficulté
- 5/5
- Temps estimé
- Plus d'une semaine
- Activité
- À l'abandon
- Clarté
- À clarifier
- Accessibilité débutants
- 25/100