github.com/thanos-io/thanos@v0.32.5/pkg/receive/limiter_config_test.go (about)

     1  // Copyright (c) The Thanos Authors.
     2  // Licensed under the Apache License 2.0.
     3  
     4  package receive
     5  
     6  import (
     7  	"net/url"
     8  	"os"
     9  	"path"
    10  	"testing"
    11  
    12  	"github.com/efficientgo/core/testutil"
    13  )
    14  
    15  func TestParseLimiterConfig(t *testing.T) {
    16  	tests := []struct {
    17  		name           string
    18  		configFileName string
    19  		want           *RootLimitsConfig
    20  		wantErr        bool
    21  	}{
    22  		{
    23  			name:           "Parses a configuration without issues",
    24  			configFileName: "good_limits.yaml",
    25  			wantErr:        false,
    26  			want: &RootLimitsConfig{
    27  				WriteLimits: WriteLimitsConfig{
    28  					GlobalLimits: GlobalLimitsConfig{
    29  						MaxConcurrency:           30,
    30  						MetaMonitoringURL:        "http://localhost:9090",
    31  						MetaMonitoringLimitQuery: "sum(prometheus_tsdb_head_series) by (tenant)",
    32  						metaMonitoringURL: &url.URL{
    33  							Scheme: "http",
    34  							Host:   "localhost:9090",
    35  						},
    36  					},
    37  					DefaultLimits: DefaultLimitsConfig{
    38  						RequestLimits: *NewEmptyRequestLimitsConfig().
    39  							SetSizeBytesLimit(1024).
    40  							SetSeriesLimit(1000).
    41  							SetSamplesLimit(10),
    42  						HeadSeriesLimit: 1000,
    43  					},
    44  					TenantsLimits: TenantsWriteLimitsConfig{
    45  						"acme": NewEmptyWriteLimitConfig().
    46  							SetRequestLimits(
    47  								NewEmptyRequestLimitsConfig().
    48  									SetSizeBytesLimit(0).
    49  									SetSeriesLimit(0).
    50  									SetSamplesLimit(0),
    51  							).
    52  							SetHeadSeriesLimit(2000),
    53  						"ajax": NewEmptyWriteLimitConfig().
    54  							SetRequestLimits(
    55  								NewEmptyRequestLimitsConfig().
    56  									SetSeriesLimit(50000).
    57  									SetSamplesLimit(500),
    58  							),
    59  					},
    60  				},
    61  			},
    62  		},
    63  	}
    64  	for _, tt := range tests {
    65  		t.Run(tt.name, func(t *testing.T) {
    66  			filePath := path.Join("testdata", "limits_config", tt.configFileName)
    67  			fileContent, err := os.ReadFile(filePath)
    68  			if err != nil {
    69  				t.Fatalf("couldn't read test limits configuration file '%s': %s", filePath, err)
    70  			}
    71  
    72  			got, err := ParseRootLimitConfig(fileContent)
    73  			testutil.Ok(t, err)
    74  			testutil.Equals(t, tt.want, got)
    75  		})
    76  	}
    77  }