From fec36f4d7e6c80c422475568ba9d4cc6993e7753 Mon Sep 17 00:00:00 2001 From: Matthieu MOREL Date: Sun, 17 Nov 2024 21:25:02 +0000 Subject: [PATCH] usestdlibvars: replace http methods Signed-off-by: Matthieu MOREL --- connector/exceptionsconnector/factory_test.go | 3 +- connector/spanmetricsconnector/config_test.go | 3 +- .../spanmetricsconnector/factory_test.go | 3 +- .../tracedata_to_logservice_test.go | 5 ++- exporter/awsxrayexporter/awsxray_test.go | 5 ++- .../internal/translator/cause_test.go | 19 ++++---- .../internal/translator/http_test.go | 45 ++++++++++--------- .../internal/translator/segment_test.go | 41 ++++++++--------- .../internal/translator/writer_pool_test.go | 3 +- .../trace_to_envelope_test.go | 3 +- .../sentryexporter/sentry_exporter_test.go | 2 +- .../httpforwarderextension/extension_test.go | 6 +-- internal/aws/cwlogs/cwlog_client_test.go | 3 +- internal/aws/ecsutil/client_test.go | 2 +- internal/aws/xray/tracesegment_test.go | 3 +- internal/aws/xray/xray_client_test.go | 3 +- .../goldendataset/span_generator.go | 9 ++-- internal/kubelet/client_test.go | 2 +- pkg/ottl/e2e/e2e_test.go | 3 +- .../azure/resourcelogs_to_logs_test.go | 7 +-- .../azurelogs/resourcelogs_to_logs_test.go | 15 ++++--- receiver/collectdreceiver/receiver_test.go | 6 +-- .../opencensusreceiver/opencensus_test.go | 4 +- .../skywalking_receiver_test.go | 2 +- .../splunkenterprisereceiver/client_test.go | 4 +- receiver/splunkhecreceiver/receiver.go | 2 +- 26 files changed, 110 insertions(+), 93 deletions(-) diff --git a/connector/exceptionsconnector/factory_test.go b/connector/exceptionsconnector/factory_test.go index f39b009d4b46..ed55b8a2b4be 100644 --- a/connector/exceptionsconnector/factory_test.go +++ b/connector/exceptionsconnector/factory_test.go @@ -5,6 +5,7 @@ package exceptionsconnector import ( "context" + "net/http" "testing" "github.com/stretchr/testify/assert" @@ -16,7 +17,7 @@ import ( ) func TestNewConnector(t *testing.T) { - defaultMethod := "GET" + defaultMethod := http.MethodGet defaultMethodValue := pcommon.NewValueStr(defaultMethod) for _, tc := range []struct { name string diff --git a/connector/spanmetricsconnector/config_test.go b/connector/spanmetricsconnector/config_test.go index d7142f84d9ad..79c823f9b574 100644 --- a/connector/spanmetricsconnector/config_test.go +++ b/connector/spanmetricsconnector/config_test.go @@ -5,6 +5,7 @@ package spanmetricsconnector import ( "errors" + "net/http" "path/filepath" "testing" "time" @@ -25,7 +26,7 @@ func TestLoadConfig(t *testing.T) { cm, err := confmaptest.LoadConf(filepath.Join("testdata", "config.yaml")) require.NoError(t, err) - defaultMethod := "GET" + defaultMethod := http.MethodGet defaultMaxPerDatapoint := 5 customTimestampCacheSize := 123 tests := []struct { diff --git a/connector/spanmetricsconnector/factory_test.go b/connector/spanmetricsconnector/factory_test.go index 75aaf79d60c7..b3fc72ac489a 100644 --- a/connector/spanmetricsconnector/factory_test.go +++ b/connector/spanmetricsconnector/factory_test.go @@ -5,6 +5,7 @@ package spanmetricsconnector import ( "context" + "net/http" "testing" "time" @@ -17,7 +18,7 @@ import ( ) func TestNewConnector(t *testing.T) { - defaultMethod := "GET" + defaultMethod := http.MethodGet defaultMethodValue := pcommon.NewValueStr(defaultMethod) for _, tc := range []struct { name string diff --git a/exporter/alibabacloudlogserviceexporter/tracedata_to_logservice_test.go b/exporter/alibabacloudlogserviceexporter/tracedata_to_logservice_test.go index b953a1385609..3731480f8c93 100644 --- a/exporter/alibabacloudlogserviceexporter/tracedata_to_logservice_test.go +++ b/exporter/alibabacloudlogserviceexporter/tracedata_to_logservice_test.go @@ -6,6 +6,7 @@ package alibabacloudlogserviceexporter import ( "encoding/json" "fmt" + "net/http" "os" "sort" "testing" @@ -97,7 +98,7 @@ func fillResource(resource pcommon.Resource) { func fillHTTPClientSpan(span ptrace.Span) { attributes := make(map[string]any) - attributes[conventions.AttributeHTTPMethod] = "GET" + attributes[conventions.AttributeHTTPMethod] = http.MethodGet attributes[conventions.AttributeHTTPURL] = "https://api.example.com/users/junit" attributes[conventions.AttributeHTTPStatusCode] = 200 endTime := time.Unix(12300, 123456789) @@ -129,7 +130,7 @@ func fillHTTPClientSpan(span ptrace.Span) { func fillHTTPServerSpan(span ptrace.Span) { attributes := make(map[string]any) - attributes[conventions.AttributeHTTPMethod] = "GET" + attributes[conventions.AttributeHTTPMethod] = http.MethodGet attributes[conventions.AttributeHTTPURL] = "https://api.example.com/users/junit" attributes[conventions.AttributeHTTPClientIP] = "192.168.15.32" attributes[conventions.AttributeHTTPStatusCode] = 200 diff --git a/exporter/awsxrayexporter/awsxray_test.go b/exporter/awsxrayexporter/awsxray_test.go index 1027624e549b..90d5c12adff9 100644 --- a/exporter/awsxrayexporter/awsxray_test.go +++ b/exporter/awsxrayexporter/awsxray_test.go @@ -8,6 +8,7 @@ import ( "crypto/rand" "encoding/binary" "fmt" + "net/http" "testing" "time" @@ -184,7 +185,7 @@ func constructResource() pcommon.Resource { func constructHTTPClientSpan(traceID pcommon.TraceID) ptrace.Span { attributes := make(map[string]any) - attributes[conventions.AttributeHTTPMethod] = "GET" + attributes[conventions.AttributeHTTPMethod] = http.MethodGet attributes[conventions.AttributeHTTPURL] = "https://api.example.com/users/junit" attributes[conventions.AttributeHTTPStatusCode] = 200 endTime := time.Now().Round(time.Second) @@ -211,7 +212,7 @@ func constructHTTPClientSpan(traceID pcommon.TraceID) ptrace.Span { func constructHTTPServerSpan(traceID pcommon.TraceID) ptrace.Span { attributes := make(map[string]any) - attributes[conventions.AttributeHTTPMethod] = "GET" + attributes[conventions.AttributeHTTPMethod] = http.MethodGet attributes[conventions.AttributeHTTPURL] = "https://api.example.com/users/junit" attributes[conventions.AttributeHTTPClientIP] = "192.168.15.32" attributes[conventions.AttributeHTTPStatusCode] = 200 diff --git a/exporter/awsxrayexporter/internal/translator/cause_test.go b/exporter/awsxrayexporter/internal/translator/cause_test.go index 6f4dbfcd9eb0..48b56aaa33a8 100644 --- a/exporter/awsxrayexporter/internal/translator/cause_test.go +++ b/exporter/awsxrayexporter/internal/translator/cause_test.go @@ -4,6 +4,7 @@ package translator import ( + "net/http" "strings" "testing" "time" @@ -174,7 +175,7 @@ func EventWithoutExceptionWithoutErrorHelper(t *testing.T, statusCode ptrace.Sta func TestCauseWithStatusMessage(t *testing.T) { errorMsg := "this is a test" attributes := make(map[string]any) - attributes[conventions.AttributeHTTPMethod] = "POST" + attributes[conventions.AttributeHTTPMethod] = http.MethodPost attributes[conventions.AttributeHTTPURL] = "https://api.example.com/widgets" attributes[conventions.AttributeHTTPStatusCode] = 500 span := constructExceptionServerSpan(attributes, ptrace.StatusCodeError) @@ -199,7 +200,7 @@ func TestCauseWithStatusMessage(t *testing.T) { func TestCauseWithHttpStatusMessage(t *testing.T) { errorMsg := "this is a test" attributes := make(map[string]any) - attributes[conventions.AttributeHTTPMethod] = "POST" + attributes[conventions.AttributeHTTPMethod] = http.MethodPost attributes[conventions.AttributeHTTPURL] = "https://api.example.com/widgets" attributes[conventions.AttributeHTTPStatusCode] = 500 attributes["http.status_text"] = errorMsg @@ -224,7 +225,7 @@ func TestCauseWithHttpStatusMessage(t *testing.T) { func TestCauseWithZeroStatusMessageAndFaultHttpCode(t *testing.T) { errorMsg := "this is a test" attributes := make(map[string]any) - attributes[conventions.AttributeHTTPMethod] = "POST" + attributes[conventions.AttributeHTTPMethod] = http.MethodPost attributes[conventions.AttributeHTTPURL] = "https://api.example.com/widgets" attributes[conventions.AttributeHTTPStatusCode] = 500 attributes["http.status_text"] = errorMsg @@ -248,7 +249,7 @@ func TestCauseWithZeroStatusMessageAndFaultHttpCode(t *testing.T) { func TestNonHttpUnsetCodeSpan(t *testing.T) { errorMsg := "this is a test" attributes := make(map[string]any) - attributes[conventions.AttributeHTTPMethod] = "POST" + attributes[conventions.AttributeHTTPMethod] = http.MethodPost attributes[conventions.AttributeHTTPURL] = "https://api.example.com/widgets" attributes["http.status_text"] = errorMsg @@ -271,7 +272,7 @@ func TestNonHttpUnsetCodeSpan(t *testing.T) { func TestNonHttpOkCodeSpan(t *testing.T) { errorMsg := "this is a test" attributes := make(map[string]any) - attributes[conventions.AttributeHTTPMethod] = "POST" + attributes[conventions.AttributeHTTPMethod] = http.MethodPost attributes[conventions.AttributeHTTPURL] = "https://api.example.com/widgets" attributes["http.status_text"] = errorMsg @@ -294,7 +295,7 @@ func TestNonHttpOkCodeSpan(t *testing.T) { func TestNonHttpErrCodeSpan(t *testing.T) { errorMsg := "this is a test" attributes := make(map[string]any) - attributes[conventions.AttributeHTTPMethod] = "POST" + attributes[conventions.AttributeHTTPMethod] = http.MethodPost attributes[conventions.AttributeHTTPURL] = "https://api.example.com/widgets" attributes["http.status_text"] = errorMsg @@ -317,7 +318,7 @@ func TestNonHttpErrCodeSpan(t *testing.T) { func TestCauseWithZeroStatusMessageAndFaultErrorCode(t *testing.T) { errorMsg := "this is a test" attributes := make(map[string]any) - attributes[conventions.AttributeHTTPMethod] = "POST" + attributes[conventions.AttributeHTTPMethod] = http.MethodPost attributes[conventions.AttributeHTTPURL] = "https://api.example.com/widgets" attributes[conventions.AttributeHTTPStatusCode] = 400 attributes["http.status_text"] = errorMsg @@ -341,7 +342,7 @@ func TestCauseWithZeroStatusMessageAndFaultErrorCode(t *testing.T) { func TestCauseWithClientErrorMessage(t *testing.T) { errorMsg := "this is a test" attributes := make(map[string]any) - attributes[conventions.AttributeHTTPMethod] = "POST" + attributes[conventions.AttributeHTTPMethod] = http.MethodPost attributes[conventions.AttributeHTTPURL] = "https://api.example.com/widgets" attributes[conventions.AttributeHTTPStatusCode] = 499 attributes["http.status_text"] = errorMsg @@ -362,7 +363,7 @@ func TestCauseWithClientErrorMessage(t *testing.T) { func TestCauseWithThrottled(t *testing.T) { errorMsg := "this is a test" attributes := make(map[string]any) - attributes[conventions.AttributeHTTPMethod] = "POST" + attributes[conventions.AttributeHTTPMethod] = http.MethodPost attributes[conventions.AttributeHTTPURL] = "https://api.example.com/widgets" attributes[conventions.AttributeHTTPStatusCode] = 429 attributes["http.status_text"] = errorMsg diff --git a/exporter/awsxrayexporter/internal/translator/http_test.go b/exporter/awsxrayexporter/internal/translator/http_test.go index d0f8b375c72f..82f678c54171 100644 --- a/exporter/awsxrayexporter/internal/translator/http_test.go +++ b/exporter/awsxrayexporter/internal/translator/http_test.go @@ -4,6 +4,7 @@ package translator import ( + "net/http" "testing" "time" @@ -17,7 +18,7 @@ import ( func TestClientSpanWithURLAttribute(t *testing.T) { attributes := make(map[string]any) - attributes[conventions.AttributeHTTPMethod] = "GET" + attributes[conventions.AttributeHTTPMethod] = http.MethodGet attributes[conventions.AttributeHTTPURL] = "https://api.example.com/users/junit" attributes[conventions.AttributeHTTPStatusCode] = 200 span := constructHTTPClientSpan(attributes) @@ -35,7 +36,7 @@ func TestClientSpanWithURLAttribute(t *testing.T) { func TestClientSpanWithURLAttributeStable(t *testing.T) { attributes := make(map[string]any) - attributes[AttributeHTTPRequestMethod] = "GET" + attributes[AttributeHTTPRequestMethod] = http.MethodGet attributes[AttributeURLFull] = "https://api.example.com/users/junit" attributes[AttributeHTTPResponseStatusCode] = 200 span := constructHTTPClientSpan(attributes) @@ -53,7 +54,7 @@ func TestClientSpanWithURLAttributeStable(t *testing.T) { func TestClientSpanWithSchemeHostTargetAttributes(t *testing.T) { attributes := make(map[string]any) - attributes[conventions.AttributeHTTPMethod] = "GET" + attributes[conventions.AttributeHTTPMethod] = http.MethodGet attributes[conventions.AttributeHTTPScheme] = "https" attributes[conventions.AttributeHTTPHost] = "api.example.com" attributes[conventions.AttributeHTTPTarget] = "/users/junit" @@ -74,7 +75,7 @@ func TestClientSpanWithSchemeHostTargetAttributes(t *testing.T) { func TestClientSpanWithPeerAttributes(t *testing.T) { attributes := make(map[string]any) - attributes[conventions.AttributeHTTPMethod] = "GET" + attributes[conventions.AttributeHTTPMethod] = http.MethodGet attributes[conventions.AttributeHTTPScheme] = "http" attributes[conventions.AttributeNetPeerName] = "kb234.example.com" attributes[conventions.AttributeNetPeerPort] = 8080 @@ -99,7 +100,7 @@ func TestClientSpanWithPeerAttributes(t *testing.T) { func TestClientSpanWithPeerAttributesStable(t *testing.T) { attributes := make(map[string]any) - attributes[AttributeHTTPRequestMethod] = "GET" + attributes[AttributeHTTPRequestMethod] = http.MethodGet attributes[AttributeURLScheme] = "http" attributes[conventions.AttributeNetPeerName] = "kb234.example.com" attributes[conventions.AttributeNetPeerPort] = 8080 @@ -153,7 +154,7 @@ func TestClientSpanWithHttpPeerAttributesStable(t *testing.T) { func TestClientSpanWithPeerIp4Attributes(t *testing.T) { attributes := make(map[string]any) - attributes[conventions.AttributeHTTPMethod] = "GET" + attributes[conventions.AttributeHTTPMethod] = http.MethodGet attributes[conventions.AttributeHTTPScheme] = "http" attributes[conventions.AttributeNetPeerIP] = "10.8.17.36" attributes[conventions.AttributeNetPeerPort] = "8080" @@ -172,7 +173,7 @@ func TestClientSpanWithPeerIp4Attributes(t *testing.T) { func TestClientSpanWithPeerIp6Attributes(t *testing.T) { attributes := make(map[string]any) - attributes[conventions.AttributeHTTPMethod] = "GET" + attributes[conventions.AttributeHTTPMethod] = http.MethodGet attributes[conventions.AttributeHTTPScheme] = "https" attributes[conventions.AttributeNetPeerIP] = "2001:db8:85a3::8a2e:370:7334" attributes[conventions.AttributeNetPeerPort] = "443" @@ -191,7 +192,7 @@ func TestClientSpanWithPeerIp6Attributes(t *testing.T) { func TestServerSpanWithURLAttribute(t *testing.T) { attributes := make(map[string]any) - attributes[conventions.AttributeHTTPMethod] = "GET" + attributes[conventions.AttributeHTTPMethod] = http.MethodGet attributes[conventions.AttributeHTTPURL] = "https://api.example.com/users/junit" attributes[conventions.AttributeHTTPClientIP] = "192.168.15.32" attributes[conventions.AttributeHTTPUserAgent] = "PostmanRuntime/7.21.0" @@ -211,7 +212,7 @@ func TestServerSpanWithURLAttribute(t *testing.T) { func TestServerSpanWithURLAttributeStable(t *testing.T) { attributes := make(map[string]any) - attributes[AttributeHTTPRequestMethod] = "GET" + attributes[AttributeHTTPRequestMethod] = http.MethodGet attributes[AttributeURLFull] = "https://api.example.com/users/junit" attributes[AttributeClientAddress] = "192.168.15.32" attributes[AttributeUserAgentOriginal] = "PostmanRuntime/7.21.0" @@ -231,7 +232,7 @@ func TestServerSpanWithURLAttributeStable(t *testing.T) { func TestServerSpanWithSchemeHostTargetAttributes(t *testing.T) { attributes := make(map[string]any) - attributes[conventions.AttributeHTTPMethod] = "GET" + attributes[conventions.AttributeHTTPMethod] = http.MethodGet attributes[conventions.AttributeHTTPScheme] = "https" attributes[conventions.AttributeHTTPHost] = "api.example.com" attributes[conventions.AttributeHTTPTarget] = "/users/junit" @@ -252,7 +253,7 @@ func TestServerSpanWithSchemeHostTargetAttributes(t *testing.T) { func TestServerSpanWithSchemeHostTargetAttributesStable(t *testing.T) { attributes := make(map[string]any) - attributes[AttributeHTTPRequestMethod] = "GET" + attributes[AttributeHTTPRequestMethod] = http.MethodGet attributes[AttributeURLScheme] = "https" attributes[AttributeServerAddress] = "api.example.com" attributes[AttributeURLPath] = "/users/junit" @@ -273,7 +274,7 @@ func TestServerSpanWithSchemeHostTargetAttributesStable(t *testing.T) { func TestServerSpanWithSchemeServernamePortTargetAttributes(t *testing.T) { attributes := make(map[string]any) - attributes[conventions.AttributeHTTPMethod] = "GET" + attributes[conventions.AttributeHTTPMethod] = http.MethodGet attributes[conventions.AttributeHTTPScheme] = "https" attributes[conventions.AttributeHTTPServerName] = "api.example.com" attributes[conventions.AttributeNetHostPort] = 443 @@ -295,7 +296,7 @@ func TestServerSpanWithSchemeServernamePortTargetAttributes(t *testing.T) { func TestServerSpanWithSchemeServernamePortTargetAttributesStable(t *testing.T) { attributes := make(map[string]any) - attributes[AttributeHTTPRequestMethod] = "GET" + attributes[AttributeHTTPRequestMethod] = http.MethodGet attributes[AttributeURLScheme] = "https" attributes[AttributeServerAddress] = "api.example.com" attributes[AttributeServerPort] = 443 @@ -317,7 +318,7 @@ func TestServerSpanWithSchemeServernamePortTargetAttributesStable(t *testing.T) func TestServerSpanWithSchemeNamePortTargetAttributes(t *testing.T) { attributes := make(map[string]any) - attributes[conventions.AttributeHTTPMethod] = "GET" + attributes[conventions.AttributeHTTPMethod] = http.MethodGet attributes[conventions.AttributeHTTPScheme] = "http" attributes[conventions.AttributeHostName] = "kb234.example.com" attributes[conventions.AttributeNetHostPort] = 8080 @@ -341,7 +342,7 @@ func TestServerSpanWithSchemeNamePortTargetAttributes(t *testing.T) { func TestServerSpanWithSchemeNamePortTargetAttributesStable(t *testing.T) { attributes := make(map[string]any) - attributes[AttributeHTTPRequestMethod] = "GET" + attributes[AttributeHTTPRequestMethod] = http.MethodGet attributes[AttributeURLScheme] = "http" attributes[AttributeServerAddress] = "kb234.example.com" attributes[AttributeServerPort] = 8080 @@ -365,7 +366,7 @@ func TestServerSpanWithSchemeNamePortTargetAttributesStable(t *testing.T) { func TestSpanWithNotEnoughHTTPRequestURLAttributes(t *testing.T) { attributes := make(map[string]any) - attributes[conventions.AttributeHTTPMethod] = "GET" + attributes[conventions.AttributeHTTPMethod] = http.MethodGet attributes[conventions.AttributeHTTPScheme] = "http" attributes[conventions.AttributeHTTPClientIP] = "192.168.15.32" attributes[conventions.AttributeHTTPUserAgent] = "PostmanRuntime/7.21.0" @@ -381,7 +382,7 @@ func TestSpanWithNotEnoughHTTPRequestURLAttributes(t *testing.T) { assert.Nil(t, httpData.Request.URL) assert.Equal(t, "192.168.15.32", *httpData.Request.ClientIP) - assert.Equal(t, "GET", *httpData.Request.Method) + assert.Equal(t, http.MethodGet, *httpData.Request.Method) assert.Equal(t, "PostmanRuntime/7.21.0", *httpData.Request.UserAgent) contentLength := *httpData.Response.ContentLength.(*int64) assert.Equal(t, int64(12452), contentLength) @@ -391,7 +392,7 @@ func TestSpanWithNotEnoughHTTPRequestURLAttributes(t *testing.T) { func TestSpanWithNotEnoughHTTPRequestURLAttributesStable(t *testing.T) { attributes := make(map[string]any) - attributes[AttributeHTTPRequestMethod] = "GET" + attributes[AttributeHTTPRequestMethod] = http.MethodGet attributes[AttributeURLScheme] = "http" attributes[AttributeClientAddress] = "192.168.15.32" attributes[AttributeUserAgentOriginal] = "PostmanRuntime/7.21.0" @@ -406,7 +407,7 @@ func TestSpanWithNotEnoughHTTPRequestURLAttributesStable(t *testing.T) { assert.Nil(t, httpData.Request.URL) assert.Equal(t, "192.168.15.32", *httpData.Request.ClientIP) - assert.Equal(t, "GET", *httpData.Request.Method) + assert.Equal(t, http.MethodGet, *httpData.Request.Method) assert.Equal(t, "PostmanRuntime/7.21.0", *httpData.Request.UserAgent) contentLength := *httpData.Response.ContentLength.(*int64) assert.Equal(t, int64(12452), contentLength) @@ -416,8 +417,8 @@ func TestSpanWithNotEnoughHTTPRequestURLAttributesStable(t *testing.T) { func TestSpanWithNotEnoughHTTPRequestURLAttributesDuplicated(t *testing.T) { attributes := make(map[string]any) - attributes[conventions.AttributeHTTPMethod] = "GET" - attributes[AttributeHTTPRequestMethod] = "GET" + attributes[conventions.AttributeHTTPMethod] = http.MethodGet + attributes[AttributeHTTPRequestMethod] = http.MethodGet attributes[conventions.AttributeHTTPScheme] = "http" attributes[AttributeURLScheme] = "http" attributes[conventions.AttributeHTTPClientIP] = "192.168.15.32" @@ -439,7 +440,7 @@ func TestSpanWithNotEnoughHTTPRequestURLAttributesDuplicated(t *testing.T) { assert.Nil(t, httpData.Request.URL) assert.Equal(t, "192.168.15.32", *httpData.Request.ClientIP) - assert.Equal(t, "GET", *httpData.Request.Method) + assert.Equal(t, http.MethodGet, *httpData.Request.Method) assert.Equal(t, "PostmanRuntime/7.21.0", *httpData.Request.UserAgent) contentLength := *httpData.Response.ContentLength.(*int64) assert.Equal(t, int64(12452), contentLength) diff --git a/exporter/awsxrayexporter/internal/translator/segment_test.go b/exporter/awsxrayexporter/internal/translator/segment_test.go index 6351ad99922c..39e17fd972ef 100644 --- a/exporter/awsxrayexporter/internal/translator/segment_test.go +++ b/exporter/awsxrayexporter/internal/translator/segment_test.go @@ -7,6 +7,7 @@ import ( "crypto/rand" "encoding/binary" "fmt" + "net/http" "testing" "time" @@ -38,7 +39,7 @@ func TestClientSpanWithRpcAwsSdkClientAttributes(t *testing.T) { parentSpanID := newSegmentID() user := "testingT" attributes := make(map[string]any) - attributes[conventions.AttributeHTTPMethod] = "POST" + attributes[conventions.AttributeHTTPMethod] = http.MethodPost attributes[conventions.AttributeHTTPScheme] = "https" attributes[conventions.AttributeHTTPHost] = "dynamodb.us-east-1.amazonaws.com" attributes[conventions.AttributeHTTPTarget] = "/" @@ -71,7 +72,7 @@ func TestClientSpanWithLegacyAwsSdkClientAttributes(t *testing.T) { parentSpanID := newSegmentID() user := "testingT" attributes := make(map[string]any) - attributes[conventions.AttributeHTTPMethod] = "POST" + attributes[conventions.AttributeHTTPMethod] = http.MethodPost attributes[conventions.AttributeHTTPScheme] = "https" attributes[conventions.AttributeHTTPHost] = "dynamodb.us-east-1.amazonaws.com" attributes[conventions.AttributeHTTPTarget] = "/" @@ -103,7 +104,7 @@ func TestClientSpanWithPeerService(t *testing.T) { spanName := "AmazonDynamoDB.getItem" parentSpanID := newSegmentID() attributes := make(map[string]any) - attributes[conventions.AttributeHTTPMethod] = "POST" + attributes[conventions.AttributeHTTPMethod] = http.MethodPost attributes[conventions.AttributeHTTPScheme] = "https" attributes[conventions.AttributeHTTPHost] = "dynamodb.us-east-1.amazonaws.com" attributes[conventions.AttributeHTTPTarget] = "/" @@ -126,7 +127,7 @@ func TestServerSpanWithInternalServerError(t *testing.T) { userAgent := "PostmanRuntime/7.21.0" enduser := "go.tester@example.com" attributes := make(map[string]any) - attributes[conventions.AttributeHTTPMethod] = "POST" + attributes[conventions.AttributeHTTPMethod] = http.MethodPost attributes[conventions.AttributeHTTPURL] = "https://api.example.org/api/locations" attributes[conventions.AttributeHTTPTarget] = "/api/locations" attributes[conventions.AttributeHTTPStatusCode] = 500 @@ -153,7 +154,7 @@ func TestServerSpanWithThrottle(t *testing.T) { userAgent := "PostmanRuntime/7.21.0" enduser := "go.tester@example.com" attributes := make(map[string]any) - attributes[conventions.AttributeHTTPMethod] = "POST" + attributes[conventions.AttributeHTTPMethod] = http.MethodPost attributes[conventions.AttributeHTTPURL] = "https://api.example.org/api/locations" attributes[conventions.AttributeHTTPTarget] = "/api/locations" attributes[conventions.AttributeHTTPStatusCode] = 429 @@ -260,7 +261,7 @@ func TestClientSpanWithHttpHost(t *testing.T) { spanName := "GET /" parentSpanID := newSegmentID() attributes := make(map[string]any) - attributes[conventions.AttributeHTTPMethod] = "GET" + attributes[conventions.AttributeHTTPMethod] = http.MethodGet attributes[conventions.AttributeHTTPScheme] = "https" attributes[conventions.AttributeNetPeerIP] = "2607:f8b0:4000:80c::2004" attributes[conventions.AttributeNetPeerPort] = "9443" @@ -280,7 +281,7 @@ func TestClientSpanWithoutHttpHost(t *testing.T) { spanName := "GET /" parentSpanID := newSegmentID() attributes := make(map[string]any) - attributes[conventions.AttributeHTTPMethod] = "GET" + attributes[conventions.AttributeHTTPMethod] = http.MethodGet attributes[conventions.AttributeHTTPScheme] = "https" attributes[conventions.AttributeNetPeerIP] = "2607:f8b0:4000:80c::2004" attributes[conventions.AttributeNetPeerPort] = "9443" @@ -299,7 +300,7 @@ func TestClientSpanWithRpcHost(t *testing.T) { spanName := "GET /com.foo.AnimalService/GetCats" parentSpanID := newSegmentID() attributes := make(map[string]any) - attributes[conventions.AttributeHTTPMethod] = "GET" + attributes[conventions.AttributeHTTPMethod] = http.MethodGet attributes[conventions.AttributeHTTPScheme] = "https" attributes[conventions.AttributeNetPeerIP] = "2607:f8b0:4000:80c::2004" attributes[conventions.AttributeNetPeerPort] = "9443" @@ -318,7 +319,7 @@ func TestClientSpanWithRpcHost(t *testing.T) { func TestSpanWithInvalidTraceId(t *testing.T) { spanName := "platformapi.widgets.searchWidgets" attributes := make(map[string]any) - attributes[conventions.AttributeHTTPMethod] = "GET" + attributes[conventions.AttributeHTTPMethod] = http.MethodGet attributes[conventions.AttributeHTTPScheme] = "ipv6" attributes[conventions.AttributeNetPeerIP] = "2607:f8b0:4000:80c::2004" attributes[conventions.AttributeNetPeerPort] = "9443" @@ -353,7 +354,7 @@ func TestSpanWithInvalidTraceIdWithoutTimestampValidation(t *testing.T) { parentSpanID := newSegmentID() user := "testingT" attributes := make(map[string]any) - attributes[conventions.AttributeHTTPMethod] = "POST" + attributes[conventions.AttributeHTTPMethod] = http.MethodPost attributes[conventions.AttributeHTTPScheme] = "https" attributes[conventions.AttributeHTTPHost] = "payment.amazonaws.com" attributes[conventions.AttributeHTTPTarget] = "/" @@ -1069,7 +1070,7 @@ func TestClientSpanWithAwsRemoteServiceName(t *testing.T) { parentSpanID := newSegmentID() user := "testingT" attributes := make(map[string]any) - attributes[conventions.AttributeHTTPMethod] = "POST" + attributes[conventions.AttributeHTTPMethod] = http.MethodPost attributes[conventions.AttributeHTTPScheme] = "https" attributes[conventions.AttributeHTTPHost] = "payment.amazonaws.com" attributes[conventions.AttributeHTTPTarget] = "/" @@ -1098,7 +1099,7 @@ func TestAwsSdkSpanWithDeprecatedAwsRemoteServiceName(t *testing.T) { user := "testingT" attributes := make(map[string]any) attributes[conventions.AttributeRPCSystem] = "aws-api" - attributes[conventions.AttributeHTTPMethod] = "POST" + attributes[conventions.AttributeHTTPMethod] = http.MethodPost attributes[conventions.AttributeHTTPScheme] = "https" attributes[conventions.AttributeRPCService] = "DynamoDb" attributes[awsRemoteService] = "AWS.SDK.DynamoDb" @@ -1126,7 +1127,7 @@ func TestAwsSdkSpanWithAwsRemoteServiceName(t *testing.T) { user := "testingT" attributes := make(map[string]any) attributes[conventions.AttributeRPCSystem] = "aws-api" - attributes[conventions.AttributeHTTPMethod] = "POST" + attributes[conventions.AttributeHTTPMethod] = http.MethodPost attributes[conventions.AttributeHTTPScheme] = "https" attributes[conventions.AttributeRPCService] = "DynamoDb" attributes[awsRemoteService] = "AWS::DynamoDB" @@ -1153,7 +1154,7 @@ func TestProducerSpanWithAwsRemoteServiceName(t *testing.T) { parentSpanID := newSegmentID() user := "testingT" attributes := make(map[string]any) - attributes[conventions.AttributeHTTPMethod] = "POST" + attributes[conventions.AttributeHTTPMethod] = http.MethodPost attributes[conventions.AttributeHTTPScheme] = "https" attributes[conventions.AttributeHTTPHost] = "payment.amazonaws.com" attributes[conventions.AttributeHTTPTarget] = "/" @@ -1200,7 +1201,7 @@ func TestServerSpanWithAwsLocalServiceName(t *testing.T) { parentSpanID := newSegmentID() user := "testingT" attributes := make(map[string]any) - attributes[conventions.AttributeHTTPMethod] = "POST" + attributes[conventions.AttributeHTTPMethod] = http.MethodPost attributes[conventions.AttributeHTTPScheme] = "https" attributes[conventions.AttributeHTTPHost] = "payment.amazonaws.com" attributes[conventions.AttributeHTTPTarget] = "/" @@ -1233,7 +1234,7 @@ func validateLocalRootDependencySubsegment(t *testing.T, segment *awsxray.Segmen assert.Equal(t, parentID, *segment.ParentID) assert.Equal(t, expectedTraceID, *segment.TraceID) assert.NotNil(t, segment.HTTP) - assert.Equal(t, "POST", *segment.HTTP.Request.Method) + assert.Equal(t, http.MethodPost, *segment.HTTP.Request.Method) assert.Len(t, segment.Annotations, 2) assert.Nil(t, segment.Annotations[awsRemoteService]) assert.Nil(t, segment.Annotations[remoteTarget]) @@ -1292,7 +1293,7 @@ func validateLocalRootServiceSegment(t *testing.T, segment *awsxray.Segment, spa func getBasicAttributes() map[string]any { attributes := make(map[string]any) - attributes[conventions.AttributeHTTPMethod] = "POST" + attributes[conventions.AttributeHTTPMethod] = http.MethodPost attributes[conventions.AttributeMessagingOperation] = "receive" attributes["otel.resource.attributes"] = "service.name=myTest" @@ -1395,7 +1396,7 @@ func TestNonLocalRootConsumerProcess(t *testing.T) { assert.Len(t, segments[0].Links, 1) assert.Equal(t, expectedTraceID, *segments[0].TraceID) assert.NotNil(t, segments[0].HTTP) - assert.Equal(t, "POST", *segments[0].HTTP.Request.Method) + assert.Equal(t, http.MethodPost, *segments[0].HTTP.Request.Method) assert.Len(t, segments[0].Annotations, 1) assert.Equal(t, "myAnnotationValue", segments[0].Annotations["myAnnotationKey"]) assert.Len(t, segments[0].Metadata["default"], 7) @@ -1476,7 +1477,7 @@ func TestLocalRootClientAwsServiceMetrics(t *testing.T) { attributes := getBasicAttributes() attributes[awsSpanKind] = "LOCAL_ROOT" attributes[conventions.AttributeRPCSystem] = "aws-api" - attributes[conventions.AttributeHTTPMethod] = "POST" + attributes[conventions.AttributeHTTPMethod] = http.MethodPost attributes[conventions.AttributeHTTPScheme] = "https" attributes[conventions.AttributeRPCService] = "SQS" attributes[awsRemoteService] = "AWS.SDK.SQS" @@ -1538,7 +1539,7 @@ func validateLocalRootWithoutDependency(t *testing.T, segment *awsxray.Segment, assert.Equal(t, span.ParentSpanID().String(), *segment.ParentID) assert.Len(t, segment.Links, 1) assert.Equal(t, expectedTraceID, *segment.TraceID) - assert.Equal(t, "POST", *segment.HTTP.Request.Method) + assert.Equal(t, http.MethodPost, *segment.HTTP.Request.Method) assert.Len(t, segment.Annotations, 2) assert.Equal(t, "myRemoteService", segment.Annotations["aws_remote_service"]) assert.Equal(t, "myAnnotationValue", segment.Annotations["myAnnotationKey"]) diff --git a/exporter/awsxrayexporter/internal/translator/writer_pool_test.go b/exporter/awsxrayexporter/internal/translator/writer_pool_test.go index a5c07b52ff7e..baea9cff3b08 100644 --- a/exporter/awsxrayexporter/internal/translator/writer_pool_test.go +++ b/exporter/awsxrayexporter/internal/translator/writer_pool_test.go @@ -6,6 +6,7 @@ package translator import ( "bytes" "encoding/json" + "net/http" "testing" "github.com/stretchr/testify/assert" @@ -66,7 +67,7 @@ func BenchmarkWithPool(b *testing.B) { func constructWriterPoolSpan() ptrace.Span { attributes := make(map[string]any) - attributes[conventions.AttributeHTTPMethod] = "GET" + attributes[conventions.AttributeHTTPMethod] = http.MethodGet attributes[conventions.AttributeHTTPURL] = "https://api.example.com/users/junit" attributes[conventions.AttributeHTTPClientIP] = "192.168.15.32" attributes[conventions.AttributeHTTPStatusCode] = 200 diff --git a/exporter/azuremonitorexporter/trace_to_envelope_test.go b/exporter/azuremonitorexporter/trace_to_envelope_test.go index e8e93b6e179c..441919546f64 100644 --- a/exporter/azuremonitorexporter/trace_to_envelope_test.go +++ b/exporter/azuremonitorexporter/trace_to_envelope_test.go @@ -5,6 +5,7 @@ package azuremonitorexporter import ( "fmt" + "net/http" "strconv" "testing" "time" @@ -29,7 +30,7 @@ const ( defaultServiceInstance = "112345" defaultScopeName = "myinstrumentationlib" defaultScopeVersion = "1.0" - defaultHTTPMethod = "GET" + defaultHTTPMethod = http.MethodGet defaultHTTPServerSpanName = "/bar" defaultHTTPClientSpanName = defaultHTTPMethod defaultHTTPStatusCode = 200 diff --git a/exporter/sentryexporter/sentry_exporter_test.go b/exporter/sentryexporter/sentry_exporter_test.go index e0ac8efbaeeb..032426758d0d 100644 --- a/exporter/sentryexporter/sentry_exporter_test.go +++ b/exporter/sentryexporter/sentry_exporter_test.go @@ -371,7 +371,7 @@ func TestGenerateSpanDescriptors(t *testing.T) { testName: "http-client", name: "/api/users/{user_id}", attrs: map[string]any{ - conventions.AttributeHTTPMethod: "GET", + conventions.AttributeHTTPMethod: http.MethodGet, }, spanKind: ptrace.SpanKindClient, op: "http.client", diff --git a/extension/httpforwarderextension/extension_test.go b/extension/httpforwarderextension/extension_test.go index f5acd26cbe30..fb2106413a32 100644 --- a/extension/httpforwarderextension/extension_test.go +++ b/extension/httpforwarderextension/extension_test.go @@ -57,7 +57,7 @@ func TestExtension(t *testing.T) { "header": "value", }, clientRequestArgs: clientRequestArgs{ - method: "GET", + method: http.MethodGet, url: fmt.Sprintf("http://%s/api/dosomething", listenAt), headers: map[string]string{ "client_header": "val1", @@ -83,7 +83,7 @@ func TestExtension(t *testing.T) { "header": "value", }, clientRequestArgs: clientRequestArgs{ - method: "PUT", + method: http.MethodPut, url: fmt.Sprintf("http://%s/api/dosomething", listenAt), }, }, @@ -123,7 +123,7 @@ func TestExtension(t *testing.T) { expectedBackendResponseBody: []byte("\n"), requestErrorAtForwarder: true, clientRequestArgs: clientRequestArgs{ - method: "GET", + method: http.MethodGet, url: fmt.Sprintf("http://%s/api/dosomething", listenAt), }, }, diff --git a/internal/aws/cwlogs/cwlog_client_test.go b/internal/aws/cwlogs/cwlog_client_test.go index b3d430c2e5c9..f44c3d0cfd13 100644 --- a/internal/aws/cwlogs/cwlog_client_test.go +++ b/internal/aws/cwlogs/cwlog_client_test.go @@ -6,6 +6,7 @@ package cwlogs import ( "errors" "fmt" + "net/http" "testing" "github.com/aws/aws-sdk-go/aws" @@ -652,7 +653,7 @@ func TestUserAgent(t *testing.T) { logClient := cwlog.svc.(*cloudwatchlogs.CloudWatchLogs) req := request.New(aws.Config{}, metadata.ClientInfo{}, logClient.Handlers, nil, &request.Operation{ - HTTPMethod: "GET", + HTTPMethod: http.MethodGet, HTTPPath: "/", }, nil, nil) diff --git a/internal/aws/ecsutil/client_test.go b/internal/aws/ecsutil/client_test.go index 2d9c92fa78f2..a015de4ee92d 100644 --- a/internal/aws/ecsutil/client_test.go +++ b/internal/aws/ecsutil/client_test.go @@ -32,7 +32,7 @@ func TestClient(t *testing.T) { require.Equal(t, baseURL.String()+"/stats", tr.url) require.Len(t, tr.header, 1) require.Equal(t, "application/json", tr.header["Content-Type"][0]) - require.Equal(t, "GET", tr.method) + require.Equal(t, http.MethodGet, tr.method) } func TestNewClientProvider(t *testing.T) { diff --git a/internal/aws/xray/tracesegment_test.go b/internal/aws/xray/tracesegment_test.go index a25b538eae80..c5daf8156f28 100644 --- a/internal/aws/xray/tracesegment_test.go +++ b/internal/aws/xray/tracesegment_test.go @@ -6,6 +6,7 @@ package awsxray import ( "encoding/json" "fmt" + "net/http" "os" "path/filepath" "testing" @@ -501,7 +502,7 @@ var rawExpectedSegmentForInstrumentedServer = Segment{ EndTime: aws.Float64(1596648396.6401389), HTTP: &HTTPData{ Request: &RequestData{ - Method: String("GET"), + Method: String(http.MethodGet), URL: String("http://localhost:8000/"), ClientIP: String("127.0.0.1"), UserAgent: String("Go-http-client/1.1"), diff --git a/internal/aws/xray/xray_client_test.go b/internal/aws/xray/xray_client_test.go index a0b5a7c648f7..e51af276d0a2 100644 --- a/internal/aws/xray/xray_client_test.go +++ b/internal/aws/xray/xray_client_test.go @@ -4,6 +4,7 @@ package awsxray import ( + "net/http" "testing" "github.com/aws/aws-sdk-go/aws" @@ -30,7 +31,7 @@ func TestUserAgent(t *testing.T) { x := xray.xRay req := request.New(aws.Config{}, metadata.ClientInfo{}, x.Handlers, nil, &request.Operation{ - HTTPMethod: "GET", + HTTPMethod: http.MethodGet, HTTPPath: "/", }, nil, nil) diff --git a/internal/coreinternal/goldendataset/span_generator.go b/internal/coreinternal/goldendataset/span_generator.go index ce2d703713b1..71720b154443 100644 --- a/internal/coreinternal/goldendataset/span_generator.go +++ b/internal/coreinternal/goldendataset/span_generator.go @@ -6,6 +6,7 @@ package goldendataset // import "github.com/open-telemetry/opentelemetry-collect import ( "fmt" "io" + "net/http" "time" "go.opentelemetry.io/collector/pdata/pcommon" @@ -228,7 +229,7 @@ func appendFaaSDatasourceAttributes(attrMap pcommon.Map) { func appendFaaSHTTPAttributes(includeStatus bool, attrMap pcommon.Map) { attrMap.PutStr(conventions.AttributeFaaSTrigger, conventions.AttributeFaaSTriggerHTTP) - attrMap.PutStr(conventions.AttributeHTTPMethod, "POST") + attrMap.PutStr(conventions.AttributeHTTPMethod, http.MethodPost) attrMap.PutStr(conventions.AttributeHTTPScheme, "https") attrMap.PutStr(conventions.AttributeHTTPHost, "api.opentelemetry.io") attrMap.PutStr(conventions.AttributeHTTPTarget, "/blog/posts") @@ -266,7 +267,7 @@ func appendFaaSOtherAttributes(attrMap pcommon.Map) { } func appendHTTPClientAttributes(includeStatus bool, attrMap pcommon.Map) { - attrMap.PutStr(conventions.AttributeHTTPMethod, "GET") + attrMap.PutStr(conventions.AttributeHTTPMethod, http.MethodGet) attrMap.PutStr(conventions.AttributeHTTPURL, "https://opentelemetry.io/registry/") if includeStatus { attrMap.PutInt(conventions.AttributeHTTPStatusCode, 200) @@ -276,7 +277,7 @@ func appendHTTPClientAttributes(includeStatus bool, attrMap pcommon.Map) { } func appendHTTPServerAttributes(includeStatus bool, attrMap pcommon.Map) { - attrMap.PutStr(conventions.AttributeHTTPMethod, "POST") + attrMap.PutStr(conventions.AttributeHTTPMethod, http.MethodPost) attrMap.PutStr(conventions.AttributeHTTPScheme, "https") attrMap.PutStr(conventions.AttributeHTTPServerName, "api22.opentelemetry.io") attrMap.PutInt(conventions.AttributeNetHostPort, 443) @@ -329,7 +330,7 @@ func appendInternalAttributes(attrMap pcommon.Map) { } func appendMaxCountAttributes(includeStatus bool, attrMap pcommon.Map) { - attrMap.PutStr(conventions.AttributeHTTPMethod, "POST") + attrMap.PutStr(conventions.AttributeHTTPMethod, http.MethodPost) attrMap.PutStr(conventions.AttributeHTTPScheme, "https") attrMap.PutStr(conventions.AttributeHTTPHost, "api.opentelemetry.io") attrMap.PutStr(conventions.AttributeNetHostName, "api22.opentelemetry.io") diff --git a/internal/kubelet/client_test.go b/internal/kubelet/client_test.go index a177e3404361..952de83db29b 100644 --- a/internal/kubelet/client_test.go +++ b/internal/kubelet/client_test.go @@ -49,7 +49,7 @@ func TestClient(t *testing.T) { require.Equal(t, baseURL+"/foo", tr.url) require.Len(t, tr.header, 1) require.Equal(t, "application/json", tr.header["Content-Type"][0]) - require.Equal(t, "GET", tr.method) + require.Equal(t, http.MethodGet, tr.method) } func TestNewTLSClientProvider(t *testing.T) { diff --git a/pkg/ottl/e2e/e2e_test.go b/pkg/ottl/e2e/e2e_test.go index d1e7b0828fd7..bb1dd43b5282 100644 --- a/pkg/ottl/e2e/e2e_test.go +++ b/pkg/ottl/e2e/e2e_test.go @@ -5,6 +5,7 @@ package e2e import ( "context" + "net/http" "testing" "time" @@ -349,7 +350,7 @@ func Test_e2e_converters(t *testing.T) { { statement: `set(attributes["test"], ConvertCase(attributes["http.method"], "upper"))`, want: func(tCtx ottllog.TransformContext) { - tCtx.GetLogRecord().Attributes().PutStr("test", "GET") + tCtx.GetLogRecord().Attributes().PutStr("test", http.MethodGet) }, }, { diff --git a/pkg/translator/azure/resourcelogs_to_logs_test.go b/pkg/translator/azure/resourcelogs_to_logs_test.go index 60e178e63f3f..6a02dd187793 100644 --- a/pkg/translator/azure/resourcelogs_to_logs_test.go +++ b/pkg/translator/azure/resourcelogs_to_logs_test.go @@ -5,6 +5,7 @@ package azure // import "github.com/open-telemetry/opentelemetry-collector-contr import ( "encoding/json" + "net/http" "os" "path/filepath" "testing" @@ -146,7 +147,7 @@ var badLevelLogRecord = func() plog.LogRecord { lr.Attributes().PutStr(conventions.AttributeCloudProvider, conventions.AttributeCloudProviderAzure) m := lr.Attributes().PutEmptyMap(azureProperties) - m.PutStr("method", "GET") + m.PutStr("method", http.MethodGet) m.PutStr("url", "https://api.azure-api.net/sessions") m.PutDouble("backendResponseCode", 200) m.PutDouble("responseCode", 200) @@ -162,7 +163,7 @@ var badLevelLogRecord = func() plog.LogRecord { m.PutStr("backendProtocol", "HTTP/1.1") m.PutStr("apiRevision", "1") m.PutStr("clientTlsVersion", "1.2") - m.PutStr("backendMethod", "GET") + m.PutStr("backendMethod", http.MethodGet) m.PutStr("backendUrl", "https://api.azurewebsites.net/sessions") return lr }() @@ -181,7 +182,7 @@ var badTimeLogRecord = func() plog.LogRecord { m.PutStr("instanceId", "appgw_2") m.PutStr("clientIP", "185.42.129.24") m.PutDouble("clientPort", 45057) - m.PutStr("httpMethod", "GET") + m.PutStr("httpMethod", http.MethodGet) m.PutStr("originalRequestUriWithArgs", "/") m.PutStr("requestUri", "/") m.PutStr("requestQuery", "") diff --git a/pkg/translator/azurelogs/resourcelogs_to_logs_test.go b/pkg/translator/azurelogs/resourcelogs_to_logs_test.go index 81cfdaa0d42d..4f4f17dbc0a2 100644 --- a/pkg/translator/azurelogs/resourcelogs_to_logs_test.go +++ b/pkg/translator/azurelogs/resourcelogs_to_logs_test.go @@ -5,6 +5,7 @@ package azurelogs // import "github.com/open-telemetry/opentelemetry-collector-c import ( "encoding/json" + "net/http" "os" "path/filepath" "testing" @@ -168,7 +169,7 @@ var badLevelLogRecord = func() plog.LogRecord { body.PutStr(conventions.AttributeCloudRegion, "West US") properties := body.PutEmptyMap(azureProperties) - properties.PutStr("method", "GET") + properties.PutStr("method", http.MethodGet) properties.PutStr("url", "https://api.azure-api.net/sessions") properties.PutDouble("backendResponseCode", 200) properties.PutDouble("responseCode", 200) @@ -184,7 +185,7 @@ var badLevelLogRecord = func() plog.LogRecord { properties.PutStr("backendProtocol", "HTTP/1.1") properties.PutStr("apiRevision", "1") properties.PutStr("clientTlsVersion", "1.2") - properties.PutStr("backendMethod", "GET") + properties.PutStr("backendMethod", http.MethodGet) properties.PutStr("backendUrl", "https://api.azurewebsites.net/sessions") return lr }() @@ -207,7 +208,7 @@ var badTimeLogRecord = func() plog.LogRecord { properties.PutStr("instanceId", "appgw_2") properties.PutStr("clientIP", "185.42.129.24") properties.PutDouble("clientPort", 45057) - properties.PutStr("httpMethod", "GET") + properties.PutStr("httpMethod", http.MethodGet) properties.PutStr("originalRequestUriWithArgs", "/") properties.PutStr("requestUri", "/") properties.PutStr("requestQuery", "") @@ -578,7 +579,7 @@ func TestAzureCdnAccessLog(t *testing.T) { record := logs.ResourceLogs().At(0).ScopeLogs().At(0).LogRecords().At(0).Body().Map().AsRaw() - assert.Equal(t, "GET", record["http.request.method"]) + assert.Equal(t, http.MethodGet, record["http.request.method"]) assert.Equal(t, "1.1.0.0", record["network.protocol.version"]) assert.Equal(t, "TRACKING_REFERENCE", record["az.service_request_id"]) assert.Equal(t, "https://test.net/", record["url.full"]) @@ -600,7 +601,7 @@ func TestFrontDoorAccessLog(t *testing.T) { record := logs.ResourceLogs().At(0).ScopeLogs().At(0).LogRecords().At(0).Body().Map().AsRaw() - assert.Equal(t, "GET", record["http.request.method"]) + assert.Equal(t, http.MethodGet, record["http.request.method"]) assert.Equal(t, "1.1.0.0", record["network.protocol.version"]) assert.Equal(t, "TRACKING_REFERENCE", record["az.service_request_id"]) assert.Equal(t, "https://test.net/", record["url.full"]) @@ -628,7 +629,7 @@ func TestFrontDoorHealthProbeLog(t *testing.T) { record := logs.ResourceLogs().At(0).ScopeLogs().At(0).LogRecords().At(0).Body().Map().AsRaw() - assert.Equal(t, "GET", record["http.request.method"]) + assert.Equal(t, http.MethodGet, record["http.request.method"]) assert.Equal(t, int64(200), record["http.response.status_code"]) assert.Equal(t, "https://probe.net/health", record["url.full"]) assert.Equal(t, "42.42.42.42", record["server.address"]) @@ -701,7 +702,7 @@ func TestAppServiceHTTPLog(t *testing.T) { assert.Equal(t, int64(80), record["server.port"]) assert.Equal(t, "/api/test/", record["url.path"]) assert.Equal(t, "foo=42", record["url.query"]) - assert.Equal(t, "GET", record["http.request.method"]) + assert.Equal(t, http.MethodGet, record["http.request.method"]) assert.Equal(t, 0.42, record["http.server.request.duration"]) assert.Equal(t, int64(200), record["http.response.status_code"]) assert.Equal(t, int64(4242), record["http.request.body.size"]) diff --git a/receiver/collectdreceiver/receiver_test.go b/receiver/collectdreceiver/receiver_test.go index 20c2d402d3fc..f9ae893824cc 100644 --- a/receiver/collectdreceiver/receiver_test.go +++ b/receiver/collectdreceiver/receiver_test.go @@ -98,7 +98,7 @@ func TestCollectDServer(t *testing.T) { testInvalidHTTPMethodCase := testCase{ Name: "invalid-http-method", - HTTPMethod: "GET", + HTTPMethod: http.MethodGet, RequestBody: `invalid-body`, ResponseCode: 400, WantData: []pmetric.Metrics{}, @@ -106,7 +106,7 @@ func TestCollectDServer(t *testing.T) { testValidRequestBodyCase := testCase{ Name: "valid-request-body", - HTTPMethod: "POST", + HTTPMethod: http.MethodPost, QueryParams: "dap_attr1=attr1val", RequestBody: `[ { @@ -134,7 +134,7 @@ func TestCollectDServer(t *testing.T) { testInValidRequestBodyCase := testCase{ Name: "invalid-request-body", - HTTPMethod: "POST", + HTTPMethod: http.MethodPost, RequestBody: `invalid-body`, ResponseCode: 400, WantData: []pmetric.Metrics{}, diff --git a/receiver/opencensusreceiver/opencensus_test.go b/receiver/opencensusreceiver/opencensus_test.go index 9daba3a64d20..003df32562c2 100644 --- a/receiver/opencensusreceiver/opencensus_test.go +++ b/receiver/opencensusreceiver/opencensus_test.go @@ -207,7 +207,7 @@ func verifyCorsResp(t *testing.T, url string, origin string, wantStatus int, wan req, err := http.NewRequest(http.MethodOptions, url, nil) require.NoError(t, err, "Error creating trace OPTIONS request: %v", err) req.Header.Set("Origin", origin) - req.Header.Set("Access-Control-Request-Method", "POST") + req.Header.Set("Access-Control-Request-Method", http.MethodPost) client := &http.Client{} defer client.CloseIdleConnections() @@ -228,7 +228,7 @@ func verifyCorsResp(t *testing.T, url string, origin string, wantStatus int, wan wantAllowMethods := "" if wantAllowed { wantAllowOrigin = origin - wantAllowMethods = "POST" + wantAllowMethods = http.MethodPost } assert.Equal(t, wantAllowOrigin, gotAllowOrigin) diff --git a/receiver/skywalkingreceiver/skywalking_receiver_test.go b/receiver/skywalkingreceiver/skywalking_receiver_test.go index 39e6b11f754f..221940950ae4 100644 --- a/receiver/skywalkingreceiver/skywalking_receiver_test.go +++ b/receiver/skywalkingreceiver/skywalking_receiver_test.go @@ -47,7 +47,7 @@ var traceJSON = []byte(` "startTime": 1588664577013, "tags": [{ "key": "http.method", - "value": "GET" + "value": http.MethodGet }, { "key": "http.params", "value": "http://localhost/ingress" diff --git a/receiver/splunkenterprisereceiver/client_test.go b/receiver/splunkenterprisereceiver/client_test.go index 28a72356d197..f2008288bea9 100644 --- a/receiver/splunkenterprisereceiver/client_test.go +++ b/receiver/splunkenterprisereceiver/client_test.go @@ -99,7 +99,7 @@ func TestClientCreateRequest(t *testing.T) { }, client: client, expected: func() *http.Request { - method := "POST" + method := http.MethodPost path := "/services/search/jobs/" testEndpoint, _ := url.Parse("https://localhost:8089") url, _ := url.JoinPath(testEndpoint.String(), path) @@ -116,7 +116,7 @@ func TestClientCreateRequest(t *testing.T) { }, client: client, expected: func() *http.Request { - method := "GET" + method := http.MethodGet path := fmt.Sprintf("/services/search/jobs/%s/results", testJobID) testEndpoint, _ := url.Parse("https://localhost:8089") url, _ := url.JoinPath(testEndpoint.String(), path) diff --git a/receiver/splunkhecreceiver/receiver.go b/receiver/splunkhecreceiver/receiver.go index 4056b6823682..2bf5458cc7f7 100644 --- a/receiver/splunkhecreceiver/receiver.go +++ b/receiver/splunkhecreceiver/receiver.go @@ -156,7 +156,7 @@ func (r *splunkReceiver) Start(ctx context.Context, host component.Host) error { } mx.NewRoute().Path(r.config.HealthPath).HandlerFunc(r.handleHealthReq) - mx.NewRoute().Path(r.config.HealthPath + "/1.0").HandlerFunc(r.handleHealthReq).Methods("GET") + mx.NewRoute().Path(r.config.HealthPath + "/1.0").HandlerFunc(r.handleHealthReq).Methods(http.MethodGet) if r.logsConsumer != nil { mx.NewRoute().Path(r.config.RawPath).HandlerFunc(r.handleRawReq) }