Skip to content
This repository has been archived by the owner on Jun 20, 2024. It is now read-only.

Commit

Permalink
feat: measure context cancellation before CAR fetches (#89)
Browse files Browse the repository at this point in the history
  • Loading branch information
aarshkshah1992 authored Apr 11, 2023
1 parent d87c915 commit b7c3c5a
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions lib/graph_gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,11 @@ type GraphGateway struct {
}

type GraphGatewayMetrics struct {
carFetchAttemptMetric prometheus.Counter
carBlocksFetchedMetric prometheus.Counter
blockRecoveryAttemptMetric prometheus.Counter
carParamsMetric *prometheus.CounterVec
contextAlreadyCancelledMetric prometheus.Counter
carFetchAttemptMetric prometheus.Counter
carBlocksFetchedMetric prometheus.Counter
blockRecoveryAttemptMetric prometheus.Counter
carParamsMetric *prometheus.CounterVec

bytesRangeStartMetric prometheus.Histogram
bytesRangeSizeMetric prometheus.Histogram
Expand Down Expand Up @@ -172,6 +173,14 @@ func registerGraphGatewayMetrics() *GraphGatewayMetrics {
})
prometheus.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)

// How many blocks were read via CARs?
// Need this as a baseline to reason about error ratio vs raw_block_recovery_attempts.
carBlocksFetchedMetric := prometheus.NewCounter(prometheus.CounterOpts{
Expand Down Expand Up @@ -223,6 +232,7 @@ func registerGraphGatewayMetrics() *GraphGatewayMetrics {
prometheus.MustRegister(bytesRangeSizeMetric)

return &GraphGatewayMetrics{
contextAlreadyCancelledMetric,
carFetchAttemptMetric,
carBlocksFetchedMetric,
blockRecoveryAttemptMetric,
Expand Down Expand Up @@ -265,6 +275,11 @@ func (api *GraphGateway) loadRequestIntoSharedBlockstoreAndBlocksGateway(ctx con
}
}()
metrics.carFetchAttemptMetric.Inc()

if ce := ctx.Err(); ce != nil && errors.Is(ce, context.Canceled) {
metrics.contextAlreadyCancelledMetric.Inc()
}

err := api.fetcher.Fetch(ctx, path, func(resource string, reader io.Reader) error {
cr, err := car.NewCarReader(reader)
if err != nil {
Expand Down

0 comments on commit b7c3c5a

Please sign in to comment.