Skip to content

Commit

Permalink
adopting PR feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathanj-square committed Jul 26, 2024
1 parent 90d0531 commit da611b6
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 20 deletions.
10 changes: 5 additions & 5 deletions backend/controller/dal/fsm.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,28 +59,28 @@ func (d *DAL) StartFSMTransition(ctx context.Context, fsm schema.RefKey, executi
return fmt.Errorf("failed to start FSM transition: %w", err)
}
if instance.CreatedAt.Equal(instance.UpdatedAt) {
observability.FSM().InstanceCreated(ctx, fsm)
observability.FSM.InstanceCreated(ctx, fsm)
}
observability.FSM().TransitionStarted(ctx, fsm, destinationState)
observability.FSM.TransitionStarted(ctx, fsm, destinationState)
return nil
}

func (d *DAL) FinishFSMTransition(ctx context.Context, fsm schema.RefKey, instanceKey string) error {
_, err := d.db.FinishFSMTransition(ctx, fsm, instanceKey)
observability.FSM().TransitionCompleted(ctx, fsm)
observability.FSM.TransitionCompleted(ctx, fsm)

return dalerrs.TranslatePGError(err)
}

func (d *DAL) FailFSMInstance(ctx context.Context, fsm schema.RefKey, instanceKey string) error {
_, err := d.db.FailFSMInstance(ctx, fsm, instanceKey)
observability.FSM().InstanceCompleted(ctx, fsm)
observability.FSM.InstanceCompleted(ctx, fsm)
return dalerrs.TranslatePGError(err)
}

func (d *DAL) SucceedFSMInstance(ctx context.Context, fsm schema.RefKey, instanceKey string) error {
_, err := d.db.SucceedFSMInstance(ctx, fsm, instanceKey)
observability.FSM().InstanceCompleted(ctx, fsm)
observability.FSM.InstanceCompleted(ctx, fsm)
return dalerrs.TranslatePGError(err)
}

Expand Down
3 changes: 0 additions & 3 deletions backend/controller/dal/fsm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package dal

import (
"context"
"github.com/TBD54566975/ftl/backend/controller/observability"
"testing"
"time"

Expand All @@ -16,8 +15,6 @@ import (
)

func TestSendFSMEvent(t *testing.T) {
_ = observability.InitControllerObservability()

ctx := log.ContextWithNewDefaultLogger(context.Background())
conn := sqltest.OpenForTesting(ctx, t)
dal, err := New(ctx, conn)
Expand Down
2 changes: 1 addition & 1 deletion backend/controller/observability/fsm.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ type FSMMetrics struct {
transitionAttempts metric.Int64Counter
}

func InitFSMMetrics() (*FSMMetrics, error) {
func initFSMMetrics() (*FSMMetrics, error) {
result := &FSMMetrics{}

var errs error
Expand Down
18 changes: 7 additions & 11 deletions backend/controller/observability/observability.go
Original file line number Diff line number Diff line change
@@ -1,23 +1,19 @@
package observability

import "fmt"
import (
"fmt"
)

var (
fsm *FSMMetrics
FSM *FSMMetrics
)

func InitControllerObservability() error {
func init() {
var err error

fsm, err = InitFSMMetrics()
FSM, err = initFSMMetrics()

if err != nil {
return fmt.Errorf("could not initialize controller metrics: %w", err)
panic(fmt.Errorf("could not initialize controller metrics: %w\n", err))
}

return nil
}

func FSM() *FSMMetrics {
return fsm
}

0 comments on commit da611b6

Please sign in to comment.