Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
michaeldmitry committed Jan 23, 2025
1 parent 112c8a8 commit a6d8a5a
Show file tree
Hide file tree
Showing 5 changed files with 101 additions and 312 deletions.
301 changes: 0 additions & 301 deletions lib/charms/observability_libs/v0/juju_topology.py

This file was deleted.

21 changes: 19 additions & 2 deletions lib/charms/parca_k8s/v0/parca_scrape.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,10 +171,11 @@ def _on_scrape_targets_changed(self, event):
import json
import logging
import socket
from cosl import JujuTopology
from typing import List, Optional, Union
from ops.model import Relation

import ops
from charms.observability_libs.v0.juju_topology import JujuTopology

# The unique Charmhub library identifier, never change it
LIBID = "dbc3d2e89cb24917b99c40e14354dd25"
Expand All @@ -184,7 +185,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 = 2
LIBPATCH = 3


logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -804,6 +805,22 @@ def _is_valid_unit_address(self, address: str) -> bool:
except ValueError:
return False

@property
def relations(self) -> List[Relation]:
"""The profiling provider relations associated with this endpoint."""
return self._charm.model.relations[self._relation_name]

def is_ready(self) -> bool:
"""Return True if any profiling provider relation is ready else return False."""
relations = self.relations

if not relations:
logger.debug(f"no relation on {self._relation_name!r}.")
return False

# TODO: once we have a pydantic model, we can also check for the integrity of the databags.
return any((relation.app and relation.data) for relation in relations)

@property
def _scrape_jobs(self) -> list:
"""Fetch list of scrape jobs.
Expand Down
Loading

0 comments on commit a6d8a5a

Please sign in to comment.