Skip to content

Commit 1f877f3

Browse files
committed
Fix deadlock, structure target logging
1 parent d0d2c38 commit 1f877f3

File tree

3 files changed

+5
-5
lines changed

3 files changed

+5
-5
lines changed

retrieval/target.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -453,6 +453,7 @@ func (t *Target) scrape(appender storage.SampleAppender) (err error) {
453453
var (
454454
samples model.Vector
455455
numOutOfOrder int
456+
logger = log.With("target", t.InstanceIdentifier())
456457
)
457458
for {
458459
if err = sdec.Decode(&samples); err != nil {
@@ -464,14 +465,14 @@ func (t *Target) scrape(appender storage.SampleAppender) (err error) {
464465
if err == local.ErrOutOfOrderSample {
465466
numOutOfOrder++
466467
} else {
467-
log.Warnf("Error inserting sample %v: %s", s, err)
468+
logger.With("sample", s).Warnf("Error inserting sample: %s", err)
468469
}
469470
}
470471

471472
}
472473
}
473474
if numOutOfOrder > 0 {
474-
log.Warnf("Error on ingesting %d out-of-order samples")
475+
logger.With("numDropped", numOutOfOrder).Warn("Error on ingesting out-of-order samples")
475476
}
476477

477478
if err == io.EOF {

storage/local/storage.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -591,6 +591,7 @@ func (s *memorySeriesStorage) Append(sample *model.Sample) error {
591591
series := s.getOrCreateSeries(fp, sample.Metric)
592592

593593
if sample.Timestamp <= series.lastTime {
594+
s.fpLocker.Unlock(fp)
594595
// Don't log and track equal timestamps, as they are a common occurrence
595596
// when using client-side timestamps (e.g. Pushgateway or federation).
596597
// It would be even better to also compare the sample values here, but
@@ -599,7 +600,6 @@ func (s *memorySeriesStorage) Append(sample *model.Sample) error {
599600
s.outOfOrderSamplesCount.Inc()
600601
return ErrOutOfOrderSample
601602
}
602-
s.fpLocker.Unlock(fp)
603603
return nil
604604
}
605605
completedChunksCount := series.add(&model.SamplePair{

storage/storage.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@ type SampleAppender interface {
2525
// of the sample after Append has returned. Remote storage
2626
// implementation will simply drop samples if they cannot keep up with
2727
// sending samples. Local storage implementations will only drop metrics
28-
// upon unrecoverable errors. Reporting any errors is done via metrics
29-
// and logs and not the concern of the caller.
28+
// upon unrecoverable errors.
3029
Append(*model.Sample) error
3130
// NeedsThrottling returns true if the underlying storage wishes to not
3231
// receive any more samples. Append will still work but might lead to

0 commit comments

Comments
 (0)