EOS Prometheus exporter needs better input sanitization

Finally tried out the EOS Prometheus exporter. We immediately ran into issues where the process would crash hard on some input:

panic: label value "ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ\xc0\xfcG\xf3\xe1\x7f" is not valid UTF-8

or

panic: label value "ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ\xa0E\xa0\xe0\xe2\x7f" is not valid UTF-8

Turns out, it’s choking on the who -a output as I eventually found this in the output:
client : 99 := http (https) [ ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ���� ] { XRoot } 28s idle time

Full output of a crash:
HTTP request sent, awaiting response… panic: label value “ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ\x80\xb9sT\xe2\x7f” is not valid UTF-8

goroutine 283 [running]:
github.com/prometheus/client_golang/prometheus.(*GaugeVec).WithLabelValues(...)
	/root/go/pkg/mod/github.com/prometheus/client_golang@v1.12.2/prometheus/gauge.go:217
gitlab.cern.ch/rvalverd/eos_exporter/collector.(*WhoCollector).collectWhoDF(0xc000245098)
	/root/eos_exporter/collector/who.go:105 +0x479
gitlab.cern.ch/rvalverd/eos_exporter/collector.(*WhoCollector).Collect(0xc000245098, 0xc00010e120?)
	/root/eos_exporter/collector/who.go:124 +0x29
main.(*EOSExporter).Collect(0xc00020ffb0?, 0xc00020ff60?)
	/root/eos_exporter/eos_exporter.go:102 +0xa2
github.com/prometheus/client_golang/prometheus.(*Registry).Gather.func1()
	/root/go/pkg/mod/github.com/prometheus/client_golang@v1.12.2/prometheus/registry.go:446 +0x102
created by github.com/prometheus/client_golang/prometheus.(*Registry).Gather in goroutine 282
	/root/go/pkg/mod/github.com/prometheus/client_golang@v1.12.2/prometheus/registry.go:538 +0xb4b

Pure (bad) luck that we ran into this I guess, but it should be a simple fix to sanitize the input from the who command.


Dan Szkola
FNAL

In the meantime, I put in a simple change that just turns unknown characters into a UTF Null character. “�” Not the cleanest of fixes, but keeps it from crashing for now. Best thing may just be to leave off the replacement char altogether and just drop the invalid characters.

diff eos.go eos.go.bak
1149c1149
< 			Gateway: strings.ToValidUTF8(strings.Trim(kv["gateway"], "\""), "�"), // clean double quotes
---
> 			Gateway: strings.Trim(kv["gateway"], "\""), // clean double quotes


Dan Szkola
FNAL