strimzi / metrics-reporter

Prometheus Metrics Reporter for Apache Kafka server and client components
Apache License 2.0
5 stars 10 forks source link

Address SpotBugs issues #20

Closed OwenCorrigan76 closed 4 months ago

OwenCorrigan76 commented 7 months ago

When running Spotbugs against the project, it was throwing the following errors:


[ERROR] Low: KafkaPrometheusMetricsReporter.httpServer not initialized in constructor and dereferenced in io.strimzi.kafka.metrics.KafkaPrometheusMetricsReporter.getPort() [io.strimzi.kafka.metrics.KafkaPrometheusMetricsReporter] At KafkaPrometheusMetricsReporter.java:[line 90] UWF_FIELD_NOT_INITIALIZED_IN_CONSTRUCTOR
[ERROR] Low: KafkaPrometheusMetricsReporter.kafkaMetricsCollector not initialized in constructor and dereferenced in io.strimzi.kafka.metrics.KafkaPrometheusMetricsReporter.contextChange(MetricsContext) [io.strimzi.kafka.metrics.KafkaPrometheusMetricsReporter] At KafkaPrometheusMetricsReporter.java:[line 86] UWF_FIELD_NOT_INITIALIZED_IN_CONSTRUCTOR
[ERROR] Low: KafkaPrometheusMetricsReporter.kafkaMetricsCollector not initialized in constructor and dereferenced in io.strimzi.kafka.metrics.KafkaPrometheusMetricsReporter.metricChange(KafkaMetric) [io.strimzi.kafka.metrics.KafkaPrometheusMetricsReporter] At KafkaPrometheusMetricsReporter.java:[line 55] UWF_FIELD_NOT_INITIALIZED_IN_CONSTRUCTOR
[ERROR] Low: KafkaPrometheusMetricsReporter.kafkaMetricsCollector not initialized in constructor and dereferenced in io.strimzi.kafka.metrics.KafkaPrometheusMetricsReporter.metricRemoval(KafkaMetric) [io.strimzi.kafka.metrics.KafkaPrometheusMetricsReporter] At KafkaPrometheusMetricsReporter.java:[line 61] UWF_FIELD_NOT_INITIALIZED_IN_CONSTRUCTOR```

This PR will try to fix this issue by making KafkaMetricsCollector configurable and adding to necessary constructors items. 
mimaison commented 4 months ago

Done in https://github.com/strimzi/metrics-reporter/pull/31, so closing this PR.