Skip to content

Commit

Permalink
Add KubeDNS/CoreDNS support in cluster metrics (#892)
Browse files Browse the repository at this point in the history
Signed-off-by: Pete Wall <[email protected]>
  • Loading branch information
petewall authored Nov 12, 2024
1 parent e113c77 commit b9f8745
Show file tree
Hide file tree
Showing 52 changed files with 944 additions and 288 deletions.
14 changes: 13 additions & 1 deletion charts/feature-cluster-metrics/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ Actual integration testing in a live environment should be done in the main [k8s

| Key | Type | Default | Description |
|-----|------|---------|-------------|
| controlPlane.enabled | bool | `false` | enable all Kubernetes Control Plane metrics sources. This includes api-server, kube-scheduler, kube-controller-manager, and etcd. |
| controlPlane.enabled | bool | `false` | enable all Kubernetes Control Plane metrics sources. This includes api-server, kube-scheduler, kube-controller-manager, and KubeDNS. |

### General settings

Expand Down Expand Up @@ -263,6 +263,18 @@ Actual integration testing in a live environment should be done in the main [k8s
| kubeControllerManager.port | int | `10257` | Port number used by the Kube Controller Manager, set by `--secure-port.` |
| kubeControllerManager.scrapeInterval | string | 60s | How frequently to scrape metrics from the Kube Controller Manager Overrides metrics.scrapeInterval |

### KubeDNS

| Key | Type | Default | Description |
|-----|------|---------|-------------|
| kubeDNS.enabled | bool | `false` | Scrape metrics from KubeDNS |
| kubeDNS.extraDiscoveryRules | string | `""` | Rule blocks to be added to the discovery.relabel component for KubeDNS. These relabeling rules are applied pre-scrape against the targets from service discovery. Before the scrape, any remaining target labels that start with `__` (i.e. `__meta_kubernetes*`) are dropped. ([docs](https://grafana.com/docs/alloy/latest/reference/components/discovery/discovery.relabel/#rule-block)) |
| kubeDNS.extraMetricProcessingRules | string | `""` | Rule blocks to be added to the prometheus.relabel component for KubeDNS. These relabeling rules are applied post-scrape against the metrics returned from the scraped target, no `__meta*` labels are present. ([docs](https://grafana.com/docs/alloy/latest/reference/components/prometheus/prometheus.relabel/#rule-block)) |
| kubeDNS.maxCacheSize | string | `nil` | Sets the max_cache_size for cadvisor prometheus.relabel component. This should be at least 2x-5x your largest scrape target or samples appended rate. ([docs](https://grafana.com/docs/alloy/latest/reference/components/prometheus/prometheus.relabel/#arguments)) Overrides metrics.maxCacheSize |
| kubeDNS.metricsTuning.excludeMetrics | list | `[]` | Metrics to drop. Can use regular expressions. |
| kubeDNS.metricsTuning.includeMetrics | list | `[]` | Metrics to keep. Can use regular expressions. An empty list means keep all. |
| kubeDNS.scrapeInterval | string | 60s | How frequently to scrape metrics from KubeDNS Overrides metrics.scrapeInterval |

### Kube Proxy

| Key | Type | Default | Description |
Expand Down
10 changes: 2 additions & 8 deletions charts/feature-cluster-metrics/templates/_api_server.alloy.tpl
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
{{ define "feature.clusterMetrics.apiServer.allowList" }}
{{ if .Values.apiServer.metricsTuning.includeMetrics }}
{{ .Values.apiServer.metricsTuning.includeMetrics | toYaml }}
{{ end }}
{{ end }}

{{- define "feature.clusterMetrics.apiServer.alloy" }}
{{- if or .Values.apiServer.enabled (and .Values.controlPlane.enabled (not (eq .Values.apiServer.enabled false))) }}
{{- $metricAllowList := .Values.apiServer.metricsTuning.includeMetrics }}
Expand All @@ -17,8 +11,8 @@ kubernetes.apiserver "scrape" {
{{- if $metricDenyList }}
drop_metrics = {{ $metricDenyList | join "|" | quote }}
{{- end }}
scrape_interval = {{ .Values.cadvisor.scrapeInterval | default .Values.global.scrapeInterval | int }}
max_cache_size = {{ .Values.cadvisor.maxCacheSize | default .Values.global.maxCacheSize | int }}
scrape_interval = {{ .Values.apiServer.scrapeInterval | default .Values.global.scrapeInterval | quote }}
max_cache_size = {{ .Values.apiServer.maxCacheSize | default .Values.global.maxCacheSize | int }}
{{- if .Values.apiServer.extraMetricProcessingRules }}
forward_to = [prometheus.relabel.apiServer.receiver]
}
Expand Down
2 changes: 1 addition & 1 deletion charts/feature-cluster-metrics/templates/_kepler.alloy.tpl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{{ define "feature.clusterMetrics.kepler.allowList" }}
{{ if .Values.cadvisor.metricsTuning.useDefaultAllowList }}
{{ if .Values.kepler.metricsTuning.useDefaultAllowList }}
{{ "default-allow-lists/kepler.yaml" | .Files.Get }}
{{ end }}
{{ if .Values.kepler.metricsTuning.includeMetrics }}
Expand Down
27 changes: 27 additions & 0 deletions charts/feature-cluster-metrics/templates/_kube_dns.alloy.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{{- define "feature.clusterMetrics.kubeDNS.alloy" }}
{{- if or .Values.kubeDNS.enabled (and .Values.controlPlane.enabled (not (eq .Values.kubeDNS.enabled false))) }}
{{- $metricAllowList := .Values.kubeDNS.metricsTuning.includeMetrics }}
{{- $metricDenyList := .Values.kubeDNS.metricsTuning.excludeMetrics }}

kubernetes.kube_dns "scrape" {
clustering = true
{{- if $metricAllowList }}
keep_metrics = "up|{{ $metricAllowList | join "|" }}"
{{- end }}
{{- if $metricDenyList }}
drop_metrics = {{ $metricDenyList | join "|" | quote }}
{{- end }}
scrape_interval = {{ .Values.kubeDNS.scrapeInterval | default .Values.global.scrapeInterval | quote }}
max_cache_size = {{ .Values.kubeDNS.maxCacheSize | default .Values.global.maxCacheSize | int }}
{{- if .Values.kubeDNS.extraMetricProcessingRules }}
forward_to = [prometheus.relabel.kube_dns.receiver]
}

prometheus.relabel "kube_dns" {
max_cache_size = {{ .Values.kubeDNS.maxCacheSize | default .Values.global.maxCacheSize | int }}
{{ .Values.kubeDNS.extraMetricProcessingRules | indent 2 }}
{{- end }}
forward_to = argument.metrics_destinations.value
}
{{- end }}
{{- end }}
10 changes: 9 additions & 1 deletion charts/feature-cluster-metrics/templates/_module.alloy.tpl
Original file line number Diff line number Diff line change
@@ -1,17 +1,25 @@
{{- define "feature.clusterMetrics.module" }}
{{- $includeKubernetesModule := false }}
{{- $includeKubernetesModule = or $includeKubernetesModule .Values.cadvisor.enabled }}
{{- $includeKubernetesModule = or $includeKubernetesModule .Values.kubelet.enabled }}
{{- $includeKubernetesModule = or $includeKubernetesModule .Values.kubeletResource.enabled }}
{{- $includeKubernetesModule = or $includeKubernetesModule .Values.apiServer.enabled }}
{{- $includeKubernetesModule = or $includeKubernetesModule .Values.kubeDNS.enabled }}
{{- $includeKubernetesModule = or $includeKubernetesModule (and .Values.controlPlane.enabled (or (not (eq .Values.apiServer.enabled false)) (not (eq .Values.kubeDNS.enabled false)))) }}
declare "cluster_metrics" {
argument "metrics_destinations" {
comment = "Must be a list of metric destinations where collected metrics should be forwarded to"
}

{{- if or .Values.cadvisor.enabled .Values.kubelet.enabled .Values.kubeletResource.enabled (or .Values.apiServer.enabled (and .Values.controlPlane.enabled (not (eq .Values.apiServer.enabled false)))) }}
{{- if $includeKubernetesModule }}
{{- include "alloyModules.load" (deepCopy $ | merge (dict "name" "kubernetes" "path" "modules/kubernetes/core/metrics.alloy")) | nindent 2 }}
{{- end }}
{{- include "feature.clusterMetrics.kubelet.alloy" . | indent 2 }}
{{- include "feature.clusterMetrics.kubeletResource.alloy" . | indent 2 }}
{{- include "feature.clusterMetrics.cadvisor.alloy" . | indent 2 }}
{{- include "feature.clusterMetrics.apiServer.alloy" . | indent 2 }}
{{- include "feature.clusterMetrics.kubeControllerManager.alloy" . | indent 2 }}
{{- include "feature.clusterMetrics.kubeDNS.alloy" . | indent 2 }}
{{- include "feature.clusterMetrics.kubeProxy.alloy" . | indent 2 }}
{{- include "feature.clusterMetrics.kubeScheduler.alloy" . | indent 2 }}
{{- include "feature.clusterMetrics.kube_state_metrics.alloy" . | indent 2 }}
Expand Down
Loading

0 comments on commit b9f8745

Please sign in to comment.