github.com/yankunsam/loki/v2@v2.6.3-0.20220817130409-389df5235c27/production/helm/loki-stack/templates/tests/loki-test-configmap.yaml (about)

     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  
    14      LOKI_URI="http://${LOKI_SERVICE}:${LOKI_PORT}"
    15  
    16      function setup() {
    17        apk add -u curl jq
    18        until (curl -s ${LOKI_URI}/api/prom/label/app/values | jq -e '.values[] | select(. == "loki")'); do
    19          sleep 1
    20        done
    21      }
    22  
    23      @test "Has labels" {
    24        curl -s ${LOKI_URI}/api/prom/label | \
    25        jq -e '.values[] | select(. == "app")'
    26      }
    27  
    28      @test "Query log entry" {
    29        curl -sG ${LOKI_URI}/api/prom/query?limit=10 --data-urlencode 'query={app="loki"}' | \
    30        jq -e '.streams[].entries | length >= 1'
    31      }
    32  
    33      @test "Push log entry legacy" {
    34        local timestamp=$(date -Iseconds -u | sed 's/UTC/.000000000+00:00/')
    35        local data=$(jq -n --arg timestamp "${timestamp}" '{"streams": [{"labels": "{app=\"loki-test\"}", "entries": [{"ts": $timestamp, "line": "foobar"}]}]}')
    36  
    37        curl -s -X POST -H "Content-Type: application/json" ${LOKI_URI}/api/prom/push -d "${data}"
    38  
    39        curl -sG ${LOKI_URI}/api/prom/query?limit=1 --data-urlencode 'query={app="loki-test"}' | \
    40        jq -e '.streams[].entries[].line == "foobar"'
    41      }
    42  
    43      @test "Push log entry" {
    44        local timestamp=$(date +%s000000000)
    45        local data=$(jq -n --arg timestamp "${timestamp}" '{"streams": [{"stream": {"app": "loki-test"}, "values": [[$timestamp, "foobar"]]}]}')
    46  
    47        curl -s -X POST -H "Content-Type: application/json" ${LOKI_URI}/loki/api/v1/push -d "${data}"
    48  
    49        curl -sG ${LOKI_URI}/api/prom/query?limit=1 --data-urlencode 'query={app="loki-test"}' | \
    50        jq -e '.streams[].entries[].line == "foobar"'
    51      }
    52