Skip to content

Prometheus Integration API

Base path: /api/v1/prometheus

Implementation reference: internal/handlers/prometheus.go, models in internal/models/prometheus.go.

Endpoints

MethodPathDescriptionAuth Required
POST/prometheus/calculate-sloCalculate SLO metrics for a specific SLOYes
GET/prometheus/real-time-metricsGet real-time metrics for all active SLOsYes
POST/prometheus/queriesCreate a Prometheus query configurationYes
GET/prometheus/queriesList Prometheus queries for an SLOYes
GET/prometheus/queries/:id/executionsGet query execution historyYes
POST/prometheus/queryExecute an ad-hoc Prometheus queryYes
GET/prometheus/healthCheck Prometheus data source healthYes

POST /prometheus/calculate-slo

Calculates SLO compliance metrics by querying Prometheus over the specified time window. The calculation service (internal/prometheus/SLOCalculationService) executes the stored metric query and returns the current value, error budget usage, and status.

Request:

json
{
  "slo_id": 1,
  "time_window": "24h",
  "include_details": true
}
FieldTypeDescription
slo_idintSLO ID to calculate metrics for
time_windowstringOne of: 5m, 15m, 30m, 1h, 6h, 24h, 7d, 30d
include_detailsboolInclude query execution details in response
extend_timestring (ISO 8601)Optional end time (defaults to now)

Response (200 OK):

json
{
  "slo_id": 1,
  "time_window": "24h",
  "start_time": "2026-06-10T10:00:00Z",
  "end_time": "2026-06-11T10:00:00Z",
  "current_value": 99.92,
  "target_value": 99.9,
  "error_budget_used": 20.0,
  "status": "healthy",
  "calculated_at": "2026-06-11T10:00:00Z",
  "query_executions": [
    {
      "id": 42,
      "query_id": 1,
      "slo_id": 1,
      "execution_time": "2026-06-11T10:00:00Z",
      "execution_duration_ms": 150,
      "status": "success",
      "result_samples": 1440
    }
  ]
}

SLO status values: healthy, warning, critical, unknown.


GET /prometheus/real-time-metrics

Returns current SLO metrics for all active SLOs in the user's organization. Metrics are computed from the last known Prometheus data.

Response (200 OK):

json
{
  "metrics": [
    {
      "slo_id": 1,
      "current_status": "healthy",
      "current_value": 99.95,
      "error_budget_percent": 50.0,
      "last_updated": "2026-06-11T10:00:00Z",
      "trends": {
        "24h_change": -0.02,
        "7d_change": 0.05
      }
    }
  ],
  "total": 1
}

POST /prometheus/queries

Creates a Prometheus query configuration associated with an SLO. The query is periodically evaluated by the calculation service.

Request:

json
{
  "slo_id": 1,
  "query_name": "Error Rate Query",
  "prometheus_query": "rate(http_requests_total{job=\"api\",status=~\"5..\"}[5m])",
  "query_type": "availability",
  "metric_labels": ["job", "status"],
  "evaluation_interval_seconds": 300
}

Response (201 Created):

json
{
  "id": 1,
  "slo_id": 1,
  "query_name": "Error Rate Query",
  "prometheus_query": "rate(http_requests_total{job=\"api\",status=~\"5..\"}[5m])",
  "query_type": "availability",
  "query_hash": "aBcDeFgHiJkLmNoPqRsTuVwXyZ...",
  "metric_labels": ["job", "status"],
  "evaluation_interval_seconds": 300,
  "is_active": true,
  "created_at": "2026-06-11T10:00:00Z",
  "updated_at": "2026-06-11T10:00:00Z"
}

Supported query_type values: availability, latency, throughput, error_rate, custom.


GET /prometheus/queries

Lists all Prometheus query configurations for a specific SLO. The SLO ID is extracted from the URL path as /api/v1/prometheus/queries — the actual route extracts the SLO ID from the path position (e.g., /api/v1/prometheus/queries).

Response (200 OK):

json
{
  "queries": [
    {
      "id": 1,
      "slo_id": 1,
      "query_name": "Error Rate Query",
      "prometheus_query": "rate(http_requests_total{job=\"api\",status=~\"5..\"}[5m])",
      "query_type": "availability",
      "is_active": true,
      "created_at": "2026-06-11T10:00:00Z",
      "updated_at": "2026-06-11T10:00:00Z"
    }
  ],
  "total": 1
}

GET /prometheus/queries/:id/executions

Returns the execution history for a specific Prometheus query.

Query Parameters:

ParameterTypeDefaultDescription
limitint100Maximum number of execution records

Response (200 OK):

json
{
  "executions": [
    {
      "id": 42,
      "query_id": 1,
      "slo_id": 1,
      "execution_time": "2026-06-11T10:00:00Z",
      "execution_duration_ms": 150,
      "status": "success",
      "result_samples": 1440,
      "metadata": {
        "time_range": "24h",
        "prometheus_source": "primary"
      },
      "created_at": "2026-06-11T10:00:00Z"
    }
  ],
  "total": 1
}

POST /prometheus/query

Executes an ad-hoc Prometheus query against the configured data source.

Request:

json
{
  "query": "rate(http_requests_total{job=\"api\"}[5m])",
  "time_range": "1h",
  "step": "15s"
}
FieldTypeDescription
querystringPromQL query string
time_rangestringOne of: 5m, 15m, 30m, 1h, 6h, 24h, 7d, 30d
stepstringQuery resolution step (e.g. 15s, 1m, 5m)
extend_timestring (ISO 8601)Optional end time

Response (200 OK):

json
{
  "query_result": {
    "result_type": "vector",
    "result": [
      {
        "metric": { "job": "api", "status": "200" },
        "value": [1718100000, "0.05"]
      }
    ]
  },
  "status": "success",
  "metadata": {
    "time_range": "1h",
    "start_time": "2026-06-11T09:00:00Z",
    "end_time": "2026-06-11T10:00:00Z"
  },
  "queried_at": "2026-06-11T10:00:00Z"
}

GET /prometheus/health

Checks the health of all active Prometheus data sources. Each data source is tested by executing a simple up query.

Response (200 OK):

json
{
  "data_sources": [
    {
      "id": 1,
      "organization_id": 1,
      "api_url": "http://prometheus:9090",
      "is_active": true,
      "status": "healthy",
      "last_check": "2026-06-11T10:00:00Z"
    }
  ],
  "total": 1,
  "checked_by": 1,
  "timestamp": "2026-06-11T10:00:00Z"
}

If all data sources are healthy, status is 200 OK. If any data source is unreachable, status is 503 Service Unavailable and the individual datasource includes an error field.

Error Codes

HTTP StatusScenario
400Invalid request body, invalid time range, missing query
404SLO not found for the given slo_id
500Prometheus query execution failure
503Prometheus data source is unreachable