Last active
June 11, 2026 16:07
-
-
Save ndom91/b14ea356b65f563424188be13edd0dfb to your computer and use it in GitHub Desktop.
Test new `threadsSingleValueMetric` GraphQL query
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env bash | |
| # Smoke test for the threadSingleValueMetric GraphQL query (PR #8525), | |
| # focusing on the new service_level_agreement_compliance_frt/nrt metrics. | |
| # | |
| # Usage: | |
| # PLAIN_API_KEY=plainApiKey_xxx ./2026-06-11-test-thread-single-value-metric.sh | |
| # PLAIN_API_KEY=... PLAIN_API_URL=https://core-api.uk.plain.com/graphql/v1 ./2026-06-11-test-thread-single-value-metric.sh | |
| # PLAIN_API_KEY=... FROM=2026-05-01T00:00:00Z TO=2026-06-11T00:00:00Z ./2026-06-11-test-thread-single-value-metric.sh | |
| set -euo pipefail | |
| : "${PLAIN_API_KEY:?Set PLAIN_API_KEY to your machine user API key}" | |
| PLAIN_API_URL="${PLAIN_API_URL:-https://core-api.uk.plain-development.com/graphql/v1}" | |
| # Default window: last 30 days | |
| TO="${TO:-$(date -u +%Y-%m-%dT%H:%M:%SZ)}" | |
| FROM="${FROM:-$(date -u -v-30d +%Y-%m-%dT%H:%M:%SZ 2>/dev/null || date -u -d '30 days ago' +%Y-%m-%dT%H:%M:%SZ)}" | |
| read -r -d '' QUERY <<'EOF' || true | |
| query ThreadSingleValueMetric($input: ThreadSingleValueMetricInput!) { | |
| threadSingleValueMetric(input: $input) { | |
| values { | |
| value | |
| group { | |
| dimension | |
| value | |
| label | |
| } | |
| } | |
| } | |
| } | |
| EOF | |
| FAILED=0 | |
| # run_case <name> <variables-json> [expected-error-code] | |
| # Without expected-error-code: passes on 200 + no GraphQL errors. | |
| # With expected-error-code: passes only if the response errors with that code. | |
| run_case() { | |
| local name="$1" | |
| local variables="$2" | |
| local expected_error="${3:-}" | |
| echo "==============================================" | |
| echo "CASE: $name" | |
| echo "variables: $variables" | |
| local payload | |
| payload=$(jq -nc --arg q "$QUERY" --argjson v "$variables" '{query: $q, variables: $v}') | |
| local response body status | |
| response=$(curl -sS -w '\n%{http_code}' \ | |
| -X POST "$PLAIN_API_URL" \ | |
| -H "Authorization: Bearer $PLAIN_API_KEY" \ | |
| -H "Content-Type: application/json" \ | |
| --data "$payload") | |
| body=$(printf '%s\n' "$response" | sed '$d') | |
| status=$(printf '%s\n' "$response" | tail -n1) | |
| echo "HTTP $status" | |
| printf '%s\n' "$body" | jq . | |
| if [[ -n "$expected_error" ]]; then | |
| if [[ "$status" == "200" ]] && printf '%s' "$body" | | |
| jq -e --arg c "$expected_error" '.errors[0].extensions.code == $c' >/dev/null; then | |
| echo "OK: $name (expected error: $expected_error)" | |
| else | |
| echo "FAIL: $name (expected error $expected_error)" | |
| FAILED=1 | |
| fi | |
| elif [[ "$status" != "200" ]] || printf '%s' "$body" | jq -e '.errors' >/dev/null; then | |
| echo "FAIL: $name" | |
| FAILED=1 | |
| else | |
| echo "OK: $name" | |
| fi | |
| echo | |
| } | |
| echo "POST $PLAIN_API_URL" | |
| echo "window: $FROM -> $TO" | |
| echo | |
| run_case "SLA compliance FRT" "$(jq -nc --arg from "$FROM" --arg to "$TO" \ | |
| '{input: {metricName: "service_level_agreement_compliance_frt", from: $from, to: $to}}')" | |
| run_case "SLA compliance NRT" "$(jq -nc --arg from "$FROM" --arg to "$TO" \ | |
| '{input: {metricName: "service_level_agreement_compliance_nrt", from: $from, to: $to}}')" | |
| run_case "SLA compliance FRT grouped by ASSIGNEE" "$(jq -nc --arg from "$FROM" --arg to "$TO" \ | |
| '{input: {metricName: "service_level_agreement_compliance_frt", from: $from, to: $to, groupBy: [{dimension: "ASSIGNEE"}], filters: { | |
| assignedToUser: [ | |
| "u_abc123" | |
| ] | |
| }}}')" | |
| # Only the two SLA compliance metrics are wired through threadSingleValueMetric today | |
| # (SLA_TYPE_BY_METRIC in packages/tinybird/src/threadSingleValueMetricSqlAssembler.ts). | |
| # All other metric names must be rejected with not_yet_implemented. | |
| run_case "Agent SLA compliance FRT (not wired yet)" "$(jq -nc --arg from "$FROM" --arg to "$TO" \ | |
| '{input: {metricName: "agent_service_level_agreement_compliance_frt", from: $from, to: $to}}')" \ | |
| "not_yet_implemented" | |
| run_case "FRT median (not wired yet)" "$(jq -nc --arg from "$FROM" --arg to "$TO" \ | |
| '{input: {metricName: "threads_first_response_time_median", from: $from, to: $to}}')" \ | |
| "not_yet_implemented" | |
| if [[ "$FAILED" != "0" ]]; then | |
| echo "One or more cases failed" | |
| exit 1 | |
| fi | |
| echo "All cases passed" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment