Skip to content

Add filter support to prometheus for /api/v1/labels /api/v1/{label}/values #270

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
36 changes: 32 additions & 4 deletions prometheus/querier.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/prometheus/prometheus/util/annotations"

"github.com/lomik/graphite-clickhouse/config"
"github.com/lomik/graphite-clickhouse/finder"
"github.com/lomik/graphite-clickhouse/helper/clickhouse"
"github.com/lomik/graphite-clickhouse/pkg/scope"
"github.com/lomik/graphite-clickhouse/pkg/where"
Expand All @@ -33,9 +34,25 @@ func (q *Querier) Close() error {

// LabelValues returns all potential values for a label name.
func (q *Querier) LabelValues(ctx context.Context, label string, hints *storage.LabelHints, matchers ...*labels.Matcher) ([]string, annotations.Annotations, error) {
// @TODO: support matchers
w := where.New()
w.And(where.HasPrefix("Tag1", label+"="))
terms := []finder.TaggedTerm{
{
Key: strings.ReplaceAll(label, `_`, `\_`),
Op: finder.TaggedTermEq,
Value: "*",
HasWildcard: true,
},
}

matcherTerms, err := makeTaggedFromPromQL(matchers)
if err != nil {
return nil, nil, err
}
terms = append(terms, matcherTerms...)

w, _, err := finder.TaggedWhere(terms, q.config.FeatureFlags.UseCarbonBehavior, q.config.FeatureFlags.DontMatchMissingTags)
if err != nil {
return nil, nil, err
}

fromDate := timeNow().AddDate(0, 0, -q.config.ClickHouse.TaggedAutocompleDays)
w.Andf("Date >= '%s'", fromDate.Format("2006-01-02"))
Expand Down Expand Up @@ -70,8 +87,19 @@ func (q *Querier) LabelValues(ctx context.Context, label string, hints *storage.

// LabelNames returns all the unique label names present in the block in sorted order.
func (q *Querier) LabelNames(ctx context.Context, hints *storage.LabelHints, matchers ...*labels.Matcher) ([]string, annotations.Annotations, error) {
// @TODO support matchers
terms, err := makeTaggedFromPromQL(matchers)
if err != nil {
return nil, nil, err
}
w := where.New()
// @TODO: this is duplicate to the for in finder.TaggedWhere. (different start...)
for i := 0; i < len(terms); i++ {
and, err := finder.TaggedTermWhereN(&terms[i], q.config.FeatureFlags.UseCarbonBehavior, q.config.FeatureFlags.DontMatchMissingTags)
if err != nil {
return nil, nil, err
}
w.And(and)
}
fromDate := time.Now().AddDate(0, 0, -q.config.ClickHouse.TaggedAutocompleDays).UTC()
w.Andf("Date >= '%s'", fromDate.Format("2006-01-02"))

Expand Down
Loading