Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Info PromQL function prototype #598

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions cmd/prometheus/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
"github.com/prometheus/prometheus/model/relabel"
"github.com/prometheus/prometheus/notifier"
_ "github.com/prometheus/prometheus/plugins" // Register plugins.
"github.com/prometheus/prometheus/promql"

Check failure on line 70 in cmd/prometheus/main.go

View workflow job for this annotation

GitHub Actions / golangci-lint

could not import github.com/prometheus/prometheus/promql (-: # github.com/prometheus/prometheus/promql

Check failure on line 70 in cmd/prometheus/main.go

View workflow job for this annotation

GitHub Actions / golangci-lint

could not import github.com/prometheus/prometheus/promql (-: # github.com/prometheus/prometheus/promql
"github.com/prometheus/prometheus/promql/parser"
"github.com/prometheus/prometheus/rules"
"github.com/prometheus/prometheus/scrape"
Expand Down Expand Up @@ -1561,6 +1561,10 @@
return 0, tsdb.ErrNotReady
}

func (n notReadyAppender) AppendInfoSample(storage.SeriesRef, labels.Labels, int64, []int) (storage.SeriesRef, error) {
return 0, tsdb.ErrNotReady
}

func (n notReadyAppender) AppendExemplar(ref storage.SeriesRef, l labels.Labels, e exemplar.Exemplar) (storage.SeriesRef, error) {
return 0, tsdb.ErrNotReady
}
Expand Down
15 changes: 15 additions & 0 deletions cmd/promtool/tsdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -635,6 +635,8 @@ func analyzeCompaction(ctx context.Context, block tsdb.BlockReader, indexr tsdb.
histogramChunkSamplesCount := make([]int, 0)
histogramChunkSize := make([]int, 0)
histogramChunkBucketsCount := make([]int, 0)
infoChunkSamplesCount := make([]int, 0)
infoChunkSize := make([]int, 0)
var builder labels.ScratchBuilder
for postingsr.Next() {
var chks []chunks.Meta
Expand Down Expand Up @@ -687,6 +689,11 @@ func analyzeCompaction(ctx context.Context, block tsdb.BlockReader, indexr tsdb.
bucketCount += len(f.NegativeBuckets)
}
histogramChunkBucketsCount = append(histogramChunkBucketsCount, bucketCount)
case chunkenc.EncInfoMetric:
infoChunkSamplesCount = append(infoChunkSamplesCount, chk.NumSamples())
infoChunkSize = append(infoChunkSize, len(chk.Bytes()))
default:
return fmt.Errorf("unrecognized encoding: %s", chk.Encoding())
}
totalChunks++
}
Expand All @@ -703,6 +710,10 @@ func analyzeCompaction(ctx context.Context, block tsdb.BlockReader, indexr tsdb.
displayHistogram("bytes per histogram chunk", histogramChunkSize, totalChunks)

displayHistogram("buckets per histogram chunk", histogramChunkBucketsCount, totalChunks)

displayHistogram("samples per info metric chunk", infoChunkSamplesCount, totalChunks)
displayHistogram("bytes per info metric chunk", infoChunkSize, totalChunks)

return nil
}

Expand Down Expand Up @@ -770,6 +781,10 @@ func formatSeriesSet(ss storage.SeriesSet) error {
ts, h := it.AtHistogram(nil)
fmt.Printf("%s %s %d\n", lbs, h.String(), ts)
}
for it.Next() == chunkenc.ValInfoSample {
ts, ils := it.AtInfoSample()
fmt.Printf("%s %v %d\n", lbs, ils, ts)
}
if it.Err() != nil {
return ss.Err()
}
Expand Down
5 changes: 5 additions & 0 deletions docs/querying/functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,11 @@ 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
38 changes: 19 additions & 19 deletions model/labels/labels_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -652,24 +652,24 @@ func TestBuilder(t *testing.T) {
want: FromStrings("aaa", "111", "ccc", "333"),
},
{
set: []Label{{"aaa", "111"}, {"bbb", "222"}, {"ccc", "333"}},
set: []Label{{Name: "aaa", Value: "111"}, {Name: "bbb", Value: "222"}, {Name: "ccc", Value: "333"}},
del: []string{"bbb"},
want: FromStrings("aaa", "111", "ccc", "333"),
},
{
base: FromStrings("aaa", "111"),
set: []Label{{"bbb", "222"}},
set: []Label{{Name: "bbb", Value: "222"}},
want: FromStrings("aaa", "111", "bbb", "222"),
},
{
base: FromStrings("aaa", "111"),
set: []Label{{"bbb", "222"}, {"bbb", "333"}},
set: []Label{{Name: "bbb", Value: "222"}, {Name: "bbb", Value: "333"}},
want: FromStrings("aaa", "111", "bbb", "333"),
},
{
base: FromStrings("aaa", "111", "bbb", "222", "ccc", "333"),
del: []string{"bbb"},
set: []Label{{"ddd", "444"}},
set: []Label{{Name: "ddd", Value: "444"}},
want: FromStrings("aaa", "111", "ccc", "333", "ddd", "444"),
},
{ // Blank value is interpreted as delete.
Expand All @@ -678,7 +678,7 @@ func TestBuilder(t *testing.T) {
},
{
base: FromStrings("aaa", "111", "bbb", "222", "ccc", "333"),
set: []Label{{"bbb", ""}},
set: []Label{{Name: "bbb", Value: ""}},
want: FromStrings("aaa", "111", "ccc", "333"),
},
{
Expand All @@ -694,7 +694,7 @@ func TestBuilder(t *testing.T) {
{
base: FromStrings("aaa", "111", "bbb", "222", "ccc", "333"),
del: []string{"bbb"},
set: []Label{{"ddd", "444"}},
set: []Label{{Name: "ddd", Value: "444"}},
keep: []string{"aaa", "ddd"},
want: FromStrings("aaa", "111", "ddd", "444"),
},
Expand Down Expand Up @@ -749,19 +749,19 @@ func TestScratchBuilder(t *testing.T) {
want: EmptyLabels(),
},
{
add: []Label{{"aaa", "111"}},
add: []Label{{Name: "aaa", Value: "111"}},
want: FromStrings("aaa", "111"),
},
{
add: []Label{{"aaa", "111"}, {"bbb", "222"}, {"ccc", "333"}},
add: []Label{{Name: "aaa", Value: "111"}, {Name: "bbb", Value: "222"}, {Name: "ccc", Value: "333"}},
want: FromStrings("aaa", "111", "bbb", "222", "ccc", "333"),
},
{
add: []Label{{"bbb", "222"}, {"aaa", "111"}, {"ccc", "333"}},
add: []Label{{Name: "bbb", Value: "222"}, {Name: "aaa", Value: "111"}, {Name: "ccc", Value: "333"}},
want: FromStrings("aaa", "111", "bbb", "222", "ccc", "333"),
},
{
add: []Label{{"ddd", "444"}},
add: []Label{{Name: "ddd", Value: "444"}},
want: FromStrings("ddd", "444"),
},
} {
Expand Down Expand Up @@ -841,15 +841,15 @@ func BenchmarkLabels_Hash(b *testing.B) {
}

var benchmarkLabels = []Label{
{"job", "node"},
{"instance", "123.123.1.211:9090"},
{"path", "/api/v1/namespaces/<namespace>/deployments/<name>"},
{"method", http.MethodGet},
{"namespace", "system"},
{"status", "500"},
{"prometheus", "prometheus-core-1"},
{"datacenter", "eu-west-1"},
{"pod_name", "abcdef-99999-defee"},
{Name: "job", Value: "node"},
{Name: "instance", Value: "123.123.1.211:9090"},
{Name: "path", Value: "/api/v1/namespaces/<namespace>/deployments/<name>"},
{Name: "method", Value: http.MethodGet},
{Name: "namespace", Value: "system"},
{Name: "status", Value: "500"},
{Name: "prometheus", Value: "prometheus-core-1"},
{Name: "datacenter", Value: "eu-west-1"},
{Name: "pod_name", Value: "abcdef-99999-defee"},
}

func BenchmarkBuilder(b *testing.B) {
Expand Down
Loading
Loading