-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
98df3cc
commit 7626663
Showing
8 changed files
with
311 additions
and
169 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package fetchers | ||
|
||
import ( | ||
"context" | ||
grpcPkg "main/pkg/clients/grpc" | ||
"main/pkg/constants" | ||
"main/pkg/query_info" | ||
|
||
"go.opentelemetry.io/otel/attribute" | ||
"go.opentelemetry.io/otel/trace" | ||
|
||
"github.com/rs/zerolog" | ||
) | ||
|
||
type NodeConfigFetcher struct { | ||
gRPC *grpcPkg.Client | ||
Logger zerolog.Logger | ||
Tracer trace.Tracer | ||
} | ||
|
||
func NewNodeConfigFetcher(logger zerolog.Logger, grpc *grpcPkg.Client, tracer trace.Tracer) *NodeConfigFetcher { | ||
return &NodeConfigFetcher{ | ||
Logger: logger.With().Str("component", "node_config_fetcher").Logger(), | ||
gRPC: grpc, | ||
Tracer: tracer, | ||
} | ||
} | ||
|
||
func (n *NodeConfigFetcher) Enabled() bool { | ||
return n.gRPC != nil | ||
} | ||
|
||
func (n *NodeConfigFetcher) Name() constants.FetcherName { | ||
return constants.FetcherNameNodeConfig | ||
} | ||
|
||
func (n *NodeConfigFetcher) Dependencies() []constants.FetcherName { | ||
return []constants.FetcherName{} | ||
} | ||
|
||
func (n *NodeConfigFetcher) Get(ctx context.Context) (interface{}, []query_info.QueryInfo) { | ||
childCtx, span := n.Tracer.Start( | ||
ctx, | ||
"NodeConfigFetcher "+string(n.Name()), | ||
trace.WithAttributes(attribute.String("node", string(n.Name()))), | ||
) | ||
defer span.End() | ||
|
||
config, queryInfo, err := n.gRPC.GetNodeConfig(childCtx) | ||
if err != nil { | ||
n.Logger.Error().Err(err).Msg("Could not fetch node config") | ||
return nil, []query_info.QueryInfo{queryInfo} | ||
} | ||
|
||
if config == nil { | ||
n.Logger.Debug(). | ||
Msg("Node config is nil, probably chain does not implement the node config endpoint.") | ||
return nil, []query_info.QueryInfo{queryInfo} | ||
} | ||
|
||
return config, []query_info.QueryInfo{queryInfo} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package generators | ||
|
||
import ( | ||
"main/pkg/constants" | ||
"main/pkg/fetchers" | ||
metricsPkg "main/pkg/metrics" | ||
|
||
"github.com/cosmos/cosmos-sdk/client/grpc/node" | ||
cosmosTypes "github.com/cosmos/cosmos-sdk/types" | ||
) | ||
|
||
type NodeConfigGenerator struct{} | ||
|
||
func NewNodeConfigGenerator() *NodeConfigGenerator { | ||
return &NodeConfigGenerator{} | ||
} | ||
|
||
func (g *NodeConfigGenerator) Get(state fetchers.State) []metricsPkg.MetricInfo { | ||
statusRaw, ok := state[constants.FetcherNameNodeConfig] | ||
if !ok || statusRaw == nil { | ||
return []metricsPkg.MetricInfo{} | ||
} | ||
|
||
config, ok := statusRaw.(*node.ConfigResponse) | ||
if !ok { | ||
panic("expected the state entry to be *node.ConfigResponse") | ||
} | ||
|
||
coinsParsed, err := cosmosTypes.ParseDecCoins(config.MinimumGasPrice) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
metrics := []metricsPkg.MetricInfo{} | ||
metrics = append(metrics, metricsPkg.MetricInfo{ | ||
MetricName: metricsPkg.MetricNameMinimumGasPricesCount, | ||
Labels: map[string]string{}, | ||
Value: float64(len(coinsParsed)), | ||
}) | ||
|
||
for _, amount := range coinsParsed { | ||
metrics = append(metrics, metricsPkg.MetricInfo{ | ||
MetricName: metricsPkg.MetricNameMinimumGasPrice, | ||
Labels: map[string]string{"denom": amount.Denom}, | ||
Value: amount.Amount.MustFloat64(), | ||
}) | ||
} | ||
|
||
if config.HaltHeight > 0 { | ||
metrics = append(metrics, metricsPkg.MetricInfo{ | ||
MetricName: metricsPkg.MetricNameHaltHeight, | ||
Labels: map[string]string{}, | ||
Value: float64(config.HaltHeight), | ||
}) | ||
} | ||
|
||
return metrics | ||
} |
Oops, something went wrong.