Skip to content

Commit

Permalink
Merge pull request #84 from celestiaorg/update_otel
Browse files Browse the repository at this point in the history
chore(deps): bump otel
  • Loading branch information
renaynay authored Jul 13, 2023
2 parents 37081bb + 3afbd1f commit fe0c963
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 89 deletions.
10 changes: 5 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ require (
github.com/ipfs/go-log/v2 v2.5.1
github.com/libp2p/go-libp2p v0.26.3
github.com/libp2p/go-libp2p-pubsub v0.9.3
github.com/stretchr/testify v1.8.1
go.opentelemetry.io/otel v1.11.2
go.opentelemetry.io/otel/metric v0.34.0
go.opentelemetry.io/otel/trace v1.11.2
github.com/stretchr/testify v1.8.3
go.opentelemetry.io/otel v1.16.0
go.opentelemetry.io/otel/metric v1.16.0
go.opentelemetry.io/otel/trace v1.16.0
golang.org/x/crypto v0.7.0
)

Expand All @@ -28,7 +28,7 @@ require (
github.com/davidlazar/go-crypto v0.0.0-20200604182044-b73af7476f6c // indirect
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.1.0 // indirect
github.com/francoispqt/gojay v1.2.13 // indirect
github.com/go-logr/logr v1.2.3 // indirect
github.com/go-logr/logr v1.2.4 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0 // indirect
github.com/golang/mock v1.6.0 // indirect
Expand Down
23 changes: 10 additions & 13 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,8 @@ github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V
github.com/go-logfmt/logfmt v0.5.0/go.mod h1:wCYkCAKZfumFQihp8CzCvQ3paCTfi41vtzG1KdI/P7A=
github.com/go-logfmt/logfmt v0.5.1/go.mod h1:WYhtIu8zTZfxdn5+rREduYbwxfcBr/Vr6KEVveWlfTs=
github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
github.com/go-logr/logr v1.2.3 h1:2DntVwHkVopvECVRSlL5PSo9eG+cAkDCuckLubN+rq0=
github.com/go-logr/logr v1.2.3/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
github.com/go-logr/logr v1.2.4 h1:g01GSCwiDw2xSZfjJ2/T9M+S6pFdcNtFYsp+Y43HYDQ=
github.com/go-logr/logr v1.2.4/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag=
github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE=
github.com/go-sql-driver/mysql v1.4.0/go.mod h1:zAC/RDZ24gD3HViQzih4MyKcchzm+sOG5ZlKdlhCg5w=
Expand Down Expand Up @@ -835,17 +835,14 @@ github.com/streadway/amqp v0.0.0-20190827072141-edfb9018d271/go.mod h1:AZpEONHx3
github.com/streadway/handy v0.0.0-20190108123426-d5acb3125c2a/go.mod h1:qNTQ5P5JnDBl6z3cMAg/SywNDC5ABu5ApDIw6lUbRmI=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk=
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
github.com/stretchr/testify v1.8.3 h1:RP3t2pwF7cMEbC1dqtB6poj3niw/9gnV4Cjg5oW5gtY=
github.com/stretchr/testify v1.8.3/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/syndtr/goleveldb v1.0.0/go.mod h1:ZVVdQEZoIme9iO1Ch2Jdy24qqXrMMOU6lpPAyBWyWuQ=
github.com/tarm/serial v0.0.0-20180830185346-98f6abe2eb07/go.mod h1:kDXzergiv9cbyO7IOYJZWg1U88JhDg3PB6klq9Hg2pA=
github.com/tmc/grpc-websocket-proxy v0.0.0-20170815181823-89b8d40f7ca8/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U=
Expand Down Expand Up @@ -877,12 +874,12 @@ go.opencensus.io v0.22.0/go.mod h1:+kGneAE2xo2IficOXnaByMWTGM9T73dGwxeWcUqIpI8=
go.opencensus.io v0.22.2/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw=
go.opencensus.io v0.22.3/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw=
go.opencensus.io v0.22.4/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw=
go.opentelemetry.io/otel v1.11.2 h1:YBZcQlsVekzFsFbjygXMOXSs6pialIZxcjfO/mBDmR0=
go.opentelemetry.io/otel v1.11.2/go.mod h1:7p4EUV+AqgdlNV9gL97IgUZiVR3yrFXYo53f9BM3tRI=
go.opentelemetry.io/otel/metric v0.34.0 h1:MCPoQxcg/26EuuJwpYN1mZTeCYAUGx8ABxfW07YkjP8=
go.opentelemetry.io/otel/metric v0.34.0/go.mod h1:ZFuI4yQGNCupurTXCwkeD/zHBt+C2bR7bw5JqUm/AP8=
go.opentelemetry.io/otel/trace v1.11.2 h1:Xf7hWSF2Glv0DE3MH7fBHvtpSBsjcBUe5MYAmZM/+y0=
go.opentelemetry.io/otel/trace v1.11.2/go.mod h1:4N+yC7QEz7TTsG9BSRLNAa63eg5E06ObSbKPmxQ/pKA=
go.opentelemetry.io/otel v1.16.0 h1:Z7GVAX/UkAXPKsy94IU+i6thsQS4nb7LviLpnaNeW8s=
go.opentelemetry.io/otel v1.16.0/go.mod h1:vl0h9NUa1D5s1nv3A5vZOYWn8av4K8Ml6JDeHrT/bx4=
go.opentelemetry.io/otel/metric v1.16.0 h1:RbrpwVG1Hfv85LgnZ7+txXioPDoh6EdbZHo26Q3hqOo=
go.opentelemetry.io/otel/metric v1.16.0/go.mod h1:QE47cpOmkwipPiefDwo2wDzwJrlfxxNYodqc4xnGCo4=
go.opentelemetry.io/otel/trace v1.16.0 h1:8JRpaObFoW0pxuVPapkgH8UhHQj+bJW8jJsCZEu5MQs=
go.opentelemetry.io/otel/trace v1.16.0/go.mod h1:Yt9vYq1SdNz3xdjZZK7wcXv1qv2pwLkqr2QVwea0ef0=
go.opentelemetry.io/proto/otlp v0.7.0/go.mod h1:PqfVotwruBrMGOCsRd/89rSnXhoiJIqeYNgFYFoEGnI=
go.uber.org/atomic v1.3.2/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE=
go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE=
Expand Down
49 changes: 21 additions & 28 deletions metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,43 +4,36 @@ import (
"context"
"time"

"go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/metric/global"
"go.opentelemetry.io/otel/metric/instrument"
"go.opentelemetry.io/otel/metric/unit"
"go.opentelemetry.io/otel/metric"
)

var meter = global.MeterProvider().Meter("header")
var meter = otel.Meter("header")

// WithMetrics enables Otel metrics to monitor head and total amount of synced headers.
func WithMetrics[H Header](store Store[H]) error {
headC, _ := meter.AsyncInt64().Counter(
headC, _ := meter.Int64ObservableCounter(
"head",
instrument.WithUnit(unit.Dimensionless),
instrument.WithDescription("Subjective head of the node"),
metric.WithDescription("Subjective head of the node"),
)

err := meter.RegisterCallback(
[]instrument.Asynchronous{
headC,
},
func(ctx context.Context) {
// add timeout to limit the time it takes to get the head
// in case there is a deadlock
ctx, cancel := context.WithTimeout(ctx, time.Second)
defer cancel()
callback := func(ctx context.Context, observer metric.Observer) error {
// add timeout to limit the time it takes to get the head
// in case there is a deadlock
ctx, cancel := context.WithTimeout(ctx, time.Second)
defer cancel()

head, err := store.Head(ctx)
if err != nil {
headC.Observe(ctx, 0, attribute.String("err", err.Error()))
return
}

headC.Observe(
ctx,
head.Height(),
)
},
)
head, err := store.Head(ctx)
if err != nil {
observer.ObserveInt64(headC, 0,
metric.WithAttributes(
attribute.String("err", err.Error())))
} else {
observer.ObserveInt64(headC, head.Height())
}
return nil
}
_, err := meter.RegisterCallback(callback, headC)
return err
}
43 changes: 17 additions & 26 deletions p2p/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,38 +3,33 @@ package p2p
import (
"context"

"go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/metric/global"
"go.opentelemetry.io/otel/metric/instrument"
"go.opentelemetry.io/otel/metric/instrument/syncfloat64"
"go.opentelemetry.io/otel/metric"
)

type metrics struct {
responseSize syncfloat64.Histogram
responseDuration syncfloat64.Histogram
responseSize metric.Float64Histogram
responseDuration metric.Float64Histogram
}

var (
meter = global.MeterProvider().Meter("header/p2p")
meter = otel.Meter("header/p2p")
)

func (ex *Exchange[H]) InitMetrics() error {
responseSize, err := meter.
SyncFloat64().
Histogram(
"header_p2p_headers_response_size",
instrument.WithDescription("Size of get headers response in bytes"),
)
responseSize, err := meter.Float64Histogram(
"header_p2p_headers_response_size",
metric.WithDescription("Size of get headers response in bytes"),
)
if err != nil {
return err
}

responseDuration, err := meter.
SyncFloat64().
Histogram(
"header_p2p_headers_request_duration",
instrument.WithDescription("Duration of get headers request in seconds"),
)
responseDuration, err := meter.Float64Histogram(
"header_p2p_headers_request_duration",
metric.WithDescription("Duration of get headers request in seconds"),
)
if err != nil {
return err
}
Expand All @@ -50,14 +45,10 @@ func (m *metrics) observeResponse(ctx context.Context, size uint64, duration uin
if m == nil {
return
}
m.responseSize.Record(
ctx,
float64(size),
attribute.Bool("failed", err != nil),
m.responseSize.Record(ctx, float64(size),
metric.WithAttributes(attribute.Bool("failed", err != nil)),
)
m.responseDuration.Record(
ctx,
float64(duration),
attribute.Bool("failed", err != nil),
m.responseDuration.Record(ctx, float64(duration),
metric.WithAttributes(attribute.Bool("failed", err != nil)),
)
}
30 changes: 13 additions & 17 deletions sync/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import (
"context"
"sync/atomic"

"go.opentelemetry.io/otel/metric/global"
"go.opentelemetry.io/otel/metric/instrument"
"go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/metric"
)

var meter = global.MeterProvider().Meter("header/sync")
var meter = otel.Meter("header/sync")

type metrics struct {
totalSynced int64
Expand All @@ -17,24 +17,20 @@ type metrics struct {
func (s *Syncer[H]) InitMetrics() error {
s.metrics = &metrics{}

totalSynced, err := meter.
AsyncFloat64().
Gauge(
"total_synced_headers",
instrument.WithDescription("total synced headers"),
)
totalSynced, err := meter.Float64ObservableGauge(
"total_synced_headers",
metric.WithDescription("total synced headers"),
)
if err != nil {
return err
}

return meter.RegisterCallback(
[]instrument.Asynchronous{
totalSynced,
},
func(ctx context.Context) {
totalSynced.Observe(ctx, float64(atomic.LoadInt64(&s.metrics.totalSynced)))
},
)
callback := func(ctx context.Context, observer metric.Observer) error {
observer.ObserveFloat64(totalSynced, float64(atomic.LoadInt64(&s.metrics.totalSynced)))
return nil
}
_, err = meter.RegisterCallback(callback, totalSynced)
return err
}

// recordTotalSynced records the total amount of synced headers.
Expand Down

0 comments on commit fe0c963

Please sign in to comment.