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

fix: set labels in grafana #343

Merged
merged 1 commit into from
Oct 11, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
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
Loading