loki-test-configmap.yaml 1.8 KB

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