generated from TBD54566975/tbd-project-template
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: write timeline events to the DB in async batches (#2873)
This should help reduce timeline writes as a bottleneck. The batches are in a transaction, whereas ideally we'd use PG's COPYFROM, but that's quite a bit more effort. We can revisit. @wesbillman this also changes the interface of the timeline service a bit. --------- Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
- Loading branch information
1 parent
cee6c95
commit 9f72cf6
Showing
12 changed files
with
222 additions
and
83 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
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,63 @@ | ||
package observability | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"go.opentelemetry.io/otel" | ||
"go.opentelemetry.io/otel/metric" | ||
"go.opentelemetry.io/otel/metric/noop" | ||
) | ||
|
||
const ( | ||
timelineMeterName = "ftl.timeline" | ||
) | ||
|
||
type TimelineMetrics struct { | ||
inserted metric.Int64Counter | ||
dropped metric.Int64Counter | ||
failed metric.Int64Counter | ||
} | ||
|
||
func initTimelineMetrics() (*TimelineMetrics, error) { | ||
result := &TimelineMetrics{ | ||
inserted: noop.Int64Counter{}, | ||
dropped: noop.Int64Counter{}, | ||
failed: noop.Int64Counter{}, | ||
} | ||
|
||
var err error | ||
meter := otel.Meter(timelineMeterName) | ||
|
||
signalName := fmt.Sprintf("%s.inserted", timelineMeterName) | ||
if result.inserted, err = meter.Int64Counter(signalName, metric.WithUnit("1"), | ||
metric.WithDescription("the number of times a timeline event was inserted")); err != nil { | ||
return nil, wrapErr(signalName, err) | ||
} | ||
|
||
signalName = fmt.Sprintf("%s.dropped", timelineMeterName) | ||
if result.dropped, err = meter.Int64Counter(signalName, metric.WithUnit("1"), | ||
metric.WithDescription("the number of times a timeline event was dropped due to the queue being full")); err != nil { | ||
return nil, wrapErr(signalName, err) | ||
} | ||
|
||
signalName = fmt.Sprintf("%s.failed", timelineMeterName) | ||
if result.dropped, err = meter.Int64Counter(signalName, metric.WithUnit("1"), | ||
metric.WithDescription("the number of times a timeline event failed to be inserted into the database")); err != nil { | ||
return nil, wrapErr(signalName, err) | ||
} | ||
|
||
return result, nil | ||
} | ||
|
||
func (m *TimelineMetrics) Inserted(ctx context.Context, count int) { | ||
m.inserted.Add(ctx, int64(count)) | ||
} | ||
|
||
func (m *TimelineMetrics) Dropped(ctx context.Context) { | ||
m.dropped.Add(ctx, 1) | ||
} | ||
|
||
func (m *TimelineMetrics) Failed(ctx context.Context, count int) { | ||
m.failed.Add(ctx, int64(count)) | ||
} |
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
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
Oops, something went wrong.