canonical / prometheus-juju-exporter

GNU General Public License v3.0
2 stars 8 forks source link

Rework usage of `Confuse` library #38

Open mkalcok opened 1 year ago

mkalcok commented 1 year ago

Currently we are using Confuse config library but I think we are doing it bit wrong. We parse config using template here https://github.com/canonical/prometheus-juju-exporter/blob/5b6ec18f807b02830eff55994b7d3324681d248a/prometheus_juju_exporter/config.py#L66-L69

But we don't use store the result. Essentially we are just validating that config matches the template. This forces use to reuse Confuse functions again when we want to get the value https://github.com/canonical/prometheus-juju-exporter/blob/5b6ec18f807b02830eff55994b7d3324681d248a/prometheus_juju_exporter/collector.py#L29

I think we should either store of the output of self.config.get(template) (which is dict) and later get values from that later (fast solution), or we could create dataclasses that represent each section of config (+root) and populate them using this dictionary. The second, bit more complex, solution would provide more unified interface to the config along with type hinting.