|
| 1 | +# Code Quality Improvement Plan |
| 2 | + |
| 3 | +This document tracks code quality improvements for the Prometheus Java Client library. Work through these items incrementally across sessions. |
| 4 | + |
| 5 | +## High Priority |
| 6 | + |
| 7 | +### 1. Add Missing Test Coverage for Exporter Modules |
| 8 | +- [x] `prometheus-metrics-exporter-common` - base module, no tests |
| 9 | +- [x] `prometheus-metrics-exporter-servlet-jakarta` - no tests |
| 10 | +- [x] `prometheus-metrics-exporter-servlet-javax` - no tests |
| 11 | +- [x] `prometheus-metrics-exporter-opentelemetry-otel-agent-resources` - no tests |
| 12 | + |
| 13 | +### 2. Eliminate Dropwizard Module Duplication |
| 14 | +- [x] Create shared base class or use generics for `prometheus-metrics-instrumentation-dropwizard` and `prometheus-metrics-instrumentation-dropwizard5` (~297 lines each, nearly identical) |
| 15 | + |
| 16 | +### 3. Address Technical Debt (TODOs) |
| 17 | +- [ ] `prometheus-metrics-core/src/main/java/io/prometheus/metrics/core/metrics/Histogram.java:965` - "reset interval isn't tested yet" |
| 18 | +- [ ] `prometheus-metrics-core/src/main/java/io/prometheus/metrics/core/metrics/Summary.java:205` - "Exemplars (are hard-coded as empty)" |
| 19 | +- [ ] `prometheus-metrics-core/src/main/java/io/prometheus/metrics/core/metrics/SlidingWindow.java:18` - "synchronized implementation, room for optimization" |
| 20 | +- [ ] `prometheus-metrics-config/src/main/java/io/prometheus/metrics/config/PrometheusPropertiesLoader.java:105` - "Add environment variables like EXEMPLARS_ENABLED" |
| 21 | +- [ ] `prometheus-metrics-exporter-opentelemetry/src/main/java/io/prometheus/metrics/exporter/opentelemetry/PrometheusMetricProducer.java:44` - "filter configuration for OpenTelemetry exporter" |
| 22 | +- [ ] `prometheus-metrics-config/src/main/java/io/prometheus/metrics/config/ExporterOpenTelemetryProperties.java:7` - "JavaDoc missing" |
| 23 | + |
| 24 | +### 4. Improve Exception Handling |
| 25 | +Replace broad `catch (Exception e)` with specific exception types: |
| 26 | +- [ ] `prometheus-metrics-instrumentation-dropwizard5/src/main/java/.../DropwizardExports.java:237` |
| 27 | +- [ ] `prometheus-metrics-instrumentation-caffeine/src/main/java/.../CacheMetricsCollector.java:229` |
| 28 | +- [ ] `prometheus-metrics-exporter-opentelemetry/src/main/java/.../PrometheusInstrumentationScope.java:47` |
| 29 | +- [ ] `prometheus-metrics-exporter-opentelemetry/src/main/java/.../OtelAutoConfig.java:115` |
| 30 | +- [ ] `prometheus-metrics-instrumentation-jvm/src/main/java/.../JvmNativeMemoryMetrics.java:166` |
| 31 | +- [ ] `prometheus-metrics-exporter-httpserver/src/main/java/.../HttpExchangeAdapter.java:115` |
| 32 | + |
| 33 | +## Medium Priority |
| 34 | + |
| 35 | +### 5. Add Branch Coverage to JaCoCo |
| 36 | +- [ ] Update `pom.xml` to add branch coverage requirement (~50% minimum) |
| 37 | +```xml |
| 38 | +<limit> |
| 39 | + <counter>BRANCH</counter> |
| 40 | + <value>COVEREDRATIO</value> |
| 41 | + <minimum>0.50</minimum> |
| 42 | +</limit> |
| 43 | +``` |
| 44 | + |
| 45 | +### 6. Raise Minimum Coverage Thresholds |
| 46 | +Current thresholds to review: |
| 47 | +- [ ] `prometheus-metrics-exporter-httpserver` - 45% (raise to 60%) |
| 48 | +- [ ] `prometheus-metrics-instrumentation-dropwizard5` - 50% (raise to 60%) |
| 49 | +- [ ] `prometheus-metrics-exposition-textformats` - 50% (raise to 60%) |
| 50 | +- [ ] `prometheus-metrics-instrumentation-jvm` - 55% (raise to 60%) |
| 51 | + |
| 52 | +### 7. Add SpotBugs |
| 53 | +- [ ] Add `spotbugs-maven-plugin` to `pom.xml` |
| 54 | +- [ ] Configure with appropriate rule set |
| 55 | + |
| 56 | +### 8. Narrow Checkstyle Suppressions |
| 57 | +- [ ] Review `checkstyle-suppressions.xml` - currently suppresses ALL Javadoc checks globally |
| 58 | +- [ ] Narrow to specific packages/classes that need exceptions |
| 59 | + |
| 60 | +## Lower Priority |
| 61 | + |
| 62 | +### 9. Refactor Large Classes |
| 63 | +- [ ] `prometheus-metrics-core/src/main/java/.../Histogram.java` (978 lines) - consider extracting native histogram logic |
| 64 | + |
| 65 | +### 10. Document Configuration Classes |
| 66 | +- [ ] `PrometheusPropertiesLoader` - add JavaDoc |
| 67 | +- [ ] `ExporterProperties` and related classes - add JavaDoc |
| 68 | +- [ ] `ExporterOpenTelemetryProperties` - add JavaDoc (noted in TODO) |
| 69 | + |
| 70 | +### 11. Consolidate Servlet Exporter Duplication |
| 71 | +- [ ] Extract common logic from `servlet-jakarta` and `servlet-javax` into `exporter-common` |
| 72 | + |
| 73 | +### 12. Add Mutation Testing |
| 74 | +- [ ] Add Pitest (`pitest-maven`) for critical modules |
| 75 | +- [ ] Start with `prometheus-metrics-core` and `prometheus-metrics-model` |
| 76 | + |
| 77 | +--- |
| 78 | + |
| 79 | +## Progress Notes |
| 80 | + |
| 81 | +_Add notes here as items are completed:_ |
| 82 | + |
| 83 | +| Date | Item | Notes | |
| 84 | +|------|------|-------| |
| 85 | +| 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. | |
| 86 | +| 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). | |
0 commit comments