René Zeidler created NIFI-10666:
-----------------------------------

             Summary: PrometheusReportingTask does not use UTF-8 encoding on 
/metrics/ endpoint
                 Key: NIFI-10666
                 URL: https://issues.apache.org/jira/browse/NIFI-10666
             Project: Apache NiFi
          Issue Type: Bug
          Components: Extensions
    Affects Versions: 1.16.3
            Reporter: René Zeidler
         Attachments: missing-header.png

We have created a default PrometheusReportingTask for our NiFi instance and 
tried to consume the metrics with Prometheus. However, Prometheus threw the 
following error:
{code:java}
ts=2022-10-19T12:25:18.110Z caller=scrape.go:1332 level=debug component="scrape 
manager" scrape_pool=nifi-cluster target=http://***nifi***:9092/metrics 
msg="Append failed" err="invalid UTF-8 label value" {code}
Upon further inspection, we noticed that the /metrics/ endpoint exposed by the 
reporting task does not use UTF-8 encoding, which is required by Prometheus.

Our flow uses non-ASCII characters (in our case German umlauts like "ü"). As a 
workaround, removing those characters fixes the Prometheus error, but this is 
not practical for a large flow in German language.

Opening the /metrics/ endpoint in a browser confirms that the encoding used is 
not UTF-8:
{code:java}
> document.characterSet
'windows-1252' {code}
----
The responsible code might be here:

[https://github.com/apache/nifi/blob/2be5c26f287469f4f19f0fa759d6c1b56dc0e348/nifi-nar-bundles/nifi-prometheus-bundle/nifi-prometheus-reporting-task/src/main/java/org/apache/nifi/reporting/prometheus/PrometheusServer.java#L67]

The PrometheusServer used by the reporting task uses an OutputStreamWriter with 
the default encoding, instead of explicitly using UTF-8. The Content-Type 
header set in that function also does not get passed along (see screenshot)
----
Our cluster is still on 1.16.3, but once we update to 1.18.0 we can update this 
report to confirm that the issue still persists. Considering that there were no 
code changes in the Prometheus reporting task, it is likely that the issue 
still persists in the current version.

If someone can confirm this before we update, feel free to update the issue :)



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to