loki-test-configmap.yaml 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. {{- if (and .Values.test_pod.enabled .Values.loki.enabled) }}
  2. apiVersion: v1
  3. kind: ConfigMap
  4. metadata:
  5. name: {{ template "loki-stack.fullname" . }}-test
  6. labels:
  7. app: {{ template "loki-stack.name" . }}
  8. chart: {{ template "loki-stack.chart" . }}
  9. release: {{ .Release.Name }}
  10. heritage: {{ .Release.Service }}
  11. data:
  12. test.sh: |
  13. #!/usr/bin/env bash
  14. LOKI_URI="http://${LOKI_SERVICE}:${LOKI_PORT}"
  15. function setup() {
  16. apk add -u curl jq
  17. until (curl -s ${LOKI_URI}/loki/api/v1/label/app/values | jq -e '.data[] | select(. == "loki")'); do
  18. sleep 1
  19. done
  20. }
  21. @test "Has labels" {
  22. curl -s ${LOKI_URI}/loki/api/v1/labels | \
  23. jq -e '.data[] | select(. == "app")'
  24. }
  25. @test "Query log entry" {
  26. curl -sG ${LOKI_URI}/api/prom/query?limit=10 --data-urlencode 'query={app="loki"}' | \
  27. jq -e '.streams[].entries | length >=1'
  28. }
  29. @test "Push log entry" {
  30. local timestamp=$(date +%s000000000)
  31. local data=$(jq -n --arg timestamp "${timestamp}" '{"streams": [{"stream": {"app": "loki-test"}, "values": [[$timestamp, "foobar"]]}]}')
  32. curl -s -X POST -H "Content-Type: application/json" ${LOKI_URI}/loki/api/v1/push --data-raw "${data}"
  33. curl -sG ${LOKI_URI}/loki/api/v1/query_range?limit=1 --data-urlencode 'query={app="loki-test"}' | \
  34. jq -e '.data.result[].values[][1] == "foobar"'
  35. }
  36. {{- end }}