Skip to content

Commit

Permalink
fix tracing
Browse files Browse the repository at this point in the history
  • Loading branch information
golangisfun123 committed Oct 15, 2024
1 parent 54eacfa commit 151d6cd
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 6 deletions.
2 changes: 1 addition & 1 deletion services/omnirpc/http/capture_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ func TestCaptureClient(t *testing.T) {
testURL := gofakeit.URL()

testReq := client.NewRequest()
testReq.SetBody(testBody)
testReq.SetContext(testCtx)
testReq.SetBody(testBody)
testReq.SetHeaderBytes(byteHeaderK, byteHeaderV)
testReq.SetHeader(strHeaderK, strHeaderV)
testReq.SetRequestURI(testURL)
Expand Down
2 changes: 1 addition & 1 deletion services/omnirpc/http/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ func (c *HTTPSuite) TestClient() {
}))

req := client.NewRequest()
req.SetContext(c.GetTestContext())
req.SetRequestURI(svr.URL)
req.SetBody(mockBody)
req.SetContext(c.GetTestContext())
for key, val := range headers {
if gofakeit.Bool() {
req.SetHeader(key, val)
Expand Down
8 changes: 4 additions & 4 deletions services/omnirpc/http/resty.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ import (
// RestyClient is a resty client for making requests to the http client.
type RestyClient struct {
client *resty.Client
metrics metrics.Handler
handler metrics.Handler
}

// NewRestyClient creates a resty client.
// while much slower than fasthttp, this client requests context cancellation.
func NewRestyClient(metrics metrics.Handler) Client {
return &RestyClient{client: resty.New(), metrics: metrics}
func NewRestyClient(handler metrics.Handler) Client {
return &RestyClient{client: resty.New(), handler: handler}
}

type restyRequest struct {
Expand All @@ -33,7 +33,7 @@ type restyRequest struct {
func (r RestyClient) NewRequest() Request {
return &restyRequest{
Request: r.client.R(),
handler: r.metrics,
handler: r.handler,
}
}

Expand Down
22 changes: 22 additions & 0 deletions services/omnirpc/http/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,21 @@ import (

"github.com/brianvoe/gofakeit/v6"
"github.com/stretchr/testify/suite"
"github.com/synapsecns/sanguine/core"
"github.com/synapsecns/sanguine/core/config"
"github.com/synapsecns/sanguine/core/metrics"
"github.com/synapsecns/sanguine/core/metrics/localmetrics"
"github.com/synapsecns/sanguine/core/testsuite"
"github.com/synapsecns/sanguine/services/omnirpc/http"
)

var buildInfo = config.NewBuildInfo(config.DefaultVersion, config.DefaultCommit, "omnirpc", config.DefaultDate)

// clientSuite defines the basic test suite.
type HTTPSuite struct {
*testsuite.TestSuite
clients []http.Client
metrics metrics.Handler
}

// NewTestSuite creates a new test suite and performs some basic checks afterward.
Expand All @@ -33,6 +39,22 @@ func (c *HTTPSuite) SetupTest() {
}
}

func (c *HTTPSuite) SetupSuite() {
c.TestSuite.SetupSuite()
// don't use metrics on ci for integration tests
isCI := core.GetEnvBool("CI", false)
useMetrics := !isCI
metricsHandler := metrics.Null

if useMetrics {
localmetrics.SetupTestJaeger(c.GetSuiteContext(), c.T())
metricsHandler = metrics.Jaeger
}
var err error
c.metrics, err = metrics.NewByType(c.GetSuiteContext(), buildInfo, metricsHandler)
c.Require().NoError(err)
}

func TestCommonSuite(t *testing.T) {
suite.Run(t, NewClientSuite(t))
}
Expand Down

0 comments on commit 151d6cd

Please sign in to comment.