Skip to content

Commit

Permalink
Make the formatAsJson actually do something and add config validation. (
Browse files Browse the repository at this point in the history
#633)

Also remove journal extraConfig which also was not used.

Signed-off-by: Pete Wall <pete.wall@grafana.com>
  • Loading branch information
petewall authored Jul 11, 2024
1 parent 8730834 commit 0f7a57c
Show file tree
Hide file tree
Showing 8 changed files with 56 additions and 16 deletions.
1 change: 0 additions & 1 deletion charts/k8s-monitoring/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,6 @@ The Prometheus and Loki services may be hosted on the same cluster, or remotely
| Key | Type | Default | Description |
|-----|------|---------|-------------|
| logs.journal.enabled | bool | `false` | Scrape Kubernetes Worker Journal Logs event |
| logs.journal.extraConfig | string | `""` | Extra configuration that will be added to the Grafana Alloy for Journal configuration file. This value is templated so that you can refer to other values from this file. This cannot be used to modify the generated configuration values, only append new components. See [Adding custom Flow configuration](#adding-custom-flow-configuration) for an example. |
| logs.journal.extraStageBlocks | string | `""` | Stage blocks to be added to the loki.process component for journal logs. ([docs](https://grafana.com/docs/alloy/latest/reference/components/loki.process/#blocks)) This value is templated so that you can refer to other values from this file. |
| logs.journal.formatAsJson | bool | `false` | Whether to forward the original journal entry as JSON. |
| logs.journal.jobLabel | string | `"integrations/kubernetes/journal"` | The value for the job label for journal logs |
Expand Down
18 changes: 13 additions & 5 deletions charts/k8s-monitoring/templates/_config_validations.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,17 @@ alloy-logs:
{{- end -}}
{{- end -}}
{{- end -}}
{{- end -}}





{{- if and .Values.logs.enabled .Values.logs.journal.enabled }}
{{- if ne (index .Values "alloy-logs").controller.type "daemonset" }}
{{/*
Invalid configuration for gathering journal logs! Grafana Alloy for Logs must be a Daemonset. Otherwise, journal logs will be missing!
Please set:
alloy-logs:
controller:
type: daemonset
*/}}
{{ fail "Invalid configuration for gathering journal logs! Grafana Alloy for Logs must be a Daemonset. Otherwise, journal logs will be missing!\nPlease set:\nalloy-logs:\n controller:\n type: daemonset"}}
{{- end }}
{{- end -}}
{{- end -}}
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@ loki.relabel "journal" {
}

loki.source.journal "worker" {
max_age = {{ .Values.logs.journal.maxAge | default "8h" | quote }}
path = {{ .Values.logs.journal.path | default "/var/logs/journal" | quote }}
format_as_json = {{ .Values.logs.journal.formatAsJson | quote }}
max_age = {{ .Values.logs.journal.maxAge | default "8h" | quote }}
relabel_rules = loki.relabel.journal.rules
labels = {
job = {{ .Values.logs.journal.jobLabel | default "integrations/kubernetes/journal" | quote }},
Expand Down
7 changes: 0 additions & 7 deletions charts/k8s-monitoring/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1483,13 +1483,6 @@ logs:
# @section -- Logs Scrape: Pod Logs
extraRelabelingRules: ""

# -- Extra configuration that will be added to the Grafana Alloy for Journal configuration file.
# This value is templated so that you can refer to other values from this file.
# This cannot be used to modify the generated configuration values, only append new components.
# See [Adding custom Flow configuration](#adding-custom-flow-configuration) for an example.
# @section -- Logs Scrape: Journal
extraConfig: ""

# Settings related to logs ingested via receivers
# @section -- Logs -> OTEL Receiver
receiver:
Expand Down
3 changes: 2 additions & 1 deletion examples/logs-journal/logs.alloy

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion examples/logs-journal/output.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
---
cluster:
name: invalid-logs-config-non-daemonset-and-journal-logs

externalServices:
prometheus:
host: https://prometheus.example.com
basicAuth:
username: 12345
password: "It's a secret to everyone"
loki:
host: https://loki.example.com
basicAuth:
username: 12345
password: "It's a secret to everyone"

logs:
pod_logs:
gatherMethod: api
journal:
enabled: true

alloy-logs:
controller:
type: deployment
12 changes: 12 additions & 0 deletions tests/spec/invalid-logs-configurations_spec.sh
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,18 @@ logs:
pod_logs:
gatherMethod: api
or
alloy-logs:
controller:
type: daemonset'
End
End

Describe 'Using non-daemonset with journal log gathering'
It 'prints a friendly error message'
When call helm template k8smon ../charts/k8s-monitoring -f "spec/fixtures/invalid-logs-config-non-daemonset-and-journal-logs_values.yaml"
The status should be failure
The error should include 'Invalid configuration for gathering journal logs! Grafana Alloy for Logs must be a Daemonset. Otherwise, journal logs will be missing!
Please set:
alloy-logs:
controller:
type: daemonset'
Expand Down

0 comments on commit 0f7a57c

Please sign in to comment.