From 49f33a4ebf47b55ee5773e87c99f9fd9e6b38ade Mon Sep 17 00:00:00 2001 From: Matthieu MOREL Date: Sun, 24 Nov 2024 15:34:14 +0100 Subject: [PATCH] Enable usestdlibvars linter (#6249) #### Description - enable [usestdlibvars](https://golangci-lint.run/usage/linters/#usestdlibvars) linter - uses standard constants or vars instead of their values. Signed-off-by: Matthieu MOREL --- .golangci.yml | 3 + .../app/anonymizer/anonymizer_test.go | 5 +- cmd/anonymizer/app/writer/writer_test.go | 3 +- cmd/internal/status/command.go | 2 +- cmd/query/app/server_test.go | 4 +- crossdock/main.go | 4 +- examples/hotrod/pkg/tracing/http.go | 2 +- .../hotrod/pkg/tracing/rpcmetrics/metrics.go | 9 +- .../adjuster/sort_tags_and_log_fields_test.go | 3 +- pkg/bearertoken/transport_test.go | 2 +- pkg/clientcfg/clientcfghttp/handler_test.go | 4 +- pkg/es/wrapper/wrapper.go | 3 +- pkg/version/handler.go | 2 +- .../adaptive/aggregator_test.go | 35 ++-- .../adaptive/post_aggregator_test.go | 177 +++++++++--------- .../adaptive/provider_test.go | 21 ++- .../strategyprovider/static/provider.go | 2 +- .../strategyprovider/static/provider_test.go | 6 +- .../cassandra/samplingstore/storage_test.go | 15 +- plugin/storage/es/options_test.go | 3 +- 20 files changed, 159 insertions(+), 146 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index 7c4e9314df8..5427041391e 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -105,6 +105,9 @@ linters: # Checks usage of github.com/stretchr/testify. - testifylint + # Detects the possibility to use variables/constants from the Go standard library. + - usestdlibvars + # TODO consider adding more linters, cf. https://olegk.dev/go-linters-configuration-the-right-version linters-settings: diff --git a/cmd/anonymizer/app/anonymizer/anonymizer_test.go b/cmd/anonymizer/app/anonymizer/anonymizer_test.go index 431cc0162a6..6d2f219c062 100644 --- a/cmd/anonymizer/app/anonymizer/anonymizer_test.go +++ b/cmd/anonymizer/app/anonymizer/anonymizer_test.go @@ -4,6 +4,7 @@ package anonymizer import ( + "net/http" "os" "path/filepath" "testing" @@ -18,7 +19,7 @@ import ( var tags = []model.KeyValue{ model.Bool("error", true), - model.String("http.method", "POST"), + model.String("http.method", http.MethodPost), model.Bool("foobar", true), } @@ -127,7 +128,7 @@ func TestAnonymizer_SaveMapping(t *testing.T) { func TestAnonymizer_FilterStandardTags(t *testing.T) { expected := []model.KeyValue{ model.Bool("error", true), - model.String("http.method", "POST"), + model.String("http.method", http.MethodPost), } actual := filterStandardTags(tags) assert.Equal(t, expected, actual) diff --git a/cmd/anonymizer/app/writer/writer_test.go b/cmd/anonymizer/app/writer/writer_test.go index c6e11434ccc..dc746f16b63 100644 --- a/cmd/anonymizer/app/writer/writer_test.go +++ b/cmd/anonymizer/app/writer/writer_test.go @@ -4,6 +4,7 @@ package writer import ( + "net/http" "testing" "time" @@ -15,7 +16,7 @@ import ( var tags = []model.KeyValue{ model.Bool("error", true), - model.String("http.method", "POST"), + model.String("http.method", http.MethodPost), model.Bool("foobar", true), } diff --git a/cmd/internal/status/command.go b/cmd/internal/status/command.go index 02f2e48683a..355719ae4a0 100644 --- a/cmd/internal/status/command.go +++ b/cmd/internal/status/command.go @@ -30,7 +30,7 @@ func Command(v *viper.Viper, adminPort int) *cobra.Command { url := convert(v.GetString(statusHTTPHostPort)) ctx, cx := context.WithTimeout(context.Background(), time.Second) defer cx() - req, _ := http.NewRequestWithContext(ctx, "GET", url, nil) + req, _ := http.NewRequestWithContext(ctx, http.MethodGet, url, nil) resp, err := http.DefaultClient.Do(req) if err != nil { return err diff --git a/cmd/query/app/server_test.go b/cmd/query/app/server_test.go index 161aeca654d..7a7d1bed674 100644 --- a/cmd/query/app/server_test.go +++ b/cmd/query/app/server_test.go @@ -760,12 +760,12 @@ func TestServerHTTPTenancy(t *testing.T) { { name: "no tenant", // no value for tenant header - status: 401, + status: http.StatusUnauthorized, }, { name: "tenant", tenant: "acme", - status: 200, + status: http.StatusOK, }, } diff --git a/crossdock/main.go b/crossdock/main.go index f4833886a42..686f6ff515d 100644 --- a/crossdock/main.go +++ b/crossdock/main.go @@ -52,7 +52,7 @@ func main() { http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { // when method is HEAD, report back with a 200 when ready to run tests - if r.Method == "HEAD" { + if r.Method == http.MethodHead { if !handler.isInitialized() { http.Error(w, "Components not ready", http.StatusServiceUnavailable) } @@ -92,7 +92,7 @@ func (h *clientHandler) isInitialized() bool { } func is2xxStatusCode(statusCode int) bool { - return statusCode >= 200 && statusCode <= 299 + return statusCode >= http.StatusOK && statusCode < http.StatusMultipleChoices } func httpHealthCheck(logger *zap.Logger, service, healthURL string) { diff --git a/examples/hotrod/pkg/tracing/http.go b/examples/hotrod/pkg/tracing/http.go index 0e938ba60b8..a37d7e70df2 100644 --- a/examples/hotrod/pkg/tracing/http.go +++ b/examples/hotrod/pkg/tracing/http.go @@ -48,7 +48,7 @@ func (c *HTTPClient) GetJSON(ctx context.Context, _ string /* endpoint */, url s defer res.Body.Close() - if res.StatusCode >= 400 { + if res.StatusCode >= http.StatusBadRequest { body, err := io.ReadAll(res.Body) if err != nil { return err diff --git a/examples/hotrod/pkg/tracing/rpcmetrics/metrics.go b/examples/hotrod/pkg/tracing/rpcmetrics/metrics.go index 48556e92170..5daa89f21de 100644 --- a/examples/hotrod/pkg/tracing/rpcmetrics/metrics.go +++ b/examples/hotrod/pkg/tracing/rpcmetrics/metrics.go @@ -5,6 +5,7 @@ package rpcmetrics import ( + "net/http" "sync" "github.com/jaegertracing/jaeger/pkg/metrics" @@ -45,13 +46,13 @@ type Metrics struct { func (m *Metrics) recordHTTPStatusCode(statusCode int64) { switch { - case statusCode >= 200 && statusCode < 300: + case statusCode >= http.StatusOK && statusCode < http.StatusMultipleChoices: m.HTTPStatusCode2xx.Inc(1) - case statusCode >= 300 && statusCode < 400: + case statusCode >= http.StatusMultipleChoices && statusCode < http.StatusBadRequest: m.HTTPStatusCode3xx.Inc(1) - case statusCode >= 400 && statusCode < 500: + case statusCode >= http.StatusBadRequest && statusCode < http.StatusInternalServerError: m.HTTPStatusCode4xx.Inc(1) - case statusCode >= 500 && statusCode < 600: + case statusCode >= http.StatusInternalServerError && statusCode < 600: m.HTTPStatusCode5xx.Inc(1) } } diff --git a/model/adjuster/sort_tags_and_log_fields_test.go b/model/adjuster/sort_tags_and_log_fields_test.go index 4d31c7248b6..afd1983cac0 100644 --- a/model/adjuster/sort_tags_and_log_fields_test.go +++ b/model/adjuster/sort_tags_and_log_fields_test.go @@ -5,6 +5,7 @@ package adjuster import ( + "net/http" "testing" "github.com/stretchr/testify/assert" @@ -88,7 +89,7 @@ func TestSortTagsAndLogFieldsDoesSortFields(t *testing.T) { func TestSortTagsAndLogFieldsDoesSortTags(t *testing.T) { testCases := []model.KeyValues{ { - model.String("http.method", "GET"), + model.String("http.method", http.MethodGet), model.String("http.url", "http://wikipedia.org"), model.Int64("http.status_code", 200), model.String("guid:x-request-id", "f61defd2-7a77-11ef-b54f-4fbb67a6d181"), diff --git a/pkg/bearertoken/transport_test.go b/pkg/bearertoken/transport_test.go index b578934cb38..e03ca8dd8a0 100644 --- a/pkg/bearertoken/transport_test.go +++ b/pkg/bearertoken/transport_test.go @@ -78,7 +78,7 @@ func TestRoundTripper(t *testing.T) { t.Run(tc.name, func(t *testing.T) { server := httptest.NewServer(nil) defer server.Close() - req, err := http.NewRequestWithContext(tc.requestContext, "GET", server.URL, nil) + req, err := http.NewRequestWithContext(tc.requestContext, http.MethodGet, server.URL, nil) require.NoError(t, err) tr := RoundTripper{ diff --git a/pkg/clientcfg/clientcfghttp/handler_test.go b/pkg/clientcfg/clientcfghttp/handler_test.go index 296468b458d..fa16f52d71c 100644 --- a/pkg/clientcfg/clientcfghttp/handler_test.go +++ b/pkg/clientcfg/clientcfghttp/handler_test.go @@ -283,14 +283,14 @@ func TestHTTPHandlerErrors(t *testing.T) { withServer("", probabilistic(0.001), restrictions("luggage", 10), withGorilla, func(ts *testServer) { handler := ts.handler - req := httptest.NewRequest("GET", "http://localhost:80/?service=X", nil) + req := httptest.NewRequest(http.MethodGet, "http://localhost:80/?service=X", nil) w := &mockWriter{header: make(http.Header)} handler.serveSamplingHTTP(w, req, handler.encodeThriftLegacy) ts.metricsFactory.AssertCounterMetrics(t, metricstest.ExpectedMetric{Name: "http-server.errors", Tags: map[string]string{"source": "write", "status": "5xx"}, Value: 1}) - req = httptest.NewRequest("GET", "http://localhost:80/baggageRestrictions?service=X", nil) + req = httptest.NewRequest(http.MethodGet, "http://localhost:80/baggageRestrictions?service=X", nil) handler.serveBaggageHTTP(w, req) ts.metricsFactory.AssertCounterMetrics(t, diff --git a/pkg/es/wrapper/wrapper.go b/pkg/es/wrapper/wrapper.go index cdca19fd768..e34b8c49590 100644 --- a/pkg/es/wrapper/wrapper.go +++ b/pkg/es/wrapper/wrapper.go @@ -7,6 +7,7 @@ package eswrapper import ( "context" "fmt" + "net/http" "strings" esV8 "github.com/elastic/go-elasticsearch/v8" @@ -193,7 +194,7 @@ func (c TemplateCreatorWrapperV8) Do(context.Context) (*elastic.IndicesPutTempla if err != nil { return nil, fmt.Errorf("error creating index template %s: %w", c.templateName, err) } - if resp.StatusCode != 200 { + if resp.StatusCode != http.StatusOK { return nil, fmt.Errorf("error creating index template %s: %s", c.templateName, resp) } return nil, nil // no response expected by span writer diff --git a/pkg/version/handler.go b/pkg/version/handler.go index bb094af94a9..a92cd11ff3b 100644 --- a/pkg/version/handler.go +++ b/pkg/version/handler.go @@ -18,7 +18,7 @@ func RegisterHandler(mu *http.ServeMux, logger *zap.Logger) { logger.Fatal("Could not get Jaeger version", zap.Error(err)) } mu.HandleFunc("/version", func(w http.ResponseWriter, _ *http.Request) { - w.WriteHeader(200) + w.WriteHeader(http.StatusOK) w.Write(jsonData) }) } diff --git a/plugin/sampling/strategyprovider/adaptive/aggregator_test.go b/plugin/sampling/strategyprovider/adaptive/aggregator_test.go index eec8ab76892..a2145f80c35 100644 --- a/plugin/sampling/strategyprovider/adaptive/aggregator_test.go +++ b/plugin/sampling/strategyprovider/adaptive/aggregator_test.go @@ -4,6 +4,7 @@ package adaptive import ( + "net/http" "testing" "time" @@ -37,12 +38,12 @@ func TestAggregator(t *testing.T) { a, err := NewAggregator(testOpts, logger, metricsFactory, mockEP, mockStorage) require.NoError(t, err) - a.RecordThroughput("A", "GET", model.SamplerTypeProbabilistic, 0.001) - a.RecordThroughput("B", "POST", model.SamplerTypeProbabilistic, 0.001) - a.RecordThroughput("C", "GET", model.SamplerTypeProbabilistic, 0.001) - a.RecordThroughput("A", "POST", model.SamplerTypeProbabilistic, 0.001) - a.RecordThroughput("A", "GET", model.SamplerTypeProbabilistic, 0.001) - a.RecordThroughput("A", "GET", model.SamplerTypeLowerBound, 0.001) + a.RecordThroughput("A", http.MethodGet, model.SamplerTypeProbabilistic, 0.001) + a.RecordThroughput("B", http.MethodPost, model.SamplerTypeProbabilistic, 0.001) + a.RecordThroughput("C", http.MethodGet, model.SamplerTypeProbabilistic, 0.001) + a.RecordThroughput("A", http.MethodPost, model.SamplerTypeProbabilistic, 0.001) + a.RecordThroughput("A", http.MethodGet, model.SamplerTypeProbabilistic, 0.001) + a.RecordThroughput("A", http.MethodGet, model.SamplerTypeLowerBound, 0.001) a.Start() defer a.Close() @@ -74,17 +75,17 @@ func TestIncrementThroughput(t *testing.T) { require.NoError(t, err) // 20 different probabilities for i := 0; i < 20; i++ { - a.RecordThroughput("A", "GET", model.SamplerTypeProbabilistic, 0.001*float64(i)) + a.RecordThroughput("A", http.MethodGet, model.SamplerTypeProbabilistic, 0.001*float64(i)) } - assert.Len(t, a.(*aggregator).currentThroughput["A"]["GET"].Probabilities, 10) + assert.Len(t, a.(*aggregator).currentThroughput["A"][http.MethodGet].Probabilities, 10) a, err = NewAggregator(testOpts, logger, metricsFactory, mockEP, mockStorage) require.NoError(t, err) // 20 of the same probabilities for i := 0; i < 20; i++ { - a.RecordThroughput("A", "GET", model.SamplerTypeProbabilistic, 0.001) + a.RecordThroughput("A", http.MethodGet, model.SamplerTypeProbabilistic, 0.001) } - assert.Len(t, a.(*aggregator).currentThroughput["A"]["GET"].Probabilities, 1) + assert.Len(t, a.(*aggregator).currentThroughput["A"][http.MethodGet].Probabilities, 1) } func TestLowerboundThroughput(t *testing.T) { @@ -100,9 +101,9 @@ func TestLowerboundThroughput(t *testing.T) { a, err := NewAggregator(testOpts, logger, metricsFactory, mockEP, mockStorage) require.NoError(t, err) - a.RecordThroughput("A", "GET", model.SamplerTypeLowerBound, 0.001) - assert.EqualValues(t, 0, a.(*aggregator).currentThroughput["A"]["GET"].Count) - assert.Empty(t, a.(*aggregator).currentThroughput["A"]["GET"].Probabilities["0.001000"]) + a.RecordThroughput("A", http.MethodGet, model.SamplerTypeLowerBound, 0.001) + assert.EqualValues(t, 0, a.(*aggregator).currentThroughput["A"][http.MethodGet].Count) + assert.Empty(t, a.(*aggregator).currentThroughput["A"][http.MethodGet].Probabilities["0.001000"]) } func TestRecordThroughput(t *testing.T) { @@ -132,7 +133,7 @@ func TestRecordThroughput(t *testing.T) { require.Empty(t, a.(*aggregator).currentThroughput) // Testing span with service name and operation but no probabilistic sampling tags - span.OperationName = "GET" + span.OperationName = http.MethodGet a.HandleRootSpan(span, logger) require.Empty(t, a.(*aggregator).currentThroughput) @@ -142,7 +143,7 @@ func TestRecordThroughput(t *testing.T) { model.String("sampler.param", "0.001"), } a.HandleRootSpan(span, logger) - assert.EqualValues(t, 1, a.(*aggregator).currentThroughput["A"]["GET"].Count) + assert.EqualValues(t, 1, a.(*aggregator).currentThroughput["A"][http.MethodGet].Count) } func TestRecordThroughputFunc(t *testing.T) { @@ -173,7 +174,7 @@ func TestRecordThroughputFunc(t *testing.T) { require.Empty(t, a.(*aggregator).currentThroughput) // Testing span with service name and operation but no probabilistic sampling tags - span.OperationName = "GET" + span.OperationName = http.MethodGet a.HandleRootSpan(span, logger) require.Empty(t, a.(*aggregator).currentThroughput) @@ -183,5 +184,5 @@ func TestRecordThroughputFunc(t *testing.T) { model.String("sampler.param", "0.001"), } a.HandleRootSpan(span, logger) - assert.EqualValues(t, 1, a.(*aggregator).currentThroughput["A"]["GET"].Count) + assert.EqualValues(t, 1, a.(*aggregator).currentThroughput["A"][http.MethodGet].Count) } diff --git a/plugin/sampling/strategyprovider/adaptive/post_aggregator_test.go b/plugin/sampling/strategyprovider/adaptive/post_aggregator_test.go index 6a0f71b1eb6..fd0da089ac6 100644 --- a/plugin/sampling/strategyprovider/adaptive/post_aggregator_test.go +++ b/plugin/sampling/strategyprovider/adaptive/post_aggregator_test.go @@ -5,6 +5,7 @@ package adaptive import ( "errors" + "net/http" "testing" "time" @@ -24,10 +25,10 @@ import ( func testThroughputs() []*model.Throughput { return []*model.Throughput{ - {Service: "svcA", Operation: "GET", Count: 4, Probabilities: map[string]struct{}{"0.1": {}}}, - {Service: "svcA", Operation: "GET", Count: 4, Probabilities: map[string]struct{}{"0.2": {}}}, - {Service: "svcA", Operation: "PUT", Count: 5, Probabilities: map[string]struct{}{"0.1": {}}}, - {Service: "svcB", Operation: "GET", Count: 3, Probabilities: map[string]struct{}{"0.1": {}}}, + {Service: "svcA", Operation: http.MethodGet, Count: 4, Probabilities: map[string]struct{}{"0.1": {}}}, + {Service: "svcA", Operation: http.MethodGet, Count: 4, Probabilities: map[string]struct{}{"0.2": {}}}, + {Service: "svcA", Operation: http.MethodPut, Count: 5, Probabilities: map[string]struct{}{"0.1": {}}}, + {Service: "svcB", Operation: http.MethodGet, Count: 3, Probabilities: map[string]struct{}{"0.1": {}}}, } } @@ -36,12 +37,12 @@ func testThroughputBuckets() []*throughputBucket { { throughput: serviceOperationThroughput{ "svcA": map[string]*model.Throughput{ - "GET": {Count: 45}, - "PUT": {Count: 60}, + http.MethodGet: {Count: 45}, + http.MethodPut: {Count: 60}, }, "svcB": map[string]*model.Throughput{ - "GET": {Count: 30}, - "PUT": {Count: 15}, + http.MethodGet: {Count: 30}, + http.MethodPut: {Count: 15}, }, }, interval: 60 * time.Second, @@ -49,10 +50,10 @@ func testThroughputBuckets() []*throughputBucket { { throughput: serviceOperationThroughput{ "svcA": map[string]*model.Throughput{ - "GET": {Count: 30}, + http.MethodGet: {Count: 30}, }, "svcB": map[string]*model.Throughput{ - "GET": {Count: 45}, + http.MethodGet: {Count: 45}, }, }, interval: 60 * time.Second, @@ -87,12 +88,12 @@ func TestAggregateThroughput(t *testing.T) { require.True(t, ok) require.Len(t, throughput, 2) - opThroughput, ok := throughput["GET"] + opThroughput, ok := throughput[http.MethodGet] require.True(t, ok) assert.Equal(t, int64(8), opThroughput.Count) assert.Equal(t, map[string]struct{}{"0.1": {}, "0.2": {}}, opThroughput.Probabilities) - opThroughput, ok = throughput["PUT"] + opThroughput, ok = throughput[http.MethodPut] require.True(t, ok) assert.Equal(t, int64(5), opThroughput.Count) assert.Equal(t, map[string]struct{}{"0.1": {}}, opThroughput.Probabilities) @@ -101,7 +102,7 @@ func TestAggregateThroughput(t *testing.T) { require.True(t, ok) require.Len(t, throughput, 1) - opThroughput, ok = throughput["GET"] + opThroughput, ok = throughput[http.MethodGet] require.True(t, ok) assert.Equal(t, int64(3), opThroughput.Count) assert.Equal(t, map[string]struct{}{"0.1": {}}, opThroughput.Probabilities) @@ -112,7 +113,7 @@ func TestInitializeThroughput(t *testing.T) { mockStorage.On("GetThroughput", time.Time{}.Add(time.Minute*19), time.Time{}.Add(time.Minute*20)). Return(testThroughputs(), nil) mockStorage.On("GetThroughput", time.Time{}.Add(time.Minute*18), time.Time{}.Add(time.Minute*19)). - Return([]*model.Throughput{{Service: "svcA", Operation: "GET", Count: 7}}, nil) + Return([]*model.Throughput{{Service: "svcA", Operation: http.MethodGet, Count: 7}}, nil) mockStorage.On("GetThroughput", time.Time{}.Add(time.Minute*17), time.Time{}.Add(time.Minute*18)). Return([]*model.Throughput{}, nil) p := &PostAggregator{storage: mockStorage, Options: Options{CalculationInterval: time.Minute, AggregationBuckets: 3}} @@ -154,22 +155,22 @@ func TestGenerateOperationQPS(t *testing.T) { require.True(t, ok) require.Len(t, opQPS, 2) - assert.Equal(t, []float64{0.75, 0.5}, opQPS["GET"]) - assert.Equal(t, []float64{1.0}, opQPS["PUT"]) + assert.Equal(t, []float64{0.75, 0.5}, opQPS[http.MethodGet]) + assert.Equal(t, []float64{1.0}, opQPS[http.MethodPut]) opQPS, ok = svcOpQPS["svcB"] require.True(t, ok) require.Len(t, opQPS, 2) - assert.Equal(t, []float64{0.5, 0.75}, opQPS["GET"]) - assert.Equal(t, []float64{0.25}, opQPS["PUT"]) + assert.Equal(t, []float64{0.5, 0.75}, opQPS[http.MethodGet]) + assert.Equal(t, []float64{0.25}, opQPS[http.MethodPut]) // Test using the previous QPS if the throughput is not provided p.prependThroughputBucket( &throughputBucket{ throughput: serviceOperationThroughput{ "svcA": map[string]*model.Throughput{ - "GET": {Count: 30}, + http.MethodGet: {Count: 30}, }, }, interval: 60 * time.Second, @@ -182,15 +183,15 @@ func TestGenerateOperationQPS(t *testing.T) { require.True(t, ok) require.Len(t, opQPS, 2) - assert.Equal(t, []float64{0.5, 0.75, 0.5}, opQPS["GET"]) - assert.Equal(t, []float64{1.0}, opQPS["PUT"]) + assert.Equal(t, []float64{0.5, 0.75, 0.5}, opQPS[http.MethodGet]) + assert.Equal(t, []float64{1.0}, opQPS[http.MethodPut]) opQPS, ok = svcOpQPS["svcB"] require.True(t, ok) require.Len(t, opQPS, 2) - assert.Equal(t, []float64{0.5, 0.75}, opQPS["GET"]) - assert.Equal(t, []float64{0.25}, opQPS["PUT"]) + assert.Equal(t, []float64{0.5, 0.75}, opQPS[http.MethodGet]) + assert.Equal(t, []float64{0.25}, opQPS[http.MethodPut]) } func TestGenerateOperationQPS_UseMostRecentBucketOnly(t *testing.T) { @@ -202,14 +203,14 @@ func TestGenerateOperationQPS_UseMostRecentBucketOnly(t *testing.T) { require.True(t, ok) require.Len(t, opQPS, 2) - assert.Equal(t, []float64{0.75}, opQPS["GET"]) - assert.Equal(t, []float64{1.0}, opQPS["PUT"]) + assert.Equal(t, []float64{0.75}, opQPS[http.MethodGet]) + assert.Equal(t, []float64{1.0}, opQPS[http.MethodPut]) p.prependThroughputBucket( &throughputBucket{ throughput: serviceOperationThroughput{ "svcA": map[string]*model.Throughput{ - "GET": {Count: 30}, + http.MethodGet: {Count: 30}, }, }, interval: 60 * time.Second, @@ -223,8 +224,8 @@ func TestGenerateOperationQPS_UseMostRecentBucketOnly(t *testing.T) { require.True(t, ok) require.Len(t, opQPS, 2) - assert.Equal(t, []float64{0.5}, opQPS["GET"]) - assert.Equal(t, []float64{1.0}, opQPS["PUT"]) + assert.Equal(t, []float64{0.5}, opQPS[http.MethodGet]) + assert.Equal(t, []float64{1.0}, opQPS[http.MethodPut]) } func TestCalculateWeightedQPS(t *testing.T) { @@ -239,14 +240,14 @@ func TestCalculateProbability(t *testing.T) { { throughput: serviceOperationThroughput{ "svcA": map[string]*model.Throughput{ - "GET": {Probabilities: map[string]struct{}{"0.500000": {}}}, + http.MethodGet: {Probabilities: map[string]struct{}{"0.500000": {}}}, }, }, }, } probabilities := model.ServiceOperationProbabilities{ "svcA": map[string]float64{ - "GET": 0.5, + http.MethodGet: 0.5, }, } cfg := Options{ @@ -269,12 +270,12 @@ func TestCalculateProbability(t *testing.T) { expectedProbability float64 errMsg string }{ - {"svcA", "GET", 2.0, 0.25, "modify existing probability"}, - {"svcA", "PUT", 2.0, 0.0005, "modify default probability"}, - {"svcB", "GET", 0.9, 0.001, "qps within equivalence threshold"}, - {"svcB", "PUT", 0.000001, 1.0, "test max probability"}, - {"svcB", "DELETE", 1000000000, 0.00001, "test min probability"}, - {"svcB", "DELETE", 0.0, 0.002, "test 0 qps"}, + {"svcA", http.MethodGet, 2.0, 0.25, "modify existing probability"}, + {"svcA", http.MethodPut, 2.0, 0.0005, "modify default probability"}, + {"svcB", http.MethodGet, 0.9, 0.001, "qps within equivalence threshold"}, + {"svcB", http.MethodPut, 0.000001, 1.0, "test max probability"}, + {"svcB", http.MethodDelete, 1000000000, 0.00001, "test min probability"}, + {"svcB", http.MethodDelete, 0.0, 0.002, "test 0 qps"}, } for _, test := range tests { probability := p.calculateProbability(test.service, test.operation, test.qps) @@ -285,13 +286,13 @@ func TestCalculateProbability(t *testing.T) { func TestCalculateProbabilitiesAndQPS(t *testing.T) { prevProbabilities := model.ServiceOperationProbabilities{ "svcB": map[string]float64{ - "GET": 0.16, - "PUT": 0.03, + http.MethodGet: 0.16, + http.MethodPut: 0.03, }, } qps := model.ServiceOperationQPS{ "svcB": map[string]float64{ - "GET": 0.625, + http.MethodGet: 0.625, }, } mets := metricstest.NewFactory(0) @@ -309,12 +310,12 @@ func TestCalculateProbabilitiesAndQPS(t *testing.T) { probabilities, qps := p.calculateProbabilitiesAndQPS() require.Len(t, probabilities, 2) - assert.Equal(t, map[string]float64{"GET": 0.00136, "PUT": 0.001}, probabilities["svcA"]) - assert.Equal(t, map[string]float64{"GET": 0.16, "PUT": 0.03}, probabilities["svcB"]) + assert.Equal(t, map[string]float64{http.MethodGet: 0.00136, http.MethodPut: 0.001}, probabilities["svcA"]) + assert.Equal(t, map[string]float64{http.MethodGet: 0.16, http.MethodPut: 0.03}, probabilities["svcB"]) require.Len(t, qps, 2) - assert.Equal(t, map[string]float64{"GET": 0.7352941176470588, "PUT": 1}, qps["svcA"]) - assert.Equal(t, map[string]float64{"GET": 0.5147058823529411, "PUT": 0.25}, qps["svcB"]) + assert.Equal(t, map[string]float64{http.MethodGet: 0.7352941176470588, http.MethodPut: 1}, qps["svcA"]) + assert.Equal(t, map[string]float64{http.MethodGet: 0.5147058823529411, http.MethodPut: 0.25}, qps["svcB"]) _, gauges := mets.Backend.Snapshot() assert.EqualValues(t, 4, gauges["test"]) @@ -477,11 +478,11 @@ func TestCalculateProbabilitiesAndQPSMultiple(t *testing.T) { { throughput: serviceOperationThroughput{ "svcA": map[string]*model.Throughput{ - "GET": {Count: 3, Probabilities: map[string]struct{}{"0.001000": {}}}, - "PUT": {Count: 60, Probabilities: map[string]struct{}{"0.001000": {}}}, + http.MethodGet: {Count: 3, Probabilities: map[string]struct{}{"0.001000": {}}}, + http.MethodPut: {Count: 60, Probabilities: map[string]struct{}{"0.001000": {}}}, }, "svcB": map[string]*model.Throughput{ - "PUT": {Count: 15, Probabilities: map[string]struct{}{"0.001000": {}}}, + http.MethodPut: {Count: 15, Probabilities: map[string]struct{}{"0.001000": {}}}, }, }, interval: 60 * time.Second, @@ -506,8 +507,8 @@ func TestCalculateProbabilitiesAndQPSMultiple(t *testing.T) { probabilities, qps := p.calculateProbabilitiesAndQPS() require.Len(t, probabilities, 2) - assert.Equal(t, map[string]float64{"GET": 0.002, "PUT": 0.001}, probabilities["svcA"]) - assert.Equal(t, map[string]float64{"PUT": 0.002}, probabilities["svcB"]) + assert.Equal(t, map[string]float64{http.MethodGet: 0.002, http.MethodPut: 0.001}, probabilities["svcA"]) + assert.Equal(t, map[string]float64{http.MethodPut: 0.002}, probabilities["svcB"]) p.probabilities = probabilities p.qps = qps @@ -518,11 +519,11 @@ func TestCalculateProbabilitiesAndQPSMultiple(t *testing.T) { p.prependThroughputBucket(&throughputBucket{ throughput: serviceOperationThroughput{ "svcA": map[string]*model.Throughput{ - "PUT": {Count: 60, Probabilities: map[string]struct{}{"0.001000": {}}}, + http.MethodPut: {Count: 60, Probabilities: map[string]struct{}{"0.001000": {}}}, }, "svcB": map[string]*model.Throughput{ - "GET": {Count: 30, Probabilities: map[string]struct{}{"0.001000": {}}}, - "PUT": {Count: 0, Probabilities: map[string]struct{}{"0.002000": {}}}, + http.MethodGet: {Count: 30, Probabilities: map[string]struct{}{"0.001000": {}}}, + http.MethodPut: {Count: 0, Probabilities: map[string]struct{}{"0.002000": {}}}, }, }, interval: 60 * time.Second, @@ -531,8 +532,8 @@ func TestCalculateProbabilitiesAndQPSMultiple(t *testing.T) { probabilities, qps = p.calculateProbabilitiesAndQPS() require.Len(t, probabilities, 2) - assert.Equal(t, map[string]float64{"GET": 0.002, "PUT": 0.001}, probabilities["svcA"]) - assert.Equal(t, map[string]float64{"PUT": 0.004, "GET": 0.002}, probabilities["svcB"]) + assert.Equal(t, map[string]float64{http.MethodGet: 0.002, http.MethodPut: 0.001}, probabilities["svcA"]) + assert.Equal(t, map[string]float64{http.MethodPut: 0.004, http.MethodGet: 0.002}, probabilities["svcB"]) p.probabilities = probabilities p.qps = qps @@ -543,11 +544,11 @@ func TestCalculateProbabilitiesAndQPSMultiple(t *testing.T) { p.prependThroughputBucket(&throughputBucket{ throughput: serviceOperationThroughput{ "svcA": map[string]*model.Throughput{ - "GET": {Count: 0, Probabilities: map[string]struct{}{"0.002000": {}}}, - "PUT": {Count: 60, Probabilities: map[string]struct{}{"0.001000": {}}}, + http.MethodGet: {Count: 0, Probabilities: map[string]struct{}{"0.002000": {}}}, + http.MethodPut: {Count: 60, Probabilities: map[string]struct{}{"0.001000": {}}}, }, "svcB": map[string]*model.Throughput{ - "GET": {Count: 30, Probabilities: map[string]struct{}{"0.001000": {}}}, + http.MethodGet: {Count: 30, Probabilities: map[string]struct{}{"0.001000": {}}}, }, }, interval: 60 * time.Second, @@ -556,8 +557,8 @@ func TestCalculateProbabilitiesAndQPSMultiple(t *testing.T) { probabilities, qps = p.calculateProbabilitiesAndQPS() require.Len(t, probabilities, 2) - assert.Equal(t, map[string]float64{"GET": 0.004, "PUT": 0.001}, probabilities["svcA"]) - assert.Equal(t, map[string]float64{"PUT": 0.008, "GET": 0.002}, probabilities["svcB"]) + assert.Equal(t, map[string]float64{http.MethodGet: 0.004, http.MethodPut: 0.001}, probabilities["svcA"]) + assert.Equal(t, map[string]float64{http.MethodPut: 0.008, http.MethodGet: 0.002}, probabilities["svcB"]) p.probabilities = probabilities p.qps = qps @@ -567,12 +568,12 @@ func TestCalculateProbabilitiesAndQPSMultiple(t *testing.T) { p.prependThroughputBucket(&throughputBucket{ throughput: serviceOperationThroughput{ "svcA": map[string]*model.Throughput{ - "GET": {Count: 1, Probabilities: map[string]struct{}{"0.004000": {}}}, - "PUT": {Count: 60, Probabilities: map[string]struct{}{"0.001000": {}}}, + http.MethodGet: {Count: 1, Probabilities: map[string]struct{}{"0.004000": {}}}, + http.MethodPut: {Count: 60, Probabilities: map[string]struct{}{"0.001000": {}}}, }, "svcB": map[string]*model.Throughput{ - "GET": {Count: 30, Probabilities: map[string]struct{}{"0.001000": {}}}, - "PUT": {Count: 15, Probabilities: map[string]struct{}{"0.001000": {}}}, + http.MethodGet: {Count: 30, Probabilities: map[string]struct{}{"0.001000": {}}}, + http.MethodPut: {Count: 15, Probabilities: map[string]struct{}{"0.001000": {}}}, }, }, interval: 60 * time.Second, @@ -581,8 +582,8 @@ func TestCalculateProbabilitiesAndQPSMultiple(t *testing.T) { probabilities, qps = p.calculateProbabilitiesAndQPS() require.Len(t, probabilities, 2) - assert.Equal(t, map[string]float64{"GET": 0.008, "PUT": 0.001}, probabilities["svcA"]) - assert.Equal(t, map[string]float64{"PUT": 0.008, "GET": 0.002}, probabilities["svcB"]) + assert.Equal(t, map[string]float64{http.MethodGet: 0.008, http.MethodPut: 0.001}, probabilities["svcA"]) + assert.Equal(t, map[string]float64{http.MethodPut: 0.008, http.MethodGet: 0.002}, probabilities["svcB"]) p.probabilities = probabilities p.qps = qps @@ -591,11 +592,11 @@ func TestCalculateProbabilitiesAndQPSMultiple(t *testing.T) { p.prependThroughputBucket(&throughputBucket{ throughput: serviceOperationThroughput{ "svcA": map[string]*model.Throughput{ - "PUT": {Count: 30, Probabilities: map[string]struct{}{"0.001000": {}}}, + http.MethodPut: {Count: 30, Probabilities: map[string]struct{}{"0.001000": {}}}, }, "svcB": map[string]*model.Throughput{ - "GET": {Count: 30, Probabilities: map[string]struct{}{"0.001000": {}}}, - "PUT": {Count: 15, Probabilities: map[string]struct{}{"0.001000": {}}}, + http.MethodGet: {Count: 30, Probabilities: map[string]struct{}{"0.001000": {}}}, + http.MethodPut: {Count: 15, Probabilities: map[string]struct{}{"0.001000": {}}}, }, }, interval: 60 * time.Second, @@ -604,8 +605,8 @@ func TestCalculateProbabilitiesAndQPSMultiple(t *testing.T) { probabilities, qps = p.calculateProbabilitiesAndQPS() require.Len(t, probabilities, 2) - assert.Equal(t, map[string]float64{"GET": 0.016, "PUT": 0.001468867216804201}, probabilities["svcA"]) - assert.Equal(t, map[string]float64{"PUT": 0.008, "GET": 0.002}, probabilities["svcB"]) + assert.Equal(t, map[string]float64{http.MethodGet: 0.016, http.MethodPut: 0.001468867216804201}, probabilities["svcA"]) + assert.Equal(t, map[string]float64{http.MethodPut: 0.008, http.MethodGet: 0.002}, probabilities["svcB"]) p.probabilities = probabilities p.qps = qps @@ -615,11 +616,11 @@ func TestCalculateProbabilitiesAndQPSMultiple(t *testing.T) { p.prependThroughputBucket(&throughputBucket{ throughput: serviceOperationThroughput{ "svcA": map[string]*model.Throughput{ - "PUT": {Count: 30, Probabilities: map[string]struct{}{"0.001000": {}}}, + http.MethodPut: {Count: 30, Probabilities: map[string]struct{}{"0.001000": {}}}, }, "svcB": map[string]*model.Throughput{ - "GET": {Count: 30, Probabilities: map[string]struct{}{"0.001000": {}}}, - "PUT": {Count: 1, Probabilities: map[string]struct{}{"0.008000": {}}}, + http.MethodGet: {Count: 30, Probabilities: map[string]struct{}{"0.001000": {}}}, + http.MethodPut: {Count: 1, Probabilities: map[string]struct{}{"0.008000": {}}}, }, }, interval: 60 * time.Second, @@ -628,8 +629,8 @@ func TestCalculateProbabilitiesAndQPSMultiple(t *testing.T) { probabilities, qps = p.calculateProbabilitiesAndQPS() require.Len(t, probabilities, 2) - assert.Equal(t, map[string]float64{"GET": 0.032, "PUT": 0.001468867216804201}, probabilities["svcA"]) - assert.Equal(t, map[string]float64{"PUT": 0.016, "GET": 0.002}, probabilities["svcB"]) + assert.Equal(t, map[string]float64{http.MethodGet: 0.032, http.MethodPut: 0.001468867216804201}, probabilities["svcA"]) + assert.Equal(t, map[string]float64{http.MethodPut: 0.016, http.MethodGet: 0.002}, probabilities["svcB"]) p.probabilities = probabilities p.qps = qps @@ -639,10 +640,10 @@ func TestCalculateProbabilitiesAndQPSMultiple(t *testing.T) { p.prependThroughputBucket(&throughputBucket{ throughput: serviceOperationThroughput{ "svcA": map[string]*model.Throughput{ - "PUT": {Count: 30, Probabilities: map[string]struct{}{"0.001000": {}}}, + http.MethodPut: {Count: 30, Probabilities: map[string]struct{}{"0.001000": {}}}, }, "svcB": map[string]*model.Throughput{ - "GET": {Count: 15, Probabilities: map[string]struct{}{"0.001000": {}}}, + http.MethodGet: {Count: 15, Probabilities: map[string]struct{}{"0.001000": {}}}, }, }, interval: 60 * time.Second, @@ -651,8 +652,8 @@ func TestCalculateProbabilitiesAndQPSMultiple(t *testing.T) { probabilities, qps = p.calculateProbabilitiesAndQPS() require.Len(t, probabilities, 2) - assert.Equal(t, map[string]float64{"GET": 0.064, "PUT": 0.001468867216804201}, probabilities["svcA"]) - assert.Equal(t, map[string]float64{"PUT": 0.032, "GET": 0.002}, probabilities["svcB"]) + assert.Equal(t, map[string]float64{http.MethodGet: 0.064, http.MethodPut: 0.001468867216804201}, probabilities["svcA"]) + assert.Equal(t, map[string]float64{http.MethodPut: 0.032, http.MethodGet: 0.002}, probabilities["svcB"]) p.probabilities = probabilities p.qps = qps @@ -662,10 +663,10 @@ func TestCalculateProbabilitiesAndQPSMultiple(t *testing.T) { p.prependThroughputBucket(&throughputBucket{ throughput: serviceOperationThroughput{ "svcA": map[string]*model.Throughput{ - "PUT": {Count: 20, Probabilities: map[string]struct{}{"0.001000": {}}}, + http.MethodPut: {Count: 20, Probabilities: map[string]struct{}{"0.001000": {}}}, }, "svcB": map[string]*model.Throughput{ - "GET": {Count: 10, Probabilities: map[string]struct{}{"0.001000": {}}}, + http.MethodGet: {Count: 10, Probabilities: map[string]struct{}{"0.001000": {}}}, }, }, interval: 60 * time.Second, @@ -674,8 +675,8 @@ func TestCalculateProbabilitiesAndQPSMultiple(t *testing.T) { probabilities, qps = p.calculateProbabilitiesAndQPS() require.Len(t, probabilities, 2) - assert.Equal(t, map[string]float64{"GET": 0.128, "PUT": 0.001468867216804201}, probabilities["svcA"]) - assert.Equal(t, map[string]float64{"PUT": 0.064, "GET": 0.002}, probabilities["svcB"]) + assert.Equal(t, map[string]float64{http.MethodGet: 0.128, http.MethodPut: 0.001468867216804201}, probabilities["svcA"]) + assert.Equal(t, map[string]float64{http.MethodPut: 0.064, http.MethodGet: 0.002}, probabilities["svcB"]) p.probabilities = probabilities p.qps = qps @@ -685,12 +686,12 @@ func TestCalculateProbabilitiesAndQPSMultiple(t *testing.T) { p.prependThroughputBucket(&throughputBucket{ throughput: serviceOperationThroughput{ "svcA": map[string]*model.Throughput{ - "PUT": {Count: 20, Probabilities: map[string]struct{}{"0.001000": {}}}, - "GET": {Count: 120, Probabilities: map[string]struct{}{"0.128000": {}}}, + http.MethodPut: {Count: 20, Probabilities: map[string]struct{}{"0.001000": {}}}, + http.MethodGet: {Count: 120, Probabilities: map[string]struct{}{"0.128000": {}}}, }, "svcB": map[string]*model.Throughput{ - "PUT": {Count: 60, Probabilities: map[string]struct{}{"0.064000": {}}}, - "GET": {Count: 10, Probabilities: map[string]struct{}{"0.001000": {}}}, + http.MethodPut: {Count: 60, Probabilities: map[string]struct{}{"0.064000": {}}}, + http.MethodGet: {Count: 10, Probabilities: map[string]struct{}{"0.001000": {}}}, }, }, interval: 60 * time.Second, @@ -699,8 +700,8 @@ func TestCalculateProbabilitiesAndQPSMultiple(t *testing.T) { probabilities, qps = p.calculateProbabilitiesAndQPS() require.Len(t, probabilities, 2) - assert.Equal(t, map[string]float64{"GET": 0.0882586677054928, "PUT": 0.001468867216804201}, probabilities["svcA"]) - assert.Equal(t, map[string]float64{"PUT": 0.09587513707888091, "GET": 0.002}, probabilities["svcB"]) + assert.Equal(t, map[string]float64{http.MethodGet: 0.0882586677054928, http.MethodPut: 0.001468867216804201}, probabilities["svcA"]) + assert.Equal(t, map[string]float64{http.MethodPut: 0.09587513707888091, http.MethodGet: 0.002}, probabilities["svcB"]) p.probabilities = probabilities p.qps = qps diff --git a/plugin/sampling/strategyprovider/adaptive/provider_test.go b/plugin/sampling/strategyprovider/adaptive/provider_test.go index 8a26d8fc34d..1342cd21790 100644 --- a/plugin/sampling/strategyprovider/adaptive/provider_test.go +++ b/plugin/sampling/strategyprovider/adaptive/provider_test.go @@ -5,6 +5,7 @@ package adaptive import ( "context" + "net/http" "testing" "time" @@ -68,10 +69,10 @@ func TestProviderRealisticRunCalculationLoop(t *testing.T) { logger := zap.NewNop() // NB: This is an extremely long test since it uses near realistic (1/6th scale) processor config values testThroughputs := []*model.Throughput{ - {Service: "svcA", Operation: "GET", Count: 10}, - {Service: "svcA", Operation: "POST", Count: 9}, - {Service: "svcA", Operation: "PUT", Count: 5}, - {Service: "svcA", Operation: "DELETE", Count: 20}, + {Service: "svcA", Operation: http.MethodGet, Count: 10}, + {Service: "svcA", Operation: http.MethodPost, Count: 9}, + {Service: "svcA", Operation: http.MethodPut, Count: 5}, + {Service: "svcA", Operation: http.MethodDelete, Count: 20}, } mockStorage := &smocks.Store{} mockStorage.On("GetThroughput", mock.AnythingOfType("time.Time"), mock.AnythingOfType("time.Time")). @@ -110,16 +111,16 @@ func TestProviderRealisticRunCalculationLoop(t *testing.T) { for _, s := range strategies { switch s.Operation { - case "GET": + case http.MethodGet: assert.InDelta(t, 0.001, s.ProbabilisticSampling.SamplingRate, 1e-4, "Already at 1QPS, no probability change") - case "POST": + case http.MethodPost: assert.InDelta(t, 0.001, s.ProbabilisticSampling.SamplingRate, 1e-4, "Within epsilon of 1QPS, no probability change") - case "PUT": + case http.MethodPut: assert.InEpsilon(t, 0.002, s.ProbabilisticSampling.SamplingRate, 0.025, "Under sampled, double probability") - case "DELETE": + case http.MethodDelete: assert.InEpsilon(t, 0.0005, s.ProbabilisticSampling.SamplingRate, 0.025, "Over sampled, halve probability") } @@ -129,7 +130,7 @@ func TestProviderRealisticRunCalculationLoop(t *testing.T) { func TestProviderGenerateStrategyResponses(t *testing.T) { probabilities := model.ServiceOperationProbabilities{ "svcA": map[string]float64{ - "GET": 0.5, + http.MethodGet: 0.5, }, } p := &Provider{ @@ -149,7 +150,7 @@ func TestProviderGenerateStrategyResponses(t *testing.T) { DefaultLowerBoundTracesPerSecond: 0.0001, PerOperationStrategies: []*api_v2.OperationSamplingStrategy{ { - Operation: "GET", + Operation: http.MethodGet, ProbabilisticSampling: &api_v2.ProbabilisticSamplingStrategy{ SamplingRate: 0.5, }, diff --git a/plugin/sampling/strategyprovider/static/provider.go b/plugin/sampling/strategyprovider/static/provider.go index 56890ed63c0..8c801de8f79 100644 --- a/plugin/sampling/strategyprovider/static/provider.go +++ b/plugin/sampling/strategyprovider/static/provider.go @@ -104,7 +104,7 @@ func (h *samplingProvider) downloadSamplingStrategies(samplingURL string) ([]byt ctx, cx := context.WithTimeout(context.Background(), time.Second) defer cx() - req, err := http.NewRequestWithContext(ctx, "GET", samplingURL, nil) + req, err := http.NewRequestWithContext(ctx, http.MethodGet, samplingURL, nil) if err != nil { return nil, fmt.Errorf("cannot construct HTTP request: %w", err) } diff --git a/plugin/sampling/strategyprovider/static/provider_test.go b/plugin/sampling/strategyprovider/static/provider_test.go index ba7992f18f8..783caeb5c54 100644 --- a/plugin/sampling/strategyprovider/static/provider_test.go +++ b/plugin/sampling/strategyprovider/static/provider_test.go @@ -73,15 +73,15 @@ func mockStrategyServer(t *testing.T) (*httptest.Server, *atomic.Pointer[string] return case "/bad-status": - w.WriteHeader(404) + w.WriteHeader(http.StatusNotFound) return case "/service-unavailable": - w.WriteHeader(503) + w.WriteHeader(http.StatusServiceUnavailable) return default: - w.WriteHeader(200) + w.WriteHeader(http.StatusOK) w.Header().Set("Content-Type", "application/json") w.Write([]byte(*strategy.Load())) } diff --git a/plugin/storage/cassandra/samplingstore/storage_test.go b/plugin/storage/cassandra/samplingstore/storage_test.go index 238d9723f56..774ffeb5422 100644 --- a/plugin/storage/cassandra/samplingstore/storage_test.go +++ b/plugin/storage/cassandra/samplingstore/storage_test.go @@ -6,6 +6,7 @@ package samplingstore import ( "errors" + "net/http" "testing" "time" @@ -329,12 +330,12 @@ func TestStringToThroughput(t *testing.T) { func TestProbabilitiesAndQPSToString(t *testing.T) { probabilities := model.ServiceOperationProbabilities{ "svc,1": map[string]float64{ - "GET": 0.001, + http.MethodGet: 0.001, }, } qps := model.ServiceOperationQPS{ "svc,1": map[string]float64{ - "GET": 62.3, + http.MethodGet: 62.3, }, } str := probabilitiesAndQPSToString(probabilities, qps) @@ -348,17 +349,17 @@ func TestStringToProbabilitiesAndQPS(t *testing.T) { assert.Len(t, probabilities, 2) assert.Equal(t, map[string]*model.ProbabilityAndQPS{ - "GET": { + http.MethodGet: { Probability: 0.001, QPS: 63.2, }, - "PUT": { + http.MethodPut: { Probability: 0.002, QPS: 0.0, }, }, probabilities["svc1"]) assert.Equal(t, map[string]*model.ProbabilityAndQPS{ - "GET": { + http.MethodGet: { Probability: 0.5, QPS: 34.2, }, @@ -371,8 +372,8 @@ func TestStringToProbabilities(t *testing.T) { probabilities := s.stringToProbabilities(testStr) assert.Len(t, probabilities, 2) - assert.Equal(t, map[string]float64{"GET": 0.001, "PUT": 0.002}, probabilities["svc1"]) - assert.Equal(t, map[string]float64{"GET": 0.5}, probabilities["svc2"]) + assert.Equal(t, map[string]float64{http.MethodGet: 0.001, http.MethodPut: 0.002}, probabilities["svc1"]) + assert.Equal(t, map[string]float64{http.MethodGet: 0.5}, probabilities["svc2"]) } func TestProbabilitiesSetToString(t *testing.T) { diff --git a/plugin/storage/es/options_test.go b/plugin/storage/es/options_test.go index 33d933b5830..87b2ce11d7f 100644 --- a/plugin/storage/es/options_test.go +++ b/plugin/storage/es/options_test.go @@ -5,6 +5,7 @@ package es import ( + "net/http" "testing" "time" @@ -117,7 +118,7 @@ func TestOptionsWithFlags(t *testing.T) { assert.Equal(t, "2006.01.02", aux.Indices.Services.DateLayout) assert.Equal(t, "2006.01.02.15", aux.Indices.Spans.DateLayout) assert.True(t, primary.UseILM) - assert.Equal(t, "POST", aux.SendGetBodyAs) + assert.Equal(t, http.MethodPost, aux.SendGetBodyAs) } func TestEmptyRemoteReadClusters(t *testing.T) {