Skip to content

Commit

Permalink
add tests to the calculateMaxLookBack
Browse files Browse the repository at this point in the history
Signed-off-by: Ed Welch <edward.welch@grafana.com>
  • Loading branch information
slim-bean committed May 14, 2020
1 parent e9442ea commit c15f5a9
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pkg/loki/modules.go
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,7 @@ func activePeriodConfig(cfg chunk.SchemaConfig) chunk.PeriodConfig {
}

func calculateMaxLookBack(pc chunk.PeriodConfig, maxLookBackConfig, maxChunkAge time.Duration) (time.Duration, error) {
if pc.ObjectType != local.FilesystemObjectStoreType && maxLookBackConfig.Milliseconds() != 0 {
if pc.ObjectType != local.FilesystemObjectStoreType && maxLookBackConfig.Nanoseconds() != 0 {
return 0, errors.New("it is an error to specify a non zero `query_store_max_look_back_period` value when using any object store other than `filesystem`")
}
// When using shipper, limit max look back for query to MaxChunkAge + upload interval by shipper + 15 mins to query only data whose index is not pushed yet
Expand Down
75 changes: 75 additions & 0 deletions pkg/loki/modules_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,78 @@ func TestActiveIndexType(t *testing.T) {
assert.Equal(t, cfg.Configs[1], activePeriodConfig(cfg))

}

func Test_calculateMaxLookBack(t *testing.T) {
type args struct {
pc chunk.PeriodConfig
maxLookBackConfig time.Duration
maxChunkAge time.Duration
}
tests := []struct {
name string
args args
want time.Duration
wantErr bool
}{
{
name: "default",
args: args{
pc: chunk.PeriodConfig{
ObjectType: "filesystem",
},
maxLookBackConfig: 0,
maxChunkAge: 1 * time.Hour,
},
want: 90 * time.Minute,
wantErr: false,
},
{
name: "infinite",
args: args{
pc: chunk.PeriodConfig{
ObjectType: "filesystem",
},
maxLookBackConfig: -1,
maxChunkAge: 1 * time.Hour,
},
want: -1,
wantErr: false,
},
{
name: "invalid store type",
args: args{
pc: chunk.PeriodConfig{
ObjectType: "gcs",
},
maxLookBackConfig: -1,
maxChunkAge: 1 * time.Hour,
},
want: 0,
wantErr: true,
},
{
name: "less than default",
args: args{
pc: chunk.PeriodConfig{
ObjectType: "filesystem",
},
maxLookBackConfig: 1 * time.Hour,
maxChunkAge: 1 * time.Hour,
},
want: 0,
wantErr: true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, err := calculateMaxLookBack(tt.args.pc, tt.args.maxLookBackConfig, tt.args.maxChunkAge)
if (err != nil) != tt.wantErr {
t.Errorf("calculateMaxLookBack() error = %v, wantErr %v", err, tt.wantErr)
return
}
if got != tt.want {
t.Errorf("calculateMaxLookBack() got = %v, want %v", got, tt.want)
}
})
}
}

0 comments on commit c15f5a9

Please sign in to comment.