Skip to content

Commit

Permalink
chore: update charm libraries (#123)
Browse files Browse the repository at this point in the history
Co-authored-by: Github Actions <github-actions@github.com>
  • Loading branch information
observability-noctua-bot and Github Actions authored Feb 1, 2023
1 parent 4c8a3be commit d2d19a9
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 5 deletions.
30 changes: 28 additions & 2 deletions lib/charms/prometheus_k8s/v0/prometheus_scrape.py
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,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 = 29
LIBPATCH = 30

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -1871,7 +1871,13 @@ class MetricsEndpointAggregator(Object):

_stored = StoredState()

def __init__(self, charm, relation_names: Optional[dict] = None, relabel_instance=True):
def __init__(
self,
charm,
relation_names: Optional[dict] = None,
relabel_instance=True,
resolve_addresses=False,
):
"""Construct a `MetricsEndpointAggregator`.
Args:
Expand All @@ -1887,6 +1893,9 @@ def __init__(self, charm, relation_names: Optional[dict] = None, relabel_instanc
the Prometheus charm.
relabel_instance: A boolean flag indicating if Prometheus
scrape job "instance" labels must refer to Juju Topology.
resolve_addresses: A boolean flag indiccating if the aggregator
should attempt to perform DNS lookups of targets and append
a `dns_name` label
"""
self._charm = charm

Expand All @@ -1902,6 +1911,7 @@ def __init__(self, charm, relation_names: Optional[dict] = None, relabel_instanc
self._stored.set_default(jobs=[], alert_rules=[])

self._relabel_instance = relabel_instance
self._resolve_addresses = resolve_addresses

# manage Prometheus charm relation events
prometheus_events = self._charm.on[self._prometheus_relation]
Expand Down Expand Up @@ -2099,6 +2109,7 @@ def _static_scrape_job(self, targets, application_name, **kwargs) -> dict:
"""
juju_model = self.model.name
juju_model_uuid = self.model.uuid

job = {
"job_name": self._job_name(application_name),
"static_configs": [
Expand All @@ -2110,6 +2121,7 @@ def _static_scrape_job(self, targets, application_name, **kwargs) -> dict:
"juju_application": application_name,
"juju_unit": unit_name,
"host": target["hostname"],
**self._static_config_extra_labels(target),
},
}
for unit_name, target in targets.items()
Expand All @@ -2120,6 +2132,20 @@ def _static_scrape_job(self, targets, application_name, **kwargs) -> dict:

return job

def _static_config_extra_labels(self, target: Dict[str, str]) -> Dict[str, str]:
"""Build a list of extra static config parameters, if specified."""
extra_info = {}

if self._resolve_addresses:
try:
dns_name = socket.gethostbyaddr(target["hostname"])[0]
except OSError:
logger.debug("Could not perform DNS lookup for %s", target["hostname"])
dns_name = target["hostname"]
extra_info["dns_name"] = dns_name

return extra_info

@property
def _relabel_configs(self) -> list:
"""Create Juju topology relabeling configuration.
Expand Down
6 changes: 3 additions & 3 deletions lib/charms/traefik_k8s/v1/ingress.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def _on_ingress_revoked(self, event: IngressPerAppRevokedEvent):

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

DEFAULT_RELATION_NAME = "ingress"
RELATION_INTERFACE = "ingress"
Expand Down Expand Up @@ -314,7 +314,7 @@ def _get_requirer_data(self, relation: Relation) -> RequirerData: # type: ignor
_validate_data(remote_data, INGRESS_REQUIRES_APP_SCHEMA)
remote_data["port"] = int(remote_data["port"])
remote_data["strip-prefix"] = bool(remote_data.get("strip-prefix", False))
return remote_data
return typing.cast(RequirerData, remote_data)

def get_data(self, relation: Relation) -> RequirerData: # type: ignore
"""Fetch the remote app's databag, i.e. the requirer data."""
Expand All @@ -339,7 +339,7 @@ def _provided_url(self, relation: Relation) -> ProviderIngressData: # type: ign
# relation_broken events.
# Also, only leader units can read own app databags.
# FIXME https://github.com/canonical/traefik-k8s-operator/issues/34
return {} # noqa
return typing.cast(ProviderIngressData, {}) # noqa

# fetch the provider's app databag
raw_data = relation.data[self.app].get("ingress")
Expand Down

0 comments on commit d2d19a9

Please sign in to comment.