diff --git a/CHANGELOG.md b/CHANGELOG.md index 853c239..23f840b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,15 @@ All notable changes; the format follows [Keep a Changelog](https://keepachangelo ## [Unreleased] +## [0.1.5] - 2026-11-23 + +### Added +- `components.logging` (opt-in, external only), the same shape as `components.tracing`: `enabled` + + `external.queryUrl` (and `external.endpoint`, the push API your collector uses, for reference) give + platform-monitoring's Grafana a Loki datasource (uid `loki`, provisioning file `loki.yaml`). No Application, no + Loki or collector of its own; without the key the render is exactly as before (tracing included). `check` refuses + `enabled` without `external.queryUrl`. A patch release on top of 0.1.4 (no 0.2.0 changes). + ## [0.1.4] - 2026-11-23 ### Added diff --git a/bin/slo-platform b/bin/slo-platform index 937634e..190ed5b 100755 --- a/bin/slo-platform +++ b/bin/slo-platform @@ -47,7 +47,7 @@ LABEL_VALUE = r"^(([A-Za-z0-9][-A-Za-z0-9_.]*)?[A-Za-z0-9])?$" # platform components (components.): Helm-sourced ones take values, kustomize-sourced ones do not HELM_COMPONENTS = ("monitoring", "blackbox", "chaos-mesh", "experiments") KUSTOMIZE_COMPONENTS = ("pyrra", "cert-manager", "argo-rollouts", "cnpg", "kyverno", "policies", "object-storage") -# components.tracing: an external Tempo (opt-in); only Grafana's datasource, no Application +# components.tracing / components.logging: an external Tempo / Loki (opt-in); only Grafana's datasource, no Application HTTP_URL = r"^https?://[^\s/]+(/\S*)?$" TRACING_SCHEMA = {"type": "object", "additionalProperties": False, "properties": { "enabled": {"type": "boolean"}, @@ -106,7 +106,7 @@ SCHEMA = { "properties": {"enabled": {"type": "boolean"}, "values": {"type": "object"}}} for c in HELM_COMPONENTS}, **{c: {"type": "object", "additionalProperties": False, "properties": {"enabled": {"type": "boolean"}}} for c in KUSTOMIZE_COMPONENTS}, - "tracing": TRACING_SCHEMA}}, + "tracing": TRACING_SCHEMA, "logging": TRACING_SCHEMA}}, "grafana": {"type": "object", "additionalProperties": False, "properties": {"adminSecret": {"type": "string", "pattern": NAME}}}, "regression": {"type": "object", "additionalProperties": False, "properties": { @@ -289,18 +289,20 @@ def check_platform(p, problems, product=None): names = [x.get("name") for x in extras or [] if isinstance(x, dict)] for n in sorted({n for n in names if names.count(n) > 1}): problems.append(f"platform.yaml: .clusters.{name}.extras: {n} twice (the Application is extras-)") - # components.tracing (top-level, then each cluster's over it): enabled needs an external Tempo's query URL + # components.tracing / logging (top-level, then each cluster's over it): enabled needs the external query URL comps = p.get("components") if isinstance(p.get("components"), dict) else {} clusters = p.get("clusters") if isinstance(p.get("clusters"), dict) else {} - for name in clusters or [None]: - cc = (clusters.get(name) or {}) if name else {} - cc = (cc.get("components") or {}) if isinstance(cc, dict) else {} - t = deep_merge(comps.get("tracing") if isinstance(comps.get("tracing"), dict) else {}, - cc.get("tracing") if isinstance(cc, dict) and isinstance(cc.get("tracing"), dict) else {}) - if t.get("enabled") is True and not (t.get("external") or {}).get("queryUrl"): - where = f" on cluster {name}" if name else "" - problems.append(f"platform.yaml: .components.tracing: enabled{where} needs external.queryUrl (an external " - "Tempo's HTTP API, e.g. http://tempo.example:3200): this release installs no Tempo of its own") + for comp, product, example in (("tracing", "Tempo", "http://tempo.example:3200"), + ("logging", "Loki", "http://loki.example:3100")): + for name in clusters or [None]: + cc = (clusters.get(name) or {}) if name else {} + cc = (cc.get("components") or {}) if isinstance(cc, dict) else {} + t = deep_merge(comps.get(comp) if isinstance(comps.get(comp), dict) else {}, + cc.get(comp) if isinstance(cc, dict) and isinstance(cc.get(comp), dict) else {}) + if t.get("enabled") is True and not (t.get("external") or {}).get("queryUrl"): + where = f" on cluster {name}" if name else "" + problems.append(f"platform.yaml: .components.{comp}: enabled{where} needs external.queryUrl (an external " + f"{product}'s HTTP API, e.g. {example}): this release installs no {product} of its own") tz = p.get("timezone") if isinstance(tz, str) and not any(e.startswith(".timezone") for e in errs): try: diff --git a/bin/test_slo_platform.py b/bin/test_slo_platform.py index 71d5935..0e1c482 100644 --- a/bin/test_slo_platform.py +++ b/bin/test_slo_platform.py @@ -468,6 +468,17 @@ def test_tracing(self): self.edit(self.p, lambda p: p.update(components={"tracing": {"values": {"x": 1}}})) self.assertProblem(".components.tracing.values: unknown key") + def test_logging(self): + ext = {"queryUrl": "http://loki.example:3100", "endpoint": "http://loki.example:3100/loki/api/v1/push"} + self.edit(self.p, lambda p: p.update(components={"logging": {"enabled": True, "external": ext}, + "tracing": {"enabled": True, "external": {"queryUrl": "http://t:3200"}}})) + for real in (False, True): + self.assertEqual(self.problems(real), []) + self.edit(self.p, lambda p: p.update(components={"logging": {"enabled": True}})) + self.assertProblem(".components.logging: enabled on cluster lab needs external.queryUrl (an external Loki's") + self.edit(self.p, lambda p: p.update(components={"logging": {"enabled": True, "external": {"queryUrl": "loki"}}})) + self.assertProblem(".components.logging.external.queryUrl") + def test_namespace_metadata(self): self.edit(self.p, lambda p: p.update(applications={"namespaceLabels": {"example.com/policies": "enforced"}, "namespaceAnnotations": {"example.com/note": "any text"}})) diff --git a/docs/configuration.md b/docs/configuration.md index 43a608f..4c26f6e 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -121,6 +121,9 @@ once per cluster with `cluster: ` added. An annotated example: [platform.e | `components.tracing.enabled` | `false` | Opt-in: Grafana gets a Tempo datasource for `components.tracing.external` ([Tracing](#tracing)) | | `components.tracing.external.queryUrl` | — | An external Tempo's HTTP API as Grafana reaches it (`http://tempo.example:3200`); required when enabled | | `components.tracing.external.endpoint` | — | Its OTLP/HTTP receiver (`http://tempo.example:4318`): recorded for people and tools, not passed into applications | +| `components.logging.enabled` | `false` | Opt-in: Grafana gets a Loki datasource for `components.logging.external` ([Logs](#logs)) | +| `components.logging.external.queryUrl` | — | An external Loki's HTTP API as Grafana reaches it (`http://loki.example:3100`); required when enabled | +| `components.logging.external.endpoint` | — | Its push API (`http://loki.example:3100/loki/api/v1/push`): recorded for your log collector, the platform installs none | | `grafana.adminSecret` | `grafana-admin` | Secret in `monitoring` with keys `admin-user`, `admin-password`; bootstrap creates it | | `regression.schedule` | `0 9 * * *` | Cron schedule of the daily experiment regression on lab clusters, in `timezone` | | `regression.experiments` | `/*/experiments` | Experiment directories (a glob or a list of globs, relative to the instance root): the daily regression runs their `*.yaml`, `check` checks them | @@ -236,6 +239,7 @@ The platform components the root chart installs, each an Argo CD Application `pl | `kyverno`, `policies` | kustomize | with `optional.policies: true` | | `object-storage` | kustomize | clusters with `objectStorage: in-cluster` | | `tracing` | none: a Grafana datasource for an external Tempo | only with `enabled: true` (opt-in): [Tracing](#tracing) | +| `logging` | none: a Grafana datasource for an external Loki | only with `enabled: true` (opt-in): [Logs](#logs) | - `enabled: false` drops the component (its Application; Argo CD prunes what it installed). `enabled: true` is the default and does not override the condition in the last column. What depends on a dropped component is yours to @@ -296,6 +300,23 @@ clusters: - `check` refuses `enabled: true` without `external.queryUrl` (top level or on a cluster), and URLs that are not `http(s)://`. +### Logs + +`logging` works like [Tracing](#tracing), for Grafana Loki: opt-in, external only — the cluster's Grafana gets a Loki +datasource (name `Loki`, uid `loki`, provisioning file `loki.yaml` next to `tempo.yaml`). The platform installs no +Loki and no collector: ship the logs with your own (e.g. Grafana Alloy through [extras](#extras)) to +`external.endpoint`, and give it a bounded queue so that an unreachable Loki costs log lines, never the workloads. + +```yaml +components: + logging: + external: + queryUrl: http://loki.example:3100 # the datasource's URL (required when enabled) + endpoint: http://loki.example:3100/loki/api/v1/push # where your collector pushes +clusters: + prod: { role: prod, components: { logging: { enabled: true } } } +``` + ## An existing repository A GitOps repository that already holds applications (one directory per application with an `app.yaml`, experiments, diff --git a/platform.example.yaml b/platform.example.yaml index 80456b8..93c50ac 100644 --- a/platform.example.yaml +++ b/platform.example.yaml @@ -41,6 +41,9 @@ optional: # tracing: # opt-in: a Grafana datasource for an external Tempo (docs/configuration.md#tracing) # enabled: true # external: { queryUrl: "http://tempo.example:3200", endpoint: "http://tempo.example:4318" } +# logging: # opt-in: a Grafana datasource for an external Loki (docs/configuration.md#logs) +# enabled: true +# external: { queryUrl: "http://loki.example:3100" } grafana: adminSecret: grafana-admin # Secret in monitoring with admin-user, admin-password (created by bootstrap) diff --git a/platform/root/templates/_helpers.tpl b/platform/root/templates/_helpers.tpl index 7157d2a..e49f902 100644 --- a/platform/root/templates/_helpers.tpl +++ b/platform/root/templates/_helpers.tpl @@ -32,16 +32,18 @@ clusters..components. deep-merged over it (clusters differ: a sma {{- dict "enabled" (ne (toString (dig "enabled" true $c)) "false") "values" (dig "values" dict $c) | toJson }} {{- end }} -{{- /* root.tracing: components.tracing with clusters..components.tracing deep-merged over it, as JSON -{enabled, external}: opt-in (enabled defaults to false); enabled needs external.queryUrl, an external Tempo (this -release installs no Tempo of its own). Only platform-monitoring's Grafana uses it (a Tempo datasource). */}} -{{- define "root.tracing" -}} -{{- $top := index (.Values.components | default dict) "tracing" | default dict }} -{{- $cl := index ((index (.Values.clusters | default dict) (.Values.cluster | default "") | default dict).components | default dict) "tracing" | default dict }} +{{- /* root.external: an opt-in component that points Grafana at a service outside the cluster ((list . "" +"" ""): tracing → Tempo, logging → Loki): components. with clusters..components. +deep-merged over it, as JSON {enabled, external}. enabled defaults to false and needs external.queryUrl (this release +installs neither of its own). Only platform-monitoring's Grafana uses them (a datasource each). */}} +{{- define "root.external" -}} +{{- $root := index . 0 }}{{ $name := index . 1 }}{{ $product := index . 2 }}{{ $example := index . 3 }} +{{- $top := index ($root.Values.components | default dict) $name | default dict }} +{{- $cl := index ((index ($root.Values.clusters | default dict) ($root.Values.cluster | default "") | default dict).components | default dict) $name | default dict }} {{- $c := include "root.deepMerge" (dict "base" $top "over" $cl) | fromJson }} {{- $on := eq (toString (dig "enabled" false $c)) "true" }} {{- $ext := dig "external" dict $c }} -{{- if and $on (not (dig "queryUrl" "" $ext)) }}{{ fail "components.tracing: enabled needs external.queryUrl (an external Tempo's HTTP API, e.g. http://tempo.example:3200): this release installs no Tempo of its own" }}{{ end }} +{{- if and $on (not (dig "queryUrl" "" $ext)) }}{{ fail (printf "components.%s: enabled needs external.queryUrl (an external %s's HTTP API, e.g. %s): this release installs no %s of its own" $name $product $example $product) }}{{ end }} {{- dict "enabled" $on "external" $ext | toJson }} {{- end }} diff --git a/platform/root/templates/platform-monitoring.yaml b/platform/root/templates/platform-monitoring.yaml index a137b0f..2d81616 100644 --- a/platform/root/templates/platform-monitoring.yaml +++ b/platform/root/templates/platform-monitoring.yaml @@ -100,16 +100,25 @@ grafana: sidecar: dashboards: { enabled: true, label: grafana_dashboard, searchNamespace: ALL } resources: { requests: { cpu: 50m, memory: 192Mi }, limits: { memory: 512Mi } } - {{- $tracing := include "root.tracing" . | fromJson }} - {{- if $tracing.enabled }} - # components.tracing: the external Tempo as a datasource (uid tempo). A provisioning file of its own (a key of the - # datasources map), not an entry of additionalDataSources: your own additionalDataSources (a list: it replaces) - # leave it in place. + {{- $tracing := include "root.external" (list . "tracing" "Tempo" "http://tempo.example:3200") | fromJson }} + {{- $logging := include "root.external" (list . "logging" "Loki" "http://loki.example:3100") | fromJson }} + {{- if or $tracing.enabled $logging.enabled }} + # components.tracing / components.logging: the external Tempo / Loki as datasources (uid tempo / loki). Provisioning + # files of their own (keys of the datasources map), not entries of additionalDataSources: your own + # additionalDataSources (a list: it replaces) leave them in place. datasources: + {{- if $tracing.enabled }} tempo.yaml: apiVersion: 1 datasources: - { name: Tempo, uid: tempo, type: tempo, access: proxy, url: {{ $tracing.external.queryUrl | quote }} } + {{- end }} + {{- if $logging.enabled }} + loki.yaml: + apiVersion: 1 + datasources: + - { name: Loki, uid: loki, type: loki, access: proxy, url: {{ $logging.external.queryUrl | quote }} } + {{- end }} {{- end }} # Grafana needs more than the default 60s to start on a small node: the liveness probe killed it in a loop # (exit 137) diff --git a/platform/root/values.schema.json b/platform/root/values.schema.json index d907781..e62d367 100644 --- a/platform/root/values.schema.json +++ b/platform/root/values.schema.json @@ -997,6 +997,38 @@ } }, "description": "Distributed tracing with an external Grafana Tempo: opt-in (enabled: false by default); needs external.queryUrl. No Application: only platform-monitoring's Grafana changes." + }, + "logging": { + "type": "object", + "additionalProperties": false, + "properties": { + "enabled": { + "type": "boolean", + "default": false, + "description": "true: Grafana gets a Loki datasource for `external` (off by default)." + }, + "external": { + "type": "object", + "additionalProperties": false, + "required": [ + "queryUrl" + ], + "properties": { + "queryUrl": { + "type": "string", + "pattern": "^https?://[^\\s/]+(/\\S*)?$", + "description": "Loki's HTTP API as Grafana reaches it, e.g. http://loki.example:3100: the Loki datasource's URL." + }, + "endpoint": { + "type": "string", + "pattern": "^https?://[^\\s/]+(/\\S*)?$", + "description": "Loki's push API, e.g. http://loki.example:3100/loki/api/v1/push: what log collectors send to. Recorded here for people and tools; the platform installs no collector." + } + }, + "description": "A Loki outside the cluster (this release has no in-cluster Loki)." + } + }, + "description": "Logs in an external Grafana Loki: opt-in (enabled: false by default); needs external.queryUrl. No Application: only platform-monitoring's Grafana changes." } } } @@ -1239,6 +1271,38 @@ } }, "description": "Distributed tracing with an external Grafana Tempo: opt-in (enabled: false by default); needs external.queryUrl. No Application: only platform-monitoring's Grafana changes." + }, + "logging": { + "type": "object", + "additionalProperties": false, + "properties": { + "enabled": { + "type": "boolean", + "default": false, + "description": "true: Grafana gets a Loki datasource for `external` (off by default)." + }, + "external": { + "type": "object", + "additionalProperties": false, + "required": [ + "queryUrl" + ], + "properties": { + "queryUrl": { + "type": "string", + "pattern": "^https?://[^\\s/]+(/\\S*)?$", + "description": "Loki's HTTP API as Grafana reaches it, e.g. http://loki.example:3100: the Loki datasource's URL." + }, + "endpoint": { + "type": "string", + "pattern": "^https?://[^\\s/]+(/\\S*)?$", + "description": "Loki's push API, e.g. http://loki.example:3100/loki/api/v1/push: what log collectors send to. Recorded here for people and tools; the platform installs no collector." + } + }, + "description": "A Loki outside the cluster (this release has no in-cluster Loki)." + } + }, + "description": "Logs in an external Grafana Loki: opt-in (enabled: false by default); needs external.queryUrl. No Application: only platform-monitoring's Grafana changes." } } }, diff --git a/scripts/test_root_chart.py b/scripts/test_root_chart.py index 18778f0..c7a38af 100644 --- a/scripts/test_root_chart.py +++ b/scripts/test_root_chart.py @@ -264,7 +264,7 @@ def test_components_enabled(self): "argo-rollouts": "platform-argo-rollouts", "cnpg": "platform-cnpg", "experiments": "platform-experiments", "kyverno": "platform-kyverno", "policies": "platform-policies", "object-storage": "platform-object-storage"} with open(os.path.join(CHART, "values.schema.json")) as f: - self.assertEqual(set(json.load(f)["properties"]["components"]["properties"]), set(names) | {"tracing"}) + self.assertEqual(set(json.load(f)["properties"]["components"]["properties"]), set(names) | {"tracing", "logging"}) both = set(ok(BASE, "prod")) | set(ok(BASE, "lab")) for c, app in names.items(): v = values(components={c: {"enabled": False}}) @@ -310,6 +310,32 @@ def test_tracing(self): self.assertNotEqual(rc, 0, t) self.assertIn(want, err) + def test_logging(self): + # like tracing: a Loki datasource in Grafana, no Application; next to Tempo's when both are on + ext = {"queryUrl": "http://loki.example:3100"} + tr = {"enabled": True, "external": {"queryUrl": "http://tempo.example:3200"}} + for cl in ("prod", "lab"): + self.assertEqual(ok(values(components={"logging": {"external": ext}}), cl), ok(BASE, cl)) + loki = {"apiVersion": 1, "datasources": [ + {"name": "Loki", "uid": "loki", "type": "loki", "access": "proxy", "url": "http://loki.example:3100"}]} + on = ok(values(components={"logging": {"enabled": True, "external": ext}}), "prod") + self.assertEqual(set(on), set(ok(BASE, "prod"))) + g, g0 = (helm_values(o["platform-monitoring"])["grafana"] for o in (on, ok(BASE, "prod"))) + self.assertEqual(g.pop("datasources"), {"loki.yaml": loki}) + self.assertEqual(g, g0) + both = helm_values(ok(values(components={"logging": {"enabled": True, "external": ext}, "tracing": tr}), + "prod")["platform-monitoring"])["grafana"]["datasources"] + self.assertEqual((sorted(both), both["loki.yaml"]), (["loki.yaml", "tempo.yaml"], loki)) + # tracing alone renders exactly as in 0.1.4 + t = helm_values(ok(values(components={"tracing": tr}), "prod")["platform-monitoring"])["grafana"]["datasources"] + self.assertEqual(list(t), ["tempo.yaml"]) + for t, want in (({"enabled": True}, "components.logging: enabled needs external.queryUrl (an external Loki's"), + ({"enabled": True, "external": {"queryUrl": "loki:3100"}}, "queryUrl"), + ({"values": {"x": 1}}, "values")): + rc, _, err = helm(values(components={"logging": t}), "prod") + self.assertNotEqual(rc, 0, t) + self.assertIn(want, err) + def test_components_per_cluster(self): # a small lab drops Grafana and keeps prod's; cluster-level values merge over the top-level ones v = values(components={"monitoring": {"values": {"grafana": {"additionalDataSources": [{"name": "x"}]}}}})