canonical / prometheus-k8s-operator

This charmed operator automates the operational procedures of running Prometheus, an open-source metrics backend.
https://charmhub.io/prometheus-k8s
Apache License 2.0
21 stars 34 forks source link

fix: tell type checkers that the config options are strings #587

Closed tonyandrewmeyer closed 4 months ago

tonyandrewmeyer commented 4 months ago

Issue

ops<=2.12 wrongly has self.config[x] typed as str, when actually it could be an int, float, bool, or str, depending on the config type. We're fixing this in ops:#1183, but that will break static checking that currently assumes that the config is a str (because ops doesn't validate the schema, so all options will be bool|int|float|str).

Solution

Six typing.cast calls where the config values are loaded and used where the type should be str.

Context

Covered above.

Testing Instructions

Run tox -e static-charm with/without the PR with ops 2.12 and with either the PR branch linked above or once that's merged ops main/2.13.

Upgrade Notes

N/A

tonyandrewmeyer commented 4 months ago

Let me know if there's anything else I need to do here - if we can get this merged then we can enable the CI tests in ops against this charm, which would be great :). Thanks!