Skip to content

Commit

Permalink
chore: update charm libraries (#60)
Browse files Browse the repository at this point in the history
Co-authored-by: Github Actions <github-actions@github.com>
  • Loading branch information
github-actions[bot] and Github Actions authored May 1, 2023
1 parent a3347af commit 34b4ffc
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 36 deletions.
56 changes: 27 additions & 29 deletions lib/charms/grafana_k8s/v0/grafana_dashboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ def __init__(self, *args):
# Increment this PATCH version before using `charmcraft publish-lib` or reset
# to 0 if you are raising the major API version

LIBPATCH = 29
LIBPATCH = 30

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -582,7 +582,7 @@ def _convert_dashboard_fields(content: str, inject_dropdowns: bool = True) -> st

# If no existing template variables exist, just insert our own
if "templating" not in dict_content:
dict_content["templating"] = {"list": [d for d in template_dropdowns]} # type: ignore
dict_content["templating"] = {"list": list(template_dropdowns)} # type: ignore
else:
# Otherwise, set a flag so we can go back later
existing_templates = True
Expand Down Expand Up @@ -830,18 +830,18 @@ def _modify_panel(panel: dict, topology: dict, transformer: "CosTool") -> dict:

if "datasource" not in panel.keys():
continue
else:
if type(panel["datasource"]) == str:
if panel["datasource"] not in known_datasources:
continue
querytype = known_datasources[panel["datasource"]]
elif type(panel["datasource"]) == dict:
if panel["datasource"]["uid"] not in known_datasources:
continue
querytype = known_datasources[panel["datasource"]["uid"]]
else:
logger.error("Unknown datasource format: skipping")

if type(panel["datasource"]) == str:
if panel["datasource"] not in known_datasources:
continue
querytype = known_datasources[panel["datasource"]]
elif type(panel["datasource"]) == dict:
if panel["datasource"]["uid"] not in known_datasources:
continue
querytype = known_datasources[panel["datasource"]["uid"]]
else:
logger.error("Unknown datasource format: skipping")
continue

# Capture all values inside `[]` into a list which we'll iterate over later to
# put them back in-order. Then apply the regex again and replace everything with
Expand Down Expand Up @@ -901,13 +901,12 @@ def _type_convert_stored(obj):
"""Convert Stored* to their appropriate types, recursively."""
if isinstance(obj, StoredList):
return list(map(_type_convert_stored, obj))
elif isinstance(obj, StoredDict):
if isinstance(obj, StoredDict):
rdict = {} # type: Dict[Any, Any]
for k in obj.keys():
rdict[k] = _type_convert_stored(obj[k])
return rdict
else:
return obj
return obj


class GrafanaDashboardsChanged(EventBase):
Expand Down Expand Up @@ -1251,7 +1250,7 @@ def _juju_topology(self) -> Dict:
@property
def dashboard_templates(self) -> List:
"""Return a list of the known dashboard templates."""
return [v for v in self._stored.dashboard_templates.values()] # type: ignore
return list(self._stored.dashboard_templates.values()) # type: ignore


class GrafanaDashboardConsumer(Object):
Expand Down Expand Up @@ -1305,7 +1304,7 @@ def __init__(
self._relation_name = relation_name
self._tranformer = CosTool(self._charm)

self._stored.set_default(dashboards=dict()) # type: ignore
self._stored.set_default(dashboards={}) # type: ignore

self.framework.observe(
self._charm.on[self._relation_name].relation_changed,
Expand Down Expand Up @@ -1495,19 +1494,18 @@ def _render_dashboards_and_signal_changed(self, relation: Relation) -> bool: #

# Dropping dashboards for a relation needs to be signalled
return True
else:
stored_data = rendered_dashboards
currently_stored_data = self._get_stored_dashboards(relation.id)

coerced_data = (
_type_convert_stored(currently_stored_data) if currently_stored_data else {}
)
stored_data = rendered_dashboards
currently_stored_data = self._get_stored_dashboards(relation.id)

if not coerced_data == stored_data:
stored_dashboards = self.get_peer_data("dashboards")
stored_dashboards[relation.id] = stored_data
self.set_peer_data("dashboards", stored_dashboards)
return True
coerced_data = _type_convert_stored(currently_stored_data) if currently_stored_data else {}

if not coerced_data == stored_data:
stored_dashboards = self.get_peer_data("dashboards")
stored_dashboards[relation.id] = stored_data
self.set_peer_data("dashboards", stored_dashboards)
return True
return None # type: ignore

def _manage_dashboard_uid(self, dashboard: str, template: dict) -> str:
"""Add an uid to the dashboard if it is not present."""
Expand Down
14 changes: 7 additions & 7 deletions lib/charms/prometheus_k8s/v0/prometheus_scrape.py
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ def _on_scrape_targets_changed(self, event):

# Increment this PATCH version before using `charmcraft publish-lib` or reset
# to 0 if you are raising the major API version
LIBPATCH = 35
LIBPATCH = 36

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -715,13 +715,12 @@ def _type_convert_stored(obj):
"""Convert Stored* to their appropriate types, recursively."""
if isinstance(obj, StoredList):
return list(map(_type_convert_stored, obj))
elif isinstance(obj, StoredDict):
if isinstance(obj, StoredDict):
rdict = {} # type: Dict[Any, Any]
for k in obj.keys():
rdict[k] = _type_convert_stored(obj[k])
return rdict
else:
return obj
return obj


def _validate_relation_by_interface_and_direction(
Expand Down Expand Up @@ -1440,7 +1439,7 @@ def _dedupe_job_names(jobs: List[dict]):
job["job_name"] = "{}_{}".format(job["job_name"], hashed)
new_jobs = []
for key in jobs_dict:
new_jobs.extend([i for i in jobs_dict[key]])
new_jobs.extend(list(jobs_dict[key]))

# Deduplicate jobs which are equal
# Again this in O(n^2) but it should be okay
Expand Down Expand Up @@ -1796,8 +1795,7 @@ def _scrape_jobs(self) -> list:
jobs = self._jobs if self._jobs else [DEFAULT_JOB]
if callable(self._lookaside_jobs):
return jobs + PrometheusConfig.sanitize_scrape_configs(self._lookaside_jobs())
else:
return jobs
return jobs

@property
def _scrape_metadata(self) -> dict:
Expand Down Expand Up @@ -2078,6 +2076,7 @@ def set_target_job_data(self, targets: dict, app_name: str, **kwargs) -> None:
Args:
targets: a `dict` containing target information
app_name: a `str` identifying the application
kwargs: a `dict` of the extra arguments passed to the function
"""
if not self._charm.unit.is_leader():
return
Expand Down Expand Up @@ -2203,6 +2202,7 @@ def _static_scrape_job(self, targets, application_name, **kwargs) -> dict:
"port".
application_name: a string name of the application for
which this static scrape job is being constructed.
kwargs: a `dict` of the extra arguments passed to the function
Returns:
A dictionary corresponding to a Prometheus static scrape
Expand Down

0 comments on commit 34b4ffc

Please sign in to comment.