Skip to content

Commit

Permalink
Reduce log noise (#256)
Browse files Browse the repository at this point in the history
* fix

* update

* update

* tidy

* update go version
  • Loading branch information
decentralgabe authored Jul 17, 2024
1 parent a8d908d commit 5891da3
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 27 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
6 changes: 3 additions & 3 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
2 changes: 1 addition & 1 deletion impl/build/Dockerfile
Original file line number Diff line number Diff line change
@@ -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
Expand Down
6 changes: 3 additions & 3 deletions impl/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
)

Expand Down Expand Up @@ -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
Expand Down
12 changes: 6 additions & 6 deletions impl/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down Expand Up @@ -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=
Expand Down
27 changes: 20 additions & 7 deletions impl/pkg/dht/dht.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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.
Expand Down
8 changes: 4 additions & 4 deletions impl/pkg/service/dht.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit 5891da3

Please sign in to comment.