diff --git a/cmd/booster-bitswap/remoteblockstore/remoteblockstore.go b/cmd/booster-bitswap/remoteblockstore/remoteblockstore.go index bd9611b08..10bc4be03 100644 --- a/cmd/booster-bitswap/remoteblockstore/remoteblockstore.go +++ b/cmd/booster-bitswap/remoteblockstore/remoteblockstore.go @@ -4,8 +4,10 @@ import ( "context" "errors" + "github.com/filecoin-project/boost/tracing" blocks "github.com/ipfs/go-block-format" logging "github.com/ipfs/go-log/v2" + "go.opentelemetry.io/otel/attribute" "github.com/ipfs/go-cid" blockstore "github.com/ipfs/go-ipfs-blockstore" @@ -33,6 +35,10 @@ func NewRemoteBlockstore(api RemoteBlockstoreAPI) blockstore.Blockstore { } 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())) + log.Debugw("Get", "cid", c) data, err := ro.api.BlockstoreGet(ctx, c) log.Debugw("Get response", "cid", c, "error", err) @@ -43,6 +49,10 @@ func (ro *RemoteBlockstore) Get(ctx context.Context, c cid.Cid) (b blocks.Block, } 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())) + log.Debugw("Has", "cid", c) has, err := ro.api.BlockstoreHas(ctx, c) log.Debugw("Has response", "cid", c, "has", has, "error", err) @@ -50,6 +60,10 @@ func (ro *RemoteBlockstore) Has(ctx context.Context, c cid.Cid) (bool, error) { } 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())) + log.Debugw("GetSize", "cid", c) size, err := ro.api.BlockstoreGetSize(ctx, c) log.Debugw("GetSize response", "cid", c, "size", size, "error", err) diff --git a/cmd/booster-bitswap/run.go b/cmd/booster-bitswap/run.go index f5c43cb36..372fc09a5 100644 --- a/cmd/booster-bitswap/run.go +++ b/cmd/booster-bitswap/run.go @@ -11,6 +11,7 @@ import ( bclient "github.com/filecoin-project/boost/api/client" cliutil "github.com/filecoin-project/boost/cli/util" "github.com/filecoin-project/boost/cmd/booster-bitswap/remoteblockstore" + "github.com/filecoin-project/boost/tracing" "github.com/filecoin-project/go-jsonrpc" lcli "github.com/filecoin-project/lotus/cli" "github.com/urfave/cli/v2" @@ -35,6 +36,16 @@ var runCmd = &cli.Command{ Usage: "the endpoint for the boost API", Required: true, }, + &cli.BoolFlag{ + Name: "tracing", + Usage: "enables tracing of booster-bitswap calls", + Value: false, + }, + &cli.StringFlag{ + Name: "tracing-endpoint", + Usage: "the endpoint for the tracing exporter", + Value: "http://tempo:14268/api/traces", + }, }, Action: func(cctx *cli.Context) error { if cctx.Bool("pprof") { @@ -46,8 +57,22 @@ var runCmd = &cli.Command{ }() } - // Connect to the Boost API ctx := lcli.ReqContext(cctx) + + // Instantiate the tracer and exporter + if cctx.Bool("tracing") { + tracingStopper, err := tracing.New("booster-bitswap", cctx.String("tracing-endpoint")) + if err != nil { + return fmt.Errorf("failed to instantiate tracer: %w", err) + } + log.Info("Tracing exporter enabled") + + defer func() { + _ = tracingStopper(ctx) + }() + } + + // Connect to the Boost API boostAPIInfo := cctx.String("api-boost") bapi, bcloser, err := getBoostAPI(ctx, boostAPIInfo) if err != nil { diff --git a/docker/devnet/.env b/docker/devnet/.env index e1ebb96a2..fbc04d80b 100644 --- a/docker/devnet/.env +++ b/docker/devnet/.env @@ -3,4 +3,5 @@ LOTUS_IMAGE=${DOCKER_USER}/lotus-dev:1.17.1-rc2 LOTUS_MINER_IMAGE=${DOCKER_USER}/lotus-miner-dev:1.17.1-rc2 BOOST_IMAGE=${DOCKER_USER}/boost-dev:dev BOOSTER_HTTP_IMAGE=${DOCKER_USER}/booster-http-dev:dev +BOOSTER_BITSWAP_IMAGE=${DOCKER_USER}/booster-bitswap-dev:dev BOOST_GUI_IMAGE=${DOCKER_USER}/boost-gui:dev diff --git a/docker/devnet/booster-bitswap/Dockerfile.source b/docker/devnet/booster-bitswap/Dockerfile.source new file mode 100644 index 000000000..4dff187c6 --- /dev/null +++ b/docker/devnet/booster-bitswap/Dockerfile.source @@ -0,0 +1,59 @@ +######################################################################################### +## docker will invoke this file from ../../.. dir in order to access the code +######################################################################################### +ARG LOTUS_TEST_IMAGE=filecoin/lotus-test:latest +FROM ${LOTUS_TEST_IMAGE} as lotus-dev +######################################################################################### +FROM golang:1.18-bullseye as builder + +RUN apt update && apt install -y \ + build-essential \ + bzr pkg-config \ + clang \ + curl \ + gcc git \ + hwloc \ + jq \ + libhwloc-dev wget \ + mesa-opencl-icd \ + ocl-icd-opencl-dev + +WORKDIR /go/src/ + +# copy src +COPY . /go/src/ + +RUN make booster-bitswap debug +######################################################################################### +FROM ubuntu:20.04 as runner + +RUN apt update && apt install -y \ + curl \ + hwloc \ + jq + +ARG BUILD_VERSION=0.1 + +LABEL org.opencontainers.image.version=$BUILD_VERSION \ + org.opencontainers.image.authors="Boost Dev Team" \ + name="booster-bitswap-dev" \ + maintainer="Boost Dev Team" \ + vendor="Boost Dev Team" \ + version=$BUILD_VERSION \ + release=$BUILD_VERSION \ + summary="This image is used to host booster-bitswap-dev" \ + description="This image is used to host booster-bitswap-dev" + +WORKDIR /app +EXPOSE 8888 + +COPY --from=builder /go/src/booster-bitswap /usr/local/bin/ +COPY --from=builder /go/src/boostd /usr/local/bin/ +COPY --from=lotus-dev /usr/local/bin/lotus /usr/local/bin/ +COPY --from=lotus-dev /usr/local/bin/lotus-miner /usr/local/bin/ +## Fix missing lib libhwloc.so.5 +RUN ls -1 /lib/x86_64-linux-gnu/libhwloc.so.* | head -n 1 | xargs -n1 -I {} ln -s {} /lib/x86_64-linux-gnu/libhwloc.so.5 + +COPY docker/devnet/booster-bitswap/entrypoint.sh /app/ + +ENTRYPOINT ["./entrypoint.sh"] diff --git a/docker/devnet/booster-bitswap/Makefile b/docker/devnet/booster-bitswap/Makefile new file mode 100644 index 000000000..05af1d355 --- /dev/null +++ b/docker/devnet/booster-bitswap/Makefile @@ -0,0 +1,19 @@ +##################################################################################### +service=$(docker_user)/booster-bitswap-dev +version=dev +########### DOCKER ################################################################## +tag=$(service):$(version) +rootdir=$(realpath .) + +dbuild: + docker build --build-arg LOTUS_TEST_IMAGE=$(lotus_test_image) \ + -t $(tag) -f Dockerfile.source $(rootdir)/../../../ + +dpush: dbuild + docker push $(tag) + +dscan: dbuild + docker scan --accept-license $(tag) +##################################################################################### +.PHONY: + dbuild dpush dscan diff --git a/docker/devnet/booster-bitswap/entrypoint.sh b/docker/devnet/booster-bitswap/entrypoint.sh new file mode 100755 index 000000000..c80a6b400 --- /dev/null +++ b/docker/devnet/booster-bitswap/entrypoint.sh @@ -0,0 +1,13 @@ +#!/usr/bin/env bash +set -e + +export FULLNODE_API_INFO=`lotus auth api-info --perm=admin | cut -f2 -d=` +export MINER_API_INFO=`lotus-miner auth api-info --perm=admin | cut -f2 -d=` +export BOOST_API_INFO=`boostd auth api-info --perm=admin | cut -f2 -d=` + +echo $FULLNODE_API_INFO +echo $MINER_API_INFO +echo $BOOST_API_INFO + +echo Starting booster-bitswap... +exec booster-bitswap run --api-boost=$BOOST_API_INFO --tracing diff --git a/docker/devnet/docker-compose.yaml b/docker/devnet/docker-compose.yaml index d00843b75..4408500eb 100644 --- a/docker/devnet/docker-compose.yaml +++ b/docker/devnet/docker-compose.yaml @@ -82,6 +82,22 @@ services: - ./data/lotus:/var/lib/lotus:ro - ./data/lotus-miner:/var/lib/lotus-miner:ro + booster-bitswap: + container_name: booster-bitswap + image: ${BOOSTER_BITSWAP_IMAGE} + ports: + - "8888:8888" + environment: + - BOOST_PATH=/var/lib/boost + - LOTUS_PATH=/var/lib/lotus + - LOTUS_MINER_PATH=/var/lib/lotus-miner + restart: unless-stopped + logging: *default-logging + volumes: + - ./data/boost:/var/lib/boost:ro + - ./data/lotus:/var/lib/lotus:ro + - ./data/lotus-miner:/var/lib/lotus-miner:ro + demo-http-server: container_name: demo-http-server image: nginx:1.23-alpine