Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[chore]: usestdlibvars: replace http methods #36407

Merged
merged 2 commits into from
Nov 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion connector/exceptionsconnector/factory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package exceptionsconnector

import (
"context"
"net/http"
"testing"

"github.com/stretchr/testify/assert"
Expand All @@ -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
Expand Down
3 changes: 2 additions & 1 deletion connector/spanmetricsconnector/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package spanmetricsconnector

import (
"errors"
"net/http"
"path/filepath"
"testing"
"time"
Expand All @@ -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 {
Expand Down
3 changes: 2 additions & 1 deletion connector/spanmetricsconnector/factory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package spanmetricsconnector

import (
"context"
"net/http"
"testing"
"time"

Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package alibabacloudlogserviceexporter
import (
"encoding/json"
"fmt"
"net/http"
"os"
"sort"
"testing"
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions exporter/awsxrayexporter/awsxray_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"crypto/rand"
"encoding/binary"
"fmt"
"net/http"
"testing"
"time"

Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand Down
19 changes: 10 additions & 9 deletions exporter/awsxrayexporter/internal/translator/cause_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
package translator

import (
"net/http"
"strings"
"testing"
"time"
Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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

Expand All @@ -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

Expand All @@ -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

Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
45 changes: 23 additions & 22 deletions exporter/awsxrayexporter/internal/translator/http_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
package translator

import (
"net/http"
"testing"
"time"

Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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"
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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"
Expand All @@ -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"
Expand All @@ -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"
Expand All @@ -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"
Expand All @@ -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"
Expand All @@ -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"
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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"
Expand All @@ -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)
Expand All @@ -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"
Expand All @@ -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)
Expand All @@ -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"
Expand All @@ -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)
Expand Down
Loading