Skip to content

Commit

Permalink
MemPostings.AddInfoMetric: Fix setting of info metric data labels
Browse files Browse the repository at this point in the history
Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>
  • Loading branch information
aknuds1 committed Apr 11, 2024
1 parent 6063d61 commit 0a08808
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
1 change: 1 addition & 0 deletions promql/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -3253,6 +3253,7 @@ func (ev *evaluator) aggregationCountValues(e *parser.AggregateExpr, grouping []
return enh.Out, nil
}

// TODO: Handle info metric samples.
func addToSeries(ss *Series, ts int64, f float64, h *histogram.FloatHistogram, numSteps int) {
if h == nil {
if ss.Floats == nil {
Expand Down
20 changes: 17 additions & 3 deletions tsdb/index/postings.go
Original file line number Diff line number Diff line change
Expand Up @@ -388,16 +388,20 @@ func (p *MemPostings) AddInfoMetric(id storage.SeriesRef, lset labels.Labels, t
defer p.mtx.Unlock()

ils := make(labels.Labels, 0, len(identifyingLabels))
dls := make(labels.Labels, 0, len(lset)-len(identifyingLabels))
j := 0
i := 0
lset.Range(func(l labels.Label) {
if j >= len(identifyingLabels) {
if j >= len(identifyingLabels) && l.Name != "__name__" {
dls = append(dls, l)
return
}

if i == identifyingLabels[j] {
j++
ils = append(ils, l)
} else if l.Name != "__name__" {
dls = append(dls, l)
}

i++
Expand All @@ -410,6 +414,7 @@ func (p *MemPostings) AddInfoMetric(id storage.SeriesRef, lset labels.Labels, t
{
MinT: t,
IdentifyingLabels: ils,
DataLabels: dls,
},
}
return
Expand All @@ -421,6 +426,7 @@ func (p *MemPostings) AddInfoMetric(id storage.SeriesRef, lset labels.Labels, t
entries = append(entries, infoMetricEntry{
MinT: t,
IdentifyingLabels: ils,
DataLabels: dls,
})

p.infoMetrics[id] = entries
Expand Down Expand Up @@ -459,6 +465,7 @@ func (p *MemPostings) InfoMetricDataLabels(ctx context.Context, lbls labels.Labe
if len(matchers) == 0 {
// Consider all info metrics.
infoMetrics = p.infoMetrics
fmt.Printf("MemPostings: not filtering info metrics\n")
} else {
// Pick only info metrics that have matching (potential data) labels.
infoMetrics = map[storage.SeriesRef][]infoMetricEntry{}
Expand All @@ -478,6 +485,7 @@ func (p *MemPostings) InfoMetricDataLabels(ctx context.Context, lbls labels.Labe
}
}
if len(infoMetrics) == 0 {
fmt.Printf("MemPostings: there are no info metrics\n")
return nil
}

Expand All @@ -489,16 +497,21 @@ func (p *MemPostings) InfoMetricDataLabels(ctx context.Context, lbls labels.Labe
dataLabels := map[string]string{}
for _, entries := range infoMetrics {
for _, entry := range entries {
if entry.MinT > t || entry.MaxT < t {
// entry.MaxT == 0 means it's current
if entry.MinT > t || (entry.MaxT > 0 && entry.MaxT < t) {
fmt.Printf("MemPostings: Entry of MinT %d and MaxT %d doesn't fit timestamp %d\n", entry.MinT, entry.MaxT, t)
continue
}

fmt.Printf("MemPostings: Entry of MinT %d and MaxT %d fits timestamp %d\n", entry.MinT, entry.MaxT, t)

// This entry is for a time range corresponding to t.
isMatch := true
for _, il := range entry.IdentifyingLabels {
l, ok := lblMap[il.Name]
if !ok || l.Name != il.Name || l.Value != il.Value {
if !ok || l.Value != il.Value {
isMatch = false
fmt.Printf("MemPostings: This entry doesn't have matching identifying labels: %s = %s\n", il.Name, il.Value)
break
}
}
Expand All @@ -507,6 +520,7 @@ func (p *MemPostings) InfoMetricDataLabels(ctx context.Context, lbls labels.Labe
continue
}

fmt.Printf("MemPostings: This entry matches: %s\n", entry.DataLabels.String())
for _, l := range entry.DataLabels {
dataLabels[l.Name] = l.Value
}
Expand Down

0 comments on commit 0a08808

Please sign in to comment.