Merge pull request #4691 from filecoin-project/fix/metrics
fix metrics wiring.
This commit is contained in:
commit
1df02d5a93
@ -16,6 +16,7 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
paramfetch "github.com/filecoin-project/go-paramfetch"
|
paramfetch "github.com/filecoin-project/go-paramfetch"
|
||||||
|
metricsprom "github.com/ipfs/go-metrics-prometheus"
|
||||||
"github.com/mitchellh/go-homedir"
|
"github.com/mitchellh/go-homedir"
|
||||||
"github.com/multiformats/go-multiaddr"
|
"github.com/multiformats/go-multiaddr"
|
||||||
"github.com/urfave/cli/v2"
|
"github.com/urfave/cli/v2"
|
||||||
@ -262,8 +263,14 @@ var DaemonCmd = &cli.Command{
|
|||||||
liteModeDeps = node.Override(new(api.GatewayAPI), gapi)
|
liteModeDeps = node.Override(new(api.GatewayAPI), gapi)
|
||||||
}
|
}
|
||||||
|
|
||||||
var api api.FullNode
|
// some libraries like ipfs/go-ds-measure and ipfs/go-ipfs-blockstore
|
||||||
|
// use ipfs/go-metrics-interface. This injects a Prometheus exporter
|
||||||
|
// for those. Metrics are exported to the default registry.
|
||||||
|
if err := metricsprom.Inject(); err != nil {
|
||||||
|
log.Warnf("unable to inject prometheus ipfs/go-metrics exporter; some metrics will be unavailable; err: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
var api api.FullNode
|
||||||
stop, err := node.New(ctx,
|
stop, err := node.New(ctx,
|
||||||
node.FullAPI(&api, node.Lite(isLite)),
|
node.FullAPI(&api, node.Lite(isLite)),
|
||||||
|
|
||||||
|
@ -14,6 +14,7 @@ import (
|
|||||||
logging "github.com/ipfs/go-log/v2"
|
logging "github.com/ipfs/go-log/v2"
|
||||||
"github.com/multiformats/go-multiaddr"
|
"github.com/multiformats/go-multiaddr"
|
||||||
manet "github.com/multiformats/go-multiaddr/net"
|
manet "github.com/multiformats/go-multiaddr/net"
|
||||||
|
promclient "github.com/prometheus/client_golang/prometheus"
|
||||||
"go.opencensus.io/tag"
|
"go.opencensus.io/tag"
|
||||||
"golang.org/x/xerrors"
|
"golang.org/x/xerrors"
|
||||||
|
|
||||||
@ -49,7 +50,16 @@ func serveRPC(a api.FullNode, stop node.StopFunc, addr multiaddr.Multiaddr, shut
|
|||||||
|
|
||||||
http.Handle("/rest/v0/import", importAH)
|
http.Handle("/rest/v0/import", importAH)
|
||||||
|
|
||||||
|
// Prometheus globals are exposed as interfaces, but the prometheus
|
||||||
|
// OpenCensus exporter expects a concrete *Registry. The concrete type of
|
||||||
|
// the globals are actually *Registry, so we downcast them, staying
|
||||||
|
// defensive in case things change under the hood.
|
||||||
|
registry, ok := promclient.DefaultRegisterer.(*promclient.Registry)
|
||||||
|
if !ok {
|
||||||
|
log.Warnf("failed to export default prometheus registry; some metrics will be unavailable; unexpected type: %T", promclient.DefaultRegisterer)
|
||||||
|
}
|
||||||
exporter, err := prometheus.NewExporter(prometheus.Options{
|
exporter, err := prometheus.NewExporter(prometheus.Options{
|
||||||
|
Registry: registry,
|
||||||
Namespace: "lotus",
|
Namespace: "lotus",
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
1
go.mod
1
go.mod
@ -81,6 +81,7 @@ require (
|
|||||||
github.com/ipfs/go-log v1.0.4
|
github.com/ipfs/go-log v1.0.4
|
||||||
github.com/ipfs/go-log/v2 v2.1.2-0.20200626104915-0016c0b4b3e4
|
github.com/ipfs/go-log/v2 v2.1.2-0.20200626104915-0016c0b4b3e4
|
||||||
github.com/ipfs/go-merkledag v0.3.2
|
github.com/ipfs/go-merkledag v0.3.2
|
||||||
|
github.com/ipfs/go-metrics-interface v0.0.1
|
||||||
github.com/ipfs/go-metrics-prometheus v0.0.2
|
github.com/ipfs/go-metrics-prometheus v0.0.2
|
||||||
github.com/ipfs/go-path v0.0.7
|
github.com/ipfs/go-path v0.0.7
|
||||||
github.com/ipfs/go-unixfs v0.2.4
|
github.com/ipfs/go-unixfs v0.2.4
|
||||||
|
@ -5,6 +5,8 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
metricsi "github.com/ipfs/go-metrics-interface"
|
||||||
|
|
||||||
"github.com/filecoin-project/lotus/chain"
|
"github.com/filecoin-project/lotus/chain"
|
||||||
"github.com/filecoin-project/lotus/chain/exchange"
|
"github.com/filecoin-project/lotus/chain/exchange"
|
||||||
"github.com/filecoin-project/lotus/chain/store"
|
"github.com/filecoin-project/lotus/chain/store"
|
||||||
@ -167,7 +169,10 @@ func defaults() []Option {
|
|||||||
Override(new(journal.DisabledEvents), journal.EnvDisabledEvents),
|
Override(new(journal.DisabledEvents), journal.EnvDisabledEvents),
|
||||||
Override(new(journal.Journal), modules.OpenFilesystemJournal),
|
Override(new(journal.Journal), modules.OpenFilesystemJournal),
|
||||||
|
|
||||||
Override(new(helpers.MetricsCtx), context.Background),
|
Override(new(helpers.MetricsCtx), func() context.Context {
|
||||||
|
return metricsi.CtxScope(context.Background(), "lotus")
|
||||||
|
}),
|
||||||
|
|
||||||
Override(new(record.Validator), modules.RecordValidator),
|
Override(new(record.Validator), modules.RecordValidator),
|
||||||
Override(new(dtypes.Bootstrapper), dtypes.Bootstrapper(false)),
|
Override(new(dtypes.Bootstrapper), dtypes.Bootstrapper(false)),
|
||||||
Override(new(dtypes.ShutdownChan), make(chan struct{})),
|
Override(new(dtypes.ShutdownChan), make(chan struct{})),
|
||||||
|
Loading…
Reference in New Issue
Block a user