-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
render: data timeout for history queries
- Loading branch information
Showing
7 changed files
with
295 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,154 @@ | ||
package data | ||
|
||
import ( | ||
"testing" | ||
"time" | ||
|
||
"github.com/lomik/graphite-clickhouse/config" | ||
) | ||
|
||
func Test_getDataTimeout(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
cfg *config.Config | ||
m *MultiTarget | ||
want time.Duration | ||
}{ | ||
{ | ||
name: "one DataTimeout", | ||
cfg: &config.Config{ | ||
ClickHouse: config.ClickHouse{ | ||
DataTimeout: time.Second, | ||
QueryParams: []config.QueryParam{ | ||
{ // default params | ||
Duration: 0, | ||
DataTimeout: time.Second, | ||
}, | ||
}, | ||
}, | ||
}, | ||
m: &MultiTarget{ | ||
TimeFrame{ | ||
From: 1647198000, | ||
Until: 1647234000, | ||
}: &Targets{}, | ||
}, | ||
want: time.Second, | ||
}, | ||
{ | ||
name: "default DataTimeout", | ||
cfg: &config.Config{ | ||
ClickHouse: config.ClickHouse{ | ||
DataTimeout: time.Second, | ||
QueryParams: []config.QueryParam{ | ||
{ // default params | ||
Duration: 0, | ||
DataTimeout: time.Second, | ||
}, | ||
{ | ||
Duration: time.Hour, | ||
DataTimeout: time.Minute, | ||
}, | ||
}, | ||
}, | ||
}, | ||
m: &MultiTarget{ | ||
TimeFrame{ // 1 hour - 1s | ||
From: 1647198000, | ||
Until: 1647201600 - 1, | ||
}: &Targets{}, | ||
}, | ||
want: time.Second, | ||
}, | ||
{ | ||
name: "1m DataTimeout (1 param), select 1h duration", | ||
cfg: &config.Config{ | ||
ClickHouse: config.ClickHouse{ | ||
DataTimeout: time.Second * 10, | ||
QueryParams: []config.QueryParam{ | ||
{ // default params | ||
Duration: 0, | ||
DataTimeout: time.Second, | ||
}, | ||
{ | ||
Duration: time.Hour, | ||
DataTimeout: time.Minute, | ||
}, | ||
}, | ||
}, | ||
}, | ||
m: &MultiTarget{ | ||
TimeFrame{ // 1 hour | ||
From: 1647198000, | ||
Until: 1647201600, | ||
}: &Targets{}, | ||
}, | ||
want: time.Minute, | ||
}, | ||
{ | ||
name: "1m DataTimeout (2 param), select 1h duration", | ||
cfg: &config.Config{ | ||
ClickHouse: config.ClickHouse{ | ||
DataTimeout: time.Second, | ||
QueryParams: []config.QueryParam{ | ||
{ // default params | ||
Duration: 0, | ||
DataTimeout: time.Second, | ||
}, | ||
{ | ||
Duration: time.Hour, | ||
DataTimeout: time.Minute, | ||
}, | ||
{ | ||
Duration: time.Hour * 2, | ||
DataTimeout: 10 * time.Minute, | ||
}, | ||
}, | ||
}, | ||
}, | ||
m: &MultiTarget{ | ||
TimeFrame{ // 1 hour | ||
From: 1647198000, | ||
Until: 1647201600, | ||
}: &Targets{}, | ||
}, | ||
want: time.Minute, | ||
}, | ||
{ | ||
name: "10m DataTimeout (2 param), select 2h1s duration", | ||
cfg: &config.Config{ | ||
ClickHouse: config.ClickHouse{ | ||
DataTimeout: time.Second, | ||
QueryParams: []config.QueryParam{ | ||
{ // default params | ||
Duration: 0, | ||
DataTimeout: time.Second, | ||
}, | ||
{ | ||
Duration: time.Hour, | ||
DataTimeout: time.Minute, | ||
}, | ||
{ | ||
Duration: time.Hour * 2, | ||
DataTimeout: 10 * time.Minute, | ||
}, | ||
}, | ||
}, | ||
}, | ||
m: &MultiTarget{ | ||
TimeFrame{ // 2 hour 1s | ||
From: 1647198000, | ||
Until: 1647205201, | ||
}: &Targets{}, | ||
}, | ||
want: 10 * time.Minute, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
if got := getDataTimeout(tt.cfg, tt.m); got != tt.want { | ||
t.Errorf("getDataTimeout() = %v, want %v", got, tt.want) | ||
} | ||
}) | ||
} | ||
} |
Oops, something went wrong.