Skip to content

Commit

Permalink
Merge branch 'rc/v1.7.0' into integrate-cacheless-core
Browse files Browse the repository at this point in the history
# Conflicts:
#	go.mod
#	go.sum
  • Loading branch information
iulianpascalau committed Nov 29, 2023
2 parents 892915c + 2114730 commit 7a00f24
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 14 deletions.
8 changes: 7 additions & 1 deletion client/transport/transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,13 @@ func (m *metricsTransport) RoundTrip(req *http.Request) (*http.Response, error)

startTime := time.Now()
size := req.ContentLength

var statusCode int
resp, err := m.transport.RoundTrip(req)
if err == nil {
statusCode = resp.StatusCode
}

duration := time.Since(startTime)

valueFromCtx := req.Context().Value(request.ContextKey)
Expand All @@ -50,7 +56,7 @@ func (m *metricsTransport) RoundTrip(req *http.Request) (*http.Response, error)
topic := fmt.Sprintf("%s", valueFromCtx)

m.statusMetrics.AddIndexingData(metrics.ArgsAddIndexingData{
StatusCode: resp.StatusCode,
StatusCode: statusCode,
GotError: err != nil,
MessageLen: uint64(size),
Topic: topic,
Expand Down
25 changes: 25 additions & 0 deletions client/transport/transport_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package transport
import (
"bytes"
"context"
"errors"
"net/http"
"testing"

Expand Down Expand Up @@ -34,6 +35,30 @@ func TestMetricsTransport_NilRequest(t *testing.T) {
require.Equal(t, errNilRequest, err)
}

func TestMetricsTransport_RoundTripNilResponseShouldWork(t *testing.T) {
t.Parallel()

metricsHandler := metrics.NewStatusMetrics()
transportHandler, _ := NewMetricsTransport(metricsHandler)

testErr := errors.New("test")
transportHandler.transport = &mock.TransportMock{
Response: nil,
Err: testErr,
}

testTopic := "test"
contextWithValue := context.WithValue(context.Background(), request.ContextKey, testTopic)
req, _ := http.NewRequestWithContext(contextWithValue, http.MethodGet, "dummy", bytes.NewBuffer([]byte("test")))

_, _ = transportHandler.RoundTrip(req)

metricsMap := metricsHandler.GetMetrics()
require.Equal(t, uint64(1), metricsMap[testTopic].OperationsCount)
require.Equal(t, uint64(1), metricsMap[testTopic].TotalErrorsCount)
require.Equal(t, uint64(4), metricsMap[testTopic].TotalData)
}

func TestMetricsTransport_RoundTrip(t *testing.T) {
t.Parallel()

Expand Down
8 changes: 4 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ require (
github.com/elastic/go-elasticsearch/v7 v7.12.0
github.com/gin-contrib/cors v1.4.0
github.com/gin-gonic/gin v1.9.1
github.com/multiversx/mx-chain-communication-go v1.0.9-0.20231025073956-fbcc7f2e3af6
github.com/multiversx/mx-chain-core-go v1.2.17-0.20231025072115-f3530bc1cab1
github.com/multiversx/mx-chain-logger-go v1.0.14-0.20231025072404-d54164fbae96
github.com/multiversx/mx-chain-vm-common-go v1.5.6-0.20231025074140-3a1d6a69921d
github.com/multiversx/mx-chain-communication-go v1.0.12
github.com/multiversx/mx-chain-core-go v1.2.16
github.com/multiversx/mx-chain-logger-go v1.0.13
github.com/multiversx/mx-chain-vm-common-go v1.5.2
github.com/prometheus/client_model v0.4.0
github.com/prometheus/common v0.37.0
github.com/stretchr/testify v1.8.4
Expand Down
18 changes: 9 additions & 9 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -247,15 +247,15 @@ github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9G
github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
github.com/mr-tron/base58 v1.2.0 h1:T/HDJBh4ZCPbU39/+c3rRvE0uKBQlU27+QI8LJ4t64o=
github.com/mr-tron/base58 v1.2.0/go.mod h1:BinMc/sQntlIE1frQmRFPUoPA1Zkr8VRgBdjWI2mNwc=
github.com/multiversx/mx-chain-communication-go v1.0.9-0.20231025073956-fbcc7f2e3af6 h1:5OEKTyoks3LvCXsXuer4oeBavtkhynOfAs3fba+xiMU=
github.com/multiversx/mx-chain-communication-go v1.0.9-0.20231025073956-fbcc7f2e3af6/go.mod h1:0NUW+wX8I0VzCEQHG/jRkjpx+KTtVAUGF33BdT65rmU=
github.com/multiversx/mx-chain-core-go v1.2.17-0.20231025072115-f3530bc1cab1 h1:JyPl8MWDT2eECtNraEtDLKBCEgXgYxJY5vYjTDAJNms=
github.com/multiversx/mx-chain-core-go v1.2.17-0.20231025072115-f3530bc1cab1/go.mod h1:B5zU4MFyJezmEzCsAHE9YNULmGCm2zbPHvl9hazNxmE=
github.com/multiversx/mx-chain-crypto-go v1.2.9-0.20231025072739-25b21500d880 h1:8XAmbtuoPsvjzRF3qb8rk6CZva5O+042PcdB0NORa6k=
github.com/multiversx/mx-chain-logger-go v1.0.14-0.20231025072404-d54164fbae96 h1:6rG9/MtlWapWkN30HfXPzX2oJc1CjLnbW1NGne2pwLo=
github.com/multiversx/mx-chain-logger-go v1.0.14-0.20231025072404-d54164fbae96/go.mod h1:996BTzWMAf0RxqE+Sqv7kB4OEnV9J6pJQ/ShKmlHxQM=
github.com/multiversx/mx-chain-vm-common-go v1.5.6-0.20231025074140-3a1d6a69921d h1:t/LcCZzqh/vhW7vRytF5y3WJBRldZMY12cCNXbUl9vE=
github.com/multiversx/mx-chain-vm-common-go v1.5.6-0.20231025074140-3a1d6a69921d/go.mod h1:dd5YAzQvYRJjXoeg1G+JbPLPzYM6UAsnACKdw9XcDnQ=
github.com/multiversx/mx-chain-communication-go v1.0.12 h1:67WOaf87gpwouydD1AAOHw5LMGZh7NfITrp/KqFY3Tw=
github.com/multiversx/mx-chain-communication-go v1.0.12/go.mod h1:+oaUowpq+SqrEmAsMPGwhz44g7L81loWb6AiNQU9Ms4=
github.com/multiversx/mx-chain-core-go v1.2.16 h1:m0hUNmZQjGJxKDLQOHoM9jSaeDfVTbyd+mqiS8+NckE=
github.com/multiversx/mx-chain-core-go v1.2.16/go.mod h1:BILOGHUOIG5dNNX8cgkzCNfDaVtoYrJRYcPnpxRMH84=
github.com/multiversx/mx-chain-crypto-go v1.2.8 h1:wOgVlUaO5X4L8iEbFjcQcL8SZvv6WZ7LqH73BiRPhxU=
github.com/multiversx/mx-chain-logger-go v1.0.13 h1:eru/TETo0MkO4ZTnXsQDKf4PBRpAXmqjT02klNT/JnY=
github.com/multiversx/mx-chain-logger-go v1.0.13/go.mod h1:MZJhTAtZTJxT+yK2EHc4ZW3YOHUc1UdjCD0iahRNBZk=
github.com/multiversx/mx-chain-vm-common-go v1.5.2 h1:iRWJNlogjkq9w+pJZIfkVkXQFmMoRxZr6pzCfg2/K68=
github.com/multiversx/mx-chain-vm-common-go v1.5.2/go.mod h1:sqkKMCnwkWl8DURdb9q7pctK8IANghdHY1KJLE0ox2c=
github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A=
Expand Down

0 comments on commit 7a00f24

Please sign in to comment.