Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[chore] improved federatingdb logging in cases of unknown iri / types #3313

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 12 additions & 14 deletions internal/federation/federatingdb/accept.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (
"errors"
"net/url"

"codeberg.org/gruf/go-logger/v2/level"
"github.com/superseriousbusiness/activity/streams/vocab"
"github.com/superseriousbusiness/gotosocial/internal/ap"
"github.com/superseriousbusiness/gotosocial/internal/db"
Expand All @@ -46,15 +45,7 @@ func (f *federatingDB) GetAccept(
}

func (f *federatingDB) Accept(ctx context.Context, accept vocab.ActivityStreamsAccept) error {
if log.Level() >= level.DEBUG {
i, err := marshalItem(accept)
if err != nil {
return err
}
l := log.WithContext(ctx).
WithField("accept", i)
l.Debug("entering Accept")
}
log.DebugKV(ctx, "accept", serialize{accept})

activityContext := getActivityContext(ctx)
if activityContext.internal {
Expand All @@ -81,10 +72,9 @@ func (f *federatingDB) Accept(ctx context.Context, accept vocab.ActivityStreamsA
// handling the ones we know how to handle.
for _, object := range ap.ExtractObjects(accept) {
if asType := object.GetType(); asType != nil {
// Check and handle any
// vocab.Type objects.
// nolint:gocritic
switch asType.GetTypeName() {

// Check and handle any vocab.Type objects.
switch name := asType.GetTypeName(); name {

// ACCEPT FOLLOW
case ap.ActivityFollow:
Expand All @@ -96,6 +86,10 @@ func (f *federatingDB) Accept(ctx context.Context, accept vocab.ActivityStreamsA
); err != nil {
return err
}

// UNHANDLED
default:
log.Debugf(ctx, "unhandled object type: %s", name)
}

} else if object.IsIRI() {
Expand Down Expand Up @@ -137,6 +131,10 @@ func (f *federatingDB) Accept(ctx context.Context, accept vocab.ActivityStreamsA
); err != nil {
return err
}

// UNHANDLED
default:
log.Debugf(ctx, "unhandled iri type: %s", objIRI)
}
}
}
Expand Down
11 changes: 1 addition & 10 deletions internal/federation/federatingdb/announce.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (
"net/url"
"slices"

"codeberg.org/gruf/go-logger/v2/level"
"github.com/superseriousbusiness/activity/streams/vocab"
"github.com/superseriousbusiness/gotosocial/internal/ap"
"github.com/superseriousbusiness/gotosocial/internal/gtserror"
Expand All @@ -31,15 +30,7 @@ import (
)

func (f *federatingDB) Announce(ctx context.Context, announce vocab.ActivityStreamsAnnounce) error {
if log.Level() >= level.DEBUG {
i, err := marshalItem(announce)
if err != nil {
return err
}
l := log.WithContext(ctx).
WithField("announce", i)
l.Debug("entering Announce")
}
log.DebugKV(ctx, "announce", serialize{announce})

activityContext := getActivityContext(ctx)
if activityContext.internal {
Expand Down
17 changes: 4 additions & 13 deletions internal/federation/federatingdb/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (
"errors"
"fmt"

"codeberg.org/gruf/go-logger/v2/level"
"github.com/miekg/dns"
"github.com/superseriousbusiness/activity/streams/vocab"
"github.com/superseriousbusiness/gotosocial/internal/ap"
Expand All @@ -48,17 +47,7 @@ import (
// Under certain conditions and network activities, Create may be called
// multiple times for the same ActivityStreams object.
func (f *federatingDB) Create(ctx context.Context, asType vocab.Type) error {
if log.Level() >= level.TRACE {
i, err := marshalItem(asType)
if err != nil {
return err
}

log.
WithContext(ctx).
WithField("create", i).
Trace("entering Create")
}
log.DebugKV(ctx, "create", serialize{asType})

activityContext := getActivityContext(ctx)
if activityContext.internal {
Expand All @@ -74,7 +63,7 @@ func (f *federatingDB) Create(ctx context.Context, asType vocab.Type) error {
return nil
}

switch asType.GetTypeName() {
switch name := asType.GetTypeName(); name {
case ap.ActivityBlock:
// BLOCK SOMETHING
return f.activityBlock(ctx, asType, receivingAcct, requestingAcct)
Expand All @@ -90,6 +79,8 @@ func (f *federatingDB) Create(ctx context.Context, asType vocab.Type) error {
case ap.ActivityFlag:
// FLAG / REPORT SOMETHING
return f.activityFlag(ctx, asType, receivingAcct, requestingAcct)
default:
log.Debugf(ctx, "unhandled object type: %s", name)
}

return nil
Expand Down
6 changes: 3 additions & 3 deletions internal/federation/federatingdb/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ import (
//
// The library makes this call only after acquiring a lock first.
func (f *federatingDB) Delete(ctx context.Context, id *url.URL) error {
log.DebugKV(ctx, "id", id)

activityContext := getActivityContext(ctx)
if activityContext.internal {
return nil // Already processed.
Expand Down Expand Up @@ -81,9 +83,7 @@ func (f *federatingDB) Delete(ctx context.Context, id *url.URL) error {
return nil
}

// Log at debug level, as lots of these could indicate federation
// issues between remote and this instance, or help with debugging.
log.Debugf(ctx, "received delete for unknown target: %s", uriStr)
log.Debugf(ctx, "unknown iri: %s", uriStr)
return nil
}

Expand Down
8 changes: 0 additions & 8 deletions internal/federation/federatingdb/exists.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@ package federatingdb
import (
"context"
"net/url"

"codeberg.org/gruf/go-kv"
"github.com/superseriousbusiness/gotosocial/internal/log"
)

// Exists returns true if the database has an entry for the specified
Expand All @@ -32,10 +29,5 @@ import (
//
// Implementation note: this just straight up isn't implemented, and doesn't *really* need to be either.
func (f *federatingDB) Exists(ctx context.Context, id *url.URL) (exists bool, err error) {
l := log.WithContext(ctx).
WithFields(kv.Fields{
{"id", id},
}...)
l.Debug("entering Exists")
return false, nil
}
5 changes: 1 addition & 4 deletions internal/federation/federatingdb/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (
"fmt"
"net/url"

"codeberg.org/gruf/go-kv"
"github.com/superseriousbusiness/activity/streams/vocab"
"github.com/superseriousbusiness/gotosocial/internal/log"
"github.com/superseriousbusiness/gotosocial/internal/uris"
Expand All @@ -32,9 +31,7 @@ import (
//
// The library makes this call only after acquiring a lock first.
func (f *federatingDB) Get(ctx context.Context, id *url.URL) (value vocab.Type, err error) {
l := log.WithContext(ctx).
WithFields(kv.Fields{{"id", id}}...)
l.Debug("entering Get")
log.DebugKV(ctx, "id", id)

switch {

Expand Down
11 changes: 1 addition & 10 deletions internal/federation/federatingdb/move.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import (
"errors"
"fmt"

"codeberg.org/gruf/go-logger/v2/level"
"github.com/superseriousbusiness/activity/streams/vocab"
"github.com/superseriousbusiness/gotosocial/internal/ap"
"github.com/superseriousbusiness/gotosocial/internal/gtserror"
Expand All @@ -37,15 +36,7 @@ import (
)

func (f *federatingDB) Move(ctx context.Context, move vocab.ActivityStreamsMove) error {
if log.Level() >= level.DEBUG {
i, err := marshalItem(move)
if err != nil {
return err
}
l := log.WithContext(ctx).
WithField("move", i)
l.Debug("entering Move")
}
log.DebugKV(ctx, "move", serialize{move})

activityContext := getActivityContext(ctx)
if activityContext.internal {
Expand Down
17 changes: 6 additions & 11 deletions internal/federation/federatingdb/owns.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (
"fmt"
"net/url"

"codeberg.org/gruf/go-kv"
"github.com/superseriousbusiness/gotosocial/internal/config"
"github.com/superseriousbusiness/gotosocial/internal/db"
"github.com/superseriousbusiness/gotosocial/internal/gtscontext"
Expand All @@ -36,15 +35,11 @@ import (
// the database has an entry for the IRI.
// The library makes this call only after acquiring a lock first.
func (f *federatingDB) Owns(ctx context.Context, id *url.URL) (bool, error) {
l := log.WithContext(ctx).
WithFields(kv.Fields{
{"id", id},
}...)
l.Debug("entering Owns")
log.DebugKV(ctx, "id", id)

// if the id host isn't this instance host, we don't own this IRI
if host := config.GetHost(); id.Host != host {
l.Tracef("we DO NOT own activity because the host is %s not %s", id.Host, host)
log.Tracef(ctx, "we DO NOT own activity because the host is %s not %s", id.Host, host)
return false, nil
}

Expand Down Expand Up @@ -85,7 +80,7 @@ func (f *federatingDB) Owns(ctx context.Context, id *url.URL) (bool, error) {
// an actual error happened
return false, fmt.Errorf("database error fetching account with username %s: %s", username, err)
}
l.Debugf("we own url %s", id.String())
log.Debugf(ctx, "we own url %s", id)
return true, nil
}

Expand All @@ -102,7 +97,7 @@ func (f *federatingDB) Owns(ctx context.Context, id *url.URL) (bool, error) {
// an actual error happened
return false, fmt.Errorf("database error fetching account with username %s: %s", username, err)
}
l.Debugf("we own url %s", id.String())
log.Debugf(ctx, "we own url %s", id)
return true, nil
}

Expand All @@ -119,7 +114,7 @@ func (f *federatingDB) Owns(ctx context.Context, id *url.URL) (bool, error) {
// an actual error happened
return false, fmt.Errorf("database error fetching account with username %s: %s", username, err)
}
l.Debugf("we own url %s", id.String())
log.Debugf(ctx, "we own url %s", id)
return true, nil
}

Expand Down Expand Up @@ -148,7 +143,7 @@ func (f *federatingDB) Owns(ctx context.Context, id *url.URL) (bool, error) {
// an actual error happened
return false, fmt.Errorf("database error fetching block with id %s: %s", blockID, err)
}
l.Debugf("we own url %s", id.String())
log.Debugf(ctx, "we own url %s", id)
return true, nil
}

Expand Down
25 changes: 11 additions & 14 deletions internal/federation/federatingdb/reject.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (
"errors"
"time"

"codeberg.org/gruf/go-logger/v2/level"
"github.com/superseriousbusiness/activity/streams/vocab"
"github.com/superseriousbusiness/gotosocial/internal/ap"
"github.com/superseriousbusiness/gotosocial/internal/db"
Expand All @@ -35,15 +34,7 @@ import (
)

func (f *federatingDB) Reject(ctx context.Context, reject vocab.ActivityStreamsReject) error {
if log.Level() >= level.DEBUG {
i, err := marshalItem(reject)
if err != nil {
return err
}
l := log.WithContext(ctx).
WithField("reject", i)
l.Debug("entering Reject")
}
log.DebugKV(ctx, "reject", serialize{reject})

activityContext := getActivityContext(ctx)
if activityContext.internal {
Expand All @@ -62,10 +53,8 @@ func (f *federatingDB) Reject(ctx context.Context, reject vocab.ActivityStreamsR

for _, object := range ap.ExtractObjects(reject) {
if asType := object.GetType(); asType != nil {
// Check and handle any
// vocab.Type objects.
// nolint:gocritic
switch asType.GetTypeName() {
// Check and handle any vocab.Type objects.
switch name := asType.GetTypeName(); name {

// REJECT FOLLOW
case ap.ActivityFollow:
Expand All @@ -77,6 +66,10 @@ func (f *federatingDB) Reject(ctx context.Context, reject vocab.ActivityStreamsR
); err != nil {
return err
}

// UNHANDLED
default:
log.Debugf(ctx, "unhandled object type: %s", name)
}

} else if object.IsIRI() {
Expand Down Expand Up @@ -118,6 +111,10 @@ func (f *federatingDB) Reject(ctx context.Context, reject vocab.ActivityStreamsR
); err != nil {
return err
}

// UNHANDLED
default:
log.Debugf(ctx, "unhandled iri type: %s", objIRI)
}
}
}
Expand Down
23 changes: 6 additions & 17 deletions internal/federation/federatingdb/undo.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (
"errors"
"fmt"

"codeberg.org/gruf/go-logger/v2/level"
"github.com/superseriousbusiness/activity/streams/vocab"
"github.com/superseriousbusiness/gotosocial/internal/ap"
"github.com/superseriousbusiness/gotosocial/internal/db"
Expand All @@ -33,15 +32,7 @@ import (
)

func (f *federatingDB) Undo(ctx context.Context, undo vocab.ActivityStreamsUndo) error {
if log.Level() >= level.DEBUG {
i, err := marshalItem(undo)
if err != nil {
return err
}
l := log.WithContext(ctx).
WithField("undo", i)
l.Debug("entering Undo")
}
log.DebugKV(ctx, "undo", serialize{undo})

activityContext := getActivityContext(ctx)
if activityContext.internal {
Expand All @@ -59,9 +50,8 @@ func (f *federatingDB) Undo(ctx context.Context, undo vocab.ActivityStreamsUndo)
continue
}

// Check and handle any
// vocab.Type objects.
switch asType.GetTypeName() {
// Check and handle any vocab.Type objects.
switch name := asType.GetTypeName(); name {

// UNDO FOLLOW
case ap.ActivityFollow:
Expand Down Expand Up @@ -99,10 +89,9 @@ func (f *federatingDB) Undo(ctx context.Context, undo vocab.ActivityStreamsUndo)
return err
}

// UNDO ANNOUNCE
case ap.ActivityAnnounce:
// TODO: actually handle this!
log.Warn(ctx, "skipped undo announce")
// UNHANDLED
default:
log.Debugf(ctx, "unhandled object type: %s", name)
}
}

Expand Down
Loading