Skip to content

Commit

Permalink
Doc fix
Browse files Browse the repository at this point in the history
  • Loading branch information
sed-i committed Sep 26, 2022
1 parent a40e05d commit bd03af3
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 20 deletions.
13 changes: 8 additions & 5 deletions lib/charms/prometheus_k8s/v0/prometheus_scrape.py
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,7 @@ def _on_scrape_targets_changed(self, event):

class PrometheusConfig:
"""A namespace for utility functions for manipulating the prometheus config dict."""

@staticmethod
def sanitize_scrape_config(job: dict) -> dict:
"""Restrict permissible scrape configuration options.
Expand Down Expand Up @@ -401,21 +402,21 @@ def sanitize_scrape_config(job: dict) -> dict:

@staticmethod
def prefix_job_names(scrape_configs: List[dict], prefix: str) -> List[dict]:
"""Adds the given prefix to all the job names in the given scrape_configs list."""
modified_scrape_configs = []
for scrape_config in scrape_configs:
job_name = scrape_config.get("job_name")
modified = scrape_config.copy()
modified["job_name"] = prefix + "_" + job_name if job_name else prefix
modified_scrape_configs.append(modified)

return modified_scrape_configs

return modified_scrape_configs

@staticmethod
def expand_wildcard_targets_into_individual_jobs(
scrape_jobs: List[dict], hosts: dict
) -> List[dict]:
# TODO append unit num to job name
"""Extract wildcard hosts from the given scrape_configs list into separate jobs."""
# hosts = self._relation_hosts(relation)

modified_scrape_jobs = []
Expand Down Expand Up @@ -1125,14 +1126,16 @@ def _static_scrape_config(self, relation) -> list:

if not scrape_metadata:
return scrape_jobs

job_name_prefix = "juju_{}_prometheus_scrape".format(
JujuTopology.from_dict(scrape_metadata).identifier
)
scrape_jobs = PrometheusConfig.prefix_job_names(scrape_jobs, job_name_prefix)

hosts = self._relation_hosts(relation)
# scrape_jobs = PrometheusConfig.expand_wildcard_targets_into_individual_jobs(scrape_jobs, hosts)
# scrape_jobs = PrometheusConfig.expand_wildcard_targets_into_individual_jobs(
# scrape_jobs, hosts
# )

labeled_job_configs = []
for job in scrape_jobs:
Expand Down
20 changes: 5 additions & 15 deletions tests/unit/test_prometheus_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@ def test_single_wildcard_target(self):
}

# WHEN the jobs are processed
expanded = PrometheusConfig.expand_wildcard_targets_into_individual_jobs(
jobs, hosts
)
expanded = PrometheusConfig.expand_wildcard_targets_into_individual_jobs(jobs, hosts)

# THEN each wildcard target is extracted into its own job
# AND the job name is suffixed by the unit number
Expand Down Expand Up @@ -61,9 +59,7 @@ def test_single_wildcard_target_with_metrics(self):
}

# WHEN the jobs are processed
expanded = PrometheusConfig.expand_wildcard_targets_into_individual_jobs(
jobs, hosts
)
expanded = PrometheusConfig.expand_wildcard_targets_into_individual_jobs(jobs, hosts)

# THEN each wildcard target is extracted into its own job
# AND the job name is suffixed by the unit number
Expand Down Expand Up @@ -101,9 +97,7 @@ def test_mixed_targets_in_same_list(self):
}

# WHEN the jobs are processed
expanded = PrometheusConfig.expand_wildcard_targets_into_individual_jobs(
jobs, hosts
)
expanded = PrometheusConfig.expand_wildcard_targets_into_individual_jobs(jobs, hosts)

# THEN each wildcard target is extracted into its own job
# AND all non-wildcard targets are kept in the same static config in their own job
Expand Down Expand Up @@ -146,9 +140,7 @@ def test_mixed_targets_in_same_list_without_port_number(self):
}

# WHEN the jobs are processed
expanded = PrometheusConfig.expand_wildcard_targets_into_individual_jobs(
jobs, hosts
)
expanded = PrometheusConfig.expand_wildcard_targets_into_individual_jobs(jobs, hosts)

# THEN port is also omitted in job specs
self.assertEqual(
Expand Down Expand Up @@ -190,9 +182,7 @@ def test_mixed_targets_in_sepatate_lists_in_same_static_config(self):
}

# WHEN the jobs are processed
expanded = PrometheusConfig.expand_wildcard_targets_into_individual_jobs(
jobs, hosts
)
expanded = PrometheusConfig.expand_wildcard_targets_into_individual_jobs(jobs, hosts)

# THEN each wildcard target is extracted into its own job
# AND all non-wildcard targets are kept in the same static configs list in their own job
Expand Down

0 comments on commit bd03af3

Please sign in to comment.