Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use as_dict() because label_matcher_dict excludes unit #67

Merged
merged 7 commits into from
Mar 8, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion lib/charms/grafana_agent/v0/cos_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -700,10 +700,17 @@ def metrics_jobs(self) -> List[Dict]:

# Apply labels to the scrape jobs
for static_config in job.get("static_configs", []):
topo_as_dict = topology.as_dict(excluded_keys=["charm_name"])
static_config["labels"] = {
# Be sure to keep labels from static_config
**static_config.get("labels", {}),
**topology.label_matcher_dict,
# TODO: We should add a new method in juju_topology.py
# that like `as_dict` method, returns the keys with juju_ prefix
Abuelodelanada marked this conversation as resolved.
Show resolved Hide resolved
Abuelodelanada marked this conversation as resolved.
Show resolved Hide resolved
**{
"juju_{}".format(key): value
for key, value in topo_as_dict.items()
if value
},
}

scrape_jobs.append(job)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from pytest_operator.plugin import OpsTest

agent = SimpleNamespace(name="agent")
hwo = SimpleNamespace(charm="hardware-observer", name="hwo")
sed-i marked this conversation as resolved.
Show resolved Hide resolved
principal = SimpleNamespace(charm="ubuntu", name="principal")

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -52,6 +53,9 @@ async def test_build_and_deploy(ops_test: OpsTest, grafana_agent_charm):
jammy_charm_path, application_name=agent.name, num_units=0, series="jammy"
)

# Hardware Observer
await ops_test.model.deploy(hwo.charm, application_name=hwo.name, series="jammy")

# Placeholder for o11y relations (otherwise grafana agent charm is in blocked status)
await ops_test.model.deploy(
"grafana-cloud-integrator",
Expand All @@ -70,6 +74,8 @@ async def test_build_and_deploy(ops_test: OpsTest, grafana_agent_charm):
async def test_service(ops_test: OpsTest):
# WHEN the charm is related to a principal over `juju-info`
await ops_test.model.add_relation("agent:juju-info", principal.name)
await ops_test.model.add_relation("hwo:general-info", principal.name)
await ops_test.model.add_relation("hwo:cos-agent", "agent:cos-agent")
await ops_test.model.add_relation("agent:grafana-cloud-config", "gci")
await ops_test.model.wait_for_idle(apps=[principal.name, agent.name], status="active")

Expand Down
Loading