1
0
Fork 0
mirror of https://github.com/anyproto/anytype-heart.git synced 2025-06-09 17:44:59 +09:00

Merge pull request #1691 from anyproto/go-3957-log-mess-cleanup

GO-3957 Clean up logs
This commit is contained in:
Mikhail 2024-10-17 18:41:01 +03:00 committed by GitHub
commit 309f54224b
Signed by: github
GPG key ID: B5690EEEBB952194
8 changed files with 50 additions and 16 deletions

View file

@ -1,6 +1,9 @@
package editor
import (
"errors"
"github.com/anyproto/any-sync/commonspace/spacestorage"
"github.com/gogo/protobuf/types"
"github.com/anyproto/anytype-heart/core/block/editor/collection"
@ -115,7 +118,7 @@ func (p *Archive) updateInStore(archivedIds []string) error {
current.Fields[bundle.RelationKeyIsArchived.String()] = pbtypes.Bool(false)
return current, nil
}); err != nil {
log.Errorf("archive: can't set detail to object: %v", err)
logArchiveError(err)
}
}(removedId)
}
@ -130,9 +133,16 @@ func (p *Archive) updateInStore(archivedIds []string) error {
current.Fields[bundle.RelationKeyIsArchived.String()] = pbtypes.Bool(true)
return current, nil
}); err != nil {
log.Errorf("archive: can't set detail to object: %v", err)
logArchiveError(err)
}
}(addedId)
}
return nil
}
func logArchiveError(err error) {
if errors.Is(err, spacestorage.ErrTreeStorageAlreadyDeleted) {
return
}
log.Errorf("archive: can't set detail to object: %v", err)
}

View file

@ -2,13 +2,16 @@ package fileobject
import (
"context"
"errors"
"fmt"
"strings"
"sync"
"time"
"github.com/anyproto/any-sync/commonspace/object/tree/treestorage"
"github.com/cheggaaa/mb/v3"
"github.com/gogo/protobuf/types"
format "github.com/ipfs/go-ipld-format"
"github.com/anyproto/anytype-heart/core/block/editor/smartblock"
"github.com/anyproto/anytype-heart/core/block/editor/state"
@ -17,6 +20,7 @@ import (
fileblock "github.com/anyproto/anytype-heart/core/block/simple/file"
"github.com/anyproto/anytype-heart/core/domain"
"github.com/anyproto/anytype-heart/core/files"
"github.com/anyproto/anytype-heart/core/filestorage/rpcstore"
"github.com/anyproto/anytype-heart/pkg/lib/bundle"
"github.com/anyproto/anytype-heart/pkg/lib/database"
"github.com/anyproto/anytype-heart/pkg/lib/localstore/objectstore"
@ -182,11 +186,24 @@ func (ind *indexer) runIndexingWorker() {
default:
}
if err := ind.indexNext(ind.indexCtx); err != nil {
log.Errorf("index loop: %v", err)
logIndexLoop(err)
}
}
}
func logIndexLoop(err error) {
if errors.Is(err, treestorage.ErrUnknownTreeId) {
return
}
if errors.Is(err, format.ErrNotFound{}) {
return
}
if errors.Is(err, rpcstore.ErrNoConnectionToAnyFileClient) {
return
}
log.Errorf("index loop: %v", err)
}
func (ind *indexer) indexNext(ctx context.Context) error {
req, err := ind.indexQueue.NewCond().WaitOne(ctx)
if err != nil {

View file

@ -643,7 +643,6 @@ func (s *service) FileByHash(ctx context.Context, id domain.FullFileId) (File, e
// info from ipfs
fileList, err = s.fileIndexInfo(ctx, id, false)
if err != nil {
log.With("fileId", id.FileId.String()).Errorf("FileByHash: failed to retrieve from IPFS: %s", err)
return nil, err
}
ok, err := s.fileStore.IsFileImported(id.FileId)

View file

@ -14,6 +14,7 @@ import (
"github.com/anyproto/any-sync/net/peer"
blocks "github.com/ipfs/go-block-format"
"github.com/ipfs/go-cid"
format "github.com/ipfs/go-ipld-format"
"github.com/samber/lo"
"go.uber.org/zap"
@ -163,10 +164,12 @@ func (s *fileSync) retryingHandler(ctx context.Context, it *QueueItem) (persiste
}
}
if limitErr == nil || !limitErrorIsLogged {
log.Error("retry uploading file error",
zap.String("fileId", fileId.String()), zap.Error(err),
zap.String("objectId", it.ObjectId),
)
if !format.IsNotFound(err) && !strings.Contains(err.Error(), "failed to fetch all nodes") {
log.Error("retry uploading file error",
zap.String("fileId", fileId.String()), zap.Error(err),
zap.String("objectId", it.ObjectId),
)
}
}
return persistentqueue.ActionRetry, nil

View file

@ -9,10 +9,12 @@ import (
"time"
"github.com/anyproto/any-sync/commonfile/fileproto"
"github.com/anyproto/any-sync/commonfile/fileproto/fileprotoerr"
"github.com/anyproto/any-sync/net/pool"
"github.com/anyproto/any-sync/net/rpc/rpcerr"
"github.com/cheggaaa/mb/v3"
"github.com/ipfs/go-cid"
format "github.com/ipfs/go-ipld-format"
"go.uber.org/zap"
"golang.org/x/exp/slices"
"storj.io/drpc"
@ -183,7 +185,11 @@ func (c *client) get(ctx context.Context, spaceID string, cd cid.Cid) (data []by
Cid: cd.Bytes(),
})
if err != nil {
return rpcerr.Unwrap(err)
err = rpcerr.Unwrap(err)
if errors.Is(err, fileprotoerr.ErrCIDNotFound) {
return format.ErrNotFound{Cid: cd}
}
return err
}
log.Debug("get cid", zap.String("cid", cd.String()))
c.stat.Add(st, len(resp.Data))

View file

@ -2,6 +2,7 @@ package rpcstore
import (
"context"
"errors"
"fmt"
"math/rand"
"time"
@ -28,7 +29,8 @@ type operationNameKeyType string
const operationNameKey operationNameKeyType = "operationName"
var (
clientCreateTimeout = 1 * time.Minute
clientCreateTimeout = 1 * time.Minute
ErrNoConnectionToAnyFileClient = errors.New("no connection to any file client")
)
func newClientManager(pool pool.Pool, peerStore peerstore.PeerStore, peerUpdateCh chan struct{}) *clientManager {
@ -199,7 +201,7 @@ func (m *clientManager) checkPeers(ctx context.Context, needClient bool) (err er
addPeer(peerId)
}
if m.ocache.Len() == 0 {
return fmt.Errorf("no connection to any file client")
return ErrNoConnectionToAnyFileClient
}
return nil
}

View file

@ -9,7 +9,6 @@ import (
"github.com/anyproto/any-sync/accountservice/mock_accountservice"
"github.com/anyproto/any-sync/app"
"github.com/anyproto/any-sync/commonfile/fileblockstore"
"github.com/anyproto/any-sync/commonfile/fileproto"
"github.com/anyproto/any-sync/commonfile/fileproto/fileprotoerr"
"github.com/anyproto/any-sync/commonspace/object/accountdata"
@ -18,6 +17,7 @@ import (
"github.com/anyproto/any-sync/nodeconf/mock_nodeconf"
blocks "github.com/ipfs/go-block-format"
"github.com/ipfs/go-cid"
format "github.com/ipfs/go-ipld-format"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"go.uber.org/mock/gomock"
@ -77,7 +77,7 @@ func TestStore_Get(t *testing.T) {
}
b, err := fx.Get(ctx, bs[0].Cid())
assert.Nil(t, b)
assert.ErrorIs(t, err, fileblockstore.ErrCIDNotFound)
assert.ErrorIs(t, err, format.ErrNotFound{})
})
}

View file

@ -132,9 +132,6 @@ func (c *client) sendNextBatch(info anymetry.AppInfoProvider, batcher *mb.MB[any
err = c.telemetry.SendEvents(msgs, info)
if err != nil {
clientMetricsLog.
With("unsent messages", len(msgs)+clientBatcher.Len()).
Error("failed to send messages")
if batcher != nil {
_ = batcher.TryAdd(msgs...) //nolint:errcheck
}