Skip to content

Commit

Permalink
fix: verbose debug logging (#3700)
Browse files Browse the repository at this point in the history
  • Loading branch information
stuartwdouglas authored Dec 10, 2024
1 parent cfe35a3 commit 4b3cf01
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
6 changes: 6 additions & 0 deletions backend/controller/state/runners.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (

"github.com/alecthomas/types/optional"

"github.com/TBD54566975/ftl/internal/eventstream"
"github.com/TBD54566975/ftl/internal/model"
)

Expand Down Expand Up @@ -42,6 +43,7 @@ func (r *State) RunnersForDeployment(deployment string) []Runner {
}

var _ ControllerEvent = (*RunnerRegisteredEvent)(nil)
var _ eventstream.VerboseMessage = (*RunnerRegisteredEvent)(nil)
var _ ControllerEvent = (*RunnerDeletedEvent)(nil)

type RunnerRegisteredEvent struct {
Expand All @@ -52,6 +54,10 @@ type RunnerRegisteredEvent struct {
Deployment model.DeploymentKey
}

func (r *RunnerRegisteredEvent) VerboseMessage() {
// Stops this message being logged every second
}

func (r *RunnerRegisteredEvent) Handle(t State) (State, error) {
if existing := t.runners[r.Key.String()]; existing != nil {
existing.LastSeen = r.Time
Expand Down
10 changes: 9 additions & 1 deletion internal/eventstream/eventstream.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,11 @@ func (i *inMemoryEventStream[T, E]) Publish(ctx context.Context, e E) error {
defer i.lock.Unlock()
logger := log.FromContext(ctx)

logger.Debugf("Publishing event %T%v", e, e)
if _, ok := any(e).(VerboseMessage); ok {
logger.Tracef("Publishing event %T%v", e, e)
} else {
logger.Debugf("Publishing event %T%v", e, e)
}
newView, err := e.Handle(reflect.DeepCopy(i.view))
if err != nil {
return fmt.Errorf("failed to handle event: %w", err)
Expand All @@ -69,3 +73,7 @@ func (i *inMemoryEventStream[T, E]) View() T {
func (i *inMemoryEventStream[T, E]) Updates() *pubsub.Topic[E] {
return i.topic
}

type VerboseMessage interface {
VerboseMessage()
}

0 comments on commit 4b3cf01

Please sign in to comment.