Skip to content

Commit

Permalink
draft commit: logging errors
Browse files Browse the repository at this point in the history
Signed-off-by: metonymic-smokey <ahuja.aditi@gmail.com>
  • Loading branch information
metonymic-smokey committed Nov 29, 2021
1 parent 7620389 commit e11d776
Showing 1 changed file with 32 additions and 7 deletions.
39 changes: 32 additions & 7 deletions pkg/compact/compact.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"github.com/go-kit/log/level"
"github.com/oklog/ulid"
"github.com/opentracing/opentracing-go"
opentracing_log "github.com/opentracing/opentracing-go/log"
"github.com/pkg/errors"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
Expand Down Expand Up @@ -766,11 +767,16 @@ func (cg *Group) Compact(ctx context.Context, dir string, planner Planner, comp
return false, ulid.ULID{}, errors.Wrap(err, "create compaction group dir")
}

var span tracing.Span
if span = opentracing.SpanFromContext(ctx); span != nil {
return false, ulid.ULID{}, errors.New("span in context found to be nil")
}
var err error
tracing.DoInSpan(ctx, "group_compaction", func(ctx context.Context) {
shouldRerun, compID, err = cg.compact(ctx, subDir, planner, comp)
}, opentracing.Tags{"group.key": cg.Key()})
if err != nil {
span.LogFields(opentracing_log.Error(err))
cg.compactionFailures.Inc()
return false, ulid.ULID{}, err
}
Expand Down Expand Up @@ -985,12 +991,19 @@ func (cg *Group) compact(ctx context.Context, dir string, planner Planner, comp
overlappingBlocks = true
}

var span tracing.Span
if span = opentracing.SpanFromContext(ctx); span != nil {
return false, ulid.ULID{}, errors.New("span in context found to be nil")
}

var toCompact []*metadata.Meta
tracing.DoInSpan(ctx, "compaction_planning", func(ctx context.Context) {
toCompact, err = planner.Plan(ctx, cg.metasByMinTime)
})
if err != nil {
return false, ulid.ULID{}, errors.Wrap(err, "plan compaction")
planErr := errors.Wrap(err, "plan compaction")
span.LogFields(opentracing_log.Error(planErr))
return false, ulid.ULID{}, planErr
}
if len(toCompact) == 0 {
// Nothing to do.
Expand Down Expand Up @@ -1021,7 +1034,9 @@ func (cg *Group) compact(ctx context.Context, dir string, planner Planner, comp
}, opentracing.Tags{"block.id": meta.ULID})

if err != nil {
return false, ulid.ULID{}, retry(errors.Wrapf(err, "download block %s", meta.ULID))
downloadErr := errors.Wrapf(err, "download block %s", meta.ULID)
span.LogFields(opentracing_log.Error(downloadErr))
return false, ulid.ULID{}, retry(downloadErr)
}

// Ensure all input blocks are valid.
Expand All @@ -1030,7 +1045,9 @@ func (cg *Group) compact(ctx context.Context, dir string, planner Planner, comp
stats, err = block.GatherIndexHealthStats(cg.logger, filepath.Join(bdir, block.IndexFilename), meta.MinTime, meta.MaxTime)
}, opentracing.Tags{"block.id": meta.ULID})
if err != nil {
return false, ulid.ULID{}, errors.Wrapf(err, "gather index issues for block %s", bdir)
indexErr := errors.Wrapf(err, "gather index issues for block %s", bdir)
span.LogFields(opentracing_log.Error(indexErr))
return false, ulid.ULID{}, indexErr
}

if err := stats.CriticalErr(); err != nil {
Expand Down Expand Up @@ -1059,7 +1076,9 @@ func (cg *Group) compact(ctx context.Context, dir string, planner Planner, comp
})

if err != nil {
return false, ulid.ULID{}, halt(errors.Wrapf(err, "compact blocks %v", toCompactDirs))
compactErr := errors.Wrapf(err, "compact blocks %v", toCompactDirs)
span.LogFields(opentracing_log.Error(compactErr))
return false, ulid.ULID{}, halt(compactErr)
}
if compID == (ulid.ULID{}) {
// Prometheus compactor found that the compacted block would have no samples.
Expand Down Expand Up @@ -1103,7 +1122,9 @@ func (cg *Group) compact(ctx context.Context, dir string, planner Planner, comp
err = block.VerifyIndex(cg.logger, index, newMeta.MinTime, newMeta.MaxTime)
})
if !cg.acceptMalformedIndex && err != nil {
return false, ulid.ULID{}, halt(errors.Wrapf(err, "invalid result block %s", bdir))
verifyErr := errors.Wrapf(err, "invalid result block %s", bdir)
span.LogFields(opentracing_log.Error(verifyErr))
return false, ulid.ULID{}, halt(verifyErr)
}

// Ensure the output block is not overlapping with anything else,
Expand All @@ -1120,7 +1141,9 @@ func (cg *Group) compact(ctx context.Context, dir string, planner Planner, comp
err = block.Upload(ctx, cg.logger, cg.bkt, bdir, cg.hashFunc)
})
if err != nil {
return false, ulid.ULID{}, retry(errors.Wrapf(err, "upload of %s failed", compID))
uploadErr := errors.Wrapf(err, "upload of %s failed", compID)
span.LogFields(opentracing_log.Error(uploadErr))
return false, ulid.ULID{}, retry(uploadErr)
}
level.Info(cg.logger).Log("msg", "uploaded block", "result_block", compID, "duration", time.Since(begin), "duration_ms", time.Since(begin).Milliseconds())

Expand All @@ -1132,7 +1155,9 @@ func (cg *Group) compact(ctx context.Context, dir string, planner Planner, comp
err = cg.deleteBlock(meta.ULID, filepath.Join(dir, meta.ULID.String()))
}, opentracing.Tags{"block.id": meta.ULID})
if err != nil {
return false, ulid.ULID{}, retry(errors.Wrapf(err, "mark old block for deletion from bucket"))
deleteErr := errors.Wrapf(err, "mark old block for deletion from bucket")
span.LogFields(opentracing_log.Error(deleteErr))
return false, ulid.ULID{}, retry(deleteErr)
}
cg.groupGarbageCollectedBlocks.Inc()
}
Expand Down

0 comments on commit e11d776

Please sign in to comment.