-
Notifications
You must be signed in to change notification settings - Fork 22
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
Showing
15 changed files
with
182 additions
and
22 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
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,17 @@ | ||
# Metrics | ||
Metrics are implemented via the OpenTelemetry [stack](https://opentelemetry.io/) and exported to the Opentelemetry [collector](https://opentelemetry.io/docs/collector/) which then be configured to export to supported metrics tools like Datadog. | ||
|
||
## 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 | ||
``` | ||
|
||
## Env variables | ||
- SYG_RELAYER_OPENTELEMETERYCOLLECTORURL - url of the opentelemetry collector application that collects metrics |
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
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,20 @@ | ||
receivers: | ||
otlp: | ||
protocols: | ||
grpc: | ||
http: | ||
|
||
exporters: | ||
prometheus: | ||
endpoint: 0.0.0.0:8889 | ||
namespace: default | ||
|
||
extensions: | ||
health_check: | ||
|
||
service: | ||
extensions: [health_check] | ||
pipelines: | ||
metrics: | ||
exporters: [prometheus] | ||
receivers: [otlp] |
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
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,44 @@ | ||
package metrics | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/ChainSafe/chainbridge-core/opentelemetry" | ||
"go.opentelemetry.io/otel/metric" | ||
) | ||
|
||
type Metrics struct { | ||
opentelemetry.ChainbridgeMetrics | ||
DepositErrorRate metric.Int64Counter | ||
TotalRelayers metric.Int64GaugeObserver | ||
AvailableRelayers metric.Int64GaugeObserver | ||
ExecutionLatency metric.Int64Histogram | ||
|
||
TotalRelayerCount *int64 | ||
AvailableRelayerCount *int64 | ||
} | ||
|
||
// NewMetrics creates an instance of metrics | ||
func NewMetrics(meter metric.Meter) *Metrics { | ||
totalRelayerCount := new(int64) | ||
availableRelayerCount := new(int64) | ||
return &Metrics{ | ||
ChainbridgeMetrics: *opentelemetry.NewChainbridgeMetrics(meter), | ||
TotalRelayers: metric.Must(meter).NewInt64GaugeObserver( | ||
"sygma.TotalRelayers", | ||
func(ctx context.Context, result metric.Int64ObserverResult) { | ||
result.Observe(*totalRelayerCount) | ||
}, | ||
metric.WithDescription("Total number of relayers currently in the subset"), | ||
), | ||
AvailableRelayers: metric.Must(meter).NewInt64GaugeObserver( | ||
"sygma.AvailableRelayers", | ||
func(ctx context.Context, result metric.Int64ObserverResult) { | ||
result.Observe(*availableRelayerCount) | ||
}, | ||
metric.WithDescription("Available number of relayers currently in the subset"), | ||
), | ||
TotalRelayerCount: totalRelayerCount, | ||
AvailableRelayerCount: availableRelayerCount, | ||
} | ||
} |
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,35 @@ | ||
package metrics | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/ChainSafe/chainbridge-core/opentelemetry" | ||
"github.com/libp2p/go-libp2p/core/peer" | ||
"go.opentelemetry.io/otel/attribute" | ||
"go.opentelemetry.io/otel/metric" | ||
) | ||
|
||
type Telemetry struct { | ||
opentelemetry.OpenTelemetry | ||
metrics *Metrics | ||
|
||
meter metric.Meter | ||
} | ||
|
||
// NewTelemetry initializes OpenTelementry metrics | ||
func NewTelemetry(meter metric.Meter) *Telemetry { | ||
coreTelemetry := opentelemetry.NewOpenTelemetry(meter) | ||
metrics := NewMetrics(meter) | ||
|
||
return &Telemetry{ | ||
OpenTelemetry: *coreTelemetry, | ||
metrics: metrics, | ||
meter: meter, | ||
} | ||
} | ||
|
||
func (t *Telemetry) TrackRelayerStatus(unavailable peer.IDSlice, all peer.IDSlice) { | ||
*t.metrics.TotalRelayerCount = int64(len(all)) | ||
*t.metrics.AvailableRelayerCount = int64(len(all) - len(unavailable)) | ||
t.meter.RecordBatch(context.Background(), []attribute.KeyValue{}) | ||
} |