Fix deadlock, structure target logging

This commit is contained in:
Fabian Reinartz 2016-02-03 10:39:34 +01:00
parent d0d2c38c68
commit 1f877f3d2a
3 changed files with 5 additions and 5 deletions

View File

@ -453,6 +453,7 @@ func (t *Target) scrape(appender storage.SampleAppender) (err error) {
var ( var (
samples model.Vector samples model.Vector
numOutOfOrder int numOutOfOrder int
logger = log.With("target", t.InstanceIdentifier())
) )
for { for {
if err = sdec.Decode(&samples); err != nil { if err = sdec.Decode(&samples); err != nil {
@ -464,14 +465,14 @@ func (t *Target) scrape(appender storage.SampleAppender) (err error) {
if err == local.ErrOutOfOrderSample { if err == local.ErrOutOfOrderSample {
numOutOfOrder++ numOutOfOrder++
} else { } else {
log.Warnf("Error inserting sample %v: %s", s, err) logger.With("sample", s).Warnf("Error inserting sample: %s", err)
} }
} }
} }
} }
if numOutOfOrder > 0 { if numOutOfOrder > 0 {
log.Warnf("Error on ingesting %d out-of-order samples") logger.With("numDropped", numOutOfOrder).Warn("Error on ingesting out-of-order samples")
} }
if err == io.EOF { if err == io.EOF {

View File

@ -591,6 +591,7 @@ func (s *memorySeriesStorage) Append(sample *model.Sample) error {
series := s.getOrCreateSeries(fp, sample.Metric) series := s.getOrCreateSeries(fp, sample.Metric)
if sample.Timestamp <= series.lastTime { if sample.Timestamp <= series.lastTime {
s.fpLocker.Unlock(fp)
// Don't log and track equal timestamps, as they are a common occurrence // Don't log and track equal timestamps, as they are a common occurrence
// when using client-side timestamps (e.g. Pushgateway or federation). // when using client-side timestamps (e.g. Pushgateway or federation).
// It would be even better to also compare the sample values here, but // 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 {
s.outOfOrderSamplesCount.Inc() s.outOfOrderSamplesCount.Inc()
return ErrOutOfOrderSample return ErrOutOfOrderSample
} }
s.fpLocker.Unlock(fp)
return nil return nil
} }
completedChunksCount := series.add(&model.SamplePair{ completedChunksCount := series.add(&model.SamplePair{

View File

@ -25,8 +25,7 @@ type SampleAppender interface {
// of the sample after Append has returned. Remote storage // of the sample after Append has returned. Remote storage
// implementation will simply drop samples if they cannot keep up with // implementation will simply drop samples if they cannot keep up with
// sending samples. Local storage implementations will only drop metrics // sending samples. Local storage implementations will only drop metrics
// upon unrecoverable errors. Reporting any errors is done via metrics // upon unrecoverable errors.
// and logs and not the concern of the caller.
Append(*model.Sample) error Append(*model.Sample) error
// NeedsThrottling returns true if the underlying storage wishes to not // NeedsThrottling returns true if the underlying storage wishes to not
// receive any more samples. Append will still work but might lead to // receive any more samples. Append will still work but might lead to