Skip to content

Commit

Permalink
follow-up after 08b306a (#70)
Browse files Browse the repository at this point in the history
  • Loading branch information
dmitryk-dk authored Sep 5, 2024
1 parent 08b306a commit 39f7920
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

## tip

* FEATURE: add support of the `$__interval` variable in queries. See [this issue](https://github.com/VictoriaMetrics/victorialogs-datasource/issues/61).
Thanks to @yincongcyincong for [the pull request](https://github.com/VictoriaMetrics/victorialogs-datasource/pull/69).

## v0.4.0

* FEATURE: make retry attempt for datasource requests if returned error is a temporary network error. See [this issue](https://github.com/VictoriaMetrics/victoriametrics-datasource/issues/193)
Expand Down
41 changes: 41 additions & 0 deletions pkg/utils/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,3 +177,44 @@ func TestGetTime(t *testing.T) {
})
}
}

func TestReplaceTemplateVariable(t *testing.T) {
tests := []struct {
name string
expr string
interval int
want string
}{
{
name: "empty string",
expr: "",
interval: 0,
want: "",
},
{
name: "no variable",
expr: "test",
interval: 0,
want: "test",
},
{
name: "variable",
expr: "$__interval",
interval: 15,
want: "15ms",
},
{
name: "variable with text",
expr: "host:~'^$host$' and compose_project:~'^$compose_project$' and compose_service:~'^$compose_service$' and $log_query | stats by (_time:$__interval, host) count() logs",
interval: 15,
want: "host:~'^$host$' and compose_project:~'^$compose_project$' and compose_service:~'^$compose_service$' and $log_query | stats by (_time:15ms, host) count() logs",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := ReplaceTemplateVariable(tt.expr, tt.interval); got != tt.want {
t.Errorf("ReplaceTemplateVariable() = %v, want %v", got, tt.want)
}
})
}
}

0 comments on commit 39f7920

Please sign in to comment.