Skip to content

Commit

Permalink
feat: http gateway metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
dirkmc committed Mar 31, 2023
1 parent 68a99ff commit f77b67e
Show file tree
Hide file tree
Showing 5 changed files with 555 additions and 34 deletions.
14 changes: 13 additions & 1 deletion cmd/booster-bitswap/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,19 @@ var runCmd = &cli.Command{
}
defer bcloser()

remoteStore := remoteblockstore.NewRemoteBlockstore(bapi)
bitswapBlockMetrics := remoteblockstore.BlockMetrics{
GetRequestCount: metrics.BitswapRblsGetRequestCount,
GetFailResponseCount: metrics.BitswapRblsGetFailResponseCount,
GetSuccessResponseCount: metrics.BitswapRblsGetSuccessResponseCount,
BytesSentCount: metrics.BitswapRblsBytesSentCount,
HasRequestCount: metrics.BitswapRblsHasRequestCount,
HasFailResponseCount: metrics.BitswapRblsHasFailResponseCount,
HasSuccessResponseCount: metrics.BitswapRblsHasSuccessResponseCount,
GetSizeRequestCount: metrics.BitswapRblsGetSizeRequestCount,
GetSizeFailResponseCount: metrics.BitswapRblsGetSizeFailResponseCount,
GetSizeSuccessResponseCount: metrics.BitswapRblsGetSizeSuccessResponseCount,
}
remoteStore := remoteblockstore.NewRemoteBlockstore(bapi, bitswapBlockMetrics)
// Create the server API
port := cctx.Int("port")
repoDir, err := homedir.Expand(cctx.String(FlagRepo.Name))
Expand Down
16 changes: 15 additions & 1 deletion cmd/booster-http/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"github.com/filecoin-project/boost/cmd/lib"
"github.com/filecoin-project/boost/cmd/lib/filters"
"github.com/filecoin-project/boost/cmd/lib/remoteblockstore"
"github.com/filecoin-project/boost/metrics"
"github.com/filecoin-project/boostd-data/shared/tracing"
"github.com/filecoin-project/dagstore/mount"
"github.com/filecoin-project/go-jsonrpc"
Expand Down Expand Up @@ -168,7 +169,20 @@ var runCmd = &cli.Command{
if err != nil {
return fmt.Errorf("starting block filter: %w", err)
}
rbs := remoteblockstore.NewRemoteBlockstore(bapi)

httpBlockMetrics := remoteblockstore.BlockMetrics{
GetRequestCount: metrics.HttpRblsGetRequestCount,
GetFailResponseCount: metrics.HttpRblsGetFailResponseCount,
GetSuccessResponseCount: metrics.HttpRblsGetSuccessResponseCount,
BytesSentCount: metrics.HttpRblsBytesSentCount,
HasRequestCount: metrics.HttpRblsHasRequestCount,
HasFailResponseCount: metrics.HttpRblsHasFailResponseCount,
HasSuccessResponseCount: metrics.HttpRblsHasSuccessResponseCount,
GetSizeRequestCount: metrics.HttpRblsGetSizeRequestCount,
GetSizeFailResponseCount: metrics.HttpRblsGetSizeFailResponseCount,
GetSizeSuccessResponseCount: metrics.HttpRblsGetSizeSuccessResponseCount,
}
rbs := remoteblockstore.NewRemoteBlockstore(bapi, httpBlockMetrics)
filtered := filters.NewFilteredBlockstore(rbs, multiFilter)
opts.Blockstore = filtered
}
Expand Down
42 changes: 28 additions & 14 deletions cmd/lib/remoteblockstore/remoteblockstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"fmt"
"strings"

"github.com/filecoin-project/boost/metrics"
"github.com/filecoin-project/boostd-data/shared/tracing"
"github.com/ipfs/go-cid"
blockstore "github.com/ipfs/go-ipfs-blockstore"
Expand All @@ -29,49 +28,64 @@ type RemoteBlockstoreAPI interface {

// RemoteBlockstore is a read-only blockstore over all cids across all pieces on a provider.
type RemoteBlockstore struct {
api RemoteBlockstoreAPI
api RemoteBlockstoreAPI
blockMetrics BlockMetrics
}

func NewRemoteBlockstore(api RemoteBlockstoreAPI) blockstore.Blockstore {
type BlockMetrics struct {
GetRequestCount *stats.Int64Measure
GetFailResponseCount *stats.Int64Measure
GetSuccessResponseCount *stats.Int64Measure
BytesSentCount *stats.Int64Measure
HasRequestCount *stats.Int64Measure
HasFailResponseCount *stats.Int64Measure
HasSuccessResponseCount *stats.Int64Measure
GetSizeRequestCount *stats.Int64Measure
GetSizeFailResponseCount *stats.Int64Measure
GetSizeSuccessResponseCount *stats.Int64Measure
}

func NewRemoteBlockstore(api RemoteBlockstoreAPI, blockMetrics BlockMetrics) blockstore.Blockstore {
return &RemoteBlockstore{
api: api,
api: api,
blockMetrics: blockMetrics,
}
}

func (ro *RemoteBlockstore) Get(ctx context.Context, c cid.Cid) (b blocks.Block, err error) {
ctx, span := tracing.Tracer.Start(ctx, "rbls.get")
defer span.End()
span.SetAttributes(attribute.String("cid", c.String()))
stats.Record(ctx, metrics.BitswapRblsGetRequestCount.M(1))
stats.Record(ctx, ro.blockMetrics.GetRequestCount.M(1))

log.Debugw("Get", "cid", c)
data, err := ro.api.BlockstoreGet(ctx, c)
err = normalizeError(err)
log.Debugw("Get response", "cid", c, "size", len(data), "error", err)
if err != nil {
log.Infow("Get failed", "cid", c, "error", err)
stats.Record(ctx, metrics.BitswapRblsGetFailResponseCount.M(1))
stats.Record(ctx, ro.blockMetrics.GetFailResponseCount.M(1))
return nil, err
}
log.Infow("Get", "cid", c, "size", len(data))
stats.Record(ctx, metrics.BitswapRblsGetSuccessResponseCount.M(1))
stats.Record(ctx, metrics.BitswapRblsBytesSentCount.M(int64(len(data))))
stats.Record(ctx, ro.blockMetrics.GetSuccessResponseCount.M(1))
stats.Record(ctx, ro.blockMetrics.BytesSentCount.M(int64(len(data))))
return blocks.NewBlockWithCid(data, c)
}

func (ro *RemoteBlockstore) Has(ctx context.Context, c cid.Cid) (bool, error) {
ctx, span := tracing.Tracer.Start(ctx, "rbls.has")
defer span.End()
span.SetAttributes(attribute.String("cid", c.String()))
stats.Record(ctx, metrics.BitswapRblsHasRequestCount.M(1))
stats.Record(ctx, ro.blockMetrics.HasRequestCount.M(1))

log.Debugw("Has", "cid", c)
has, err := ro.api.BlockstoreHas(ctx, c)
log.Debugw("Has response", "cid", c, "has", has, "error", err)
if err != nil {
stats.Record(ctx, metrics.BitswapRblsHasFailResponseCount.M(1))
stats.Record(ctx, ro.blockMetrics.HasFailResponseCount.M(1))
} else {
stats.Record(ctx, metrics.BitswapRblsHasSuccessResponseCount.M(1))
stats.Record(ctx, ro.blockMetrics.HasSuccessResponseCount.M(1))
}
return has, err
}
Expand All @@ -80,16 +94,16 @@ func (ro *RemoteBlockstore) GetSize(ctx context.Context, c cid.Cid) (int, error)
ctx, span := tracing.Tracer.Start(ctx, "rbls.get_size")
defer span.End()
span.SetAttributes(attribute.String("cid", c.String()))
stats.Record(ctx, metrics.BitswapRblsGetSizeRequestCount.M(1))
stats.Record(ctx, ro.blockMetrics.GetSizeRequestCount.M(1))

log.Debugw("GetSize", "cid", c)
size, err := ro.api.BlockstoreGetSize(ctx, c)
err = normalizeError(err)
log.Debugw("GetSize response", "cid", c, "size", size, "error", err)
if err != nil {
stats.Record(ctx, metrics.BitswapRblsGetSizeFailResponseCount.M(1))
stats.Record(ctx, ro.blockMetrics.GetSizeFailResponseCount.M(1))
} else {
stats.Record(ctx, metrics.BitswapRblsGetSizeSuccessResponseCount.M(1))
stats.Record(ctx, ro.blockMetrics.GetSizeSuccessResponseCount.M(1))
}
return size, err
}
Expand Down
Loading

0 comments on commit f77b67e

Please sign in to comment.