-
Notifications
You must be signed in to change notification settings - Fork 919
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
4 changed files
with
70 additions
and
34 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package core | ||
|
||
import ( | ||
"context" | ||
"time" | ||
|
||
"go.opentelemetry.io/otel/metric" | ||
) | ||
|
||
type exchangeMetrics struct { | ||
getByHeightDuration metric.Float64Histogram // TODO move this one | ||
} | ||
|
||
func newExchangeMetrics() (*exchangeMetrics, error) { | ||
m := new(exchangeMetrics) | ||
|
||
var err error | ||
m.getByHeightDuration, err = meter.Float64Histogram( | ||
"core_ex_get_by_height_request_time", | ||
metric.WithDescription("core exchange client getByHeight request time in seconds (per single height)"), | ||
) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return m, nil | ||
} | ||
|
||
func (m *exchangeMetrics) observe(ctx context.Context, observeFn func(ctx context.Context)) { | ||
if m == nil { | ||
return | ||
} | ||
|
||
if ctx.Err() != nil { | ||
ctx = context.Background() | ||
} | ||
|
||
observeFn(ctx) | ||
} | ||
|
||
func (m *exchangeMetrics) requestDurationPerHeader(ctx context.Context, duration time.Duration, amount uint64) { | ||
m.observe(ctx, func(ctx context.Context) { | ||
if amount == 0 { | ||
// TODO could this happen? | ||
return | ||
} | ||
durationPerHeader := duration.Seconds() / float64(amount) | ||
m.getByHeightDuration.Record(ctx, durationPerHeader) | ||
}) | ||
} |
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