Skip to content

Commit 50a84a2

Browse files
committed
Wip
Signed-off-by: Pete Wall <[email protected]>
1 parent 0e6fc87 commit 50a84a2

File tree

86 files changed

+8002
-2353
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

86 files changed

+8002
-2353
lines changed

charts/k8s-monitoring/charts/feature-pod-logs/README.md

+39-11
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,6 @@ Be sure perform actual integration testing in a live environment in the main [k8
4747
| staticLabels | object | `{}` | Log labels to set with static values. |
4848
| staticLabelsFrom | object | `{}` | Log labels to set with static values, not quoted so it can reference config components. |
4949

50-
### Pod Discovery
51-
52-
| Key | Type | Default | Description |
53-
|-----|------|---------|-------------|
54-
| excludeNamespaces | list | `[]` | Do not capture logs from any pods in these namespaces. |
55-
| extraDiscoveryRules | string | `""` | Rules to filter pods for log gathering. Only used for "volumes" or "kubernetesApi" gather methods. |
56-
| gatherMethod | string | `"volumes"` | The method to gather pod logs. Options are "volumes", "kubernetesApi", "OpenShiftClusterLogForwarder" (experimental). |
57-
| namespaces | list | `[]` | Only capture logs from pods in these namespaces (`[]` means all namespaces). |
58-
5950
### General settings
6051

6152
| Key | Type | Default | Description |
@@ -69,14 +60,51 @@ Be sure perform actual integration testing in a live environment in the main [k8
6960
|-----|------|---------|-------------|
7061
| global.platform | string | `""` | The specific platform for this cluster. Will enable compatibility for some platforms. Supported options: (empty) or "openshift". |
7162

63+
### Kubernetes API Gathering: Discovery
64+
65+
| Key | Type | Default | Description |
66+
|-----|------|---------|-------------|
67+
| kubernetesApiGathering.excludeNamespaces | list | `[]` | Do not capture logs from any pods in these namespaces. |
68+
| kubernetesApiGathering.extraDiscoveryRules | string | `""` | Rules to filter pods for log gathering. |
69+
| kubernetesApiGathering.fieldSelectors | list | `[]` | Discover Pods based on field selectors. |
70+
| kubernetesApiGathering.labelSelectors | object | `{}` | Discover Pods based on label selectors. |
71+
| kubernetesApiGathering.namespaces | list | `[]` | Only capture logs from pods in these namespaces (`[]` means all namespaces). |
72+
| kubernetesApiGathering.nodeFieldSelectors | list | `[]` | Discover Pods based on Node field selectors. |
73+
| kubernetesApiGathering.nodeLabelSelectors | object | `{}` | Discover Pods based on Node label selectors. |
74+
| kubernetesApiGathering.nodes | list | `[]` | Do not capture logs from any pods in these namespaces. |
75+
| volumeGathering.nodeFieldSelectors | list | `[]` | Discover Pods based on Node field selectors. |
76+
| volumeGathering.nodeLabelSelectors | object | `{}` | Discover Pods based on Node label selectors. |
77+
7278
### Processing settings
7379

7480
| Key | Type | Default | Description |
7581
|-----|------|---------|-------------|
7682
| structuredMetadata | object | `{}` | The structured metadata mappings to set. To not set any structured metadata, set this to an empty object (e.g. `{}`) Format: `<key>: <extracted_key>`. Example: structuredMetadata: component: component kind: kind name: name |
7783

78-
### Volume Log Gathering
84+
### Volume Gathering: Discovery
85+
86+
| Key | Type | Default | Description |
87+
|-----|------|---------|-------------|
88+
| volumeGathering.excludeNamespaces | list | `[]` | Do not capture logs from any pods in these namespaces. |
89+
| volumeGathering.extraDiscoveryRules | string | `""` | Rules to filter pods for log gathering. |
90+
| volumeGathering.fieldSelectors | list | `[]` | Discover Pods based on field selectors. |
91+
| volumeGathering.labelSelectors | object | `{}` | Discover Pods based on label selectors. |
92+
| volumeGathering.namespaces | list | `[]` | Only capture logs from pods in these namespaces (`[]` means all namespaces). |
93+
| volumeGathering.podLogsPath | string | `"/var/log/pods"` | Path on the Kubernetes nodes where the Pod logs are stored. |
94+
95+
### Volume Gathering: Gathering
96+
97+
| Key | Type | Default | Description |
98+
|-----|------|---------|-------------|
99+
| volumeGathering.onlyGatherNewLogLines | bool | `false` | Only gather new log lines since this was deployed. Do not gather historical log lines. |
100+
101+
### Other Values
79102

80103
| Key | Type | Default | Description |
81104
|-----|------|---------|-------------|
82-
| volumeGatherSettings.onlyGatherNewLogLines | bool | `false` | Only gather new log lines since this was deployed. Do not gather historical log lines. |
105+
| kubernetesApiGathering.enabled | bool | `false` | Only capture logs from pods in these namespaces (`[]` means all namespaces). |
106+
| lokiReceiver.enabled | bool | `false` | Enable receiving logs using the Loki protocol. |
107+
| lokiReceiver.openShiftClusterLogForwarder.enabled | bool | `false` | |
108+
| lokiReceiver.openShiftClusterLogForwarder.namespaces | list | `[]` | |
109+
| lokiReceiver.port | int | `3100` | The port to listen on for logs. |
110+
| volumeGathering.enabled | bool | `true` | |

charts/k8s-monitoring/charts/feature-pod-logs/templates/_api.alloy.tpl

+22-6
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,46 @@
11
{{- define "feature.podLogs.kubernetesApi.alloy" }}
2+
{{- $labelSelectors := list }}
3+
{{- range $k, $v := .Values.kubernetesApiGathering.labelSelectors }}
4+
{{- if kindIs "slice" $v }}
5+
{{- $labelSelectors = append $labelSelectors (printf "%s in (%s)" $k (join "," $v)) }}
6+
{{- else }}
7+
{{- $labelSelectors = append $labelSelectors (printf "%s=%s" $k $v) }}
8+
{{- end }}
9+
{{- end }}
10+
{{- $nodeLabelSelectors := list }}
11+
{{- range $k, $v := .Values.kubernetesApiGathering.nodeLabelSelectors }}
12+
{{- if kindIs "slice" $v }}
13+
{{- $nodeLabelSelectors = append $nodeLabelSelectors (printf "%s in (%s)" $k (join "," $v)) }}
14+
{{- else }}
15+
{{- $nodeLabelSelectors = append $nodeLabelSelectors (printf "%s=%s" $k $v) }}
16+
{{- end }}
17+
{{- end }}
218
discovery.kubernetes "kubernetes_api_pods" {
319
role = "pod"
420
{{- if .Values.kubernetesApiGathering.namespaces }}
521
namespaces {
622
names = {{ .Values.namespaces | toJson }}
723
}
824
{{- end }}
9-
{{- if or .Values.kubernetesApiGathering.labelSelectors .Values.kubernetesApiGathering.fieldSelectors }}
25+
{{- if or $labelSelectors .Values.kubernetesApiGathering.fieldSelectors }}
1026
selectors {
1127
role = "pod"
12-
{{- if .Values.kubernetesApiGathering.labelSelectors }}
13-
label = {{ .Values.kubernetesApiGathering.labelSelectors | toJson }}
28+
{{- if $labelSelectors }}
29+
label = {{ $labelSelectors | join "," | quote }}
1430
{{- end }}
1531
{{- if .Values.kubernetesApiGathering.fieldSelectors }}
1632
field = {{ .Values.kubernetesApiGathering.fieldSelectors | join "," | quote }}
1733
{{- end }}
1834
}
1935
{{- end }}
20-
{{- if or .Values.kubernetesApiGathering.nodeLabelSelectors .Values.kubernetesApiGathering.nodeFieldSelectors }}
36+
{{- if or $nodeLabelSelectors .Values.kubernetesApiGathering.nodeFieldSelectors }}
2137
attach_metadata {
2238
node = true
2339
}
2440
selectors {
2541
role = "node"
26-
{{- if .Values.kubernetesApiGathering.nodeLabelSelectors }}
27-
label = {{ .Values.kubernetesApiGathering.nodeLabelSelectors | toJson }}
42+
{{- if $nodeLabelSelectors }}
43+
label = {{ $nodeLabelSelectors | join "," | quote }}
2844
{{- end }}
2945
{{- if .Values.kubernetesApiGathering.nodeFieldSelectors }}
3046
field = {{ .Values.kubernetesApiGathering.nodeFieldSelectors | join "," | quote }}
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{{/* Validates that the Alloy instance is appropriate for the given Pod Logs settings */}}
22
{{/* Inputs: Values (Pod Logs values), Collector (Alloy values), CollectorName (string) */}}
33
{{- define "feature.podLogs.collector.validate" -}}
4-
{{- if or .Values.volumeGathering.enabled (eq .Values.gatherMethod "volumes") }}
4+
{{- if or (and .Values.volumeGathering.enabled (not .Values.gatherMethod)) (eq .Values.gatherMethod "volumes") }}
55
{{- if not (eq .Collector.controller.type "daemonset") }}
66
{{- fail (printf "Pod Logs feature requires Alloy to be a DaemonSet when using the \"volumes\" gather method.\nPlease set:\n%s:\n controller:\n type: daemonset" .CollectorName) }}
77
{{- end -}}
@@ -10,7 +10,7 @@
1010
{{- end -}}
1111
{{- end -}}
1212

13-
{{- if or .Values.kubernetesApiGathering.enabled (eq .Values.gatherMethod "kubernetesApi") }}
13+
{{- if or (and .Values.kubernetesApiGathering.enabled (not .Values.gatherMethod)) (eq .Values.gatherMethod "kubernetesApi") }}
1414
{{- if not .Collector.alloy.clustering.enabled }}
1515
{{- if eq .Collector.controller.type "daemonset" }}
1616
{{- fail (printf "Pod Logs feature requires Alloy DaemonSet to be in clustering mode when using the \"kubernetesApi\" gather method.\nPlease set:\n%s:\n alloy:\n clustering:\n enabled: true" .CollectorName) }}
@@ -19,12 +19,23 @@
1919
{{- end -}}
2020
{{- end -}}
2121
{{- end -}}
22+
{{- end -}}
2223

23-
{{- if .Values.lokiReceiver.enabled }}
24-
{{- if not .Collector.alloy.clustering.enabled }}
25-
{{- fail (printf "Pod Logs feature requires Alloy to be in clustering mode when using the \"kubernetesApi\" gather method.\nPlease set:\n%s:\n alloy:\n clustering:\n enabled: true" .CollectorName) }}
24+
{{- define "feature.podLogs.validate" -}}
25+
{{/*Validate that if both volume gathering and k8s api gathering, there are some selectors set*/}}
26+
{{- if and .Values.volumeGathering.enabled .Values.kubernetesApiGathering.enabled }}
27+
{{- if not (or .Values.kubernetesApiGathering.labelSelectors .Values.kubernetesApiGathering.fieldSelectors .Values.kubernetesApiGathering.nodeLabelSelectors .Values.kubernetesApiGathering.nodeFieldSelectors)}}
28+
{{- $msg := list "" "When gathering Pod logs by Volumes and the Kubernetes API, you must set selectors to targets pods not covered by the Collector DaemonSet." }}
29+
{{- $msg = append $msg "Please set at least one of:" }}
30+
{{- $msg = append $msg "podLogs:" }}
31+
{{- $msg = append $msg " kubernetesApiGathering:" }}
32+
{{- $msg = append $msg " fieldSelectors: [<field selector>]" }}
33+
{{- $msg = append $msg " labelSelectors:" }}
34+
{{- $msg = append $msg " <Kubernetes Pod Label>: <value> OR [<value1>, <value2>]" }}
35+
{{- $msg = append $msg " nodeFieldSelectors: [<field selector>]" }}
36+
{{- $msg = append $msg " nodeLabelSelectors:" }}
37+
{{- $msg = append $msg " <Kubernetes Node Label>: <value> OR [<value1>, <value2>]" }}
38+
{{- $errorMessage := join "\n" $msg }}
2639
{{- end -}}
2740
{{- end -}}
28-
29-
3041
{{- end -}}

charts/k8s-monitoring/charts/feature-pod-logs/templates/_notes.tpl

+19-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,25 @@ Gather logs from Kubernetes Pods
66

77
{{- define "feature.podLogs.notes.actions" }}{{- end }}
88

9+
{{- define "feature.podLogs.notes.deprecations" }}
10+
{{- if .Values.gatherMethod }}
11+
* The `gatherMethod` value is deprecated and will be removed in a future release.
12+
Please enable the desired Pod log gathering methods individually:
13+
volumeGathering:
14+
enabled: true
15+
kubernetesApiGathering:
16+
enabled: true
17+
lokiReceiver:
18+
enabled: true
19+
{{- end }}
20+
{{- end }}
21+
922
{{- define "feature.podLogs.summary" -}}
23+
{{- $methods := list }}
24+
{{- if .Values.volumeGathering.enabled }}{{- $methods = append $methods "volumes" }}{{ end }}
25+
{{- if .Values.kubernetesApiGathering.enabled }}{{- $methods = append $methods "kubernetesApi" }}{{ end }}
26+
{{- if .Values.lokiReceiver.enabled }}{{- $methods = append $methods "lokiReceiver" }}{{ end }}
27+
{{- if .Values.lokiReceiver.openShiftClusterLogForwarder.enabled }}{{- $methods = append $methods "OSClusterLogForwarder" }}{{ end }}
1028
version: {{ .Chart.Version }}
11-
method: {{ .Values.gatherMethod }}
29+
methods: {{ $methods | join "," }}
1230
{{- end }}

charts/k8s-monitoring/charts/feature-pod-logs/templates/_volumeGathering.alloy.tpl

+24-8
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,20 @@
11
{{- define "feature.podLogs.volumeGathering.alloy" }}
2+
{{- $labelSelectors := list }}
3+
{{- range $k, $v := .Values.volumeGathering.labelSelectors }}
4+
{{- if kindIs "slice" $v }}
5+
{{- $labelSelectors = append $labelSelectors (printf "%s in (%s)" $k (join "," $v)) }}
6+
{{- else }}
7+
{{- $labelSelectors = append $labelSelectors (printf "%s=%s" $k $v) }}
8+
{{- end }}
9+
{{- end }}
10+
{{- $nodeLabelSelectors := list }}
11+
{{- range $k, $v := .Values.volumeGathering.nodeLabelSelectors }}
12+
{{- if kindIs "slice" $v }}
13+
{{- $nodeLabelSelectors = append $nodeLabelSelectors (printf "%s in (%s)" $k (join "," $v)) }}
14+
{{- else }}
15+
{{- $nodeLabelSelectors = append $nodeLabelSelectors (printf "%s=%s" $k $v) }}
16+
{{- end }}
17+
{{- end }}
218
discovery.kubernetes "volume_gathering_pods" {
319
role = "pod"
420
selectors {
@@ -10,25 +26,25 @@ discovery.kubernetes "volume_gathering_pods" {
1026
names = {{ .Values.namespaces | toJson }}
1127
}
1228
{{- end }}
13-
{{- if or .Values.volumeGathering.labelSelectors .Values.volumeGathering.fieldSelectors }}
29+
{{- if or $labelSelectors .Values.volumeGathering.fieldSelectors }}
1430
selectors {
1531
role = "pod"
16-
{{- if .Values.volumeGathering.labelSelectors }}
17-
label = {{ .Values.volumeGathering.labelSelectors | toJson }}
32+
{{- if $labelSelectors }}
33+
label = {{ $labelSelectors | join "," | quote }}
1834
{{- end }}
1935
{{- if .Values.volumeGathering.fieldSelectors }}
2036
field = {{ .Values.volumeGathering.fieldSelectors | join "," | quote }}
2137
{{- end }}
2238
}
2339
{{- end }}
24-
{{- if or .Values.volumeGathering.nodeLabelSelectors .Values.volumeGathering.nodeFieldSelectors }}
40+
{{- if or $nodeLabelSelectors .Values.volumeGathering.nodeFieldSelectors }}
2541
attach_metadata {
2642
node = true
2743
}
2844
selectors {
2945
role = "node"
30-
{{- if .Values.volumeGathering.nodeLabelSelectors }}
31-
label = {{ .Values.volumeGathering.nodeLabelSelectors | toJson }}
46+
{{- if $nodeLabelSelectors }}
47+
label = {{ $nodeLabelSelectors | join "," | quote }}
3248
{{- end }}
3349
{{- if .Values.volumeGathering.nodeFieldSelectors }}
3450
field = {{ .Values.volumeGathering.nodeFieldSelectors | join "," | quote }}
@@ -175,8 +191,8 @@ local.file_match "volume_gathering_pods" {
175191

176192
loki.source.file "volume_gathering_pods" {
177193
targets = local.file_match.volume_gathering_pods.targets
178-
{{- if .Values.volumeGathering.onlyGatherNewLogLines | default .Values.volumeGatherSettings.onlyGatherNewLogLines }}
179-
tail_from_end = {{ .Values.volumeGathering.onlyGatherNewLogLines | default .Values.volumeGatherSettings.onlyGatherNewLogLines }}
194+
{{- if .Values.volumeGathering.onlyGatherNewLogLines | default (dig "volumeGatherSettings" "onlyGatherNewLogLines" false .Values) }}
195+
tail_from_end = {{ .Values.volumeGathering.onlyGatherNewLogLines | default (dig "volumeGatherSettings" "onlyGatherNewLogLines" false .Values) }}
180196
{{- end }}
181197
forward_to = [loki.process.pod_log_processor.receiver]
182198
}

0 commit comments

Comments
 (0)