Skip to content

Commit

Permalink
booster-bitswap devnet and tracing (#796)
Browse files Browse the repository at this point in the history
* add booster-bitswap docker image and container to stack

* add tracing

* lint
  • Loading branch information
nonsense authored Sep 13, 2022
1 parent 83ad7dd commit 7f2aed0
Show file tree
Hide file tree
Showing 7 changed files with 148 additions and 1 deletion.
14 changes: 14 additions & 0 deletions cmd/booster-bitswap/remoteblockstore/remoteblockstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
Expand All @@ -43,13 +49,21 @@ 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)
return has, err
}

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)
Expand Down
27 changes: 26 additions & 1 deletion cmd/booster-bitswap/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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") {
Expand All @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions docker/devnet/.env
Original file line number Diff line number Diff line change
Expand Up @@ -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
59 changes: 59 additions & 0 deletions docker/devnet/booster-bitswap/Dockerfile.source
Original file line number Diff line number Diff line change
@@ -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"]
19 changes: 19 additions & 0 deletions docker/devnet/booster-bitswap/Makefile
Original file line number Diff line number Diff line change
@@ -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
13 changes: 13 additions & 0 deletions docker/devnet/booster-bitswap/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -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
16 changes: 16 additions & 0 deletions docker/devnet/docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 7f2aed0

Please sign in to comment.