Skip to content
This repository has been archived by the owner on May 9, 2024. It is now read-only.

Commit

Permalink
feat: update OTLP sdk version and add metric tags (#343)
Browse files Browse the repository at this point in the history
* feat: update OTLP sdk version and add metric tags

* renmame opentelemetry file to metrics

* feat: bump go version in workflows

* fix: fix mocks

* fix: fix unit tests

* remove deprecated package from imports

* linter fixes

* feat: replace hardocded params with extandable param list for metric constructor
  • Loading branch information
P1sar committed Jun 6, 2023
1 parent cda9c26 commit bf6ab00
Show file tree
Hide file tree
Showing 15 changed files with 304 additions and 253 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
- name: Install Go
uses: actions/setup-go@v2
with:
go-version: 1.18
go-version: 1.19

- uses: actions/checkout@v2

Expand All @@ -25,7 +25,7 @@ jobs:
steps:
- uses: actions/setup-go@v2
with:
go-version: "1.17.x"
go-version: "1.19.x"
- uses: actions/checkout@v2

- name: Run go vet
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
name: E2E Tests
strategy:
matrix:
go-version: [ 1.15.x ]
go-version: [ 1.19.x ]
platform: [ ubuntu-latest ]
runs-on: ${{ matrix.platform }}
steps:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
test:
strategy:
matrix:
go-version: [1.16.x]
go-version: [1.19.x]
platform: [ubuntu-latest]
runs-on: ${{ matrix.platform }}
steps:
Expand Down
6 changes: 3 additions & 3 deletions chains/evm/listener/listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ type ChainClient interface {
LatestBlock() (*big.Int, error)
}

type Metrics interface {
type BlockDeltaMeter interface {
TrackBlockDelta(domainID uint8, head *big.Int, current *big.Int)
}

type EVMListener struct {
client ChainClient
eventHandlers []EventHandler
metrics Metrics
metrics BlockDeltaMeter

domainID uint8
blockstore *store.BlockStore
Expand All @@ -47,7 +47,7 @@ func NewEVMListener(
client ChainClient,
eventHandlers []EventHandler,
blockstore *store.BlockStore,
metrics Metrics,
metrics BlockDeltaMeter,
domainID uint8,
blockRetryInterval time.Duration,
blockConfirmations *big.Int,
Expand Down
8 changes: 3 additions & 5 deletions config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package config_test

import (
"encoding/json"
"io/ioutil"
"os"
"testing"

Expand Down Expand Up @@ -32,10 +31,9 @@ func (s *GetConfigTestSuite) Test_MissingChainType() {
}},
}
file, _ := json.Marshal(data)
_ = ioutil.WriteFile("test.json", file, 0644)
_ = os.WriteFile("test.json", file, 0644)

_, err := config.GetConfig("test.json")

_ = os.Remove("test.json")
s.NotNil(err)
s.Equal(err.Error(), "Chain 'type' must be provided for every configured chain")
Expand All @@ -51,7 +49,7 @@ func (s *GetConfigTestSuite) Test_InvalidRelayerConfig() {
}},
}
file, _ := json.Marshal(data)
_ = ioutil.WriteFile("test.json", file, 0644)
_ = os.WriteFile("test.json", file, 0644)

_, err := config.GetConfig("test.json")

Expand All @@ -71,7 +69,7 @@ func (s *GetConfigTestSuite) Test_ValidConfig() {
}},
}
file, _ := json.Marshal(data)
_ = ioutil.WriteFile("test.json", file, 0644)
_ = os.WriteFile("test.json", file, 0644)

actualConfig, err := config.GetConfig("test.json")

Expand Down
6 changes: 6 additions & 0 deletions config/relayer/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,16 @@ type RelayerConfig struct {
OpenTelemetryCollectorURL string
LogLevel zerolog.Level
LogFile string
Env string
Id string
}

type RawRelayerConfig struct {
OpenTelemetryCollectorURL string `mapstructure:"OpenTelemetryCollectorURL" json:"opentelemetryCollectorURL"`
LogLevel string `mapstructure:"LogLevel" json:"logLevel" default:"info"`
LogFile string `mapstructure:"LogFile" json:"logFile" default:"out.log"`
Env string `mapstructure:"Env" json:"env"`
Id string `mapstructure:"Id" json:"id"`
}

func (c *RawRelayerConfig) Validate() error {
Expand All @@ -38,6 +42,8 @@ func NewRelayerConfig(rawConfig RawRelayerConfig) (RelayerConfig, error) {

config.LogFile = rawConfig.LogFile
config.OpenTelemetryCollectorURL = rawConfig.OpenTelemetryCollectorURL
config.Env = rawConfig.Env
config.Id = rawConfig.Id

return config, nil
}
15 changes: 13 additions & 2 deletions example/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import (
"syscall"
"time"

"go.opentelemetry.io/otel/attribute"

secp256k1 "github.com/ethereum/go-ethereum/crypto"

"github.com/ChainSafe/chainbridge-core/chains/evm"
Expand Down Expand Up @@ -47,11 +49,20 @@ func Run() error {
}
blockstore := store.NewBlockStore(db)

meter, err := opentelemetry.DefaultMeter(context.Background(), configuration.RelayerConfig.OpenTelemetryCollectorURL)
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)
}
}()

metrics, err := opentelemetry.NewRelayerMetrics(mp.Meter("relayer-metric-provider"), attribute.String("relayerid", configuration.RelayerConfig.Id), attribute.String("env", configuration.RelayerConfig.Env))
if err != nil {
panic(err)
}
metrics := opentelemetry.NewOpenTelemetry(meter)

ctx, cancel := context.WithCancel(context.Background())
chains := []relayer.RelayedChain{}
Expand Down
54 changes: 29 additions & 25 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/ChainSafe/chainbridge-core

go 1.17
go 1.19

require (
github.com/centrifuge/go-substrate-rpc-client v2.0.0+incompatible
Expand All @@ -13,36 +13,42 @@ require (
github.com/spf13/cobra v1.2.1
github.com/spf13/pflag v1.0.5
github.com/spf13/viper v1.9.0
github.com/stretchr/testify v1.7.0
github.com/stretchr/testify v1.8.3
github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7
go.opentelemetry.io/otel/exporters/otlp/otlpmetric v0.24.0
go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp v0.24.0
go.opentelemetry.io/otel/metric v0.24.0
go.opentelemetry.io/otel/sdk/export/metric v0.24.0
go.opentelemetry.io/otel/sdk/metric v0.24.0
go.opentelemetry.io/otel v1.16.0
go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp v0.39.0
go.opentelemetry.io/otel/metric v1.16.0
go.opentelemetry.io/otel/sdk/metric v0.39.0
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211
golang.org/x/term v0.6.0
)

require github.com/status-im/keycard-go v0.0.0-20211004132608-c32310e39b86 // indirect
require (
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
github.com/status-im/keycard-go v0.0.0-20211004132608-c32310e39b86 // indirect
go.opentelemetry.io/otel/exporters/otlp/internal/retry v1.16.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlpmetric v0.39.0 // indirect
)

require (
github.com/StackExchange/wmi v0.0.0-20180116203802-5d049714c4a6 // indirect
github.com/VictoriaMetrics/fastcache v1.6.0 // indirect
github.com/btcsuite/btcd v0.20.1-beta // indirect
github.com/cespare/xxhash/v2 v2.1.1 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/deckarep/golang-set v0.0.0-20180603214616-504e848d77ea // indirect
github.com/edsrzf/mmap-go v1.0.0 // indirect
github.com/fsnotify/fsnotify v1.5.1 // indirect
github.com/gballet/go-libpcsclite v0.0.0-20190607065134-2772fd86a8ff // indirect
github.com/go-ole/go-ole v1.2.1 // indirect
github.com/go-stack/stack v1.8.0 // 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/uuid v1.1.5 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/gorilla/websocket v1.4.2 // indirect
github.com/grpc-ecosystem/grpc-gateway v1.16.0 // indirect
github.com/hashicorp/golang-lru v0.5.5-0.20210104140557-80c98217689d // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/holiman/bloomfilter/v2 v2.0.3 // indirect
Expand All @@ -69,20 +75,18 @@ require (
github.com/tklauser/go-sysconf v0.3.5 // indirect
github.com/tklauser/numcpus v0.2.2 // indirect
github.com/tyler-smith/go-bip39 v1.0.1-0.20181017060643-dbb3b84ba2ef // indirect
go.opentelemetry.io/otel v1.0.1 // indirect
go.opentelemetry.io/otel/internal/metric v0.24.0 // indirect
go.opentelemetry.io/otel/sdk v1.0.1 // indirect
go.opentelemetry.io/otel/trace v1.0.1 // indirect
go.opentelemetry.io/proto/otlp v0.9.0 // indirect
golang.org/x/net v0.0.0-20210805182204-aaa1db679c0d // indirect
go.opentelemetry.io/otel/sdk v1.16.0
go.opentelemetry.io/otel/trace v1.16.0 // indirect
go.opentelemetry.io/proto/otlp v0.19.0 // indirect
golang.org/x/net v0.8.0 // indirect
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c // indirect
golang.org/x/sys v0.0.0-20210823070655-63515b42dcdf // indirect
golang.org/x/text v0.3.6 // indirect
google.golang.org/genproto v0.0.0-20210828152312-66f60bf46e71 // indirect
google.golang.org/grpc v1.41.0 // indirect
google.golang.org/protobuf v1.27.1 // indirect
golang.org/x/sys v0.8.0 // indirect
golang.org/x/text v0.8.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/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
Loading

0 comments on commit bf6ab00

Please sign in to comment.