-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(libp2p): expose libp2p bandwidth metrics (#12402)
This exposes bandwidth metrics via async callback to avoid allocating/reporting metrics on any hot-paths. I'm using open telemetry as we've already setup a bridge for F3 and opencensus is deprecated in favor of open telemetry (so we're going to slowly move over anyways).
- Loading branch information
Showing
7 changed files
with
85 additions
and
26 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,21 @@ | ||
package metrics | ||
|
||
import ( | ||
"go.opentelemetry.io/otel" | ||
"go.opentelemetry.io/otel/exporters/prometheus" | ||
"go.opentelemetry.io/otel/sdk/metric" | ||
) | ||
|
||
func init() { | ||
// Set up otel to prometheus reporting so that F3 metrics are reported via lotus | ||
// prometheus metrics. This bridge eventually gets picked up by opencensus | ||
// exporter as HTTP handler. This by default registers an otel collector against | ||
// the global prometheus registry. In the future, we should clean up metrics in | ||
// Lotus and move it all to use otel. For now, bridge away. | ||
if bridge, err := prometheus.New(); err != nil { | ||
log.Errorf("could not create the otel prometheus exporter: %v", err) | ||
} else { | ||
provider := metric.NewMeterProvider(metric.WithReader(bridge)) | ||
otel.SetMeterProvider(provider) | ||
} | ||
} |
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,30 @@ | ||
package lp2p | ||
|
||
import ( | ||
"go.opentelemetry.io/otel" | ||
"go.opentelemetry.io/otel/attribute" | ||
"go.opentelemetry.io/otel/metric" | ||
) | ||
|
||
var otelmeter = otel.Meter("libp2p") | ||
|
||
var attrIdentity = attribute.Key("identity") | ||
var attrProtocolID = attribute.Key("protocol") | ||
var attrDirectionInbound = attribute.String("direction", "inbound") | ||
var attrDirectionOutbound = attribute.String("direction", "outbound") | ||
|
||
var otelmetrics = struct { | ||
bandwidth metric.Int64ObservableCounter | ||
}{ | ||
bandwidth: must(otelmeter.Int64ObservableCounter("lotus_libp2p_bandwidth", | ||
metric.WithDescription("Libp2p stream bandwidth."), | ||
metric.WithUnit("By"), | ||
)), | ||
} | ||
|
||
func must[T any](v T, err error) T { | ||
if err != nil { | ||
panic(err) | ||
} | ||
return v | ||
} |
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