Skip to content
Latchkey

How to Gate CI on API Response Times

Tagging requests by endpoint and scoping thresholds to those tags gives a per-endpoint latency gate instead of one blended number.

Tag each request with a name, then declare a threshold scoped to that tag such as http_req_duration{name:orders}: p(95)<300. Each endpoint gates independently.

Steps

  • Tag requests with a stable name per endpoint.
  • Declare thresholds scoped to each tag.
  • A breach on any one endpoint fails the run.

Scoped thresholds

k6-script.js
import http from 'k6/http';

export const options = {
  thresholds: {
    'http_req_duration{name:health}': ['p(95)<150'],
    'http_req_duration{name:orders}': ['p(95)<300'],
  },
};

export default function () {
  http.get(`${__ENV.BASE_URL}/health`, { tags: { name: 'health' } });
  http.get(`${__ENV.BASE_URL}/api/orders`, { tags: { name: 'orders' } });
}

Gotchas

  • Use a static name tag; a URL with an id creates a new metric series per request and no gate works.
  • Group similar endpoints so the threshold count stays manageable.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →