Skip to content

Add anomaly detail and time filters - #1316

Draft
heyglassy wants to merge 1 commit into
mainfrom
agent/add-anomaly-detail-time-filters
Draft

Add anomaly detail and time filters#1316
heyglassy wants to merge 1 commit into
mainfrom
agent/add-anomaly-detail-time-filters

Conversation

@heyglassy

@heyglassy heyglassy commented Jul 29, 2026

Copy link
Copy Markdown

What changed

  • add --period, --from, and --to filtering to pscale insights anomalies
  • accept human-readable local dates and exact RFC3339 timestamps, including inclusive date-only end dates
  • add anomaly lookup by ID with correlated query fingerprints and SQL
  • add the vendored API-client request/response types, endpoint method, mocks, tests, and agent-guide examples

Why

The anomalies command previously only listed the API's default window and could not retrieve the query correlations attached to a specific anomaly. This makes historical investigation and root-cause analysis available directly from the CLI.

Before and after

This came out of an investigation into July 24 anomalies. Before this change, the CLI could only list summary records from the API's default window: there was no CLI invocation that could select July 24 or retrieve one anomaly by ID. Investigating a possible cause required fetching 47 Query Insights fingerprints and drilling into them individually. The result was execution data like this, which was not linked to an anomaly (tags was empty):

{
  "started_at": "2026-07-24T19:15:34.000Z",
  "total_duration_millis": 3968,
  "rows_read": 3,
  "rows_returned": 1,
  "shard_queries": 6,
  "error_message": null,
  "tags": []
}

After this change, the historical anomalies can be requested directly:

$ pscale insights anomalies game main --org <org> --from 07/23 --to 07/25 --format json
[
  {
    "id": "4888442",
    "period_start": "2026-07-24T19:15:00Z",
    "period_end": "2026-07-25T00:02:00Z",
    "minutes_in_violation": 234,
    "active": false,
    "duration": 17220,
    "metrics_start": "2026-07-24T16:51:00Z",
    "metrics_end": "2026-07-25T02:25:59.999Z"
  },
  {
    "id": "4890736",
    "period_start": "2026-07-25T00:35:00Z",
    "period_end": "2026-07-25T01:01:00Z",
    "minutes_in_violation": 6
  },
  {
    "id": "4890952",
    "period_start": "2026-07-25T01:13:00Z",
    "period_end": "2026-07-25T03:02:00Z",
    "minutes_in_violation": 52
  }
]

The returned ID can then be used to fetch the anomaly's complete detail payload:

$ pscale insights anomalies game main 4888442 --org <org> --format json
{
  "id": "4888442",
  "period_start": "2026-07-24T19:15:00Z",
  "period_end": "2026-07-25T00:02:00Z",
  "minutes_in_violation": 234,
  "active": false,
  "duration": 17220,
  "metrics_start": "2026-07-24T16:51:00Z",
  "metrics_end": "2026-07-25T02:25:59.999Z"
}

This real anomaly had no correlations recorded, so the API omitted correlations. When correlations are present, the same detail response includes their coefficient, keyspace, fingerprint, normalized SQL, and tablet type.

Impact

Users can select a supported named period or explicit time range, then drill into an anomaly without leaving pscale. Existing list usage remains compatible and continues to use the API default window when no time flags are provided.

Validation

  • go test ./internal/cmd/insights ./internal/planetscale
  • go test ./...
  • git diff --check

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant