Skip to content

Commit

Permalink
custom kube_metric support is added to monitoring
Browse files Browse the repository at this point in the history
  • Loading branch information
sametd committed Dec 20, 2023
1 parent 42a4f50 commit 37fd36f
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions aviso-server/monitoring/aviso_monitoring/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ def __init__(
aviso_auth_reporter=None,
etcd_reporter=None,
prometheus_reporter=None,
kube_state_metrics=None,
):
try:
# we build the configuration in priority order from the lower to the higher
Expand All @@ -41,6 +42,7 @@ def __init__(
self.aviso_auth_reporter = aviso_auth_reporter
self.etcd_reporter = etcd_reporter
self.prometheus_reporter = prometheus_reporter
self.kube_state_metrics = kube_state_metrics

logger.debug("Loading configuration completed")

Expand Down Expand Up @@ -113,6 +115,8 @@ def _create_default_config() -> Dict:
},
}

kube_state_metrics = {"ssl_enabled": False, "token": None}

# main config
config = {}
config["udp_server"] = udp_server
Expand All @@ -121,6 +125,7 @@ def _create_default_config() -> Dict:
config["aviso_auth_reporter"] = aviso_auth_reporter
config["etcd_reporter"] = etcd_reporter
config["prometheus_reporter"] = prometheus_reporter
config["kube_state_metrics"] = kube_state_metrics
return config

def _read_env_variables(self) -> Dict:
Expand Down Expand Up @@ -246,6 +251,23 @@ def prometheus_reporter(self, prometheus_reporter):
assert pr.get("port") is not None, "prometheus_reporter port has not been configured"
self._prometheus_reporter = pr

@property
def kube_state_metrics(self):
return self._kube_state_metrics

@kube_state_metrics.setter
def kube_state_metrics(self, kube_state_metrics):
ksm = self._config.get("kube_state_metrics")
if kube_state_metrics is not None and ksm is not None:
Config.deep_update(ksm, kube_state_metrics)
elif kube_state_metrics is not None:
ksm = kube_state_metrics
# verify is valid
assert ksm is not None, "kube_state_metrics has not been configured"
assert ksm.get("ssl_enabled") is not None, "kube_state_metrics ssl_enabled has not been configured"
assert ksm.get("token") is not None, "kube_state_metrics token has not been configured"
self._kube_state_metrics = ksm

def __str__(self):
config_string = (
f"udp_server: {self.udp_server}"
Expand All @@ -254,6 +276,7 @@ def __str__(self):
+ f", aviso_auth_reporter: {self.aviso_auth_reporter}"
+ f", etcd_reporter: {self.etcd_reporter}"
+ f", prometheus_reporter: {self.prometheus_reporter}"
+ f", kube_state_metrics: {self.kube_state_metrics}"
)
return config_string

Expand Down

0 comments on commit 37fd36f

Please sign in to comment.