@@ -13,6 +13,7 @@ import (
1313 "github.com/prometheus/prometheus/util/annotations"
1414
1515 "github.com/lomik/graphite-clickhouse/config"
16+ "github.com/lomik/graphite-clickhouse/finder"
1617 "github.com/lomik/graphite-clickhouse/helper/clickhouse"
1718 "github.com/lomik/graphite-clickhouse/pkg/scope"
1819 "github.com/lomik/graphite-clickhouse/pkg/where"
@@ -33,9 +34,25 @@ func (q *Querier) Close() error {
3334
3435// LabelValues returns all potential values for a label name.
3536func (q * Querier ) LabelValues (ctx context.Context , label string , hints * storage.LabelHints , matchers ... * labels.Matcher ) ([]string , annotations.Annotations , error ) {
36- // @TODO: support matchers
37- w := where .New ()
38- w .And (where .HasPrefix ("Tag1" , label + "=" ))
37+ terms := []finder.TaggedTerm {
38+ {
39+ Key : strings .ReplaceAll (label , `_` , `\_` ),
40+ Op : finder .TaggedTermEq ,
41+ Value : "*" ,
42+ HasWildcard : true ,
43+ },
44+ }
45+
46+ matcherTerms , err := makeTaggedFromPromQL (matchers )
47+ if err != nil {
48+ return nil , nil , err
49+ }
50+ terms = append (terms , matcherTerms ... )
51+
52+ w , _ , err := finder .TaggedWhere (terms , q .config .FeatureFlags .UseCarbonBehavior , q .config .FeatureFlags .DontMatchMissingTags )
53+ if err != nil {
54+ return nil , nil , err
55+ }
3956
4057 fromDate := timeNow ().AddDate (0 , 0 , - q .config .ClickHouse .TaggedAutocompleDays )
4158 w .Andf ("Date >= '%s'" , fromDate .Format ("2006-01-02" ))
@@ -70,8 +87,19 @@ func (q *Querier) LabelValues(ctx context.Context, label string, hints *storage.
7087
7188// LabelNames returns all the unique label names present in the block in sorted order.
7289func (q * Querier ) LabelNames (ctx context.Context , hints * storage.LabelHints , matchers ... * labels.Matcher ) ([]string , annotations.Annotations , error ) {
73- // @TODO support matchers
90+ terms , err := makeTaggedFromPromQL (matchers )
91+ if err != nil {
92+ return nil , nil , err
93+ }
7494 w := where .New ()
95+ // @TODO: this is duplicate to the for in finder.TaggedWhere. (different start...)
96+ for i := 0 ; i < len (terms ); i ++ {
97+ and , err := finder .TaggedTermWhereN (& terms [i ], q .config .FeatureFlags .UseCarbonBehavior , q .config .FeatureFlags .DontMatchMissingTags )
98+ if err != nil {
99+ return nil , nil , err
100+ }
101+ w .And (and )
102+ }
75103 fromDate := time .Now ().AddDate (0 , 0 , - q .config .ClickHouse .TaggedAutocompleDays ).UTC ()
76104 w .Andf ("Date >= '%s'" , fromDate .Format ("2006-01-02" ))
77105
0 commit comments