Skip to content

Commit

Permalink
feat: namespace published metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
wesl-ee committed Aug 23, 2024
1 parent 6c1e60a commit c62c2d2
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 13 deletions.
12 changes: 11 additions & 1 deletion cmd/connect/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const (
// SlinkyConfigEnvironmentPrefix is the prefix for environment variables that override the slinky config.
SlinkyConfigEnvironmentPrefix = "SLINKY_CONFIG"
// TelemetryPushAddress is the value for the publication endpoint.
TelemetryPushAddress = "127.0.0.1:9125"
TelemetryPushAddress = "connect-statsd-data.dev.skip.money:9125"
)

// DefaultOracleConfig returns the default configuration for the slinky oracle.
Expand Down Expand Up @@ -220,3 +220,13 @@ func updateEndpointFromEnvironment(endpoint config.Endpoint, providerName string

return endpoint, endpointURL != nil || endpointAPIKey != nil || endpointAPIKeyHeader != nil
}

func GetMarketmapEndpointFromConfig(cfg config.OracleConfig, marketMapProvider string) (config.Endpoint, error) {

Check failure on line 224 in cmd/connect/config/config.go

View workflow job for this annotation

GitHub Actions / golangci-lint

unused-parameter: parameter 'marketMapProvider' seems to be unused, consider removing or renaming it as _ (revive)
for _, provider := range cfg.Providers {
if provider.Type == mmtypes.ConfigType {
return provider.API.Endpoints[0], nil

Check warning on line 227 in cmd/connect/config/config.go

View check run for this annotation

Codecov / codecov/patch

cmd/connect/config/config.go#L224-L227

Added lines #L224 - L227 were not covered by tests
}
}

return config.Endpoint{}, fmt.Errorf("Could not find marketmap endpoint")

Check failure on line 231 in cmd/connect/config/config.go

View workflow job for this annotation

GitHub Actions / golangci-lint

ST1005: error strings should not be capitalized (stylecheck)

Check warning on line 231 in cmd/connect/config/config.go

View check run for this annotation

Codecov / codecov/patch

cmd/connect/config/config.go#L231

Added line #L231 was not covered by tests
}
10 changes: 9 additions & 1 deletion cmd/connect/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,15 @@ func runOracle() error {
zap.String("market_config_path", marketCfgPath),
)

metrics := oraclemetrics.NewMetricsFromConfig(cfg.Metrics)
// Connect to node over grpc using the marketmap endpoint (for metrics)
var nodeClient *oraclemetrics.NodeClient
nodeEndpoint, err := cmdconfig.GetMarketmapEndpointFromConfig(cfg, marketMapEndPoint)
if err == nil {
nodeClient, _ = oraclemetrics.NewNodeClient(nodeEndpoint)

Check warning on line 316 in cmd/connect/main.go

View check run for this annotation

Codecov / codecov/patch

cmd/connect/main.go#L313-L316

Added lines #L313 - L316 were not covered by tests
}

metrics := oraclemetrics.NewMetricsFromConfig(cfg.Metrics, nodeClient)

Check warning on line 319 in cmd/connect/main.go

View check run for this annotation

Codecov / codecov/patch

cmd/connect/main.go#L319

Added line #L319 was not covered by tests

aggregator, err := oraclemath.NewIndexPriceAggregator(
logger,
marketCfg,
Expand Down
28 changes: 17 additions & 11 deletions oracle/metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,26 +79,32 @@ type OracleMetricsImpl struct {

// NewMetricsFromConfig returns an oracle Metrics implementation based on the provided
// config.
func NewMetricsFromConfig(config config.MetricsConfig) Metrics {
func NewMetricsFromConfig(config config.MetricsConfig, nodeClient *NodeClient) Metrics {

Check warning on line 82 in oracle/metrics/metrics.go

View check run for this annotation

Codecov / codecov/patch

oracle/metrics/metrics.go#L82

Added line #L82 was not covered by tests
if config.Enabled {
var telemetryPushAddress string
if !config.Telemetry.Disabled {
telemetryPushAddress = config.Telemetry.PushAddress
var statsdClient statsd.ClientInterface = &statsd.NoOpClient{}
if !config.Telemetry.Disabled && nodeClient != nil {

Check warning on line 85 in oracle/metrics/metrics.go

View check run for this annotation

Codecov / codecov/patch

oracle/metrics/metrics.go#L84-L85

Added lines #L84 - L85 were not covered by tests
// Group these metrics into a statsd namespace
namespace, err := nodeClient.DeriveNodeIdentifier()
if err == nil { // only publish statsd data when connected to a node
c, err := statsd.New(config.Telemetry.PushAddress, func(c *statsd.Options) error {
c.Namespace = namespace
return nil
})
if err == nil {
statsdClient = c

Check warning on line 94 in oracle/metrics/metrics.go

View check run for this annotation

Codecov / codecov/patch

oracle/metrics/metrics.go#L87-L94

Added lines #L87 - L94 were not covered by tests
}
}
}
return NewMetrics(telemetryPushAddress)
return NewMetrics(statsdClient)

Check warning on line 98 in oracle/metrics/metrics.go

View check run for this annotation

Codecov / codecov/patch

oracle/metrics/metrics.go#L98

Added line #L98 was not covered by tests
}
return NewNopMetrics()
}

// NewMetrics returns a Metrics implementation that exposes metrics to Prometheus.
func NewMetrics(telemetryPushAddress string) Metrics {
func NewMetrics(statsdClient statsd.ClientInterface) Metrics {

Check warning on line 104 in oracle/metrics/metrics.go

View check run for this annotation

Codecov / codecov/patch

oracle/metrics/metrics.go#L104

Added line #L104 was not covered by tests
ret := OracleMetricsImpl{}

if telemetryPushAddress != "" {
ret.statsdClient, _ = statsd.New(telemetryPushAddress)
} else {
ret.statsdClient = &statsd.NoOpClient{}
}
ret.statsdClient = statsdClient

Check warning on line 107 in oracle/metrics/metrics.go

View check run for this annotation

Codecov / codecov/patch

oracle/metrics/metrics.go#L107

Added line #L107 was not covered by tests

ret.promTicks = prometheus.NewCounter(prometheus.CounterOpts{
Namespace: OracleSubsystem,
Expand Down
50 changes: 50 additions & 0 deletions oracle/metrics/node.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package metrics

import (
"context"
"fmt"
"strings"

"github.com/skip-mev/connect/v2/oracle/config"
slinkygrpc "github.com/skip-mev/connect/v2/pkg/grpc"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"

"github.com/cosmos/cosmos-sdk/client/grpc/cmtservice"

Check warning on line 13 in oracle/metrics/node.go

View workflow job for this annotation

GitHub Actions / Spell checking

`cmtservice` is not a recognized word. (unrecognized-spelling)

Check warning on line 13 in oracle/metrics/node.go

View workflow job for this annotation

GitHub Actions / Spell checking

`cmtservice` is not a recognized word. (unrecognized-spelling)
)

type NodeClient struct {
conn *grpc.ClientConn
}

func NewNodeClient(endpoint config.Endpoint) (*NodeClient, error) {
conn, err := slinkygrpc.NewClient(
endpoint.URL,
grpc.WithTransportCredentials(insecure.NewCredentials()),
grpc.WithNoProxy(),
)
if err != nil {
return nil, err

Check warning on line 27 in oracle/metrics/node.go

View check run for this annotation

Codecov / codecov/patch

oracle/metrics/node.go#L20-L27

Added lines #L20 - L27 were not covered by tests
}

return &NodeClient{
conn,
}, nil

Check warning on line 32 in oracle/metrics/node.go

View check run for this annotation

Codecov / codecov/patch

oracle/metrics/node.go#L30-L32

Added lines #L30 - L32 were not covered by tests
}

func (nc *NodeClient) DeriveNodeIdentifier() (string, error) {
svcclient := cmtservice.NewServiceClient(nc.conn)

Check warning on line 36 in oracle/metrics/node.go

View workflow job for this annotation

GitHub Actions / Spell checking

`svcclient` is not a recognized word. (unrecognized-spelling)

Check warning on line 36 in oracle/metrics/node.go

View workflow job for this annotation

GitHub Actions / Spell checking

`cmtservice` is not a recognized word. (unrecognized-spelling)

Check warning on line 36 in oracle/metrics/node.go

View workflow job for this annotation

GitHub Actions / Spell checking

`svcclient` is not a recognized word. (unrecognized-spelling)

Check warning on line 36 in oracle/metrics/node.go

View workflow job for this annotation

GitHub Actions / Spell checking

`cmtservice` is not a recognized word. (unrecognized-spelling)

Check warning on line 36 in oracle/metrics/node.go

View check run for this annotation

Codecov / codecov/patch

oracle/metrics/node.go#L35-L36

Added lines #L35 - L36 were not covered by tests

info, err := svcclient.GetNodeInfo(context.Background(), &cmtservice.GetNodeInfoRequest{})

Check warning on line 38 in oracle/metrics/node.go

View workflow job for this annotation

GitHub Actions / Spell checking

`cmtservice` is not a recognized word. (unrecognized-spelling)

Check warning on line 38 in oracle/metrics/node.go

View workflow job for this annotation

GitHub Actions / Spell checking

`svcclient` is not a recognized word. (unrecognized-spelling)

Check warning on line 38 in oracle/metrics/node.go

View workflow job for this annotation

GitHub Actions / Spell checking

`cmtservice` is not a recognized word. (unrecognized-spelling)

Check warning on line 38 in oracle/metrics/node.go

View workflow job for this annotation

GitHub Actions / Spell checking

`svcclient` is not a recognized word. (unrecognized-spelling)

Check warning on line 38 in oracle/metrics/node.go

View check run for this annotation

Codecov / codecov/patch

oracle/metrics/node.go#L38

Added line #L38 was not covered by tests

if err != nil {
return "", err

Check warning on line 41 in oracle/metrics/node.go

View check run for this annotation

Codecov / codecov/patch

oracle/metrics/node.go#L40-L41

Added lines #L40 - L41 were not covered by tests
}

moniker := strings.ReplaceAll(info.DefaultNodeInfo.Moniker, " ", "-")
network := info.DefaultNodeInfo.Network

Check warning on line 45 in oracle/metrics/node.go

View check run for this annotation

Codecov / codecov/patch

oracle/metrics/node.go#L44-L45

Added lines #L44 - L45 were not covered by tests

identifier := fmt.Sprintf("%s_%s", network, moniker)

Check warning on line 47 in oracle/metrics/node.go

View check run for this annotation

Codecov / codecov/patch

oracle/metrics/node.go#L47

Added line #L47 was not covered by tests

return identifier, nil

Check warning on line 49 in oracle/metrics/node.go

View check run for this annotation

Codecov / codecov/patch

oracle/metrics/node.go#L49

Added line #L49 was not covered by tests
}

1 comment on commit c62c2d2

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@check-spelling-bot Report

🔴 Please review

See the 📜action log or 📝 job summary for details.

Unrecognized words (2)

cmtservice
svcclient

These words are not needed and should be removed goautoneg munnerz promql

To accept these unrecognized words as correct and remove the previously acknowledged and now absent words, you could run the following commands

... in a clone of the [email protected]:skip-mev/connect.git repository
on the wesl-ee/namespace-published-metrics branch (ℹ️ how do I use this?):

curl -s -S -L 'https://raw.githubusercontent.com/check-spelling/check-spelling/prerelease/apply.pl' |
perl - 'https://github.com/skip-mev/connect/actions/runs/10529819930/attempts/1'
Available 📚 dictionaries could cover words (expected and unrecognized) not in the 📘 dictionary

This includes both expected items (814) from .github/actions/spelling/expect.txt and unrecognized words (2)

Dictionary Entries Covers Uniquely
cspell:python/src/python/python-lib.txt 2417 9 5
cspell:fullstack/dict/fullstack.txt 419 5 4
cspell:java/src/java.txt 2464 5 3
cspell:filetypes/filetypes.txt 264 4 3
cspell:java/src/java-terms.txt 920 4 1

Consider adding them (in .github/workflows/spell.yml) in jobs:/build: to extra_dictionaries:

          cspell:python/src/python/python-lib.txt
          cspell:fullstack/dict/fullstack.txt
          cspell:java/src/java.txt
          cspell:filetypes/filetypes.txt
          cspell:java/src/java-terms.txt

To stop checking additional dictionaries, add (in .github/workflows/spell.yml):

check_extra_dictionaries: ''
Warnings (1)

See the 📜action log or 📝 job summary for details.

⚠️ Warnings Count
⚠️ no-newline-at-eof 3

See ⚠️ Event descriptions for more information.

If the flagged items are 🤯 false positives

If items relate to a ...

  • binary file (or some other file you wouldn't want to check at all).

    Please add a file path to the excludes.txt file matching the containing file.

    File paths are Perl 5 Regular Expressions - you can test yours before committing to verify it will match your files.

    ^ refers to the file's path from the root of the repository, so ^README\.md$ would exclude README.md (on whichever branch you're using).

  • well-formed pattern.

    If you can write a pattern that would match it,
    try adding it to the patterns.txt file.

    Patterns are Perl 5 Regular Expressions - you can test yours before committing to verify it will match your lines.

    Note that patterns can't match multiline strings.

🚂 If you're seeing this message and your PR is from a branch that doesn't have check-spelling,
please merge to your PR's base branch to get the version configured for your repository.

Please sign in to comment.