-
Notifications
You must be signed in to change notification settings - Fork 313
Prometheus sink NPE in sanitizeMetricName when unit or aggregationTemporality is null. #6683
Description
Describe the bug
The prometheus sink throws NullPointerException in PrometheusTimeSeries.sanitizeMetricName() when processing metric events where the unit field or the aggregationTemporality field is null. The method calls .equals() on getAggregationTemporality() and .startsWith() on unit without null checks. These fields are optional in the OTEL metric model and are null when metrics come from sources that do not carry this metadata, such as Prometheus Remote Write v1.
To Reproduce
Steps to reproduce the behavior:
- Configure a Data Prepper pipeline with the prometheus source receiving Remote Write v1 data
- Configure the prometheus sink as the output of that pipeline
- Start a Prometheus instance with remote_write pointing to the Data Prepper source
- Observe repeated NullPointerException warnings in Data Prepper logs for every metric event
Expected behavior
The prometheus sink should handle null unit and null aggregationTemporality gracefully instead of throwing NullPointerException. A simple nullcheck before calling .equals() and .startsWith() on these fields would resolve both issues.
Exceptions
Stack trace for aggregationTemporality:
NullPointerException: Cannot invoke "String.equals(Object)" because the return value of
"org.opensearch.dataprepper.model.metric.Sum.getAggregationTemporality()" is null
at PrometheusTimeSeries.sanitizeMetricName(PrometheusTimeSeries.java:305)
at PrometheusTimeSeries.(PrometheusTimeSeries.java:96)
at PrometheusSinkBufferEntry.getTimeSeriesForEvent(PrometheusSinkBufferEntry.java:49)
Stack trace for unit:
NullPointerException: Cannot invoke "String.startsWith(String)" because "unit" is null
at PrometheusTimeSeries.sanitizeMetricName(PrometheusTimeSeries.java:310)
at PrometheusTimeSeries.(PrometheusTimeSeries.java:96)
at PrometheusSinkBufferEntry.getTimeSeriesForEvent(PrometheusSinkBufferEntry.java:49)
Environment (please complete the following information):
- OS: macOS (Darwin 25.3.0)
- Version: Data Prepper 2.15.0-SNAPSHOT (main branch)
Additional context
Found during end-to-end testing of the prometheus source plugin (PR #6627). The prometheus source produces valid OTEL metric events but Prometheus Remote Write v1 protocol does not carry unit or aggregation temporality metadata, so these fields are null.
The sink was built assuming these fields are always populated, which is only true for metrics coming from the OTel Collector. Current workaround is to set sanitize_names: false in the prometheus sink configuration to bypass the sanitizeMetricName() method entirely.
Metadata
Metadata
Assignees
Labels
Type
Projects
Status