Skip to content

Commit

Permalink
Helm: Integration testing (grafana#641)
Browse files Browse the repository at this point in the history
* Helm chart integration testing

Signed-off-by: Steven Sheehy <ssheehy@firescope.com>

* Don't check helm version on every push

Signed-off-by: Steven Sheehy <ssheehy@firescope.com>

* Remove chart upgrade testing

Signed-off-by: Steven Sheehy <ssheehy@firescope.com>
  • Loading branch information
Steven Sheehy authored and cyriltovena committed Jun 12, 2019
1 parent fcd19e4 commit 8ed4a47
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -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"'
}
30 changes: 30 additions & 0 deletions production/helm/loki-stack/templates/tests/loki-test-pod.yaml
Original file line number Diff line number Diff line change
@@ -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
4 changes: 2 additions & 2 deletions production/helm/loki/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
9 changes: 4 additions & 5 deletions production/helm/promtail/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -127,4 +127,3 @@ config:
target_config:
# Period to resync directories being watched and files being tailed
sync_period: 10s

0 comments on commit 8ed4a47

Please sign in to comment.