Skip to content

Commit e41e329

Browse files
committed
refactor(monit): remove retired API commands
1 parent 2e19d39 commit e41e329

10 files changed

Lines changed: 32 additions & 411 deletions

‎internal/cli/coverage_test.go‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,14 @@ var curatedOperationIDs = map[string]bool{
2424
"automation-trigger-write-fire": true,
2525
}
2626

27+
// retiredOperationIDs bridges the release window where the server-side route
28+
// is gone but the CLI still compiles against the previous released SDK spec.
29+
var retiredOperationIDs = map[string]bool{
30+
"monit-preview-sync": true,
31+
"monit-read-query-rows": true,
32+
"monit-rule-write-status": true,
33+
}
34+
2735
// loadSpecOps reads every public GET/POST operation from the openapi spec
2836
// shipped in the linked go-flashduty module — the same spec cligen generates
2937
// against — recording each op's id, path, and whether its 200 response is a
@@ -80,6 +88,9 @@ func loadSpecPaths(t *testing.T) map[string]string {
8088
t.Helper()
8189
ids := map[string]string{}
8290
for _, op := range loadSpecOps(t) {
91+
if retiredOperationIDs[op.id] {
92+
continue
93+
}
8394
ids[op.id] = op.path
8495
}
8596
return ids
@@ -158,6 +169,9 @@ func TestGeneratorTargetsFullSpec(t *testing.T) {
158169
curated := map[string]bool{}
159170
wantGenerated := map[string]bool{}
160171
for _, op := range ops {
172+
if retiredOperationIDs[op.id] {
173+
continue
174+
}
161175
if op.streaming {
162176
streaming[op.id] = true
163177
continue

‎internal/cli/monit_query.go‎

Lines changed: 1 addition & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package cli
22

33
import (
4-
"encoding/json"
54
"fmt"
65
"strconv"
76

@@ -15,7 +14,6 @@ func newMonitQueryCmd() *cobra.Command {
1514
cmd := newGroupCmd("monit-query", "Probe monit-backed datasources (9 types via data; diagnose: loki|victorialogs log patterns, prometheus metric trends)")
1615
cmd.AddCommand(newMonitQueryDiagnoseCmd())
1716
cmd.AddCommand(newMonitQueryDataCmd())
18-
cmd.AddCommand(newMonitQueryRowsCmd())
1917
return cmd
2018
}
2119

@@ -135,74 +133,8 @@ func newMonitQueryDataCmd() *cobra.Command {
135133
return cmd
136134
}
137135

138-
func newMonitQueryRowsCmd() *cobra.Command {
139-
var (
140-
dsType, dsName, expr string
141-
argsKV []string
142-
)
143-
144-
cmd := &cobra.Command{
145-
Use: "rows",
146-
Short: "Raw datasource passthrough (returns values/rows as the datasource itself would). Deprecated — prefer 'monit-query data'",
147-
Deprecated: "use 'monit-query data' instead",
148-
Long: curatedLong("Deprecated. Raw datasource passthrough returning values/rows as the datasource itself would. Migrate to 'monit-query data', which preserves frames/records/samples without forcing results into legacy rows.", "Diagnostics", "QueryRows"),
149-
RunE: func(cmd *cobra.Command, args []string) error {
150-
if dsType == "" || dsName == "" || expr == "" {
151-
return fmt.Errorf("--ds-type, --ds-name, --expr are required")
152-
}
153-
argsMap, err := parseKVSlice(argsKV)
154-
if err != nil {
155-
return fmt.Errorf("invalid --args: %w", err)
156-
}
157-
if err := normalizeRawTimeArgs(dsType, argsMap); err != nil {
158-
return err
159-
}
160-
161-
return runCommand(cmd, args, func(ctx *RunContext) error {
162-
input := &flashduty.QueryRowsRequest{
163-
DsType: dsType,
164-
DsName: dsName,
165-
Expr: expr,
166-
Args: argsMap,
167-
}
168-
result, _, err := ctx.Client.Diagnostics.QueryRows(cmdContext(ctx.Cmd), input)
169-
if err != nil {
170-
return err
171-
}
172-
// This command is a raw datasource passthrough. The legacy SDK
173-
// captured the response body (a JSON array of {fields,values}
174-
// objects) as a RawMessage and wrote it through verbatim,
175-
// independent of the --json/--toon output format. go-flashduty
176-
// decodes that same array into []QueryRow, so re-marshal it to
177-
// the equivalent JSON array and write it through unchanged to
178-
// preserve the legacy single-blob output shape.
179-
if result == nil {
180-
_, err = fmt.Fprintln(ctx.Writer, "{}")
181-
return err
182-
}
183-
body, err := json.Marshal(*result)
184-
if err != nil {
185-
return fmt.Errorf("failed to marshal query rows: %w", err)
186-
}
187-
_, err = fmt.Fprintln(ctx.Writer, string(body))
188-
return err
189-
})
190-
},
191-
}
192-
193-
cmd.Flags().StringVar(&dsType, "ds-type", "", "Datasource type (required)")
194-
cmd.Flags().StringVar(&dsName, "ds-name", "", "Datasource name (required)")
195-
registerEnumFlag(cmd, "ds-type", "prometheus", "victorialogs", "loki", "mysql")
196-
cmd.Flags().StringVar(&expr, "expr", "", "Query expression (required)")
197-
cmd.Flags().StringSliceVar(&argsKV, "args", nil, "Arg entries KEY=VALUE (repeatable; values must be strings per monit-query contract). "+
198-
"For loki/victorialogs raw mode, <ds-type>.start/<ds-type>.end accept a relative duration ('15m'), 'now', a date/RFC3339 timestamp, "+
199-
"or a unix epoch in seconds or milliseconds — normalized to the form the datasource requires before sending")
200-
201-
return cmd
202-
}
203-
204136
// normalizeRawTimeArgs rewrites the raw-mode time-window args of a
205-
// monit-query rows call (<ds-type>.start / <ds-type>.end) into the unix-
137+
// monit-query data call (<ds-type>.start / <ds-type>.end) into the unix-
206138
// seconds form the server requires, accepting any format timeutil.Parse
207139
// understands (RFC3339, date/datetime, relative duration, unix seconds or
208140
// milliseconds). Loki and VictoriaLogs are the only ds-types whose raw mode

‎internal/cli/monit_query_test.go‎

Lines changed: 5 additions & 126 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,6 @@ func TestMonitQueryDiagnoseFlags(t *testing.T) {
2222
}
2323
}
2424

25-
func TestMonitQueryRowsFlags(t *testing.T) {
26-
cmd := newMonitQueryRowsCmd()
27-
for _, name := range []string{"ds-type", "ds-name", "expr", "args"} {
28-
if cmd.Flags().Lookup(name) == nil {
29-
t.Errorf("flag --%s missing", name)
30-
}
31-
}
32-
}
33-
3425
func TestMonitQueryDataFlags(t *testing.T) {
3526
cmd := newMonitQueryDataCmd()
3627
for _, name := range []string{"ds-type", "ds-name", "expr", "args", "delay-seconds"} {
@@ -209,7 +200,7 @@ func TestMonitQueryDiagnoseInvalidTimeStart(t *testing.T) {
209200
}
210201
}
211202

212-
// --- monit-query rows -----------------------------------------------------
203+
// --- monit-query data -----------------------------------------------------
213204

214205
func TestMonitQueryDataHappyPath(t *testing.T) {
215206
saveAndResetGlobals(t)
@@ -309,96 +300,6 @@ func TestMonitQueryDataRequiredFlags(t *testing.T) {
309300
}
310301
}
311302

312-
func TestMonitQueryRowsHappyPath(t *testing.T) {
313-
saveAndResetGlobals(t)
314-
stub := newGFStub(t)
315-
// rows is a raw datasource passthrough: the response envelope "data" is a
316-
// JSON array of QueryRow ({fields,values}) objects, decoded into
317-
// QueryRowsResponse ([]QueryRow) and re-marshalled verbatim to the writer.
318-
stub.data = []any{
319-
map[string]any{
320-
"fields": map[string]any{"instance": "node-1"},
321-
"values": map[string]any{"__value__": 1},
322-
},
323-
}
324-
325-
out, err := execCommand(
326-
"monit-query", "rows",
327-
"--ds-type", "prometheus",
328-
"--ds-name", "prom-prod",
329-
"--expr", "up",
330-
"--args", "step=15s",
331-
"--args", "tenant=acme",
332-
)
333-
if err != nil {
334-
t.Fatalf("unexpected error: %v", err)
335-
}
336-
if stub.lastPath != "/monit/query/rows" {
337-
t.Fatalf("expected /monit/query/rows, got %q", stub.lastPath)
338-
}
339-
body := stub.lastBody
340-
if body["ds_type"] != "prometheus" || body["ds_name"] != "prom-prod" || body["expr"] != "up" {
341-
t.Errorf("unexpected rows input: %#v", body)
342-
}
343-
args, _ := body["args"].(map[string]any)
344-
if args["step"] != "15s" || args["tenant"] != "acme" {
345-
t.Errorf("expected args step=15s tenant=acme, got %#v", args)
346-
}
347-
// The rendered output is the re-marshalled row array (passthrough shape).
348-
if !strings.Contains(out, "node-1") || !strings.Contains(out, "__value__") {
349-
t.Errorf("expected rendered rows to carry the datasource payload, got:\n%s", out)
350-
}
351-
}
352-
353-
func TestMonitQueryRowsRequiredFlags(t *testing.T) {
354-
cases := []struct {
355-
name string
356-
args []string
357-
}{
358-
{
359-
name: "missing ds-type",
360-
args: []string{
361-
"monit-query", "rows",
362-
"--ds-name", "prom-prod",
363-
"--expr", "up",
364-
},
365-
},
366-
{
367-
name: "missing ds-name",
368-
args: []string{
369-
"monit-query", "rows",
370-
"--ds-type", "prometheus",
371-
"--expr", "up",
372-
},
373-
},
374-
{
375-
name: "missing expr",
376-
args: []string{
377-
"monit-query", "rows",
378-
"--ds-type", "prometheus",
379-
"--ds-name", "prom-prod",
380-
},
381-
},
382-
}
383-
for _, tc := range cases {
384-
t.Run(tc.name, func(t *testing.T) {
385-
saveAndResetGlobals(t)
386-
stub := newGFStub(t)
387-
388-
_, err := execCommand(tc.args...)
389-
if err == nil {
390-
t.Fatal("expected required-flag error, got nil")
391-
}
392-
if !strings.Contains(err.Error(), "required") {
393-
t.Errorf("expected error to mention 'required', got %q", err.Error())
394-
}
395-
if stub.requests != 0 {
396-
t.Errorf("rows should not have been called: %d request(s)", stub.requests)
397-
}
398-
})
399-
}
400-
}
401-
402303
// --- normalizeRawTimeArgs --------------------------------------------------
403304

404305
func TestNormalizeRawTimeArgsAcceptedFormats(t *testing.T) {
@@ -469,17 +370,17 @@ func TestNormalizeRawTimeArgsInvalidValue(t *testing.T) {
469370
}
470371
}
471372

472-
// TestMonitQueryRowsRawModeNormalizesRFC3339 is the regression test for the
373+
// TestMonitQueryDataRawModeNormalizesRFC3339 is the regression test for the
473374
// raw-vs-stats time format inconsistency: a raw-mode VictoriaLogs query given
474375
// RFC3339 --args timestamps must reach the server as the unix-seconds form
475376
// the raw query path requires.
476-
func TestMonitQueryRowsRawModeNormalizesRFC3339(t *testing.T) {
377+
func TestMonitQueryDataRawModeNormalizesRFC3339(t *testing.T) {
477378
saveAndResetGlobals(t)
478379
stub := newGFStub(t)
479-
stub.data = []any{}
380+
stub.data = map[string]any{"format": "query_result.v1", "result": map[string]any{"kind": "records", "records": []any{}}}
480381

481382
_, err := execCommand(
482-
"monit-query", "rows",
383+
"monit-query", "data",
483384
"--ds-type", "victorialogs",
484385
"--ds-name", "vl-prod",
485386
"--expr", `{app="api"} |= "error"`,
@@ -534,25 +435,3 @@ func TestMonitQueryDataInvalidArgs(t *testing.T) {
534435
t.Errorf("data should not have been called: %d request(s)", stub.requests)
535436
}
536437
}
537-
538-
func TestMonitQueryRowsInvalidArgs(t *testing.T) {
539-
saveAndResetGlobals(t)
540-
stub := newGFStub(t)
541-
542-
_, err := execCommand(
543-
"monit-query", "rows",
544-
"--ds-type", "prometheus",
545-
"--ds-name", "prom-prod",
546-
"--expr", "up",
547-
"--args", "no-equals-sign",
548-
)
549-
if err == nil {
550-
t.Fatal("expected error for malformed --args, got nil")
551-
}
552-
if !strings.Contains(err.Error(), "--args") {
553-
t.Errorf("expected error to mention --args, got %q", err.Error())
554-
}
555-
if stub.requests != 0 {
556-
t.Errorf("rows should not have been called: %d request(s)", stub.requests)
557-
}
558-
}

‎internal/cli/zz_generated_alert_rules.go‎

Lines changed: 0 additions & 51 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)