Eliminate need to get fingerprints during query execution time.

This commit is contained in:
Julius Volz 2013-03-27 14:06:30 +01:00
parent a4f0578a7e
commit b836066c71
3 changed files with 12 additions and 21 deletions

View file

@ -146,6 +146,8 @@ type (
// Vector literal, i.e. metric name plus labelset. // Vector literal, i.e. metric name plus labelset.
VectorLiteral struct { VectorLiteral struct {
labels model.LabelSet labels model.LabelSet
// Fingerprints are populated from labels at query analysis time.
fingerprints model.Fingerprints
} }
// A function of vector return type. // A function of vector return type.
@ -176,6 +178,8 @@ type (
// Matrix literal, i.e. metric name plus labelset and timerange. // Matrix literal, i.e. metric name plus labelset and timerange.
MatrixLiteral struct { MatrixLiteral struct {
labels model.LabelSet labels model.LabelSet
// Fingerprints are populated from labels at query analysis time.
fingerprints model.Fingerprints
interval time.Duration interval time.Duration
} }
) )
@ -358,7 +362,7 @@ func (node *VectorAggregation) Eval(timestamp *time.Time, view *viewAdapter) Vec
} }
func (node *VectorLiteral) Eval(timestamp *time.Time, view *viewAdapter) Vector { func (node *VectorLiteral) Eval(timestamp *time.Time, view *viewAdapter) Vector {
values, err := view.GetValueAtTime(node.labels, timestamp) values, err := view.GetValueAtTime(node.fingerprints, timestamp)
if err != nil { if err != nil {
log.Printf("Unable to get vector values") log.Printf("Unable to get vector values")
return Vector{} return Vector{}
@ -546,7 +550,7 @@ func (node *MatrixLiteral) Eval(timestamp *time.Time, view *viewAdapter) Matrix
OldestInclusive: timestamp.Add(-node.interval), OldestInclusive: timestamp.Add(-node.interval),
NewestInclusive: *timestamp, NewestInclusive: *timestamp,
} }
values, err := view.GetRangeValues(node.labels, interval) values, err := view.GetRangeValues(node.fingerprints, interval)
if err != nil { if err != nil {
log.Printf("Unable to get values for vector interval") log.Printf("Unable to get values for vector interval")
return Matrix{} return Matrix{}
@ -559,7 +563,7 @@ func (node *MatrixLiteral) EvalBoundaries(timestamp *time.Time, view *viewAdapte
OldestInclusive: timestamp.Add(-node.interval), OldestInclusive: timestamp.Add(-node.interval),
NewestInclusive: *timestamp, NewestInclusive: *timestamp,
} }
values, err := view.GetBoundaryValues(node.labels, interval) values, err := view.GetBoundaryValues(node.fingerprints, interval)
if err != nil { if err != nil {
log.Printf("Unable to get boundary values for vector interval") log.Printf("Unable to get boundary values for vector interval")
return Matrix{} return Matrix{}

View file

@ -57,12 +57,7 @@ func (v *viewAdapter) chooseClosestSample(samples []model.SamplePair, timestamp
return return
} }
func (v *viewAdapter) GetValueAtTime(labels model.LabelSet, timestamp *time.Time) (samples []*model.Sample, err error) { func (v *viewAdapter) GetValueAtTime(fingerprints model.Fingerprints, timestamp *time.Time) (samples []*model.Sample, err error) {
fingerprints, err := queryStorage.GetFingerprintsForLabelSet(labels)
if err != nil {
return
}
for _, fingerprint := range fingerprints { for _, fingerprint := range fingerprints {
sampleCandidates := v.view.GetValueAtTime(fingerprint, *timestamp) sampleCandidates := v.view.GetValueAtTime(fingerprint, *timestamp)
samplePair := v.chooseClosestSample(sampleCandidates, timestamp) samplePair := v.chooseClosestSample(sampleCandidates, timestamp)
@ -81,12 +76,7 @@ func (v *viewAdapter) GetValueAtTime(labels model.LabelSet, timestamp *time.Time
return return
} }
func (v *viewAdapter) GetBoundaryValues(labels model.LabelSet, interval *model.Interval) (sampleSets []*model.SampleSet, err error) { func (v *viewAdapter) GetBoundaryValues(fingerprints model.Fingerprints, interval *model.Interval) (sampleSets []*model.SampleSet, err error) {
fingerprints, err := queryStorage.GetFingerprintsForLabelSet(labels)
if err != nil {
return
}
for _, fingerprint := range fingerprints { for _, fingerprint := range fingerprints {
// TODO: change to GetBoundaryValues() once it has the right return type. // TODO: change to GetBoundaryValues() once it has the right return type.
samplePairs := v.view.GetRangeValues(fingerprint, *interval) samplePairs := v.view.GetRangeValues(fingerprint, *interval)
@ -109,12 +99,7 @@ func (v *viewAdapter) GetBoundaryValues(labels model.LabelSet, interval *model.I
return sampleSets, nil return sampleSets, nil
} }
func (v *viewAdapter) GetRangeValues(labels model.LabelSet, interval *model.Interval) (sampleSets []*model.SampleSet, err error) { func (v *viewAdapter) GetRangeValues(fingerprints model.Fingerprints, interval *model.Interval) (sampleSets []*model.SampleSet, err error) {
fingerprints, err := queryStorage.GetFingerprintsForLabelSet(labels)
if err != nil {
return
}
for _, fingerprint := range fingerprints { for _, fingerprint := range fingerprints {
samplePairs := v.view.GetRangeValues(fingerprint, *interval) samplePairs := v.view.GetRangeValues(fingerprint, *interval)
if samplePairs == nil { if samplePairs == nil {

View file

@ -66,6 +66,7 @@ func (analyzer *QueryAnalyzer) Visit(node Node) {
log.Printf("Error getting fingerprints for labelset %v: %v", n.labels, err) log.Printf("Error getting fingerprints for labelset %v: %v", n.labels, err)
return return
} }
n.fingerprints = fingerprints
for _, fingerprint := range fingerprints { for _, fingerprint := range fingerprints {
if !analyzer.IntervalRanges[fingerprint] { if !analyzer.IntervalRanges[fingerprint] {
analyzer.IntervalRanges[fingerprint] = true analyzer.IntervalRanges[fingerprint] = true
@ -77,6 +78,7 @@ func (analyzer *QueryAnalyzer) Visit(node Node) {
log.Printf("Error getting fingerprints for labelset %v: %v", n.labels, err) log.Printf("Error getting fingerprints for labelset %v: %v", n.labels, err)
return return
} }
n.fingerprints = fingerprints
for _, fingerprint := range fingerprints { for _, fingerprint := range fingerprints {
interval := n.interval interval := n.interval
// If an interval has already been recorded for this fingerprint, merge // If an interval has already been recorded for this fingerprint, merge