generated from TBD54566975/tbd-project-template
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: metric integration for fsm (#2155)
- Loading branch information
1 parent
bbe565d
commit cbc4118
Showing
6 changed files
with
77 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package observability | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"github.com/TBD54566975/ftl/backend/schema" | ||
"github.com/TBD54566975/ftl/internal/observability" | ||
"go.opentelemetry.io/otel" | ||
"go.opentelemetry.io/otel/attribute" | ||
"go.opentelemetry.io/otel/metric" | ||
) | ||
|
||
const ( | ||
fsmMeterName = "ftl.fsm" | ||
fsmRefAttribute = "ftl.fsm.ref" | ||
) | ||
|
||
var fsmMeter = otel.Meter("ftl.fsm") | ||
|
||
var fsmCounters = struct { | ||
instancesActive metric.Int64UpDownCounter | ||
}{} | ||
|
||
func InitFSMMetrics() error { | ||
var err error | ||
|
||
fsmCounters.instancesActive, err = fsmMeter.Int64UpDownCounter( | ||
fmt.Sprintf("%s.instances.active", fsmMeterName), | ||
metric.WithDescription("counts the number of active FSM instances")) | ||
|
||
if err != nil { | ||
return fmt.Errorf("could not initialize fsm metrics: %w", err) | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func FSMInstanceCreated(ctx context.Context, fsm schema.RefKey) { | ||
if fsmCounters.instancesActive != nil { | ||
fsmCounters.instancesActive.Add(ctx, 1, metric.WithAttributes( | ||
attribute.String(observability.ModuleNameAttribute, fsm.Module), | ||
attribute.String(fsmRefAttribute, fsm.String()))) | ||
} | ||
} | ||
|
||
func FSMInstanceCompleted(ctx context.Context, fsm schema.RefKey) { | ||
if fsmCounters.instancesActive != nil { | ||
fsmCounters.instancesActive.Add(ctx, -1, metric.WithAttributes( | ||
attribute.String(observability.ModuleNameAttribute, fsm.Module), | ||
attribute.String(fsmRefAttribute, fsm.String()))) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package observability | ||
|
||
import "fmt" | ||
|
||
func InitControllerObservability() error { | ||
if err := InitFSMMetrics(); err != nil { | ||
return fmt.Errorf("could not initialize controller metrics: %w", err) | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package observability | ||
|
||
const ( | ||
ModuleNameAttribute = "ftl.module.name" | ||
) |
This file was deleted.
Oops, something went wrong.