diff --git a/internal/cli/monit_query.go b/internal/cli/monit_query.go index e12769b..adcbfb4 100644 --- a/internal/cli/monit_query.go +++ b/internal/cli/monit_query.go @@ -102,6 +102,10 @@ func newMonitQueryRowsCmd() *cobra.Command { if err != nil { return fmt.Errorf("invalid --args: %w", err) } + if dsType == "victorialogs" && argsMap["victorialogs.type"] == "raw" && + (argsMap["victorialogs.start"] == "" || argsMap["victorialogs.end"] == "") { + return fmt.Errorf("victorialogs raw mode requires --args victorialogs.start= --args victorialogs.end=") + } return runCommand(cmd, args, func(ctx *RunContext) error { input := &flashduty.QueryRowsRequest{ diff --git a/internal/cli/monit_query_test.go b/internal/cli/monit_query_test.go index 70c56c2..0fd6ce5 100644 --- a/internal/cli/monit_query_test.go +++ b/internal/cli/monit_query_test.go @@ -259,3 +259,25 @@ func TestMonitQueryRowsInvalidArgs(t *testing.T) { t.Errorf("rows should not have been called: %d request(s)", stub.requests) } } + +func TestMonitQueryRowsVictorialogsRawRequiresTimeRange(t *testing.T) { + saveAndResetGlobals(t) + stub := newGFStub(t) + + _, err := execCommand( + "monit-query", "rows", + "--ds-type", "victorialogs", + "--ds-name", "vl-prod", + "--expr", "* | limit 2", + "--args", "victorialogs.type=raw", + ) + if err == nil { + t.Fatal("expected error for victorialogs raw mode missing start/end, got nil") + } + if !strings.Contains(err.Error(), "victorialogs.start") || !strings.Contains(err.Error(), "victorialogs.end") { + t.Errorf("expected error to mention victorialogs.start/end, got %q", err.Error()) + } + if stub.requests != 0 { + t.Errorf("rows should not have been called: %d request(s)", stub.requests) + } +}