diff --git a/production/helm/loki-stack/templates/tests/loki-test-configmap.yaml b/production/helm/loki-stack/templates/tests/loki-test-configmap.yaml new file mode 100644 index 000000000000..205fd774c795 --- /dev/null +++ b/production/helm/loki-stack/templates/tests/loki-test-configmap.yaml @@ -0,0 +1,42 @@ +apiVersion: v1 +kind: ConfigMap +metadata: + name: {{ template "loki-stack.fullname" . }}-test + labels: + app: {{ template "loki-stack.name" . }} + chart: {{ template "loki-stack.chart" . }} + release: {{ .Release.Name }} + heritage: {{ .Release.Service }} +data: + test.sh: | + #!/usr/bin/env bash + + LOKI_URI="http://${LOKI_SERVICE}:${LOKI_PORT}" + + function setup() { + apk add -u curl jq + until (curl -s ${LOKI_URI}/api/prom/label/app/values | jq -e '.values[] | select(. == "loki")'); do + sleep 1 + done + } + + @test "Has labels" { + curl -s ${LOKI_URI}/api/prom/label | \ + jq -e '.values[] | select(. == "app")' + } + + @test "Query log entry" { + curl -sG ${LOKI_URI}/api/prom/query?limit=10 --data-urlencode 'query={app="loki"}' | \ + jq -e '.streams[].entries | length >= 1' + } + + @test "Push log entry" { + local timestamp=$(date -Iseconds -u | sed 's/UTC/.000000000+00:00/') + local data=$(jq -n --arg timestamp "${timestamp}" '{"streams": [{"labels": "{app=\"loki-test\"}", "entries": [{"ts": $timestamp, "line": "foobar"}]}]}') + + curl -s -X POST -H "Content-Type: application/json" ${LOKI_URI}/api/prom/push -d "${data}" + + curl -sG ${LOKI_URI}/api/prom/query?limit=1 --data-urlencode 'query={app="loki-test"}' | \ + jq -e '.streams[].entries[].line == "foobar"' + } + diff --git a/production/helm/loki-stack/templates/tests/loki-test-pod.yaml b/production/helm/loki-stack/templates/tests/loki-test-pod.yaml new file mode 100644 index 000000000000..a153a05df929 --- /dev/null +++ b/production/helm/loki-stack/templates/tests/loki-test-pod.yaml @@ -0,0 +1,30 @@ +apiVersion: v1 +kind: Pod +metadata: + annotations: + "helm.sh/hook": test-success + labels: + app: {{ template "loki-stack.name" . }} + chart: {{ template "loki-stack.chart" . }} + release: {{ .Release.Name }} + heritage: {{ .Release.Service }} + name: {{ template "loki-stack.fullname" . }}-test +spec: + containers: + - name: test + image: bats/bats:v1.1.0 + args: + - /var/lib/loki/test.sh + env: + - name: LOKI_SERVICE + value: {{ template "loki.serviceName" . }} + - name: LOKI_PORT + value: "{{ .Values.loki.service.port }}" + volumeMounts: + - name: tests + mountPath: /var/lib/loki + restartPolicy: Never + volumes: + - name: tests + configMap: + name: {{ template "loki-stack.fullname" . }}-test diff --git a/production/helm/loki/values.yaml b/production/helm/loki/values.yaml index 7ac6129ae690..c6725a5f8b9b 100644 --- a/production/helm/loki/values.yaml +++ b/production/helm/loki/values.yaml @@ -105,8 +105,8 @@ podLabels: {} ## Pod Annotations podAnnotations: - prometheus.io/scrape: "true" - prometheus.io/port: "http-metrics" + prometheus.io/scrape: "true" + prometheus.io/port: "http-metrics" podManagementPolicy: OrderedReady diff --git a/production/helm/promtail/values.yaml b/production/helm/promtail/values.yaml index 9848bf364031..ae75dfccaba9 100644 --- a/production/helm/promtail/values.yaml +++ b/production/helm/promtail/values.yaml @@ -14,7 +14,7 @@ image: livenessProbe: {} loki: - serviceName: "" # Defaults to "${RELEASE}-loki" if not set + serviceName: "" # Defaults to "${RELEASE}-loki" if not set servicePort: 3100 serviceScheme: http # user: user @@ -32,9 +32,9 @@ pipelineStages: ## Pod Labels podLabels: {} -podAnnotations: - prometheus.io/scrape: "true" - prometheus.io/port: "http-metrics" +podAnnotations: + prometheus.io/scrape: "true" + prometheus.io/port: "http-metrics" # This should match config.server.http_listen_port port: 3101 @@ -127,4 +127,3 @@ config: target_config: # Period to resync directories being watched and files being tailed sync_period: 10s -