Skip to content
This repository was archived by the owner on Jun 23, 2026. It is now read-only.

feat: add Monitor V2 subcommands - #10

Open
beengud wants to merge 1 commit into
observeinc:mainfrom
beengud:upstream/feat-monitor-v2-commands
Open

feat: add Monitor V2 subcommands#10
beengud wants to merge 1 commit into
observeinc:mainfrom
beengud:upstream/feat-monitor-v2-commands

Conversation

@beengud

@beengud beengud commented Jun 2, 2026

Copy link
Copy Markdown

Summary

Adds observe subcommands for Monitor V2 management and alarm inspection:

Command Description
observe list monitor List all monitors in a workspace
observe get monitor <id> Fetch a monitor definition as JSON
observe monitor preview-query <file.json> Preview the OPAL query result for a monitor definition
observe monitor preview <file.json> Preview firing behaviour: would the monitor have fired?
observe monitor alarms [--monitor <id>] [--since <dur>] [--level <l>] List recent alarm events

The preview commands are useful for validating monitor definitions before saving, and for debugging why a monitor did or didn't fire during an incident.

Files

  • cmd_monitorv2.go — CLI command handlers
  • ot_monitorv2.go — GraphQL operations
  • cmd_monitorv2_test.go — unit tests
  • cmd_monitorv2_integration_test.go — integration tests (build tag: integration)
  • testdata/monitor_input_stub.json — example monitor definition
  • docs/monitor.md — usage documentation

* feat: implement observe list monitor and observe get monitor (Monitor V2)

Add ot_monitorv2.go defining the 'monitor' object type backed by the
searchMonitorV2 and monitorV2 GraphQL queries. Add cmd_monitorv2.go
registering the 'monitor' command with preview-query, preview, and alarms
subcommands, using cfg.WorkspaceIdOrName (global --workspace flag) with a
default of workspace 42379913. Add docs/monitor.md and comprehensive unit
tests in cmd_monitorv2_test.go covering all subcommands, empty results,
multiple groupings, and error paths.

Closes #15

* feat: add comprehensive unit test coverage for monitor V2 commands

Review existing monitor V2 tests and add missing coverage:
- TestCmdListMonitorDisabledTrue/False: verify disabled field rendering
- TestCmdMonitorPreviewQueryInvalidJSON: error on bad JSON input
- TestCmdMonitorPreviewInvalidJSON: error on bad JSON input
- TestCmdMonitorAlarmsSingleGrouping: single-grouping alarm in table
- TestMonitorV2FromObjectHelper: direct helper function tests
- TestMonitorV2FromObjectHelperNilFields: nil-safe field handling
- TestCmdGetMonitorDefinitionJSON: definition JSON in get output
- TestCmdMonitorPreviewQueryEmptyFields: empty result schema fields
- TestCmdMonitorAlarmsNoSamples: alarm with null groupings field

All 31 monitor-related tests pass.

Closes #19

* feat: add integration tests for monitor V2 commands against live tenant

Add cmd_monitorv2_integration_test.go with //go:build integration tag.
Tests cover all four monitor V2 GraphQL operations against workspace 42379913:

- TestIntegrationListMonitors: searchMonitorV2, tolerates empty result;
  if monitors exist, gets the first one by ID via monitorV2 query
- TestIntegrationSearchAlarms: searchMonitorV2Alarms for all time,
  skips gracefully if API is unavailable
- TestIntegrationPreviewQuery: evaluateMonitorV2Source using stub JSON,
  skipped if stub input is invalid for the tenant
- TestIntegrationPreview: previewMonitorV2 using stub JSON,
  skipped if stub input is invalid for the tenant

Add testdata/monitor_input_stub.json: a minimal MonitorV2Input definition
for use in preview-query and preview integration tests.

Run with: go test -tags integration ./...

Closes #20

* fix: rename integrationConfig to integrationMonitorConfig to avoid redeclaration

The integrationConfig function in cmd_dataset_integration_test.go (added in
an earlier MR) uses no args. This file's integrationConfig(t *testing.T)
caused a redeclaration compile error under the integration build tag. Rename
to integrationMonitorConfig to resolve the conflict.

---------

Co-authored-by: Aaron Brewbaker <abrewbaker@nhl.com>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant