From 8085a6da9f323c0805c50911ba13f61405fd3a12 Mon Sep 17 00:00:00 2001 From: Sergey Date: Mon, 9 Sep 2024 01:09:03 +0300 Subject: [PATCH] chore: removed node_stats fetcher --- pkg/queriers/node_stats/querier.go | 84 ------------------- pkg/queriers/node_stats/querier_test.go | 104 ------------------------ 2 files changed, 188 deletions(-) delete mode 100644 pkg/queriers/node_stats/querier.go delete mode 100644 pkg/queriers/node_stats/querier_test.go diff --git a/pkg/queriers/node_stats/querier.go b/pkg/queriers/node_stats/querier.go deleted file mode 100644 index ccb7d0e..0000000 --- a/pkg/queriers/node_stats/querier.go +++ /dev/null @@ -1,84 +0,0 @@ -package node_stats - -import ( - "context" - "main/pkg/clients/tendermint" - "main/pkg/metrics" - "main/pkg/query_info" - "main/pkg/utils" - - "go.opentelemetry.io/otel/attribute" - "go.opentelemetry.io/otel/trace" - - "github.com/rs/zerolog" -) - -type Querier struct { - TendermintRPC *tendermint.RPC - Logger zerolog.Logger - Tracer trace.Tracer -} - -func NewQuerier(logger zerolog.Logger, tendermintRPC *tendermint.RPC, tracer trace.Tracer) *Querier { - return &Querier{ - Logger: logger.With().Str("component", "node-stats-querier").Logger(), - TendermintRPC: tendermintRPC, - Tracer: tracer, - } -} - -func (n *Querier) Enabled() bool { - return n.TendermintRPC != nil -} - -func (n *Querier) Name() string { - return "node-stats-querier" -} - -func (n *Querier) Get(ctx context.Context) ([]metrics.MetricInfo, []query_info.QueryInfo) { - childCtx, span := n.Tracer.Start( - ctx, - "Querier "+n.Name(), - trace.WithAttributes(attribute.String("node", n.Name())), - ) - defer span.End() - - status, queryInfo, err := n.TendermintRPC.Status(childCtx) - if err != nil { - n.Logger.Error().Err(err).Msg("Could not fetch node status") - return []metrics.MetricInfo{}, []query_info.QueryInfo{queryInfo} - } - - querierMetrics := []metrics.MetricInfo{ - { - MetricName: metrics.MetricNameCatchingUp, - Labels: map[string]string{}, - Value: utils.BoolToFloat64(status.Result.SyncInfo.CatchingUp), - }, - { - MetricName: metrics.MetricNameLatestBlockTime, - Labels: map[string]string{}, - Value: float64(status.Result.SyncInfo.LatestBlockTime.Unix()), - }, - { - MetricName: metrics.MetricNameNodeInfo, - Labels: map[string]string{ - "moniker": status.Result.NodeInfo.Moniker, - "chain": status.Result.NodeInfo.Network, - }, - Value: 1, - }, - { - MetricName: metrics.MetricNameTendermintVersion, - Labels: map[string]string{"version": status.Result.NodeInfo.Version}, - Value: 1, - }, - { - MetricName: metrics.MetricNameVotingPower, - Labels: map[string]string{}, - Value: float64(status.Result.ValidatorInfo.VotingPower), - }, - } - - return querierMetrics, []query_info.QueryInfo{queryInfo} -} diff --git a/pkg/queriers/node_stats/querier_test.go b/pkg/queriers/node_stats/querier_test.go deleted file mode 100644 index 37c8e60..0000000 --- a/pkg/queriers/node_stats/querier_test.go +++ /dev/null @@ -1,104 +0,0 @@ -package node_stats - -import ( - "context" - "errors" - "main/assets" - "main/pkg/clients/tendermint" - configPkg "main/pkg/config" - loggerPkg "main/pkg/logger" - "main/pkg/tracing" - "testing" - - "github.com/jarcoal/httpmock" - - "github.com/stretchr/testify/assert" -) - -func TestNodeStatsQuerierBase(t *testing.T) { - t.Parallel() - - config := configPkg.TendermintConfig{ - Address: "https://example.com", - } - logger := loggerPkg.GetNopLogger() - tracer := tracing.InitNoopTracer() - client := tendermint.NewRPC(config, *logger, tracer) - querier := NewQuerier(*logger, client, tracer) - assert.True(t, querier.Enabled()) - assert.Equal(t, "node-stats-querier", querier.Name()) -} - -//nolint:paralleltest // disabled due to httpmock usage -func TestNodeStatsQuerierFail(t *testing.T) { - httpmock.Activate() - defer httpmock.DeactivateAndReset() - - httpmock.RegisterResponder( - "GET", - "https://example.com/status", - httpmock.NewErrorResponder(errors.New("custom error")), - ) - - config := configPkg.TendermintConfig{ - Address: "https://example.com", - } - logger := loggerPkg.GetNopLogger() - tracer := tracing.InitNoopTracer() - client := tendermint.NewRPC(config, *logger, tracer) - querier := NewQuerier(*logger, client, tracer) - - metrics, queryInfos := querier.Get(context.Background()) - assert.Len(t, queryInfos, 1) - assert.False(t, queryInfos[0].Success) - assert.Empty(t, metrics) -} - -//nolint:paralleltest // disabled due to httpmock usage -func TestNodeStatsQuerierOk(t *testing.T) { - httpmock.Activate() - defer httpmock.DeactivateAndReset() - - httpmock.RegisterResponder( - "GET", - "https://example.com/status", - httpmock.NewBytesResponder(200, assets.GetBytesOrPanic("status.json")), - ) - - config := configPkg.TendermintConfig{ - Address: "https://example.com", - } - logger := loggerPkg.GetDefaultLogger() - tracer := tracing.InitNoopTracer() - client := tendermint.NewRPC(config, *logger, tracer) - querier := NewQuerier(*logger, client, tracer) - - metrics, queryInfos := querier.Get(context.Background()) - assert.Len(t, queryInfos, 1) - assert.True(t, queryInfos[0].Success) - assert.Len(t, metrics, 5) - - catchingUp := metrics[0] - assert.Empty(t, catchingUp.Labels) - assert.Zero(t, catchingUp.Value) - - timeSinceLatest := metrics[1] - assert.Empty(t, timeSinceLatest.Labels) - - nodeInfo := metrics[2] - assert.Equal(t, map[string]string{ - "chain": "cosmoshub-4", - "moniker": "freak12techno", - }, nodeInfo.Labels) - assert.InDelta(t, 1, nodeInfo.Value, 0.01) - - tendermintVersion := metrics[3] - assert.Equal(t, map[string]string{ - "version": "0.37.6", - }, tendermintVersion.Labels) - assert.InDelta(t, 1, tendermintVersion.Value, 0.01) - - votingPower := metrics[4] - assert.Empty(t, votingPower.Labels) - assert.Zero(t, votingPower.Value) -}