Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions internal/cli/monit_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -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=<unix> --args victorialogs.end=<unix>")
}

return runCommand(cmd, args, func(ctx *RunContext) error {
input := &flashduty.QueryRowsRequest{
Expand Down
22 changes: 22 additions & 0 deletions internal/cli/monit_query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}