Skip to content

Commit

Permalink
feat: update otlp sdk version and add metric tags (#192)
Browse files Browse the repository at this point in the history
Co-authored-by: Matija Petrunić <[email protected]>
  • Loading branch information
P1sar and mpetrun5 authored Jun 7, 2023
1 parent c45f3ee commit ba919d6
Show file tree
Hide file tree
Showing 8 changed files with 186 additions and 172 deletions.
26 changes: 17 additions & 9 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,20 @@ func Run() error {
exitLock := &sync.RWMutex{}
defer exitLock.Lock()

mp, err := opentelemetry.InitMetricProvider(context.Background(), configuration.RelayerConfig.OpenTelemetryCollectorURL)
if err != nil {
panic(err)
}
defer func() {
if err := mp.Shutdown(context.Background()); err != nil {
log.Error().Msgf("Error shutting down meter provider: %v", err)
}
}()
sygmaMetrics, err := metrics.NewSygmaMetrics(mp.Meter("relayer-metric-provider"), configuration.RelayerConfig.Env, configuration.RelayerConfig.Id)
if err != nil {
panic(err)
}

ctx, cancel := context.WithCancel(context.Background())
defer cancel()
chains := []relayer.RelayedChain{}
Expand Down Expand Up @@ -193,7 +207,7 @@ func Run() error {
eventHandlers = append(eventHandlers, listener.NewKeygenEventHandler(l, tssListener, coordinator, host, communication, keyshareStore, bridgeAddress, networkTopology.Threshold))
eventHandlers = append(eventHandlers, listener.NewRefreshEventHandler(l, topologyProvider, topologyStore, tssListener, coordinator, host, communication, connectionGate, keyshareStore, bridgeAddress))
eventHandlers = append(eventHandlers, listener.NewRetryEventHandler(l, tssListener, depositHandler, bridgeAddress, *config.GeneralChainConfig.Id, config.BlockConfirmations))
evmListener := coreListener.NewEVMListener(client, eventHandlers, blockstore, *config.GeneralChainConfig.Id, config.BlockRetryInterval, config.BlockConfirmations, config.BlockInterval)
evmListener := coreListener.NewEVMListener(client, eventHandlers, blockstore, sygmaMetrics, *config.GeneralChainConfig.Id, config.BlockRetryInterval, config.BlockConfirmations, config.BlockInterval)
executor := executor.NewExecutor(host, communication, coordinator, mh, bridgeContract, keyshareStore, exitLock)

chain := evm.NewEVMChain(
Expand Down Expand Up @@ -244,17 +258,11 @@ func Run() error {
}
}

meter, err := opentelemetry.DefaultMeter(context.Background(), configuration.RelayerConfig.OpenTelemetryCollectorURL)
if err != nil {
panic(err)
}
metrics := metrics.NewTelemetry(meter, configuration.RelayerConfig.Env, configuration.RelayerConfig.Id)

go jobs.StartCommunicationHealthCheckJob(host, configuration.RelayerConfig.MpcConfig.CommHealthCheckInterval, metrics)
go jobs.StartCommunicationHealthCheckJob(host, configuration.RelayerConfig.MpcConfig.CommHealthCheckInterval, sygmaMetrics)

r := relayer.NewRelayer(
chains,
metrics,
sygmaMetrics,
)

errChn := make(chan error)
Expand Down
16 changes: 9 additions & 7 deletions docs/general/Metrics.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@ Metrics are implemented via the OpenTelemetry [stack](https://opentelemetry.io/)
## Exported metrics
The following metrics are exported:
```
chainbridge.DepositEventCount (counter) - count of indexed deposits
chainbridge.ExecutionErrorCount (counter) - count of executions that failed
chainbridge.ExecutionLatencyPerRoute (histogram) - latency between indexing event and executing it per route
chainbridge.ExecutionLatency (histogram) - latency between indexing event and executing it across all routes
sygma.TotalRelayers (gauge) - number of relayers currently in the subset for MPC
sygma.availableRelayers (gauge) - number of currently available relayers from the subset
relayer.DepositEventCount (counter) - count of indexed deposits
relayer.ExecutionErrorCount (counter) - count of executions that failed
relayer.ExecutionLatencyPerRoute (histogram) - latency between indexing event and executing it per route
relayer.ExecutionLatency (histogram) - latency between indexing event and executing it across all routes
relayer.TotalRelayers (gauge) - number of relayers currently in the subset for MPC
relayer.availableRelayers (gauge) - number of currently available relayers from the subset
relayer.BlockDelta (gauge) - "Difference between chain head and current indexed block per domain
```

## Env variables
- SYG_RELAYER_OPENTELEMETRYCOLLECTORURL - url of the opentelemetry collector application that collects metrics
- SYG_RELAYER_ID - Set as a metrics tag (relayerid:0). Used to distinguish one Relayer from another. NOTE: should be unique and if you are planning to run Sygma relayer please agree on your relayerID with the team
- SYG_RELAYER_ENV - Set as a metrics tag (env:test). Used to distinguish Relayer environment
26 changes: 17 additions & 9 deletions example/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,20 @@ func Run() error {
exitLock := &sync.RWMutex{}
defer exitLock.Lock()

mp, err := opentelemetry.InitMetricProvider(context.Background(), configuration.RelayerConfig.OpenTelemetryCollectorURL)
if err != nil {
panic(err)
}
defer func() {
if err := mp.Shutdown(context.Background()); err != nil {
log.Error().Msgf("Error shutting down meter provider: %v", err)
}
}()
sygmaMetrics, err := metrics.NewSygmaMetrics(mp.Meter("relayer-metric-provider"), configuration.RelayerConfig.Env, configuration.RelayerConfig.Id)
if err != nil {
panic(err)
}

ctx, cancel := context.WithCancel(context.Background())
defer cancel()
chains := []relayer.RelayedChain{}
Expand Down Expand Up @@ -168,7 +182,7 @@ func Run() error {
eventHandlers = append(eventHandlers, listener.NewKeygenEventHandler(l, tssListener, coordinator, host, communication, keyshareStore, bridgeAddress, networkTopology.Threshold))
eventHandlers = append(eventHandlers, listener.NewRefreshEventHandler(l, nil, nil, tssListener, coordinator, host, communication, connectionGate, keyshareStore, bridgeAddress))
eventHandlers = append(eventHandlers, listener.NewRetryEventHandler(l, tssListener, depositHandler, bridgeAddress, *config.GeneralChainConfig.Id, config.BlockConfirmations))
evmListener := coreListener.NewEVMListener(client, eventHandlers, blockstore, *config.GeneralChainConfig.Id, config.BlockRetryInterval, config.BlockConfirmations, config.BlockInterval)
evmListener := coreListener.NewEVMListener(client, eventHandlers, blockstore, sygmaMetrics, *config.GeneralChainConfig.Id, config.BlockRetryInterval, config.BlockConfirmations, config.BlockInterval)
executor := executor.NewExecutor(host, communication, coordinator, mh, bridgeContract, keyshareStore, exitLock)

chain := evm.NewEVMChain(
Expand Down Expand Up @@ -222,17 +236,11 @@ func Run() error {
}
}

meter, err := opentelemetry.DefaultMeter(context.Background(), configuration.RelayerConfig.OpenTelemetryCollectorURL)
if err != nil {
panic(err)
}
metrics := metrics.NewTelemetry(meter, configuration.RelayerConfig.Env, configuration.RelayerConfig.Id)

go jobs.StartCommunicationHealthCheckJob(host, configuration.RelayerConfig.MpcConfig.CommHealthCheckInterval, metrics)
go jobs.StartCommunicationHealthCheckJob(host, configuration.RelayerConfig.MpcConfig.CommHealthCheckInterval, sygmaMetrics)

r := relayer.NewRelayer(
chains,
metrics,
sygmaMetrics,
)

errChn := make(chan error)
Expand Down
53 changes: 27 additions & 26 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/ChainSafe/sygma-relayer
go 1.19

require (
github.com/ChainSafe/chainbridge-core v1.3.1
github.com/ChainSafe/chainbridge-core v1.4.0
github.com/binance-chain/tss-lib v0.0.0-00010101000000-000000000000
github.com/centrifuge/go-substrate-rpc-client v2.0.0+incompatible
github.com/centrifuge/go-substrate-rpc-client/v4 v4.0.13-0.20230328172517-bf8a95095d4d
Expand All @@ -18,15 +18,18 @@ require (
github.com/rs/zerolog v1.25.0
github.com/spf13/cobra v1.2.1
github.com/spf13/viper v1.9.0
github.com/stretchr/testify v1.8.1
go.opentelemetry.io/otel v1.0.1
go.opentelemetry.io/otel/metric v0.24.0
github.com/stretchr/testify v1.8.3
go.opentelemetry.io/otel v1.16.0
go.opentelemetry.io/otel/metric v1.16.0
golang.org/x/exp v0.0.0-20220916125017-b168a2c6b86b
)

require (
github.com/bmatcuk/doublestar/v4 v4.6.0 // indirect
github.com/google/addlicense v1.1.1 // indirect
github.com/cenkalti/backoff/v4 v4.2.1 // indirect
github.com/go-logr/logr v1.2.4 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.7.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/internal/retry v1.16.0 // indirect
)

require (
Expand All @@ -39,7 +42,7 @@ require (
github.com/btcsuite/btcd v0.22.0-beta.0.20220201204404-81fbd9b67e54 // indirect
github.com/btcsuite/btcd/btcec/v2 v2.2.0 // indirect
github.com/btcsuite/btcutil v1.0.3-0.20211129182920-9c4bbabe7acd // indirect
github.com/cespare/xxhash/v2 v2.1.2 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/containerd/cgroups v1.0.4 // indirect
github.com/coreos/go-systemd/v22 v22.4.0 // indirect
github.com/cosmos/go-bip39 v1.0.0 // indirect
Expand All @@ -60,12 +63,11 @@ require (
github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0 // indirect
github.com/godbus/dbus/v5 v5.1.0 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/golang/snappy v0.0.4 // indirect
github.com/google/gopacket v1.1.19 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/gorilla/websocket v1.5.0 // indirect
github.com/grpc-ecosystem/grpc-gateway v1.16.0 // indirect
github.com/gtank/merlin v0.1.1 // indirect
github.com/gtank/ristretto255 v0.1.2 // indirect
github.com/hashicorp/golang-lru v0.5.5-0.20210104140557-80c98217689d // indirect
Expand Down Expand Up @@ -143,28 +145,26 @@ require (
github.com/tklauser/go-sysconf v0.3.5 // indirect
github.com/tklauser/numcpus v0.2.2 // indirect
github.com/vedhavyas/go-subkey v1.0.3 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlpmetric v0.24.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp v0.24.0 // indirect
go.opentelemetry.io/otel/internal/metric v0.24.0 // indirect
go.opentelemetry.io/otel/sdk v1.0.1 // indirect
go.opentelemetry.io/otel/sdk/export/metric v0.24.0 // indirect
go.opentelemetry.io/otel/sdk/metric v0.24.0 // indirect
go.opentelemetry.io/otel/trace v1.0.1 // indirect
go.opentelemetry.io/proto/otlp v0.9.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlpmetric v0.39.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp v0.39.0 // indirect
go.opentelemetry.io/otel/sdk v1.16.0 // indirect
go.opentelemetry.io/otel/sdk/metric v0.39.0 // indirect
go.opentelemetry.io/otel/trace v1.16.0 // indirect
go.opentelemetry.io/proto/otlp v0.19.0 // indirect
go.uber.org/atomic v1.10.0 // indirect
go.uber.org/multierr v1.9.0 // indirect
go.uber.org/zap v1.23.0 // indirect
golang.org/x/crypto v0.0.0-20220525230936-793ad666bf5e // indirect
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4 // indirect
golang.org/x/net v0.0.0-20220920183852-bf014ff85ad5 // indirect
golang.org/x/mod v0.8.0 // indirect
golang.org/x/net v0.8.0 // indirect
golang.org/x/sync v0.2.0 // indirect
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab // indirect
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 // indirect
golang.org/x/text v0.3.7 // indirect
golang.org/x/tools v0.1.12 // indirect
google.golang.org/genproto v0.0.0-20210828152312-66f60bf46e71 // indirect
google.golang.org/grpc v1.41.0 // indirect
google.golang.org/protobuf v1.28.1 // indirect
golang.org/x/sys v0.8.0 // indirect
golang.org/x/term v0.6.0 // indirect
golang.org/x/text v0.8.0 // indirect
golang.org/x/tools v0.6.0 // indirect
google.golang.org/genproto v0.0.0-20230306155012-7f2fa6fef1f4 // indirect
google.golang.org/grpc v1.55.0 // indirect
google.golang.org/protobuf v1.30.0 // indirect
gopkg.in/ini.v1 v1.63.2 // indirect
gopkg.in/natefinch/npipe.v2 v2.0.0-20160621034901-c1b8fa8bdcce // indirect
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 // indirect
Expand All @@ -176,4 +176,5 @@ require (
replace (
github.com/agl/ed25519 => github.com/binance-chain/edwards25519 v0.0.0-20200305024217-f36fc4b53d43
github.com/binance-chain/tss-lib => github.com/ChainSafe/threshlib v0.0.0-20230420112309-603112eb4684

)
Loading

0 comments on commit ba919d6

Please sign in to comment.