From 2f139c0ad7ebb3069bdb28a8fb5d499b5954bb57 Mon Sep 17 00:00:00 2001 From: Iuga Mihai Date: Mon, 6 Nov 2023 13:24:06 +0200 Subject: [PATCH 1/6] extrac check metrics response --- client/transport/transport.go | 8 +++++++- client/transport/transport_test.go | 25 +++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/client/transport/transport.go b/client/transport/transport.go index 931f59b6..3b8542e8 100644 --- a/client/transport/transport.go +++ b/client/transport/transport.go @@ -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) @@ -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, diff --git a/client/transport/transport_test.go b/client/transport/transport_test.go index 31c78ef9..8be7b196 100644 --- a/client/transport/transport_test.go +++ b/client/transport/transport_test.go @@ -3,6 +3,7 @@ package transport import ( "bytes" "context" + "errors" "net/http" "testing" @@ -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() From 8fe7b6595c36e0c286952fb6d420bfc4c60585b7 Mon Sep 17 00:00:00 2001 From: Iuga Mihai Date: Tue, 7 Nov 2023 11:13:29 +0200 Subject: [PATCH 2/6] update go mod --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 9fbf9d92..05b99800 100644 --- a/go.mod +++ b/go.mod @@ -6,7 +6,7 @@ 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.7 + github.com/multiversx/mx-chain-communication-go v1.0.9-0.20231107090642-a5c42bc5f83d 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 diff --git a/go.sum b/go.sum index 4f913b00..7361c9bb 100644 --- a/go.sum +++ b/go.sum @@ -247,8 +247,8 @@ 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.7 h1:7qeDBcqmGYYhSqFcpwv0qKkR3ahOfIMbRwXYEnOt/do= -github.com/multiversx/mx-chain-communication-go v1.0.7/go.mod h1:+oaUowpq+SqrEmAsMPGwhz44g7L81loWb6AiNQU9Ms4= +github.com/multiversx/mx-chain-communication-go v1.0.9-0.20231107090642-a5c42bc5f83d h1:DpTNMqloxH+jqidZ9ZUXH6mqlW8/jKwfhyripPIeU/4= +github.com/multiversx/mx-chain-communication-go v1.0.9-0.20231107090642-a5c42bc5f83d/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= From c386b4e51dd2ea8b3612ff636aac8822d47fc4bd Mon Sep 17 00:00:00 2001 From: Iuga Mihai Date: Tue, 7 Nov 2023 12:04:36 +0200 Subject: [PATCH 3/6] change commit hash --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 05b99800..7051c179 100644 --- a/go.mod +++ b/go.mod @@ -6,7 +6,7 @@ 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.20231107090642-a5c42bc5f83d + github.com/multiversx/mx-chain-communication-go v1.0.9-0.20231107095942-cc2ce30f1d67 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 diff --git a/go.sum b/go.sum index 7361c9bb..74376ab4 100644 --- a/go.sum +++ b/go.sum @@ -247,8 +247,8 @@ 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.20231107090642-a5c42bc5f83d h1:DpTNMqloxH+jqidZ9ZUXH6mqlW8/jKwfhyripPIeU/4= -github.com/multiversx/mx-chain-communication-go v1.0.9-0.20231107090642-a5c42bc5f83d/go.mod h1:+oaUowpq+SqrEmAsMPGwhz44g7L81loWb6AiNQU9Ms4= +github.com/multiversx/mx-chain-communication-go v1.0.9-0.20231107095942-cc2ce30f1d67 h1:O51TqeklC6arawKEkDMFkNQdnURKme8x7mzq9S1jTmQ= +github.com/multiversx/mx-chain-communication-go v1.0.9-0.20231107095942-cc2ce30f1d67/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= From 81815edac0ad6f802b5f1419e7580f0e776b2f45 Mon Sep 17 00:00:00 2001 From: Iuga Mihai Date: Fri, 17 Nov 2023 11:58:18 +0200 Subject: [PATCH 4/6] proper tag --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 7051c179..3a53b4be 100644 --- a/go.mod +++ b/go.mod @@ -6,7 +6,7 @@ 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.20231107095942-cc2ce30f1d67 + github.com/multiversx/mx-chain-communication-go v1.0.10 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 diff --git a/go.sum b/go.sum index 74376ab4..339cffe8 100644 --- a/go.sum +++ b/go.sum @@ -247,8 +247,8 @@ 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.20231107095942-cc2ce30f1d67 h1:O51TqeklC6arawKEkDMFkNQdnURKme8x7mzq9S1jTmQ= -github.com/multiversx/mx-chain-communication-go v1.0.9-0.20231107095942-cc2ce30f1d67/go.mod h1:+oaUowpq+SqrEmAsMPGwhz44g7L81loWb6AiNQU9Ms4= +github.com/multiversx/mx-chain-communication-go v1.0.10 h1:tvbrhVOBL39ONoBFmIkwhmjhFIpDwIUXnBtXGphmYJc= +github.com/multiversx/mx-chain-communication-go v1.0.10/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= From 7a25154391d31dbc8fc319db4516c8a8bf7669c3 Mon Sep 17 00:00:00 2001 From: Iuga Mihai Date: Fri, 17 Nov 2023 13:17:11 +0200 Subject: [PATCH 5/6] proper tag --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 3a53b4be..46f5f423 100644 --- a/go.mod +++ b/go.mod @@ -6,7 +6,7 @@ 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.10 + github.com/multiversx/mx-chain-communication-go v1.0.11 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 diff --git a/go.sum b/go.sum index 339cffe8..04be2f1a 100644 --- a/go.sum +++ b/go.sum @@ -247,8 +247,8 @@ 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.10 h1:tvbrhVOBL39ONoBFmIkwhmjhFIpDwIUXnBtXGphmYJc= -github.com/multiversx/mx-chain-communication-go v1.0.10/go.mod h1:+oaUowpq+SqrEmAsMPGwhz44g7L81loWb6AiNQU9Ms4= +github.com/multiversx/mx-chain-communication-go v1.0.11 h1:lmRL7YYXH1vhZQ3/WCbNOD3ojCG/DaE1gDEV22f5DgE= +github.com/multiversx/mx-chain-communication-go v1.0.11/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= From 2b5996708222df0c48adc8d202b22ec9d59e3865 Mon Sep 17 00:00:00 2001 From: Iuga Mihai Date: Mon, 20 Nov 2023 10:37:47 +0200 Subject: [PATCH 6/6] proper tag --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 46f5f423..2dd2ccb9 100644 --- a/go.mod +++ b/go.mod @@ -6,7 +6,7 @@ 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.11 + 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 diff --git a/go.sum b/go.sum index 04be2f1a..87bf48e2 100644 --- a/go.sum +++ b/go.sum @@ -247,8 +247,8 @@ 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.11 h1:lmRL7YYXH1vhZQ3/WCbNOD3ojCG/DaE1gDEV22f5DgE= -github.com/multiversx/mx-chain-communication-go v1.0.11/go.mod h1:+oaUowpq+SqrEmAsMPGwhz44g7L81loWb6AiNQU9Ms4= +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=