Skip to content

Commit a9fee12

Browse files
Flux CD: Add kube_state_metrics endpoint config, add metric fluxcd.gotk.resource.info, and update the Flux CD overview dashboard (#24053)
* Add fluxcd.gotk.resource.info * Update dashboard to use resource.info (Flux 2.1+) while keeping legacy reconcile.condition / suspend.status panels * Reference metrics are deprecated in metadata.csv * Remove addition to README * Add changelog * Correct dashboard titles and update changelog name * Fix language mentioning deprecration * Update fluxcd.json based on feedback Co-authored-by: DeForest Richards <56796055+drichards-87@users.noreply.github.com> * update changelog * Add config kube_state_metrics_endpoint to collect kube-state-metrics * Add code path for KSM metrics * Add test for KSM metrics * Fix lint issue * Fix dashboard titles * Update changelog to include kube_state_metrics_endpoint config option * Fix queries to use lowercase values * Fix dashboard note and widget titles --------- Co-authored-by: DeForest Richards <56796055+drichards-87@users.noreply.github.com>
1 parent ea7afb2 commit a9fee12

14 files changed

Lines changed: 294 additions & 20 deletions

File tree

fluxcd/assets/configuration/spec.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,9 @@ files:
99
- template: instances
1010
options:
1111
- template: instances/openmetrics
12+
- name: kube_state_metrics_endpoint
13+
description: |
14+
URL exposing a kube-state-metrics endpoint. Enables collection of kube-state-metrics
15+
for Flux custom resources (Flux 2.1+).
16+
value:
17+
type: string

fluxcd/assets/dashboards/fluxcd.json

Lines changed: 215 additions & 17 deletions
Large diffs are not rendered by default.

fluxcd/changelog.d/24053.added

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Add `fluxcd.gotk.resource.info` metric and `kube_state_metrics_endpoint` configuration option for Flux 2.1+ kube-state-metrics monitoring.

fluxcd/datadog_checks/fluxcd/check.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,23 @@
33
# Licensed under a 3-clause BSD style license (see LICENSE)
44
from datadog_checks.base import OpenMetricsBaseCheckV2
55
from datadog_checks.fluxcd.config_models import ConfigMixin
6-
from datadog_checks.fluxcd.metrics import METRIC_MAP
6+
from datadog_checks.fluxcd.metrics import KSM_METRICS, METRIC_MAP
77

88

99
class FluxcdCheck(OpenMetricsBaseCheckV2, ConfigMixin):
1010
__NAMESPACE__ = "fluxcd"
1111
DEFAULT_METRIC_LIMIT = 0
1212

13+
def __init__(self, name, init_config, instances):
14+
super().__init__(name, init_config, instances)
15+
self.check_initializations.appendleft(self._parse_config)
16+
17+
def _parse_config(self):
18+
ksm_endpoint = self.instance.get("kube_state_metrics_endpoint")
19+
if ksm_endpoint:
20+
self.scraper_configs.append(
21+
{**self.instance, "openmetrics_endpoint": ksm_endpoint, "metrics": [KSM_METRICS]}
22+
)
23+
1324
def get_default_config(self):
1425
return {"metrics": [METRIC_MAP]}

fluxcd/datadog_checks/fluxcd/config_models/instance.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ class InstanceConfig(BaseModel):
123123
kerberos_hostname: Optional[str] = None
124124
kerberos_keytab: Optional[str] = None
125125
kerberos_principal: Optional[str] = None
126+
kube_state_metrics_endpoint: Optional[str] = None
126127
log_requests: Optional[bool] = None
127128
metric_patterns: Optional[MetricPatterns] = None
128129
metrics: Optional[tuple[Union[str, MappingProxyType[str, Union[str, Metrics]]], ...]] = None

fluxcd/datadog_checks/fluxcd/data/conf.yaml.example

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -640,3 +640,9 @@ instances:
640640
# - <INCLUDE_REGEX>
641641
# exclude:
642642
# - <EXCLUDE_REGEX>
643+
644+
## @param kube_state_metrics_endpoint - string - optional
645+
## URL exposing a kube-state-metrics endpoint. Enables collection of kube-state-metrics
646+
## for Flux custom resources (Flux 2.1+).
647+
#
648+
# kube_state_metrics_endpoint: <KUBE_STATE_METRICS_ENDPOINT>

fluxcd/datadog_checks/fluxcd/metrics.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@
1515
}
1616
assert sorted(FLUX_V1_METRICS) == list(FLUX_V1_METRICS)
1717

18+
KSM_METRICS = {
19+
"gotk_resource_info": "gotk.resource.info",
20+
}
21+
1822
FLUX_V2_METRICS = {
1923
"leader_election_master_status": "leader_election_master_status",
2024
"process_cpu_seconds": "process.cpu_seconds",

fluxcd/metadata.csv

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ fluxcd.gotk.reconcile.condition,gauge,,,,The current condition status of a GitOp
1010
fluxcd.gotk.reconcile.duration.seconds.bucket,count,,,,Bucket of the duration in seconds of a GitOps Toolkit resource reconciliation.,0,fluxcd,reconcile duration seconds,
1111
fluxcd.gotk.reconcile.duration.seconds.count,count,,,,Count of the duration in seconds of a GitOps Toolkit resource reconciliation.,0,fluxcd,reconcile duration seconds,
1212
fluxcd.gotk.reconcile.duration.seconds.sum,count,,second,,Sum of the duration in seconds of a GitOps Toolkit resource reconciliation.,0,fluxcd,reconcile duration seconds,
13+
fluxcd.gotk.resource.info,gauge,,,,Flux custom resource state from kube-state-metrics (gotk_resource_info). Use with Flux 2.1+ monitoring.,0,fluxcd,gotk resource info,
1314
fluxcd.gotk.suspend.status,gauge,,,,The current suspend status of a GitOps Toolkit resource [Deprecated since 2.1.0].,0,fluxcd,gotk suspend status,
1415
fluxcd.leader_election_master_status,gauge,,,,"Gauge of if the reporting system is master of the relevant lease, 0 indicates backup, 1 indicates master. 'name' is the string used to identify the lease. Make sure to group by name.",0,fluxcd,,
1516
fluxcd.process.cpu_seconds.count,count,,second,,Total user and system CPU time spent in seconds.,0,fluxcd,,

fluxcd/tests/common.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,7 @@
4545
"fluxcd.workqueue.unfinished_work",
4646
},
4747
}
48+
49+
KSM_METRICS = {
50+
"fluxcd.gotk.resource.info",
51+
}

fluxcd/tests/conftest.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,3 +102,21 @@ def mock_metrics_v2():
102102
),
103103
):
104104
yield
105+
106+
107+
@pytest.fixture()
108+
def mock_metrics_ksm():
109+
fixture_file = os.path.join(os.path.dirname(__file__), "fixtures", "metrics-ksm.txt")
110+
111+
with open(fixture_file, "r") as f:
112+
content = f.read()
113+
114+
with mock.patch(
115+
"requests.Session.get",
116+
return_value=mock.MagicMock(
117+
status_code=200,
118+
iter_lines=lambda **kwargs: content.split("\n"),
119+
headers={"Content-Type": "text/plain"},
120+
),
121+
):
122+
yield

0 commit comments

Comments
 (0)