rkosegi / tuya-smartplug-exporter

Prometheus exporter for Tuya-based smartplug devices
Apache License 2.0
14 stars 3 forks source link

Runtime error after a single request to :9999/metrics #77

Closed Strimblaster closed 3 months ago

Strimblaster commented 3 months ago

Hi, tried to use your exporter in a container. The only thing I changed was the default config file to "/config/config.yaml" so I could mount a whole folder.

Honestly I have no idea were to start. Can this be a problem with my config file?

ts=2024-04-02T21:28:51.287Z caller=main.go:76 level=info msg="Starting tuya_smartplug_exporter" version="(version=v1.0.1, branch=HEAD, revision=db4abe8)" config=/config/config.yaml
ts=2024-04-02T21:28:51.288Z caller=main.go:89 level=info msg="Configured 1 devices"
ts=2024-04-02T21:28:51.288Z caller=tls_config.go:313 level=info msg="Listening on" address=[::]:9999
ts=2024-04-02T21:28:51.288Z caller=tls_config.go:316 level=info msg="TLS is disabled." http2=false address=[::]:9999
panic: runtime error: slice bounds out of range [:-86]

goroutine 49 [running]:
github.com/rkosegi/tuya-smartplug-exporter/pkg/proto.unpad(...)
        /build/pkg/proto/client.go:111
github.com/rkosegi/tuya-smartplug-exporter/pkg/proto.(*proto).Status(0x906a40?)
        /build/pkg/proto/client.go:71 +0xe5
github.com/rkosegi/tuya-smartplug-exporter/pkg/exporter.(*exporter).Collect(0xc0000d2540, 0xc0001ba760?)
        /build/pkg/exporter/exporter.go:54 +0x2e7
github.com/prometheus/client_golang/prometheus.(*Registry).Gather.func1()
        /go/pkg/mod/github.com/prometheus/client_golang@v1.18.0/prometheus/registry.go:455 +0x102
created by github.com/prometheus/client_golang/prometheus.(*Registry).Gather in goroutine 25
        /go/pkg/mod/github.com/prometheus/client_golang@v1.18.0/prometheus/registry.go:466 +0x568

Thanks

rkosegi commented 3 months ago

Hi @Strimblaster, thanks for bug report. Just by looking at stacktrace, it's clear that this is problem of invalid data reception. I was able to replicate same problem by putting incorrect device key in config file. I guess that's your problem as well. I will fix code to put more meaningful error in log instead of this stacktrace

Strimblaster commented 3 months ago

Just confirmed that it was in fact a incorrect device key. Fixed and now it works. Thanks!

rkosegi commented 3 months ago

If you encounter similar situation in future, you will got this message instead

ts=2024-04-05T05:54:47.658Z caller=exporter.go:56 level=warn msg="error during scrape" device=mydevice error="protocol error: runtime error: slice bounds out of range [:-1], check device key"