Skip to content

Commit

Permalink
revert graph backend prometheus
Browse files Browse the repository at this point in the history
  • Loading branch information
hacdias committed Mar 26, 2024
1 parent 07ed1ed commit 5685076
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 11 deletions.
16 changes: 13 additions & 3 deletions gateway/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@ import (
"github.com/ipfs/go-cid"
routinghelpers "github.com/libp2p/go-libp2p-routing-helpers"
"github.com/libp2p/go-libp2p/core/routing"
"github.com/prometheus/client_golang/prometheus"
)

type backendOptions struct {
ns namesys.NameSystem
vs routing.ValueStore
r resolver.Resolver
ns namesys.NameSystem
vs routing.ValueStore
r resolver.Resolver
promRegistry prometheus.Registerer
}

// WithNameSystem sets the name system to use with the different backends. If not set
Expand Down Expand Up @@ -48,6 +50,14 @@ func WithResolver(r resolver.Resolver) BackendOption {
}

Check warning on line 50 in gateway/backend.go

View check run for this annotation

Codecov / codecov/patch

gateway/backend.go#L46-L50

Added lines #L46 - L50 were not covered by tests
}

// WithPrometheusRegistry sets the registry to use with [GraphBackend].
func WithPrometheusRegistry(reg prometheus.Registerer) BackendOption {
return func(opts *backendOptions) error {
opts.promRegistry = reg
return nil
}

Check warning on line 58 in gateway/backend.go

View check run for this annotation

Codecov / codecov/patch

gateway/backend.go#L54-L58

Added lines #L54 - L58 were not covered by tests
}

type BackendOption func(options *backendOptions) error

// baseBackend contains some common backend functionalities that are shared by
Expand Down
21 changes: 13 additions & 8 deletions gateway/backend_graph.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,15 @@ func NewGraphBackend(f CarFetcher, opts ...BackendOption) (*GraphBackend, error)
return nil, err
}

Check warning on line 81 in gateway/backend_graph.go

View check run for this annotation

Codecov / codecov/patch

gateway/backend_graph.go#L80-L81

Added lines #L80 - L81 were not covered by tests

var promReg prometheus.Registerer = prometheus.NewRegistry()
if compiledOptions.promRegistry != nil {
promReg = compiledOptions.promRegistry
}

Check warning on line 86 in gateway/backend_graph.go

View check run for this annotation

Codecov / codecov/patch

gateway/backend_graph.go#L85-L86

Added lines #L85 - L86 were not covered by tests

return &GraphBackend{
baseBackend: baseBackend,
fetcher: f,
metrics: registerGraphBackendMetrics(),
metrics: registerGraphBackendMetrics(promReg),
pc: dagpb.AddSupportToChooser(func(lnk ipld.Link, lnkCtx ipld.LinkContext) (ipld.NodePrototype, error) {
if tlnkNd, ok := lnkCtx.LinkNode.(schema.TypedLinkNode); ok {
return tlnkNd.LinkTargetNodePrototype(), nil
Expand All @@ -93,7 +98,7 @@ func NewGraphBackend(f CarFetcher, opts ...BackendOption) (*GraphBackend, error)
}, nil
}

func registerGraphBackendMetrics() *GraphBackendMetrics {
func registerGraphBackendMetrics(promReg prometheus.Registerer) *GraphBackendMetrics {
// How many CAR Fetch attempts we had? Need this to calculate % of various graph request types.
// We only count attempts here, because success/failure with/without retries are provided by caboose:
// - ipfs_caboose_fetch_duration_car_success_count
Expand All @@ -106,15 +111,15 @@ func registerGraphBackendMetrics() *GraphBackendMetrics {
Name: "car_fetch_attempts",
Help: "The number of times a CAR fetch was attempted by IPFSBackend.",
})
prometheus.MustRegister(carFetchAttemptMetric)
promReg.MustRegister(carFetchAttemptMetric)

contextAlreadyCancelledMetric := prometheus.NewCounter(prometheus.CounterOpts{
Namespace: "ipfs",
Subsystem: "gw_graph_backend",
Name: "car_fetch_context_already_cancelled",
Help: "The number of times context is already cancelled when a CAR fetch was attempted by IPFSBackend.",
})
prometheus.MustRegister(contextAlreadyCancelledMetric)
promReg.MustRegister(contextAlreadyCancelledMetric)

// How many blocks were read via CARs?
// Need this as a baseline to reason about error ratio vs raw_block_recovery_attempts.
Expand All @@ -124,15 +129,15 @@ func registerGraphBackendMetrics() *GraphBackendMetrics {
Name: "car_blocks_fetched",
Help: "The number of blocks successfully read via CAR fetch.",
})
prometheus.MustRegister(carBlocksFetchedMetric)
promReg.MustRegister(carBlocksFetchedMetric)

carParamsMetric := prometheus.NewCounterVec(prometheus.CounterOpts{
Namespace: "ipfs",
Subsystem: "gw_graph_backend",
Name: "car_fetch_params",
Help: "How many times specific CAR parameter was used during CAR data fetch.",
}, []string{"dagScope", "entityRanges"}) // we use 'ranges' instead of 'bytes' here because we only count the number of ranges present
prometheus.MustRegister(carParamsMetric)
promReg.MustRegister(carParamsMetric)

bytesRangeStartMetric := prometheus.NewHistogram(prometheus.HistogramOpts{
Namespace: "ipfs",
Expand All @@ -141,7 +146,7 @@ func registerGraphBackendMetrics() *GraphBackendMetrics {
Help: "Tracks where did the range request start.",
Buckets: prometheus.ExponentialBuckets(1024, 2, 24), // 1024 bytes to 8 GiB
})
prometheus.MustRegister(bytesRangeStartMetric)
promReg.MustRegister(bytesRangeStartMetric)

bytesRangeSizeMetric := prometheus.NewHistogram(prometheus.HistogramOpts{
Namespace: "ipfs",
Expand All @@ -150,7 +155,7 @@ func registerGraphBackendMetrics() *GraphBackendMetrics {
Help: "Tracks the size of range requests.",
Buckets: prometheus.ExponentialBuckets(256*1024, 2, 10), // From 256KiB to 100MiB
})
prometheus.MustRegister(bytesRangeSizeMetric)
promReg.MustRegister(bytesRangeSizeMetric)

return &GraphBackendMetrics{
contextAlreadyCancelledMetric,
Expand Down

0 comments on commit 5685076

Please sign in to comment.