diff --git a/backend/main.go b/backend/main.go index 0cf7eec..1d3d0d3 100644 --- a/backend/main.go +++ b/backend/main.go @@ -3,6 +3,12 @@ package main import ( "errors" "fmt" + "log" + "net/http" + "os" + "os/signal" + "sync" + "github.com/ipfs/bifrost-gateway/lib" "github.com/ipfs/boxo/bitswap/client" "github.com/ipfs/boxo/bitswap/network" @@ -15,14 +21,9 @@ import ( "github.com/libp2p/go-libp2p/core/host" "github.com/libp2p/go-libp2p/core/routing" "github.com/spf13/cobra" - "log" - "net/http" - "os" - "os/signal" - "sync" ) -var goLog = golog.Logger("bifrost-gateway-backend") +var goLog = golog.Logger("test-backend") func main() { if err := rootCmd.Execute(); err != nil { diff --git a/blockstore_caboose.go b/blockstore_caboose.go index 19a376a..5021f4e 100644 --- a/blockstore_caboose.go +++ b/blockstore_caboose.go @@ -41,7 +41,7 @@ func newCabooseBlockStore(orchestrator, loggingEndpoint string, cdns *cachedDNS) } saturnOrchestratorClient := &http.Client{ - Timeout: caboose.DefaultSaturnRequestTimeout, + Timeout: caboose.DefaultSaturnOrchestratorRequestTimeout, Transport: &customTransport{ RoundTripper: &http.Transport{ DialContext: cdns.dialWithCachedDNS, @@ -50,7 +50,7 @@ func newCabooseBlockStore(orchestrator, loggingEndpoint string, cdns *cachedDNS) } saturnLoggerClient := &http.Client{ - Timeout: caboose.DefaultSaturnRequestTimeout, + Timeout: caboose.DefaultSaturnLoggerRequestTimeout, Transport: &customTransport{ AuthorizationBearerToken: os.Getenv(EnvSaturnLoggerSecret), RoundTripper: &http.Transport{ @@ -60,7 +60,7 @@ func newCabooseBlockStore(orchestrator, loggingEndpoint string, cdns *cachedDNS) } saturnRetrievalClient := &http.Client{ - Timeout: caboose.DefaultSaturnRequestTimeout, + Timeout: caboose.DefaultSaturnCarRequestTimeout, Transport: &customTransport{ RoundTripper: &http.Transport{ // Increasing concurrency defaults from http.DefaultTransport @@ -93,10 +93,10 @@ func newCabooseBlockStore(orchestrator, loggingEndpoint string, cdns *cachedDNS) LoggingEndpoint: *loggURL, LoggingClient: saturnLoggerClient, - LoggingInterval: 5 * time.Second, + LoggingInterval: caboose.DefaultLoggingInterval, DoValidation: true, - PoolRefresh: 5 * time.Minute, + PoolRefresh: caboose.DefaultPoolRefreshInterval, SaturnClient: saturnRetrievalClient, }) } diff --git a/go.mod b/go.mod index 800c55c..b888f57 100644 --- a/go.mod +++ b/go.mod @@ -4,7 +4,7 @@ go 1.19 require ( github.com/cskr/pubsub v1.0.2 - github.com/filecoin-saturn/caboose v0.0.0-20230329141039-b4cc70873ccd + github.com/filecoin-saturn/caboose v0.0.0-20230329183830-206d01a34454 github.com/gogo/protobuf v1.3.2 github.com/hashicorp/golang-lru/v2 v2.0.1 github.com/ipfs/boxo v0.8.0-rc2.0.20230329082438-360b031ed895 diff --git a/go.sum b/go.sum index 246de2b..d768889 100644 --- a/go.sum +++ b/go.sum @@ -63,8 +63,8 @@ github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymF github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98= github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c= -github.com/filecoin-saturn/caboose v0.0.0-20230329141039-b4cc70873ccd h1:+Je9eB4IlUAG/NP8seXFC5vD+hPM6mYMN4dOEQESSZI= -github.com/filecoin-saturn/caboose v0.0.0-20230329141039-b4cc70873ccd/go.mod h1:u8END6RLUG9ZWudtVHAOOg7ptGiAgKjf/QnNOUOC160= +github.com/filecoin-saturn/caboose v0.0.0-20230329183830-206d01a34454 h1:MXiXj1layzllmRo0FU1zxRQeNDHJPu29tmcjTuWvBAk= +github.com/filecoin-saturn/caboose v0.0.0-20230329183830-206d01a34454/go.mod h1:u8END6RLUG9ZWudtVHAOOg7ptGiAgKjf/QnNOUOC160= github.com/flynn/go-shlex v0.0.0-20150515145356-3f9db97f8568/go.mod h1:xEzjJPgXI435gkrCt3MPfRiAkVrwSbHsst4LCFVfpJc= github.com/flynn/noise v1.0.0 h1:DlTHqmzmvcEiKj+4RYo/imoswx/4r6iBlCMfVtrMXpQ= github.com/flynn/noise v1.0.0/go.mod h1:xbMo+0i6+IGbYdJhF31t2eR1BIU0CYc12+BNAKwUTag= diff --git a/lib/blockstore_cache.go b/lib/blockstore_cache.go index 10fe85e..3bf63f8 100644 --- a/lib/blockstore_cache.go +++ b/lib/blockstore_cache.go @@ -8,7 +8,7 @@ import ( format "github.com/ipfs/go-ipld-format" blockstore "github.com/ipfs/boxo/blockstore" - "github.com/ipfs/go-block-format" + blocks "github.com/ipfs/go-block-format" golog "github.com/ipfs/go-log/v2" lru "github.com/hashicorp/golang-lru/v2" @@ -19,7 +19,7 @@ import ( const DefaultCacheBlockStoreSize = 1024 -var goLog = golog.Logger("cache-blockstore") +var cacheLog = golog.Logger("bifrost-gateway:cache-blockstore") func NewCacheBlockStore(size int) (blockstore.Blockstore, error) { c, err := lru.New2Q[string, []byte](size) @@ -80,16 +80,16 @@ func (l *cacheBlockStore) Get(ctx context.Context, c cid.Cid) (blocks.Block, err blkData, found := l.cache.Get(string(c.Hash())) if !found { - if goLog.Level().Enabled(zapcore.DebugLevel) { - goLog.Debugw("block not found in cache", "cid", c.String()) + if cacheLog.Level().Enabled(zapcore.DebugLevel) { + cacheLog.Debugw("block not found in cache", "cid", c.String()) } return nil, format.ErrNotFound{Cid: c} } // It's a HIT! l.cacheHitsMetric.Add(1) - if goLog.Level().Enabled(zapcore.DebugLevel) { - goLog.Debugw("block found in cache", "cid", c.String()) + if cacheLog.Level().Enabled(zapcore.DebugLevel) { + cacheLog.Debugw("block found in cache", "cid", c.String()) } if l.rehash.Load() { diff --git a/lib/graph_gateway.go b/lib/graph_gateway.go index ad9991b..7b1c1aa 100644 --- a/lib/graph_gateway.go +++ b/lib/graph_gateway.go @@ -4,6 +4,11 @@ import ( "context" "errors" "fmt" + "io" + "net/http" + "runtime" + "sync" + "github.com/filecoin-saturn/caboose" "github.com/ipfs/boxo/blockservice" blockstore "github.com/ipfs/boxo/blockstore" @@ -16,21 +21,20 @@ import ( "github.com/ipfs/boxo/namesys" "github.com/ipfs/boxo/namesys/resolve" ipfspath "github.com/ipfs/boxo/path" - "github.com/ipfs/go-block-format" + blocks "github.com/ipfs/go-block-format" "github.com/ipfs/go-cid" format "github.com/ipfs/go-ipld-format" + golog "github.com/ipfs/go-log/v2" routinghelpers "github.com/libp2p/go-libp2p-routing-helpers" "github.com/libp2p/go-libp2p/core/peer" "github.com/libp2p/go-libp2p/core/routing" "github.com/multiformats/go-multicodec" "github.com/multiformats/go-multihash" "go.uber.org/multierr" - "io" - "net/http" - "runtime" - "sync" ) +var graphLog = golog.Logger("bifrost-gateway:graph-backend") + // type DataCallback = func(resource string, reader io.Reader) error // TODO: Don't use a caboose type, perhaps ask them to use a type alias instead of a type type DataCallback = caboose.DataCallback @@ -187,10 +191,10 @@ func (api *GraphGateway) loadRequestIntoSharedBlockstoreAndBlocksGateway(ctx con } }) if err != nil { - goLog.Error(err) + graphLog.Error(err) } if err := carFetchingExch.Close(); err != nil { - goLog.Error(err) + graphLog.Error(err) } doneWithFetcher <- struct{}{} close(doneWithFetcher) @@ -214,7 +218,7 @@ func (api *GraphGateway) notifyAllOngoingRequests(ctx context.Context, blks ...b for n := range api.notifiers { err := n.NotifyNewBlocks(ctx, blks...) if err != nil { - goLog.Error(fmt.Errorf("notifyAllOngoingRequests failed: %w", err)) + graphLog.Error(fmt.Errorf("notifyAllOngoingRequests failed: %w", err)) } } api.lk.RUnlock() @@ -489,7 +493,7 @@ func (f *handoffExchange) GetBlock(ctx context.Context, c cid.Cid) (blocks.Block select { case <-f.handoffCh: - goLog.Infof("needed to use use a backup fetcher for cid %s", c) + graphLog.Infof("needed to use use a backup fetcher for cid %s", c) return f.followupExchange.GetBlock(ctx, c) case <-ctx.Done(): return nil, ctx.Err() @@ -529,10 +533,10 @@ func (f *handoffExchange) GetBlocks(ctx context.Context, cids []cid.Cid) (<-chan newCidArr = append(newCidArr, c) } } - goLog.Infof("needed to use use a backup fetcher for cids %v", newCidArr) + graphLog.Infof("needed to use use a backup fetcher for cids %v", newCidArr) fch, err := f.followupExchange.GetBlocks(ctx, newCidArr) if err != nil { - goLog.Error(fmt.Errorf("error getting blocks from followup exchange %w", err)) + graphLog.Error(fmt.Errorf("error getting blocks from followup exchange %w", err)) return } for cs.Len() < len(cids) {