storage: add LastSamplePairForFingerprint method

pull/786/head
Fabian Reinartz 10 years ago
parent 39a8254963
commit 6bfb4549a6

@ -142,6 +142,20 @@ func (cd *chunkDesc) lastTime() clientmodel.Timestamp {
return cd.c.newIterator().lastTimestamp()
}
func (cd *chunkDesc) lastSamplePair() *metric.SamplePair {
cd.Lock()
defer cd.Unlock()
if cd.c == nil {
return nil
}
it := cd.c.newIterator()
return &metric.SamplePair{
Timestamp: it.lastTimestamp(),
Value: it.lastSampleValue(),
}
}
func (cd *chunkDesc) isEvicted() bool {
cd.Lock()
defer cd.Unlock()

@ -40,6 +40,9 @@ type Storage interface {
// label matchers. At least one label matcher must be specified that does not
// match the empty string.
MetricsForLabelMatchers(matchers ...*metric.LabelMatcher) map[clientmodel.Fingerprint]clientmodel.COWMetric
// LastSamplePairForFingerprint returns the last sample pair for the provided fingerprint.
// If the respective time series is evicted, nil is returned.
LastSamplePairForFingerprint(clientmodel.Fingerprint) *metric.SamplePair
// Get all of the label values that are associated with a given label name.
LabelValuesForLabelName(clientmodel.LabelName) clientmodel.LabelValues
// Get the metric associated with the provided fingerprint.

@ -301,7 +301,7 @@ func (s *memorySeriesStorage) WaitForIndexing() {
s.persistence.waitForIndexing()
}
// NewIterator implements storage.
// NewIterator implements Storage.
func (s *memorySeriesStorage) NewIterator(fp clientmodel.Fingerprint) SeriesIterator {
s.fpLocker.Lock(fp)
defer s.fpLocker.Unlock(fp)
@ -321,6 +321,18 @@ func (s *memorySeriesStorage) NewIterator(fp clientmodel.Fingerprint) SeriesIter
}
}
// LastSampleForFingerprint implements Storage.
func (s *memorySeriesStorage) LastSamplePairForFingerprint(fp clientmodel.Fingerprint) *metric.SamplePair {
s.fpLocker.Lock(fp)
defer s.fpLocker.Unlock(fp)
series, ok := s.fpToSeries.get(fp)
if !ok {
return nil
}
return series.head().lastSamplePair()
}
// boundedIterator wraps a SeriesIterator and does not allow fetching
// data from earlier than the configured start time.
type boundedIterator struct {

Loading…
Cancel
Save