While I was looking at the other issue, my IDE started notifying me that there were some issues with the code. I fixed those.
One of these was that a new logger was created and passed forward. This is actually not needed, as far as I remember, in logrus. You can just set the default and use log directly. Passing it on, copies a lock that exists inside the logger:
$ go vet .
# github.com/scross01/prometheus-klipper-exporter
./main.go:26:61: handler passes lock by value: github.com/sirupsen/logrus.Logger contains github.com/sirupsen/logrus.MutexWrap
./main.go:59:59: call of collector.New copies lock value: github.com/sirupsen/logrus.Logger contains github.com/sirupsen/logrus.MutexWrap
./main.go:87:17: call of handler copies lock value: github.com/sirupsen/logrus.Logger contains github.com/sirupsen/logrus.MutexWrap
The ioutil.ReadAll was replaced by io.ReadAll a while back. It's a drop-in replacement.
In New in collector.go, a collector was returned, which should then be exported (start with a capital letter).
There were some explicit type castings to float64 from a float64, which is reduntant.
The service's unit file has restart=Always. In systemd, this doesn't work as expected. If your service starts up too quickly, and then crashes to quickly, it will trigger the rate limit and stop trying to restart the service. This happened on my system when it crashed over the bug fixed in the previous PR. I added the rate limit configuration to hopefully make sure it doesn't trigger anymore.
I hope the changes in this PR are helpful. Please don't see them as nitpicking or critique on the code, I just can't stand my IDE yelling at me :)
While I was looking at the other issue, my IDE started notifying me that there were some issues with the code. I fixed those.
log
directly. Passing it on, copies a lock that exists inside the logger:The
ioutil.ReadAll
was replaced byio.ReadAll
a while back. It's a drop-in replacement.In
New
in collector.go, acollector
was returned, which should then be exported (start with a capital letter).There were some explicit type castings to float64 from a float64, which is reduntant.
The service's unit file has
restart=Always
. In systemd, this doesn't work as expected. If your service starts up too quickly, and then crashes to quickly, it will trigger the rate limit and stop trying to restart the service. This happened on my system when it crashed over the bug fixed in the previous PR. I added the rate limit configuration to hopefully make sure it doesn't trigger anymore.I hope the changes in this PR are helpful. Please don't see them as nitpicking or critique on the code, I just can't stand my IDE yelling at me :)