github.com/thanos-io/thanos@v0.32.5/pkg/queryfrontend/config_test.go (about)

     1  // Copyright (c) The Thanos Authors.
     2  // Licensed under the Apache License 2.0.
     3  
     4  package queryfrontend
     5  
     6  import (
     7  	"fmt"
     8  	"testing"
     9  	"time"
    10  
    11  	"github.com/efficientgo/core/testutil"
    12  	"github.com/thanos-io/thanos/internal/cortex/chunk/cache"
    13  	"github.com/thanos-io/thanos/internal/cortex/querier/queryrange"
    14  )
    15  
    16  func TestConfig_Validate(t *testing.T) {
    17  
    18  	type testCase struct {
    19  		name   string
    20  		config Config
    21  		err    string
    22  	}
    23  
    24  	testCases := []testCase{
    25  		{
    26  			name: "invalid query range options",
    27  			config: Config{
    28  				QueryRangeConfig: QueryRangeConfig{
    29  					SplitQueriesByInterval: 10 * time.Hour,
    30  					HorizontalShards:       10,
    31  					MinQuerySplitInterval:  1 * time.Hour,
    32  					MaxQuerySplitInterval:  day,
    33  				},
    34  			},
    35  			err: "split queries interval and dynamic query split interval cannot be set at the same time",
    36  		},
    37  		{
    38  			name: "invalid parameters for dynamic query range split",
    39  			config: Config{
    40  				QueryRangeConfig: QueryRangeConfig{
    41  					SplitQueriesByInterval: 0,
    42  					HorizontalShards:       0,
    43  					MinQuerySplitInterval:  1 * time.Hour,
    44  				},
    45  			},
    46  			err: "min horizontal shards should be greater than 0 when query split threshold is enabled",
    47  		},
    48  		{
    49  			name: "invalid parameters for dynamic query range split - 2",
    50  			config: Config{
    51  				QueryRangeConfig: QueryRangeConfig{
    52  					SplitQueriesByInterval: 0,
    53  					HorizontalShards:       10,
    54  					MaxQuerySplitInterval:  0,
    55  					MinQuerySplitInterval:  1 * time.Hour,
    56  				},
    57  			},
    58  			err: "max query split interval should be greater than 0 when query split threshold is enabled",
    59  		},
    60  		{
    61  			name: "invalid parameters for dynamic query range split - 3",
    62  			config: Config{
    63  				QueryRangeConfig: QueryRangeConfig{
    64  					SplitQueriesByInterval: 0,
    65  					HorizontalShards:       10,
    66  					MaxQuerySplitInterval:  1 * time.Hour,
    67  					MinQuerySplitInterval:  0,
    68  				},
    69  				LabelsConfig: LabelsConfig{
    70  					DefaultTimeRange: day,
    71  				},
    72  			},
    73  			err: "min query split interval should be greater than 0 when query split threshold is enabled",
    74  		},
    75  		{
    76  			name: "valid config with caching",
    77  			config: Config{
    78  				DownstreamURL: "localhost:8080",
    79  				QueryRangeConfig: QueryRangeConfig{
    80  					SplitQueriesByInterval: 10 * time.Hour,
    81  					HorizontalShards:       0,
    82  					MaxQuerySplitInterval:  0,
    83  					MinQuerySplitInterval:  0,
    84  					ResultsCacheConfig: &queryrange.ResultsCacheConfig{
    85  						CacheConfig:                cache.Config{},
    86  						Compression:                "",
    87  						CacheQueryableSamplesStats: false,
    88  					},
    89  				},
    90  				LabelsConfig: LabelsConfig{
    91  					DefaultTimeRange: day,
    92  				},
    93  			},
    94  			err: "",
    95  		},
    96  	}
    97  
    98  	for _, tc := range testCases {
    99  		t.Run(tc.name, func(t *testing.T) {
   100  			err := tc.config.Validate()
   101  			if tc.err != "" {
   102  				testutil.NotOk(t, err)
   103  				testutil.Equals(t, tc.err, err.Error())
   104  			} else {
   105  				testutil.Ok(t, err)
   106  				fmt.Println(err)
   107  			}
   108  		})
   109  	}
   110  }