Skip to content

Commit

Permalink
otel instrumentation
Browse files Browse the repository at this point in the history
  • Loading branch information
louiseschmidtgen committed Aug 5, 2024
1 parent 58eff17 commit 42d97f5
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
15 changes: 13 additions & 2 deletions pkg/kine/drivers/generic/generic.go
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,7 @@ func (d *Generic) Create(ctx context.Context, key string, value []byte, ttl int6
// a compacted error.
func (d *Generic) Compact(ctx context.Context, revision int64) (err error) {
compactCnt.Add(ctx, 1)
ctx, span := otelTracer.Start(ctx, fmt.Sprintf("%s.compact", otelName))
ctx, span := otelTracer.Start(ctx, fmt.Sprintf("%s.Compact", otelName))
defer func() {
span.RecordError(err)
span.End()
Expand All @@ -490,6 +490,10 @@ func (d *Generic) Compact(ctx context.Context, revision int64) (err error) {
if err != nil {
return err
}
span.SetAttributes(
attribute.Int64("compact_start", compactStart),
attribute.Int64("current_revision", currentRevision), attribute.Int64("revision", revision),
)
if compactStart >= revision {
return nil // Nothing to compact.
}
Expand All @@ -506,7 +510,14 @@ func (d *Generic) Compact(ctx context.Context, revision int64) (err error) {
return err
}

func (d *Generic) tryCompact(ctx context.Context, start, end int64) error {
func (d *Generic) tryCompact(ctx context.Context, start, end int64) (err error) {
ctx, span := otelTracer.Start(ctx, fmt.Sprintf("%s.tryCompact", otelName))
defer func() {
span.RecordError(err)
span.End()
}()
span.SetAttributes(attribute.Int64("start", start), attribute.Int64("end", end))

tx, err := d.DB.BeginTx(ctx, nil)
if err != nil {
return err
Expand Down
9 changes: 8 additions & 1 deletion pkg/kine/logstructured/sqllog/sql.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,12 @@ func (s *SQLLog) compactStart(ctx context.Context) error {

// DoCompact makes a single compaction run when called. It is intended to be called
// from test functions that have access to the backend.
func (s *SQLLog) DoCompact(ctx context.Context) error {
func (s *SQLLog) DoCompact(ctx context.Context) (err error) {
ctx, span := otelTracer.Start(ctx, fmt.Sprintf("%s.DoCompact", otelName))
defer func() {
span.RecordError(err)
span.End()
}()
if err := s.compactStart(ctx); err != nil {
return fmt.Errorf("failed to initialise compaction: %v", err)
}
Expand All @@ -155,11 +160,13 @@ func (s *SQLLog) DoCompact(ctx context.Context) error {
if err != nil {
return err
}
span.SetAttributes(attribute.Int64("start", start))
// NOTE: Upstream is ignoring the last 1000 revisions, however that causes the following CNCF conformance test to fail.
// This is because of low activity, where the created list is part of the last 1000 revisions and is not compacted.
// Link to failing test: https://github.com/kubernetes/kubernetes/blob/f2cfbf44b1fb482671aedbfff820ae2af256a389/test/e2e/apimachinery/chunking.go#L144
// To address this, we only ignore the last 100 revisions instead
target -= SupersededCount
span.SetAttributes(attribute.Int64("target", target))
for start < target {
batchRevision := start + compactBatchSize
if batchRevision > target {
Expand Down

0 comments on commit 42d97f5

Please sign in to comment.