Skip to content
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