billykwooten / openweather-exporter

Prometheus exporter utilizing Openweather API (https://openweathermap.org/api) to gather weather metrics.
Apache License 2.0
57 stars 23 forks source link

Fix bug where ttlCache returns the same values for multiple locations #36

Closed jssjr closed 1 year ago

jssjr commented 1 year ago

https://github.com/billykwooten/openweather-exporter/pull/29 introduced caching, but uses a common cache key for all locations in OpenweatherCollector resulting in the same result being returned for each location queried.

To confirm the prior behavior, list multiple pipe-delimited locations (e.g. --location 'New York, US|Chicago, US') and curl the metrics endpoint. Each metric key will have the same value for both location tags.

This sets the cache key strings for each location in the Location struct when instantiated, then uses those keys in subsequent calls to the ttlcache when fetching data from the OWM API. I don't work with golang daily, so there may be a more idiomatic approach to fixing this. Suggestions welcome!

billykwooten commented 1 year ago

Thank you for this one @jssjr, this was an oversight on my part when implementing TTL