Skip to content

Commit

Permalink
fix: set labels in grafana (#343)
Browse files Browse the repository at this point in the history
  • Loading branch information
Gu1nness authored Oct 11, 2024
1 parent 7d8d0bf commit 134c10c
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 9 deletions.
30 changes: 22 additions & 8 deletions src/charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import logging
import re
import time
from typing import Dict, List, Optional, Set
from typing import Any, Dict, List, Optional, Set

import jinja2
from charms.grafana_k8s.v0.grafana_dashboard import GrafanaDashboardProvider
Expand Down Expand Up @@ -126,8 +126,14 @@ def __init__(self, *args):
self.tls = MongoDBTLS(self, Config.Relations.PEERS, Config.SUBSTRATE)
self.backups = MongoDBBackups(self)

self.status = MongoDBStatusHandler(self)
self.secrets = SecretCache(self)

self.shard = ConfigServerRequirer(self)
self.config_server = ShardingProvider(self)
self.cluster = ClusterProvider(self)
self.metrics_endpoint = MetricsEndpointProvider(
self, refresh_event=self.on.start, jobs=Config.Monitoring.JOBS
self, refresh_event=[self.on.start, self.on.update_status], jobs=self.monitoring_jobs
)
self.grafana_dashboards = GrafanaDashboardProvider(self)
self.loki_push = LogProxyConsumer(
Expand All @@ -136,12 +142,6 @@ def __init__(self, *args):
relation_name=Config.Relations.LOGGING,
container_name=Config.CONTAINER_NAME,
)
self.status = MongoDBStatusHandler(self)
self.secrets = SecretCache(self)

self.shard = ConfigServerRequirer(self)
self.config_server = ShardingProvider(self)
self.cluster = ClusterProvider(self)

self.version_checker = CrossAppVersionChecker(
self,
Expand All @@ -154,6 +154,20 @@ def __init__(self, *args):

# BEGIN: properties

@property
def monitoring_jobs(self) -> list[dict[str, Any]]:
"""Defines the labels and targets for metrics."""
return [
{
"static_configs": [
{
"targets": [f"*:{Config.Monitoring.MONGODB_EXPORTER_PORT}"],
"labels": {"cluster": self.get_config_server_name() or self.app.name},
}
]
}
]

@property
def app_hosts(self) -> List[str]:
"""Retrieve IP addresses associated with MongoDB application.
Expand Down
2 changes: 1 addition & 1 deletion src/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class Monitoring:
LOG_SLOTS = ["charmed-mongodb:logs"]
URI_PARAM_NAME = "monitor-uri"
SERVICE_NAME = "mongodb-exporter"
JOBS = [{"static_configs": [{"targets": [f"*:{MONGODB_EXPORTER_PORT}"]}]}]
JOBS = [{"static_configs": [{"targets": [f"*:{MONGODB_EXPORTER_PORT}"], "labels": []}]}]
APP_SCOPE = "app"
UNIT_SCOPE = "unit"

Expand Down

0 comments on commit 134c10c

Please sign in to comment.