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

Commit bf6ab00

Browse files
authored
feat: update OTLP sdk version and add metric tags (#343)
* 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
1 parent cda9c26 commit bf6ab00

File tree

15 files changed

+304
-253
lines changed

15 files changed

+304
-253
lines changed

.github/workflows/checks.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ jobs:
1010
- name: Install Go
1111
uses: actions/setup-go@v2
1212
with:
13-
go-version: 1.18
13+
go-version: 1.19
1414

1515
- uses: actions/checkout@v2
1616

@@ -25,7 +25,7 @@ jobs:
2525
steps:
2626
- uses: actions/setup-go@v2
2727
with:
28-
go-version: "1.17.x"
28+
go-version: "1.19.x"
2929
- uses: actions/checkout@v2
3030

3131
- name: Run go vet

.github/workflows/e2e.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ jobs:
1212
name: E2E Tests
1313
strategy:
1414
matrix:
15-
go-version: [ 1.15.x ]
15+
go-version: [ 1.19.x ]
1616
platform: [ ubuntu-latest ]
1717
runs-on: ${{ matrix.platform }}
1818
steps:

.github/workflows/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ jobs:
1111
test:
1212
strategy:
1313
matrix:
14-
go-version: [1.16.x]
14+
go-version: [1.19.x]
1515
platform: [ubuntu-latest]
1616
runs-on: ${{ matrix.platform }}
1717
steps:

chains/evm/listener/listener.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,14 @@ type ChainClient interface {
2323
LatestBlock() (*big.Int, error)
2424
}
2525

26-
type Metrics interface {
26+
type BlockDeltaMeter interface {
2727
TrackBlockDelta(domainID uint8, head *big.Int, current *big.Int)
2828
}
2929

3030
type EVMListener struct {
3131
client ChainClient
3232
eventHandlers []EventHandler
33-
metrics Metrics
33+
metrics BlockDeltaMeter
3434

3535
domainID uint8
3636
blockstore *store.BlockStore
@@ -47,7 +47,7 @@ func NewEVMListener(
4747
client ChainClient,
4848
eventHandlers []EventHandler,
4949
blockstore *store.BlockStore,
50-
metrics Metrics,
50+
metrics BlockDeltaMeter,
5151
domainID uint8,
5252
blockRetryInterval time.Duration,
5353
blockConfirmations *big.Int,

config/config_test.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package config_test
22

33
import (
44
"encoding/json"
5-
"io/ioutil"
65
"os"
76
"testing"
87

@@ -32,10 +31,9 @@ func (s *GetConfigTestSuite) Test_MissingChainType() {
3231
}},
3332
}
3433
file, _ := json.Marshal(data)
35-
_ = ioutil.WriteFile("test.json", file, 0644)
34+
_ = os.WriteFile("test.json", file, 0644)
3635

3736
_, err := config.GetConfig("test.json")
38-
3937
_ = os.Remove("test.json")
4038
s.NotNil(err)
4139
s.Equal(err.Error(), "Chain 'type' must be provided for every configured chain")
@@ -51,7 +49,7 @@ func (s *GetConfigTestSuite) Test_InvalidRelayerConfig() {
5149
}},
5250
}
5351
file, _ := json.Marshal(data)
54-
_ = ioutil.WriteFile("test.json", file, 0644)
52+
_ = os.WriteFile("test.json", file, 0644)
5553

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

@@ -71,7 +69,7 @@ func (s *GetConfigTestSuite) Test_ValidConfig() {
7169
}},
7270
}
7371
file, _ := json.Marshal(data)
74-
_ = ioutil.WriteFile("test.json", file, 0644)
72+
_ = os.WriteFile("test.json", file, 0644)
7573

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

config/relayer/config.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,16 @@ type RelayerConfig struct {
1010
OpenTelemetryCollectorURL string
1111
LogLevel zerolog.Level
1212
LogFile string
13+
Env string
14+
Id string
1315
}
1416

1517
type RawRelayerConfig struct {
1618
OpenTelemetryCollectorURL string `mapstructure:"OpenTelemetryCollectorURL" json:"opentelemetryCollectorURL"`
1719
LogLevel string `mapstructure:"LogLevel" json:"logLevel" default:"info"`
1820
LogFile string `mapstructure:"LogFile" json:"logFile" default:"out.log"`
21+
Env string `mapstructure:"Env" json:"env"`
22+
Id string `mapstructure:"Id" json:"id"`
1923
}
2024

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

3943
config.LogFile = rawConfig.LogFile
4044
config.OpenTelemetryCollectorURL = rawConfig.OpenTelemetryCollectorURL
45+
config.Env = rawConfig.Env
46+
config.Id = rawConfig.Id
4147

4248
return config, nil
4349
}

example/app/app.go

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ import (
1111
"syscall"
1212
"time"
1313

14+
"go.opentelemetry.io/otel/attribute"
15+
1416
secp256k1 "github.com/ethereum/go-ethereum/crypto"
1517

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

50-
meter, err := opentelemetry.DefaultMeter(context.Background(), configuration.RelayerConfig.OpenTelemetryCollectorURL)
52+
mp, err := opentelemetry.InitMetricProvider(context.Background(), configuration.RelayerConfig.OpenTelemetryCollectorURL)
53+
if err != nil {
54+
panic(err)
55+
}
56+
defer func() {
57+
if err := mp.Shutdown(context.Background()); err != nil {
58+
log.Error().Msgf("Error shutting down meter provider: %v", err)
59+
}
60+
}()
61+
62+
metrics, err := opentelemetry.NewRelayerMetrics(mp.Meter("relayer-metric-provider"), attribute.String("relayerid", configuration.RelayerConfig.Id), attribute.String("env", configuration.RelayerConfig.Env))
5163
if err != nil {
5264
panic(err)
5365
}
54-
metrics := opentelemetry.NewOpenTelemetry(meter)
5566

5667
ctx, cancel := context.WithCancel(context.Background())
5768
chains := []relayer.RelayedChain{}

go.mod

Lines changed: 29 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module github.com/ChainSafe/chainbridge-core
22

3-
go 1.17
3+
go 1.19
44

55
require (
66
github.com/centrifuge/go-substrate-rpc-client v2.0.0+incompatible
@@ -13,36 +13,42 @@ require (
1313
github.com/spf13/cobra v1.2.1
1414
github.com/spf13/pflag v1.0.5
1515
github.com/spf13/viper v1.9.0
16-
github.com/stretchr/testify v1.7.0
16+
github.com/stretchr/testify v1.8.3
1717
github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7
18-
go.opentelemetry.io/otel/exporters/otlp/otlpmetric v0.24.0
19-
go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp v0.24.0
20-
go.opentelemetry.io/otel/metric v0.24.0
21-
go.opentelemetry.io/otel/sdk/export/metric v0.24.0
22-
go.opentelemetry.io/otel/sdk/metric v0.24.0
18+
go.opentelemetry.io/otel v1.16.0
19+
go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp v0.39.0
20+
go.opentelemetry.io/otel/metric v1.16.0
21+
go.opentelemetry.io/otel/sdk/metric v0.39.0
2322
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519
24-
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211
23+
golang.org/x/term v0.6.0
2524
)
2625

27-
require github.com/status-im/keycard-go v0.0.0-20211004132608-c32310e39b86 // indirect
26+
require (
27+
github.com/cenkalti/backoff/v4 v4.2.1 // indirect
28+
github.com/go-logr/logr v1.2.4 // indirect
29+
github.com/go-logr/stdr v1.2.2 // indirect
30+
github.com/grpc-ecosystem/grpc-gateway/v2 v2.7.0 // indirect
31+
github.com/status-im/keycard-go v0.0.0-20211004132608-c32310e39b86 // indirect
32+
go.opentelemetry.io/otel/exporters/otlp/internal/retry v1.16.0 // indirect
33+
go.opentelemetry.io/otel/exporters/otlp/otlpmetric v0.39.0 // indirect
34+
)
2835

2936
require (
3037
github.com/StackExchange/wmi v0.0.0-20180116203802-5d049714c4a6 // indirect
3138
github.com/VictoriaMetrics/fastcache v1.6.0 // indirect
3239
github.com/btcsuite/btcd v0.20.1-beta // indirect
33-
github.com/cespare/xxhash/v2 v2.1.1 // indirect
40+
github.com/cespare/xxhash/v2 v2.2.0 // indirect
3441
github.com/davecgh/go-spew v1.1.1 // indirect
3542
github.com/deckarep/golang-set v0.0.0-20180603214616-504e848d77ea // indirect
3643
github.com/edsrzf/mmap-go v1.0.0 // indirect
3744
github.com/fsnotify/fsnotify v1.5.1 // indirect
3845
github.com/gballet/go-libpcsclite v0.0.0-20190607065134-2772fd86a8ff // indirect
3946
github.com/go-ole/go-ole v1.2.1 // indirect
4047
github.com/go-stack/stack v1.8.0 // indirect
41-
github.com/golang/protobuf v1.5.2 // indirect
48+
github.com/golang/protobuf v1.5.3 // indirect
4249
github.com/golang/snappy v0.0.4 // indirect
43-
github.com/google/uuid v1.1.5 // indirect
50+
github.com/google/uuid v1.3.0 // indirect
4451
github.com/gorilla/websocket v1.4.2 // indirect
45-
github.com/grpc-ecosystem/grpc-gateway v1.16.0 // indirect
4652
github.com/hashicorp/golang-lru v0.5.5-0.20210104140557-80c98217689d // indirect
4753
github.com/hashicorp/hcl v1.0.0 // indirect
4854
github.com/holiman/bloomfilter/v2 v2.0.3 // indirect
@@ -69,20 +75,18 @@ require (
6975
github.com/tklauser/go-sysconf v0.3.5 // indirect
7076
github.com/tklauser/numcpus v0.2.2 // indirect
7177
github.com/tyler-smith/go-bip39 v1.0.1-0.20181017060643-dbb3b84ba2ef // indirect
72-
go.opentelemetry.io/otel v1.0.1 // indirect
73-
go.opentelemetry.io/otel/internal/metric v0.24.0 // indirect
74-
go.opentelemetry.io/otel/sdk v1.0.1 // indirect
75-
go.opentelemetry.io/otel/trace v1.0.1 // indirect
76-
go.opentelemetry.io/proto/otlp v0.9.0 // indirect
77-
golang.org/x/net v0.0.0-20210805182204-aaa1db679c0d // indirect
78+
go.opentelemetry.io/otel/sdk v1.16.0
79+
go.opentelemetry.io/otel/trace v1.16.0 // indirect
80+
go.opentelemetry.io/proto/otlp v0.19.0 // indirect
81+
golang.org/x/net v0.8.0 // indirect
7882
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c // indirect
79-
golang.org/x/sys v0.0.0-20210823070655-63515b42dcdf // indirect
80-
golang.org/x/text v0.3.6 // indirect
81-
google.golang.org/genproto v0.0.0-20210828152312-66f60bf46e71 // indirect
82-
google.golang.org/grpc v1.41.0 // indirect
83-
google.golang.org/protobuf v1.27.1 // indirect
83+
golang.org/x/sys v0.8.0 // indirect
84+
golang.org/x/text v0.8.0 // indirect
85+
google.golang.org/genproto v0.0.0-20230306155012-7f2fa6fef1f4 // indirect
86+
google.golang.org/grpc v1.55.0 // indirect
87+
google.golang.org/protobuf v1.30.0 // indirect
8488
gopkg.in/ini.v1 v1.63.2 // indirect
8589
gopkg.in/natefinch/npipe.v2 v2.0.0-20160621034901-c1b8fa8bdcce // indirect
8690
gopkg.in/yaml.v2 v2.4.0 // indirect
87-
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect
91+
gopkg.in/yaml.v3 v3.0.1 // indirect
8892
)

0 commit comments

Comments
 (0)