mirror of
https://github.com/prometheus/prometheus.git
synced 2024-12-28 23:19:41 -08:00
6579dc3e40
The first sort in groupByFingerprint already ensures that all resulting sample
lists contain only one fingerprint. We also already assume that all
samples passed into AppendSamples (and thus groupByFingerprint) are
chronologically sorted within each fingerprint.
The extra chronological sort is thus superfluous. Furthermore, this
second sort didn't only sort chronologically, but also compared all
metric fingerprints again (although we already know that we're only
sorting within samples for the same fingerprint). This caused a huge
memory and runtime overhead.
In a heavily loaded real Prometheus, this brought down disk flush times
from ~9 minutes to ~1 minute.
OLD:
BenchmarkLevelDBAppendRepeatingValues 5 331391808 ns/op 44542953 B/op 597788 allocs/op
BenchmarkLevelDBAppendsRepeatingValues 5 329893512 ns/op 46968288 B/op 3104373 allocs/op
NEW:
BenchmarkLevelDBAppendRepeatingValues 5 299298635 ns/op 43329497 B/op 567616 allocs/op
BenchmarkLevelDBAppendsRepeatingValues 20 92204601 ns/op 1779454
B/op 70975 allocs/op
Change-Id: Ie2d8db3569b0102a18010f9e106e391fda7f7883
143 lines
5.8 KiB
Go
143 lines
5.8 KiB
Go
// Copyright 2013 Prometheus Team
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
// you may not use this file except in compliance with the License.
|
|
// You may obtain a copy of the License at
|
|
//
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
//
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
// See the License for the specific language governing permissions and
|
|
// limitations under the License.
|
|
|
|
package metric
|
|
|
|
import (
|
|
"time"
|
|
|
|
clientmodel "github.com/prometheus/client_golang/model"
|
|
|
|
"github.com/prometheus/prometheus/stats"
|
|
)
|
|
|
|
// Persistence is a system for storing metric samples in a persistence
|
|
// layer.
|
|
type Persistence interface {
|
|
// A storage system may rely on external resources and thusly should be
|
|
// closed when finished.
|
|
Close()
|
|
|
|
// Record a group of new samples in the storage layer. Multiple samples for
|
|
// the same fingerprint need to be submitted in chronological order, from
|
|
// oldest to newest (both in the same call to AppendSamples and across
|
|
// multiple calls).
|
|
AppendSamples(clientmodel.Samples) error
|
|
|
|
// Get all of the metric fingerprints that are associated with the
|
|
// provided label matchers.
|
|
GetFingerprintsForLabelMatchers(LabelMatchers) (clientmodel.Fingerprints, error)
|
|
|
|
// Get all of the label values that are associated with a given label name.
|
|
GetLabelValuesForLabelName(clientmodel.LabelName) (clientmodel.LabelValues, error)
|
|
|
|
// Get the metric associated with the provided fingerprint.
|
|
GetMetricForFingerprint(*clientmodel.Fingerprint) (clientmodel.Metric, error)
|
|
|
|
// Get all label values that are associated with a given label name.
|
|
GetAllValuesForLabel(clientmodel.LabelName) (clientmodel.LabelValues, error)
|
|
}
|
|
|
|
// PreloadingPersistence is a Persistence which supports building
|
|
// preloaded views.
|
|
type PreloadingPersistence interface {
|
|
Persistence
|
|
// NewViewRequestBuilder furnishes a ViewRequestBuilder for remarking what
|
|
// types of queries to perform.
|
|
NewViewRequestBuilder() ViewRequestBuilder
|
|
}
|
|
|
|
// View provides a view of the values in the datastore subject to the request
|
|
// of a preloading operation.
|
|
type View interface {
|
|
// Get the two values that are immediately adjacent to a given time.
|
|
GetValueAtTime(*clientmodel.Fingerprint, clientmodel.Timestamp) Values
|
|
// Get the boundary values of an interval: the first value older than
|
|
// the interval start, and the first value younger than the interval
|
|
// end.
|
|
GetBoundaryValues(*clientmodel.Fingerprint, Interval) Values
|
|
// Get all values contained within a provided interval.
|
|
GetRangeValues(*clientmodel.Fingerprint, Interval) Values
|
|
}
|
|
|
|
// ViewablePersistence is a Persistence that is able to present the
|
|
// samples it has stored as a View.
|
|
type ViewablePersistence interface {
|
|
Persistence
|
|
View
|
|
}
|
|
|
|
// ViewRequestBuilder represents the summation of all datastore queries that
|
|
// shall be performed to extract values. Call the Get... methods to record the
|
|
// queries. Once done, use HasOp and PopOp to retrieve the resulting
|
|
// operations. The operations are sorted by their fingerprint (and, for equal
|
|
// fingerprints, by the StartsAt timestamp of their operation).
|
|
type ViewRequestBuilder interface {
|
|
// GetMetricAtTime records a query to get, for the given Fingerprint,
|
|
// either the value at that time if there is a match or the one or two
|
|
// values adjacent thereto.
|
|
GetMetricAtTime(fingerprint *clientmodel.Fingerprint, time clientmodel.Timestamp)
|
|
// GetMetricAtInterval records a query to get, for the given
|
|
// Fingerprint, either the value at that interval from From through
|
|
// Through if there is a match or the one or two values adjacent for
|
|
// each point.
|
|
GetMetricAtInterval(fingerprint *clientmodel.Fingerprint, from, through clientmodel.Timestamp, interval time.Duration)
|
|
// GetMetricRange records a query to get, for the given Fingerprint, the
|
|
// values that occur inclusively from From through Through.
|
|
GetMetricRange(fingerprint *clientmodel.Fingerprint, from, through clientmodel.Timestamp)
|
|
// GetMetricRangeAtInterval records a query to get value ranges at
|
|
// intervals for the given Fingerprint:
|
|
//
|
|
// |----| |----| |----| |----|
|
|
// ^ ^ ^ ^ ^ ^
|
|
// | \------------/ \----/ |
|
|
// from interval rangeDuration through
|
|
GetMetricRangeAtInterval(fp *clientmodel.Fingerprint, from, through clientmodel.Timestamp, interval, rangeDuration time.Duration)
|
|
// Execute materializes a View, subject to a timeout.
|
|
Execute(deadline time.Duration, queryStats *stats.TimerGroup) (View, error)
|
|
// PopOp emits the next operation in the queue (sorted by
|
|
// fingerprint). If called while HasOps returns false, the
|
|
// behavior is undefined.
|
|
PopOp() Op
|
|
// HasOp returns true if there is at least one more operation in the
|
|
// queue.
|
|
HasOp() bool
|
|
}
|
|
|
|
// Op encapsulates a primitive query operation.
|
|
type Op interface {
|
|
// Fingerprint returns the fingerprint of the metric this operation
|
|
// operates on.
|
|
Fingerprint() *clientmodel.Fingerprint
|
|
// ExtractSamples extracts samples from a stream of values and advances
|
|
// the operation time.
|
|
ExtractSamples(Values) Values
|
|
// Consumed returns whether the operator has consumed all data it needs.
|
|
Consumed() bool
|
|
// CurrentTime gets the current operation time. In a newly created op,
|
|
// this is the starting time of the operation. During ongoing execution
|
|
// of the op, the current time is advanced accordingly. Once no
|
|
// subsequent work associated with the operation remains, nil is
|
|
// returned.
|
|
CurrentTime() clientmodel.Timestamp
|
|
}
|
|
|
|
// CurationState contains high-level curation state information for the
|
|
// heads-up-display.
|
|
type CurationState struct {
|
|
Active bool
|
|
Name string
|
|
Limit time.Duration
|
|
Fingerprint *clientmodel.Fingerprint
|
|
}
|