From 5891da3817bbb7815c4c08468d9738c54d536f7a Mon Sep 17 00:00:00 2001 From: Gabe <7622243+decentralgabe@users.noreply.github.com> Date: Wed, 17 Jul 2024 09:39:08 -0400 Subject: [PATCH] Reduce log noise (#256) * fix * update * update * tidy * update go version --- .github/workflows/ci.yml | 4 ++-- CONTRIBUTING.md | 6 +++--- README.md | 2 +- impl/build/Dockerfile | 2 +- impl/go.mod | 6 +++--- impl/go.sum | 12 ++++++------ impl/pkg/dht/dht.go | 27 ++++++++++++++++++++------- impl/pkg/service/dht.go | 8 ++++---- 8 files changed, 40 insertions(+), 27 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c26da3a9..e0975407 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -20,7 +20,7 @@ jobs: - name: Set up Go uses: actions/setup-go@v3 with: - go-version: 1.22.4 + go-version: 1.22.5 - name: Install Mage run: go install github.com/magefile/mage @@ -38,7 +38,7 @@ jobs: - name: Set up Go uses: actions/setup-go@v3 with: - go-version: 1.22.4 + go-version: 1.22.5 - name: Install Mage run: go install github.com/magefile/mage diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 9fdbf4c3..d8214fc8 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -16,7 +16,7 @@ This guide is for you. | Requirement | Tested Version | Installation Instructions | |-------------|----------------|-------------------------------------------------------| -| Go | 1.22.4 | [go.dev](https://go.dev/doc/tutorial/compile-install) | +| Go | 1.22.5 | [go.dev](https://go.dev/doc/tutorial/compile-install) | | Mage | 1.15.0-5 | [magefile.org](https://magefile.org/) | ### Go @@ -27,7 +27,7 @@ You may verify your `go` installation via the terminal: ``` $> go version -go version go1.22.4 darwin/amd64 +go version go1.22.5 darwin/amd64 ``` If you do not have go, we recommend installing it by: @@ -54,7 +54,7 @@ $> mage --version Mage Build Tool v1.15.0-5-g2385abb Build Date: 2024-03-21T12:20:13-07:00 Commit: 2385abb -built with: go1.22.4 +built with: go1.22.5 ``` #### MacOS diff --git a/README.md b/README.md index 139da963..931080e2 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ [![godoc did-dht](https://img.shields.io/badge/godoc-did_dht-blue)](https://github.com/TBD54566975/did-dht/impl) -[![go version 1.22.4](https://img.shields.io/badge/go_version-1.22.4-brightgreen)](https://go.dev/) +[![go version 1.22.5](https://img.shields.io/badge/go_version-1.22.5-brightgreen)](https://go.dev/) [![license Apache 2](https://img.shields.io/badge/license-Apache%202-black)](https://github.com/TBD54566975/did-dht/blob/main/LICENSE) [![issues](https://img.shields.io/github/issues/TBD54566975/did-dht)](https://github.com/TBD54566975/did-dht/issues) ![GitHub Actions Workflow Status](https://img.shields.io/github/actions/workflow/status/TBD54566975/did-dht/ci.yml) diff --git a/impl/build/Dockerfile b/impl/build/Dockerfile index 5c0efc65..f4077ffe 100644 --- a/impl/build/Dockerfile +++ b/impl/build/Dockerfile @@ -1,4 +1,4 @@ -FROM golang:1.22.4-alpine +FROM golang:1.22.5-alpine # Create directory for our app inside the container WORKDIR /app diff --git a/impl/go.mod b/impl/go.mod index 6c656446..426a667e 100644 --- a/impl/go.mod +++ b/impl/go.mod @@ -38,7 +38,7 @@ require ( go.opentelemetry.io/otel/sdk v1.27.0 go.opentelemetry.io/otel/sdk/metric v1.27.0 go.opentelemetry.io/otel/trace v1.27.0 - golang.org/x/term v0.21.0 + golang.org/x/term v0.22.0 golang.org/x/time v0.5.0 ) @@ -144,12 +144,12 @@ require ( golang.org/x/mod v0.18.0 // indirect golang.org/x/net v0.26.0 // indirect golang.org/x/sync v0.7.0 // indirect - golang.org/x/sys v0.21.0 // indirect + golang.org/x/sys v0.22.0 // indirect golang.org/x/text v0.16.0 // indirect golang.org/x/tools v0.22.0 // indirect google.golang.org/genproto/googleapis/api v0.0.0-20240520151616-dc85e6b867a5 // indirect google.golang.org/genproto/googleapis/rpc v0.0.0-20240515191416-fc5f0ca64291 // indirect - google.golang.org/grpc v1.64.0 // indirect + google.golang.org/grpc v1.64.1 // indirect google.golang.org/protobuf v1.34.1 // indirect gopkg.in/ini.v1 v1.67.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect diff --git a/impl/go.sum b/impl/go.sum index 9580b3be..d15432b9 100644 --- a/impl/go.sum +++ b/impl/go.sum @@ -550,13 +550,13 @@ golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.21.0 h1:rF+pYz3DAGSQAxAu1CbC7catZg4ebC4UIeIhKxBZvws= -golang.org/x/sys v0.21.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/sys v0.22.0 h1:RI27ohtqKCnwULzJLqkv897zojh5/DwS/ENaMzUOaWI= +golang.org/x/sys v0.22.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k= -golang.org/x/term v0.21.0 h1:WVXCp+/EBEHOj53Rvu+7KiT/iElMrO8ACK16SMZ3jaA= -golang.org/x/term v0.21.0/go.mod h1:ooXLefLobQVslOqselCNF4SxFAaoS6KujMbsGzSDmX0= +golang.org/x/term v0.22.0 h1:BbsgPEJULsl2fV/AT3v15Mjva5yXKQDyKf+TbDz7QJk= +golang.org/x/term v0.22.0/go.mod h1:F3qCibpT5AMpCRfhfT53vVJwhLtIVHhB9XDjfFvnMI4= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= @@ -591,8 +591,8 @@ google.golang.org/genproto/googleapis/rpc v0.0.0-20240515191416-fc5f0ca64291/go. google.golang.org/grpc v1.17.0/go.mod h1:6QZJwpn2B+Zp71q/5VxRsJ6NXXVCE5NRUHRo+f3cWCs= google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= google.golang.org/grpc v1.20.1/go.mod h1:10oTOabMzJvdu6/UiuZezV6QK5dSlG84ov/aaiqXj38= -google.golang.org/grpc v1.64.0 h1:KH3VH9y/MgNQg1dE7b3XfVK0GsPSIzJwdF617gUSbvY= -google.golang.org/grpc v1.64.0/go.mod h1:oxjF8E3FBnjp+/gVFYdWacaLDx9na1aqy9oovLpxQYg= +google.golang.org/grpc v1.64.1 h1:LKtvyfbX3UGVPFcGqJ9ItpVWW6oN/2XqTxfAnwRRXiA= +google.golang.org/grpc v1.64.1/go.mod h1:hiQF4LFZelK2WKaP6W0L92zGHtiQdZxk8CrSdvyjeP0= google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8= google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0= google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM= diff --git a/impl/pkg/dht/dht.go b/impl/pkg/dht/dht.go index 90a41bab..9da395d6 100644 --- a/impl/pkg/dht/dht.go +++ b/impl/pkg/dht/dht.go @@ -11,6 +11,7 @@ import ( "github.com/anacrolix/dht/v2" "github.com/anacrolix/dht/v2/bep44" "github.com/anacrolix/dht/v2/exts/getput" + "github.com/anacrolix/dht/v2/traversal" "github.com/anacrolix/log" "github.com/anacrolix/torrent/types/infohash" "github.com/pkg/errors" @@ -95,17 +96,29 @@ func (d *DHT) Put(ctx context.Context, request bep44.Put) (string, error) { t, err := getput.Put(ctx, request.Target(), d.Server, nil, func(int64) bep44.Put { return request }) - if err != nil { - if t == nil { - return "", fmt.Errorf("failed to put key[%s] into dht: %v", key, err) - } - return "", fmt.Errorf("failed to put key[%s] into dht, tried %d nodes, got %d responses", key, t.NumAddrsTried, t.NumResponses) - } else { - logrus.WithContext(ctx).WithField("key", key).Debug("successfully put key into dht") + if err = isPutSuccessful(key, t, err); err != nil { + logrus.WithContext(ctx).WithField("key", key).Error("error putting key into dht") + return "", err } + logrus.WithContext(ctx).WithField("key", key).Debug("successfully put key into dht") return util.Z32Encode(request.K[:]), nil } +const successThreshold = 0.33 + +func isPutSuccessful(key string, t *traversal.Stats, err error) error { + if err != nil { + return nil + } + if t == nil { + return fmt.Errorf("failed to put key[%s] into dht: %v", key, err) + } + if float64(t.NumResponses)/float64(t.NumAddrsTried) < successThreshold { + return fmt.Errorf("failed to put key[%s] into dht, tried %d nodes, got %d responses", key, t.NumAddrsTried, t.NumResponses) + } + return nil +} + // GetFull returns the full BEP-44 result for the given key from the DHT, using our modified // implementation of getput.Get. It should ONLY be used when it's needed to get the signature // data for a record. diff --git a/impl/pkg/service/dht.go b/impl/pkg/service/dht.go index 49a500ae..67d405e2 100644 --- a/impl/pkg/service/dht.go +++ b/impl/pkg/service/dht.go @@ -145,7 +145,7 @@ func (s *DHTService) GetDHT(ctx context.Context, id string) (*dht.BEP44Response, if got, err := s.cache.Get(id); err == nil { var resp dht.BEP44Response if err = json.Unmarshal(got, &resp); err == nil { - logrus.WithContext(ctx).WithField("record_id", id).Info("resolved record from cache") + logrus.WithContext(ctx).WithField("record_id", id).Debug("resolved record from cache") return &resp, nil } logrus.WithContext(ctx).WithError(err).WithField("record_id", id).Warn("failed to get record from cache, falling back to dht") @@ -175,7 +175,7 @@ func (s *DHTService) GetDHT(ctx context.Context, id string) (*dht.BEP44Response, return nil, err } - logrus.WithContext(ctx).WithField("record_id", id).Info("resolved record from storage") + logrus.WithContext(ctx).WithField("record_id", id).Debug("resolved record from storage") resp := record.Response() // add the record back to the cache for future lookups if err = s.addRecordToCache(id, record.Response()); err != nil { @@ -204,7 +204,7 @@ func (s *DHTService) GetDHT(ctx context.Context, id string) (*dht.BEP44Response, if err = s.addRecordToCache(id, resp); err != nil { logrus.WithContext(ctx).WithField("record_id", id).WithError(err).Error("failed to set record in cache") } else { - logrus.WithContext(ctx).WithField("record_id", id).Info("added record back to cache") + logrus.WithContext(ctx).WithField("record_id", id).Debug("added record back to cache") } return &resp, nil @@ -294,7 +294,7 @@ func (s *DHTService) republishRecords(ctx context.Context) []failedRecord { "success": seenRecords - int32(len(failedRecords)), "errors": len(failedRecords), "total": seenRecords, - }).Infof("republishing complete with [%d] batches of [%d] total records with a [%.2f] percent success rate", batchCnt, seenRecords, successRate) + }).Debugf("republishing complete with [%d] batches of [%d] total records with a [%.2f] percent success rate", batchCnt, seenRecords, successRate) return failedRecords }