Skip to content

Commit

Permalink
Drop info function from this branch
Browse files Browse the repository at this point in the history
Various cleanup.

Signed-off-by: Arve Knudsen <[email protected]>
  • Loading branch information
aknuds1 committed Aug 1, 2024
1 parent 5437059 commit ec03404
Show file tree
Hide file tree
Showing 13 changed files with 13 additions and 166 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

* [FEATURE] OTLP receiver: Add new option `otlp.promote_resource_attributes`, for any OTel resource attributes that should be promoted to metric labels. #14200
* [FEATURE] Remote-Write: Add sender and receiver support for [Remote Write 2.0-rc.2](https://prometheus.io/docs/specs/remote_write_spec_2_0/) specification #14395 #14427 #14444
* [FEATURE] PromQL: Add `info` function. #14495
* [FEATURE] PromQL engine: Support automatic inclusion of target_info data labels.
* [ENHANCEMENT] Remote-Write: 1.x messages against Remote Write 2.x Receivers will have now correct values for `prometheus_storage_<samples|histograms|exemplar>_failed_total` in case of partial errors #14444

## 2.53.1 / 2024-07-10
Expand Down
5 changes: 0 additions & 5 deletions docs/querying/functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -432,11 +432,6 @@ by the number of seconds under the specified time range window, and should be
used primarily for human readability. Use `rate` in recording rules so that
increases are tracked consistently on a per-second basis.

## `info()`

For each time series in `v`, `info(v instant-vector, [label-selector string])` finds all info metrics with corresponding
identifying labels, and adds the union of their data labels to the time series, that gets returned.

## `irate()`

`irate(v range-vector)` calculates the per-second instant rate of increase of
Expand Down
6 changes: 1 addition & 5 deletions promql/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -685,7 +685,6 @@ func durationMilliseconds(d time.Duration) int64 {
func (ng *Engine) execEvalStmt(ctx context.Context, query *query, s *parser.EvalStmt) (parser.Value, annotations.Annotations, error) {
prepareSpanTimer, ctxPrepare := query.stats.GetSpanTimer(ctx, stats.QueryPreparationTime, ng.metrics.queryPrepareTime)
mint, maxt := FindMinMaxTime(s)
fmt.Printf("Calling Querier on %T\n", query.queryable)
querier, err := query.queryable.Querier(mint, maxt)
if err != nil {
prepareSpanTimer.Finish()
Expand Down Expand Up @@ -942,7 +941,6 @@ func (ng *Engine) populateSeries(ctx context.Context, querier storage.Querier, s
hints.By, hints.Grouping = extractGroupsFromPath(path)
// TODO: Make configurable.
hints.IncludeInfoMetricDataLabels = true
fmt.Printf("Selecting, querier: %T\n", querier)
n.UnexpandedSeriesSet = querier.Select(ctx, false, hints, n.LabelMatchers...)

case *parser.MatrixSelector:
Expand Down Expand Up @@ -1109,8 +1107,6 @@ type EvalNodeHelper struct {
rightSigs map[string]Sample
matchedSigs map[string]map[uint64]struct{}
resultMetric map[string]labels.Labels

Querier storage.Querier
}

func (enh *EvalNodeHelper) resetBuilder(lbls labels.Labels) {
Expand Down Expand Up @@ -1160,7 +1156,7 @@ func (ev *evaluator) rangeEval(prepSeries func(labels.Labels, *EvalSeriesHelper)
biggestLen = len(matrixes[i])
}
}
enh := &EvalNodeHelper{Out: make(Vector, 0, biggestLen), Querier: ev.querier}
enh := &EvalNodeHelper{Out: make(Vector, 0, biggestLen)}
type seriesAndTimestamp struct {
Series
ts int64
Expand Down
54 changes: 0 additions & 54 deletions promql/functions.go
Original file line number Diff line number Diff line change
Expand Up @@ -1537,59 +1537,6 @@ func funcYear(vals []parser.Value, args parser.Expressions, enh *EvalNodeHelper)
}), nil
}

// === info(vector parser.ValueTypeVector, [ls label-selector]) (Vector, Annotations) ===
func funcInfo(vals []parser.Value, args parser.Expressions, enh *EvalNodeHelper) (Vector, annotations.Annotations) {
/*
vector := vals[0].(Vector)
var dataLabelMatchers []*labels.Matcher
if len(args) > 1 {
// TODO: Introduce a dedicated LabelSelector type
labelSelector := args[1].(*parser.VectorSelector)
dataLabelMatchers = labelSelector.LabelMatchers
}
if len(vector) == 0 {
return enh.Out, nil
}
ts := vector[0].T
var annos annotations.Annotations
for _, s := range vector {
// Find info metrics for which all of their identifying labels are contained among the metric's labels.
// Pick the union of the data labels belonging to the various info metrics.
dataLabels, curAnnos, err := enh.Querier.InfoMetricDataLabels(context.TODO(), s.Metric, ts, dataLabelMatchers...)
annos.Merge(curAnnos)
if err != nil {
annos.Add(fmt.Errorf("querying for info metric data labels: %w", err))
return nil, annos
}
lb := labels.NewBuilder(s.Metric)
dataLabels.Range(func(l labels.Label) {
fmt.Printf("Data label %q = %q\n", l.Name, l.Value)
if lb.Get(l.Name) == "" {
lb.Set(l.Name, l.Value)
}
})
// If info metric data label matchers are specified, we should only include series where
// info metric data labels are found
if len(dataLabelMatchers) > 0 && dataLabels.IsEmpty() {
continue
}
enh.Out = append(enh.Out, Sample{
Metric: lb.Labels(),
F: s.F,
H: s.H,
})
}
*/
return enh.Out, annotations.Annotations{}
}

// FunctionCalls is a list of all functions supported by PromQL, including their types.
var FunctionCalls = map[string]FunctionCall{
"abs": funcAbs,
Expand Down Expand Up @@ -1630,7 +1577,6 @@ var FunctionCalls = map[string]FunctionCall{
"hour": funcHour,
"idelta": funcIdelta,
"increase": funcIncrease,
"info": funcInfo,
"irate": funcIrate,
"label_replace": funcLabelReplace,
"label_join": funcLabelJoin,
Expand Down
7 changes: 0 additions & 7 deletions promql/parser/functions.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,13 +223,6 @@ var Functions = map[string]*Function{
ArgTypes: []ValueType{ValueTypeMatrix},
ReturnType: ValueTypeVector,
},
"info": {
Name: "info",
ArgTypes: []ValueType{ValueTypeVector, ValueTypeVector},
ReturnType: ValueTypeVector,
Experimental: true,
Variadic: 1,
},
"irate": {
Name: "irate",
ArgTypes: []ValueType{ValueTypeMatrix},
Expand Down
2 changes: 0 additions & 2 deletions storage/fanout.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ package storage

import (
"context"
"fmt"

"github.com/go-kit/log"
"github.com/go-kit/log/level"
Expand Down Expand Up @@ -74,7 +73,6 @@ func (f *fanout) StartTime() (int64, error) {
}

func (f *fanout) Querier(mint, maxt int64) (Querier, error) {
fmt.Printf("fanout.Querier: Primary %T, %d secondaries\n", f.primary, len(f.secondaries))
primary, err := f.primary.Querier(mint, maxt)
if err != nil {
return nil, err
Expand Down
7 changes: 5 additions & 2 deletions storage/generic.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,11 @@ func (a *seriesSetAdapter) At() Series {
}

func (q *querierAdapter) Select(ctx context.Context, sortSeries bool, hints *SelectHints, matchers ...*labels.Matcher) SeriesSet {
includeInfoMetricDataLabels := hints.IncludeInfoMetricDataLabels
hints.IncludeInfoMetricDataLabels = false
includeInfoMetricDataLabels := false
if hints != nil {
includeInfoMetricDataLabels = hints.IncludeInfoMetricDataLabels
hints.IncludeInfoMetricDataLabels = false
}
ss := &seriesSetAdapter{q.genericQuerier.Select(ctx, sortSeries, hints, matchers...)}
if includeInfoMetricDataLabels {
fmt.Printf("querierAdapter.Select: Returning SeriesSetWithInfoLabels\n")
Expand Down
16 changes: 2 additions & 14 deletions storage/infolabels.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,6 @@ import (
"github.com/prometheus/prometheus/util/annotations"
)

type InfoSeries struct {
DataLabels labels.Labels
Samples SampleIterable
}

type InfoMetricDataLabels struct {
// Name is the info metric name.
Name string
Series map[SeriesRef]InfoSeries
}

type infoSeries struct {
name string
identifyingLabels labels.Labels
Expand Down Expand Up @@ -141,7 +130,7 @@ func (ss *SeriesSetWithInfoLabels) init() bool {
hints.DisableTrimming = ss.Hints.DisableTrimming
}
// NB: We only support target_info for now.
// TODO: Pass the base series, in order to filter out irrelevant info series.
// TODO: Pass regexp matchers for all of the base series' identifying label sets, in order to ignore irrelevant info series.
// TODO: Pass data label matchers.
infoIt := ss.Q.Select(context.TODO(), false, hints, labels.MustNewMatcher(labels.MatchEqual, labels.MetricName, "target_info"))
iLB := labels.NewScratchBuilder(0)
Expand Down Expand Up @@ -185,7 +174,6 @@ func (ss *SeriesSetWithInfoLabels) enrichSeries(s Series, t int64, lb *labels.Sc
lblMap := s.Labels().Map()
isTimestamps := map[string]int64{}
isLbls := map[string]labels.Labels{}
// Add all matching info metric data labels to lb.
for _, is := range ss.infoSeries {
// Match identifying labels.
isMatch := true
Expand Down Expand Up @@ -270,7 +258,7 @@ func (ss *SeriesSetWithInfoLabels) At() Series {
}

func (ss *SeriesSetWithInfoLabels) Err() error {
return nil
return ss.err
}

func (ss *SeriesSetWithInfoLabels) Warnings() annotations.Annotations {
Expand Down
1 change: 1 addition & 0 deletions storage/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ type SelectHints struct {
// may be improved.
DisableTrimming bool

// IncludeInfoMetricDataLabels specifies whether to enrich resulting time series with matching info metric data labels.
IncludeInfoMetricDataLabels bool
}

Expand Down
64 changes: 3 additions & 61 deletions tsdb/querier.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import (

"github.com/prometheus/prometheus/model/histogram"
"github.com/prometheus/prometheus/model/labels"
"github.com/prometheus/prometheus/model/value"
"github.com/prometheus/prometheus/storage"
"github.com/prometheus/prometheus/tsdb/chunkenc"
"github.com/prometheus/prometheus/tsdb/chunks"
Expand Down Expand Up @@ -78,61 +77,6 @@ func newBlockBaseQuerier(b BlockReader, mint, maxt int64) (*blockBaseQuerier, er
}, nil
}

func (q *blockBaseQuerier) LatestTimestamp(t int64, chks []chunks.Meta) (int64, error) {
// Find the info metric's latest non-stale timestamp versus t among the chunks.
st := int64(math.MinInt64)
for _, meta := range chks {
chk, _, err := q.chunks.ChunkOrIterable(meta)
if err != nil {
if errors.Is(err, fmt.Errorf("not found")) {
continue
}
return 0, err
}

// Find the latest non-stale sample.
it := chk.Iterator(nil)
curST := int64(math.MinInt64)
prevST := int64(math.MinInt64)
prevV := float64(0)
for vt := it.Next(); vt != chunkenc.ValNone; vt = it.Next() {
st, v := it.At()
if st > t {
// We've progressed past t, pick the previous timestamp if non-stale.
if !value.IsStaleNaN(prevV) {
curST = prevST
}
break
}
if vt != chunkenc.ValFloat {
continue
}

if st < t {
prevST = t
prevV = v
continue
}

// st == t.
if !value.IsStaleNaN(v) {
// We've got a non-stale sample exactly at t.
curST = st
}
break
}

if curST > t {
panic(fmt.Sprintf("chunk range should be max %d", t))
}
if curST > 0 && curST > st {
st = curST
}
}

return st, nil
}

func (q *blockBaseQuerier) LabelValues(ctx context.Context, name string, hints *storage.LabelHints, matchers ...*labels.Matcher) ([]string, annotations.Annotations, error) {
res, err := q.index.SortedLabelValues(ctx, name, matchers...)
return res, nil, err
Expand Down Expand Up @@ -194,13 +138,13 @@ func (q *blockQuerier) Select(ctx context.Context, sortSeries bool, hints *stora
disableTrimming = hints.DisableTrimming
if hints.Func == "series" {
// When you're only looking up metadata (for example series API), you don't need to load any chunks.
return newBlockSeriesSet(q.index, newNopChunkReader(), q.tombstones, q, p, mint, maxt, disableTrimming)
return newBlockSeriesSet(q.index, newNopChunkReader(), q.tombstones, p, mint, maxt, disableTrimming)
}
includeInfoMetricDataLabels = hints.IncludeInfoMetricDataLabels
hints.IncludeInfoMetricDataLabels = false
}

ss := newBlockSeriesSet(q.index, q.chunks, q.tombstones, q, p, mint, maxt, disableTrimming)
ss := newBlockSeriesSet(q.index, q.chunks, q.tombstones, p, mint, maxt, disableTrimming)
if includeInfoMetricDataLabels {
fmt.Printf("blockQuerier.Select: Returning SeriesSetWithInfoLabels\n")
return &storage.SeriesSetWithInfoLabels{
Expand Down Expand Up @@ -1116,7 +1060,7 @@ type blockSeriesSet struct {
blockBaseSeriesSet
}

func newBlockSeriesSet(i IndexReader, c ChunkReader, t tombstones.Reader, q storage.LabelQuerier, p index.Postings, mint, maxt int64, disableTrimming bool) storage.SeriesSet {
func newBlockSeriesSet(i IndexReader, c ChunkReader, t tombstones.Reader, p index.Postings, mint, maxt int64, disableTrimming bool) storage.SeriesSet {
return &blockSeriesSet{
blockBaseSeriesSet{
index: i,
Expand All @@ -1130,7 +1074,6 @@ func newBlockSeriesSet(i IndexReader, c ChunkReader, t tombstones.Reader, q stor
}
}

// At returns the iterator's current series, which has a certain label set and a sample iterator.
func (b *blockSeriesSet) At() storage.Series {
// At can be looped over before iterating, so save the current values locally.
return &blockSeriesEntry{
Expand Down Expand Up @@ -1162,7 +1105,6 @@ func NewBlockChunkSeriesSet(id ulid.ULID, i IndexReader, c ChunkReader, t tombst
}
}

// At returns the iterator's current series, which has a certain label set and a sample iterator.
func (b *blockChunkSeriesSet) At() storage.ChunkSeries {
// At can be looped over before iterating, so save the current values locally.
return &chunkSeriesEntry{
Expand Down
6 changes: 0 additions & 6 deletions web/ui/module/codemirror-promql/src/complete/promql.terms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -281,12 +281,6 @@ export const functionIdentifierTerms = [
info: 'Calculate the increase in value over a range of time (for counters)',
type: 'function',
},
{
label: 'info',
detail: 'function',
info: 'Add data labels from corresponding info metrics',
type: 'function',
},
{
label: 'irate',
detail: 'function',
Expand Down
7 changes: 0 additions & 7 deletions web/ui/module/codemirror-promql/src/types/function.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ import {
Hour,
Idelta,
Increase,
Info,
Irate,
LabelJoin,
LabelReplace,
Expand Down Expand Up @@ -337,12 +336,6 @@ const promqlFunctions: { [key: number]: PromQLFunction } = {
variadic: 0,
returnType: ValueType.vector,
},
[Info]: {
name: 'info',
argTypes: [ValueType.vector, ValueType.vector],
variadic: 0,
returnType: ValueType.vector,
},
[Irate]: {
name: 'irate',
argTypes: [ValueType.matrix],
Expand Down
2 changes: 0 additions & 2 deletions web/ui/module/lezer-promql/src/promql.grammar
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,6 @@ FunctionIdentifier {
Hour |
Idelta |
Increase |
Info |
Irate |
LabelReplace |
LabelJoin |
Expand Down Expand Up @@ -389,7 +388,6 @@ NumberLiteral {
Hour { condFn<"hour"> }
Idelta { condFn<"idelta"> }
Increase { condFn<"increase"> }
Info { condFn<"info"> }
Irate { condFn<"irate"> }
LabelReplace { condFn<"label_replace"> }
LabelJoin { condFn<"label_join"> }
Expand Down

0 comments on commit ec03404

Please sign in to comment.