diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index ab057c8..276de52 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -162,12 +162,34 @@ jobs: - name: Test run: go test -race ./... + # The chart is rendered with the defaults and with values YAML or --set types + # as a boolean or a number where the API wants a string, and every object is + # validated against the Kubernetes schemas, so a value the API would refuse + # fails here and not at install. + chart: + needs: changes + if: needs.changes.outputs.chart == 'true' + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4.4.0 + + - uses: actions/setup-go@40f1582b2485089dde7abd97c1529aa768e1baff # v5.6.0 + with: + go-version-file: go.mod + cache: false + + - name: Install kubeconform + run: go install github.com/yannh/kubeconform/cmd/kubeconform@v0.6.7 + + - name: Render and validate the chart + run: hack/chart-test/run.sh + # The one check a pull request must pass. A required check is a fixed job # name, so a job skipped above for paths a pull request never touched would # still be listed as required; this job waits for every test job instead # and fails if one that ran failed, and main asks for this job alone. ci: - needs: [changes, test, gcpevents, promevents] + needs: [changes, test, gcpevents, promevents, chart] if: always() runs-on: ubuntu-latest steps: @@ -179,8 +201,9 @@ jobs: ! echo "$RESULTS" | grep -Eq '"(failure|cancelled)"' # Decides what a push or pull request can change: the image (anything but - # the chart, the docs and Markdown), and the two modules of their own, - # gcpevents and promevents, which only their directories touch. A tag, or + # the chart, the docs and Markdown), the chart check (the chart and + # hack/chart-test), and the two modules of their own, gcpevents and + # promevents, which only their directories touch. A tag, or # a push whose previous commit is unknown, changes everything. A job # skipped here is not run and not required: the ci job above passes. changes: @@ -189,6 +212,7 @@ jobs: code: ${{ steps.diff.outputs.code }} gcpevents: ${{ steps.diff.outputs.gcpevents }} promevents: ${{ steps.diff.outputs.promevents }} + chart: ${{ steps.diff.outputs.chart }} steps: - uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4.4.0 with: @@ -200,7 +224,7 @@ jobs: BASE: ${{ github.event.pull_request.base.sha }} run: | set -euo pipefail - all() { printf 'code=true\ngcpevents=true\npromevents=true\n' >> "$GITHUB_OUTPUT"; } + all() { printf 'code=true\ngcpevents=true\npromevents=true\nchart=true\n' >> "$GITHUB_OUTPUT"; } case "$GITHUB_EVENT_NAME" in push) from="$BEFORE" ;; pull_request) from="$BASE" ;; @@ -209,17 +233,18 @@ jobs: if [ "$GITHUB_REF_TYPE" = tag ] || ! git cat-file -e "${from}^{commit}" 2>/dev/null; then all; exit 0 fi - code=false gcpevents=false promevents=false + code=false gcpevents=false promevents=false chart=false while IFS= read -r f; do case "$f" in - .github/workflows/ci.yaml) code=true gcpevents=true promevents=true ;; + .github/workflows/ci.yaml) code=true gcpevents=true promevents=true chart=true ;; gcpevents/*) gcpevents=true; code=true ;; promevents/*) promevents=true; code=true ;; - charts/*|docs/*|*.md|.github/CODEOWNERS|.github/dependabot.yml) ;; + charts/*|hack/chart-test/*) chart=true ;; + docs/*|*.md|.github/CODEOWNERS|.github/dependabot.yml) ;; *) echo "image input changed: $f"; code=true ;; esac done < <(git diff --name-only "$from" "$GITHUB_SHA") - printf 'code=%s\ngcpevents=%s\npromevents=%s\n' "$code" "$gcpevents" "$promevents" >> "$GITHUB_OUTPUT" + printf 'code=%s\ngcpevents=%s\npromevents=%s\nchart=%s\n' "$code" "$gcpevents" "$promevents" "$chart" >> "$GITHUB_OUTPUT" image: needs: [test, changes] diff --git a/CHANGELOG.md b/CHANGELOG.md index c41ae25..f8ccf48 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/). ### Fixed +- **The chart renders values the API wants as strings as strings.** A value that YAML or `--set` types as a boolean or a number (`value: true` in a toleration, `--set tolerations[0].value=true`, a node selector `dedicated: true`, an annotation `count: 3`, a label value in an affinity) was passed to the pod template as typed and the API server refused it: `cannot unmarshal bool into Go struct field Toleration.spec.template.spec.tolerations.value of type string`. The controller, the OTLP sensor and the eBPF DaemonSet now render toleration values, node selectors, pod annotations and affinity label values as strings (an affinity `weight` and `tolerationSeconds` stay numbers). (chart) - **A certificate that expires under a running session is renewed, not replaced by a spent key.** The agent renewed its certificate only when it (re)connected, and only with less than a third of the 24 hours left, while the core keeps a connected session past the certificate's end: an agent connected for a day held an expired certificate, and at the next reconnect (a core roll) it saw no usable certificate, joined with its one-time key, which was spent at the first join, and was refused until someone minted a new key. A session now sets a timer at a third of the lifetime before the end and reconnects to renew (`agent certificate renewal is due; reconnecting to renew it`), and a certificate that expired less than seven days ago is sent as a renewal instead of being dropped; the core accepts the expired one in that grace from 3.6.0 (`agentjoin.Service.RenewGrace`). A certificate past the grace, or one for another core or tenant set, still falls back to the key. (`TestJoin_ExpiredCertificateIsRenewedNotReplacedByAKey`, `TestJoin_SessionReconnectsToRenewBeforeExpiry`, `TestJoinCertState`) - **The OTLP receiver is a sensor: it translates each export as it arrives, forwards it and drops it.** It kept a copy of the latest point of every series it had ever received, as protobuf messages under a key of the same attributes, rebuilt every changed resource's whole set for the sink on a tick and kept that second copy fifteen minutes for a reconnect to replay; a node-level scrape (cAdvisor, a kubelet) never goes silent, so its series of pods long gone stayed until the per-resource limit refused what was live, and the pod's memory grew with the cluster. What is kept across exports is now numbers: the last timestamp of a cumulative series (so an older point cannot take a newer one's place), a delta series' running total, a span route's counts, a log source's counts and a pod's previous PSI reading, each expiring after `--otlp-expire`, and `Held()` in the summary line counts them. Exemplars are dropped at intake, a cAdvisor scrape is admitted by the twelve series read and the pod cgroups alone, a resource that names no namespace, itself or in its points, is refused at intake (the core could not place it), and the otlp role's send queue holds what the stream has not sent yet and nothing else, bounded by points. The controller's hub merges a source's exports per series (`sensorstream.mergeOTLP`, newest value per attribute set, a series dropped after twice `Stale` without an export), so a source whose Collector splits a batch is whole there, where a point costs a few hundred bytes. The limits are sanity bounds on the state kept (`--otlp-max-series` now 2000000, since an entry is tens of bytes). The chart gives the otlp-role pods requests and a 2 GiB memory limit, and every mode sets the Go memory limit to 90% of the container's cgroup limit (`GOMEMLIMIT` in the environment wins). (`TestHeld_DoesNotGrowWithExports`, `TestSweep_*`, `TestMaxSeries_CountsSpanRoutes`, `TestExemplarsDropped`, `TestCAdvisor_IntakeKeepsOnlyWhatIsRead`, `TestExport_DropsAPointOlderThanTheLastForwarded`, `TestIdentity_ForwarderMissingNamespaceIsRefused`, `TestIngest_MergesASourcesExportsPerSeries`, `TestIngest_DropsSeriesNoExportRefreshed`, `TestOTLPRole_Queue*`, `TestCgroupMemoryLimit_*`) - **The OTLP receiver sheds instead of growing: backpressure before the request is read.** With more exports in flight than `--otlp-max-in-flight` (`otlp.limits.maxInFlight`; twice the CPUs, at least 4), or with the live heap past 75% of the Go memory limit (until it is back under 60%), a sender's next export is refused in the gRPC tap, before it is decoded, with RESOURCE_EXHAUSTED and a retry delay (1 s, 5 s for memory) in the status details, which a Collector's exporter queue honours by backing off and sending again. The refusals are logged like every other refusal and counted as refused exports. `--otlp-expire` (`otlp.expire`, 3m: three export intervals of a minute) is how long a series' state lives without an export; it was a fixed 10 minutes. (`TestBackpressure_*`) @@ -23,6 +24,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/). ### Added +- **CI renders the chart and validates it against the Kubernetes schemas.** A chart-only change ran no job, so nothing rendered the chart at all. The `chart` job runs `helm lint` and `helm template` with the defaults and with `hack/chart-test/typed-values.yaml` (booleans and numbers where the API wants strings, every pod template with a toleration, node selector, annotation and affinity) and checks every object with kubeconform; the run fails on a chart that renders a value the API would refuse. - **The sensor_state frame carries the OTLP intake per sender.** The receiver counts, per sender and per minute, the exports and points offered, the points no collector reads (by metric name, every name of the window up to 1024 per sender and the rest as "other", which is never ranked), the points refused and the exports refused before reading, and reports the state entries and sources held for the sender. The otlp role sends it in its SensorState, the controller sums it over the replicas and its own receiver, and the frame's new `intake` list carries it with the top 20 unread names, so the core can show per agent what share of a Collector's export is read and what to filter out at the Collector. (`TestIntake_*`, `TestOTLPIntakeFromNodes_*`, `TestSensorStateFrame_CarriesIntake`) - **Two images: `agent` without OBI and `agent-obi` with it.** The default image, `agent` (`.ko.yaml`, `make ko-push`), is built without `-tags obi`: it links no OBI package, needs no generated eBPF bindings, is 54 MB against 93 MB for linux/amd64, and runs the controller and the OTLP role; `--mode role ebpf` fails fast in it. `agent-obi` (`hack/ko-obi/.ko.yaml`, `make ko-push-obi`, published to `-obi`) is the build with the instrumenter for the eBPF DaemonSet. Every file that imports OBI (`ebpf_config.go`, `ebpf_attach.go`, `ebpf_host_red.go`, `ebpf_metrics.go` and their tests) now carries the `obi` build tag, and a CI step fails if the plain build imports one. CI builds, signs and attests both images with the same tags. The chart runs the controller and the OTLP role from `image.repository` and the DaemonSet from `image.ebpf.repository` (default `-obi`, tag `image.ebpf.tag`, default `image.tag`). - **A Collector can send everything it has.** The OTLP receiver drops a metric no collector reads at intake (`Options.Wanted`, `ReadByCollectors`: the RED histograms and their legacy names, the spanmetrics output, `log.*`, the cAdvisor series, `use.*` and the workload counts), before its resource is stored or counted against a quota. A sender that exports the whole k8s_cluster, runtime and Collector self-telemetry therefore no longer fills the per-sender and total quotas ahead of the resources that matter; the dropped points show as `unread` in the receiver's summary and the ledger, not as refused. (`TestWanted_*`, `TestReadByCollectors`) diff --git a/charts/triage-agent/templates/_helpers.tpl b/charts/triage-agent/templates/_helpers.tpl index bdb0913..2bed533 100644 --- a/charts/triage-agent/templates/_helpers.tpl +++ b/charts/triage-agent/templates/_helpers.tpl @@ -240,3 +240,77 @@ core.endpoint is set. {{- $_ := set $c "storage" ($c.storage | default "secret") -}} {{- toYaml $c -}} {{- end -}} + +{{/* +Tolerations as the API wants them: a toleration's value is a string. An +unquoted `true` or `1` (a YAML value, or `--set ...tolerations[0].value=true`, +which Helm types as a boolean) would otherwise render as a boolean and the +API server refuses the pod template. +*/}} +{{- define "triage-agent.tolerations" -}} +{{- $out := list -}} +{{- range . -}} +{{- $t := deepCopy . -}} +{{- if hasKey $t "value" -}} +{{- $_ := set $t "value" (toString $t.value) -}} +{{- end -}} +{{- $out = append $out $t -}} +{{- end -}} +{{- toYaml $out -}} +{{- end -}} + +{{/* +A map whose values the API wants as strings (nodeSelector, annotations): +`true` or `3` typed by YAML or --set is rendered as "true" or "3". +*/}} +{{- define "triage-agent.stringMap" -}} +{{- $out := dict -}} +{{- range $k, $v := . -}} +{{- $_ := set $out $k (include "triage-agent.scalarString" $v) -}} +{{- end -}} +{{- toYaml $out -}} +{{- end -}} + +{{/* A scalar as the string it is written as: a number that is whole prints + without an exponent. */}} +{{- define "triage-agent.scalarString" -}} +{{- if kindIs "float64" . -}} +{{- if eq (floor .) . -}}{{- printf "%d" (int64 .) -}}{{- else -}}{{- toString . -}}{{- end -}} +{{- else -}} +{{- toString . -}} +{{- end -}} +{{- end -}} + +{{/* +An affinity with every scalar a string (label values in matchLabels and +matchExpressions, namespaces, topology keys) except `weight`, the one number. +Called with {v: }; returns {"v": } as JSON. +*/}} +{{- define "triage-agent.affinityValue" -}} +{{- $v := .v -}} +{{- if kindIs "map" $v -}} +{{- $o := dict -}} +{{- range $k, $x := $v -}} +{{- if eq $k "weight" -}} +{{- $_ := set $o $k $x -}} +{{- else -}} +{{- $_ := set $o $k ((include "triage-agent.affinityValue" (dict "v" $x) | fromJson).v) -}} +{{- end -}} +{{- end -}} +{{- dict "v" $o | toJson -}} +{{- else if kindIs "slice" $v -}} +{{- $o := list -}} +{{- range $x := $v -}} +{{- $o = append $o ((include "triage-agent.affinityValue" (dict "v" $x) | fromJson).v) -}} +{{- end -}} +{{- dict "v" $o | toJson -}} +{{- else if kindIs "invalid" $v -}} +{{- dict "v" nil | toJson -}} +{{- else -}} +{{- dict "v" (include "triage-agent.scalarString" $v) | toJson -}} +{{- end -}} +{{- end -}} + +{{- define "triage-agent.affinity" -}} +{{- toYaml ((include "triage-agent.affinityValue" (dict "v" .) | fromJson).v) -}} +{{- end -}} diff --git a/charts/triage-agent/templates/deployment.yaml b/charts/triage-agent/templates/deployment.yaml index b9987cb..4867838 100644 --- a/charts/triage-agent/templates/deployment.yaml +++ b/charts/triage-agent/templates/deployment.yaml @@ -88,7 +88,7 @@ spec: {{- include "triage-agent.selectorLabels" . | nindent 8 }} {{- with .Values.podAnnotations }} annotations: - {{- toYaml . | nindent 8 }} + {{- include "triage-agent.stringMap" . | nindent 8 }} {{- end }} spec: serviceAccountName: {{ include "triage-agent.serviceAccountName" . }} @@ -484,13 +484,13 @@ spec: {{- end }} {{- with .Values.nodeSelector }} nodeSelector: - {{- toYaml . | nindent 8 }} + {{- include "triage-agent.stringMap" . | nindent 8 }} {{- end }} {{- with .Values.tolerations }} tolerations: - {{- toYaml . | nindent 8 }} + {{- include "triage-agent.tolerations" . | nindent 8 }} {{- end }} {{- with .Values.affinity }} affinity: - {{- toYaml . | nindent 8 }} + {{- include "triage-agent.affinity" . | nindent 8 }} {{- end }} diff --git a/charts/triage-agent/templates/ebpf-daemonset.yaml b/charts/triage-agent/templates/ebpf-daemonset.yaml index a288e87..4e6d12d 100644 --- a/charts/triage-agent/templates/ebpf-daemonset.yaml +++ b/charts/triage-agent/templates/ebpf-daemonset.yaml @@ -145,11 +145,11 @@ spec: {{- end }} {{- with $ebpf.tolerations }} tolerations: - {{- toYaml . | nindent 8 }} + {{- include "triage-agent.tolerations" . | nindent 8 }} {{- end }} {{- with $ebpf.nodeSelector }} nodeSelector: - {{- toYaml . | nindent 8 }} + {{- include "triage-agent.stringMap" . | nindent 8 }} {{- end }} containers: {{- /* ONE container running all three roles in one process: the diff --git a/charts/triage-agent/templates/otlp-sensor.yaml b/charts/triage-agent/templates/otlp-sensor.yaml index 2f368ae..42e0ebc 100644 --- a/charts/triage-agent/templates/otlp-sensor.yaml +++ b/charts/triage-agent/templates/otlp-sensor.yaml @@ -72,7 +72,7 @@ spec: {{- include "triage-agent.otlpSensorSelectorLabels" . | nindent 8 }} {{- with .Values.podAnnotations }} annotations: - {{- toYaml . | nindent 8 }} + {{- include "triage-agent.stringMap" . | nindent 8 }} {{- end }} spec: serviceAccountName: {{ $name }} @@ -197,15 +197,15 @@ spec: {{- end }} {{- with $s.nodeSelector }} nodeSelector: - {{- toYaml . | nindent 8 }} + {{- include "triage-agent.stringMap" . | nindent 8 }} {{- end }} {{- with $s.affinity }} affinity: - {{- toYaml . | nindent 8 }} + {{- include "triage-agent.affinity" . | nindent 8 }} {{- end }} {{- with $s.tolerations }} tolerations: - {{- toYaml . | nindent 8 }} + {{- include "triage-agent.tolerations" . | nindent 8 }} {{- end }} {{- if gt (int ($s.replicas | default 2)) 1 }} --- diff --git a/hack/chart-test/run.sh b/hack/chart-test/run.sh new file mode 100755 index 0000000..6611ca6 --- /dev/null +++ b/hack/chart-test/run.sh @@ -0,0 +1,14 @@ +#!/usr/bin/env bash +# Renders the chart with the defaults and with typed-values.yaml and validates +# every object against the Kubernetes schemas, so a value the API would refuse +# (a boolean where a string is required) fails here and not at install. +set -euo pipefail +cd "$(dirname "$0")/../.." + +chart=charts/triage-agent +helm lint "$chart" +for values in "" hack/chart-test/typed-values.yaml; do + echo "== render ${values:-defaults}" + helm template chart-test "$chart" ${values:+-f "$values"} \ + | kubeconform -strict -summary -ignore-missing-schemas -kubernetes-version 1.30.0 +done diff --git a/hack/chart-test/typed-values.yaml b/hack/chart-test/typed-values.yaml new file mode 100644 index 0000000..0c0f7c5 --- /dev/null +++ b/hack/chart-test/typed-values.yaml @@ -0,0 +1,50 @@ +# Values that YAML or `helm --set` types as a boolean or a number where the +# API wants a string: a toleration value, a node selector, an annotation, a +# label value in an affinity. The chart has to render them as strings, so +# `helm template | kubeconform` passes on this file (hack/chart-test/run.sh). +core: + host: core.example.test + clusterName: chart-test + caFingerprint: "SHA256:0000000000000000000000000000000000000000000000000000000000000000" +podAnnotations: + flag: true + count: 3 +nodeSelector: + pool: 7 + dedicated: true +tolerations: + - {key: dedicated, operator: Equal, value: true, effect: NoSchedule} + - {key: gen, operator: Equal, value: 2, effect: NoSchedule} + - {key: transient, operator: Exists, effect: NoExecute, tolerationSeconds: 300} +affinity: + nodeAffinity: + requiredDuringSchedulingIgnoredDuringExecution: + nodeSelectorTerms: + - matchExpressions: + - {key: gpu, operator: In, values: [true, 1]} + preferredDuringSchedulingIgnoredDuringExecution: + - weight: 10 + preference: + matchExpressions: + - {key: pool, operator: In, values: [7]} +ebpf: + enabled: true + nodeSelector: + dedicated: true + tolerations: + - {key: dedicated, operator: Equal, value: true, effect: NoSchedule} +otlp: + enabled: true + clientCASecret: ca + sensor: + enabled: true + nodeSelector: + dedicated: true + tolerations: + - {key: dedicated, operator: Equal, value: true, effect: NoSchedule} + affinity: + nodeAffinity: + requiredDuringSchedulingIgnoredDuringExecution: + nodeSelectorTerms: + - matchExpressions: + - {key: gpu, operator: In, values: [true]}