Skip to content

Commit 217e11a

Browse files
committed
Merge remote-tracking branch 'refs/remotes/upstream/master' into 2-prometheus-label-filters
# Conflicts: # prometheus/querier.go
2 parents da934cc + 4a8766e commit 217e11a

File tree

1,596 files changed

+218303
-61117
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,596 files changed

+218303
-61117
lines changed

.github/workflows/release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ jobs:
3232
- name: Set up Ruby
3333
uses: ruby/setup-ruby@v1
3434
with:
35-
ruby-version: '2.7' # Version range or exact version of a Ruby version to use, using semvers version range syntax.
35+
ruby-version: '3.3' # Version range or exact version of a Ruby version to use, using semvers version range syntax.
3636
- name: Install packaging dependencies
3737
run: |
3838
gem install fpm package_cloud

.github/workflows/tests.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,14 +93,14 @@ jobs:
9393
- name: Set up Ruby
9494
uses: ruby/setup-ruby@v1
9595
with:
96-
ruby-version: '2.7' # Version range or exact version of a Ruby version to use, using semvers version range syntax.
96+
ruby-version: '3.3' # Version range or exact version of a Ruby version to use, using semvers version range syntax.
9797

98+
# gem install dotenv -v 2.8.1 # workaroaund for ruby version 2.7.8.225
9899
- name: Install packaging dependencies
99100
run: |
100-
gem install dotenv -v 2.8.1 # workaroaund for ruby version 2.7.8.225
101101
gem install fpm package_cloud
102102
go install github.com/mitchellh/gox@latest
103-
103+
104104
- name: Check packaging
105105
run: |
106106
make DEVEL=1 gox-build fpm-deb fpm-rpm

autocomplete/autocomplete.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ func (h *Handler) requestExpr(r *http.Request) (*where.Where, *where.Where, map[
9393
return wr, pw, usedTags, err
9494
}
9595

96-
wr, pw, err = finder.TaggedWhere(terms)
96+
wr, pw, err = finder.TaggedWhere(terms, h.config.FeatureFlags.UseCarbonBehavior, h.config.FeatureFlags.DontMatchMissingTags)
9797
if err != nil {
9898
return wr, pw, usedTags, err
9999
}

config/config.go

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,12 @@ type Common struct {
118118
FindCache cache.BytesCache `toml:"-" json:"-"`
119119
}
120120

121+
// FeatureFlags contains feature flags that significantly change how gch responds to some requests
122+
type FeatureFlags struct {
123+
UseCarbonBehavior bool `toml:"use-carbon-behaviour" json:"use-carbon-behaviour" comment:"if true, prefers carbon's behaviour on how tags are treated"`
124+
DontMatchMissingTags bool `toml:"dont-match-missing-tags" json:"dont-match-missing-tags" comment:"if true, seriesByTag terms containing '!=' or '!=~' operators will not match metrics that don't have the tag at all"`
125+
}
126+
121127
// IndexReverseRule contains rules to use direct or reversed request to index table
122128
type IndexReverseRule struct {
123129
Suffix string `toml:"suffix,omitempty" json:"suffix" comment:"rule is used when the target suffix is matched"`
@@ -341,15 +347,16 @@ type Debug struct {
341347

342348
// Config is the daemon configuration
343349
type Config struct {
344-
Common Common `toml:"common" json:"common"`
345-
Metrics metrics.Config `toml:"metrics" json:"metrics"`
346-
ClickHouse ClickHouse `toml:"clickhouse" json:"clickhouse"`
347-
DataTable []DataTable `toml:"data-table" json:"data-table" comment:"data tables, see doc/config.md for additional info"`
348-
Tags Tags `toml:"tags" json:"tags" comment:"is not recommended to use, https://github.com/lomik/graphite-clickhouse/wiki/TagsRU" commented:"true"`
349-
Carbonlink Carbonlink `toml:"carbonlink" json:"carbonlink"`
350-
Prometheus Prometheus `toml:"prometheus" json:"prometheus"`
351-
Debug Debug `toml:"debug" json:"debug" comment:"see doc/debugging.md"`
352-
Logging []zapwriter.Config `toml:"logging" json:"logging"`
350+
Common Common `toml:"common" json:"common"`
351+
FeatureFlags FeatureFlags `toml:"feature-flags" json:"feature-flags"`
352+
Metrics metrics.Config `toml:"metrics" json:"metrics"`
353+
ClickHouse ClickHouse `toml:"clickhouse" json:"clickhouse"`
354+
DataTable []DataTable `toml:"data-table" json:"data-table" comment:"data tables, see doc/config.md for additional info"`
355+
Tags Tags `toml:"tags" json:"tags" comment:"is not recommended to use, https://github.com/lomik/graphite-clickhouse/wiki/TagsRU" commented:"true"`
356+
Carbonlink Carbonlink `toml:"carbonlink" json:"carbonlink"`
357+
Prometheus Prometheus `toml:"prometheus" json:"prometheus"`
358+
Debug Debug `toml:"debug" json:"debug" comment:"see doc/debugging.md"`
359+
Logging []zapwriter.Config `toml:"logging" json:"logging"`
353360
}
354361

355362
// New returns *Config with default values

deploy/doc/config.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,36 @@ shortTimeoutSec = 300
2929
findTimeoutSec = 600
3030
```
3131

32+
## Feature flags `[feature-flags]`
33+
34+
`use-carbon-behaviour=true`.
35+
36+
- Tagged terms with `=` operator and empty value (e.g. `t=`) match all metrics that don't have that tag.
37+
38+
`dont-match-missing-tags=true`.
39+
40+
- Tagged terms with `!=`, `!=~` operators only match metrics that have that tag.
41+
42+
### Examples
43+
44+
Given tagged metrics:
45+
```
46+
metric.two;env=prod
47+
metric.one;env=stage;dc=mydc1
48+
metric.one;env=prod;dc=otherdc1
49+
```
50+
| Target | use-carbon-behaviour | Matched metrics |
51+
|-----------------------------|----------------------|---------------------------------------------------|
52+
| seriesByTag('dc=') | false | - |
53+
| seriesByTag('dc=') | true | metric.two;env=prod |
54+
55+
| Target | dont-match-missing-tags | Matched metrics |
56+
|--------------------------|-------------------------|--------------------------------------------------------|
57+
| seriesByTag('dc!=mydc1') | false | metric.two;env=prod<br>metric.one;env=prod;dc=otherdc1 |
58+
| seriesByTag('dc!=mydc1') | true | metric.one;env=prod;dc=otherdc1 |
59+
| seriesByTag('dc!=~otherdc') | false | metric.two;env=prod<br>metric.one;env=stage;dc=mydc1 |
60+
| seriesByTag('dc!=~otherdc') | true | metric.one;env=stage;dc=mydc1 |
61+
3262
## ClickHouse `[clickhouse]`
3363

3464
### URL `url`

doc/config.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,36 @@ shortTimeoutSec = 300
3232
findTimeoutSec = 600
3333
```
3434

35+
## Feature flags `[feature-flags]`
36+
37+
`use-carbon-behaviour=true`.
38+
39+
- Tagged terms with `=` operator and empty value (e.g. `t=`) match all metrics that don't have that tag.
40+
41+
`dont-match-missing-tags=true`.
42+
43+
- Tagged terms with `!=`, `!=~` operators only match metrics that have that tag.
44+
45+
### Examples
46+
47+
Given tagged metrics:
48+
```
49+
metric.two;env=prod
50+
metric.one;env=stage;dc=mydc1
51+
metric.one;env=prod;dc=otherdc1
52+
```
53+
| Target | use-carbon-behaviour | Matched metrics |
54+
|-----------------------------|----------------------|---------------------------------------------------|
55+
| seriesByTag('dc=') | false | - |
56+
| seriesByTag('dc=') | true | metric.two;env=prod |
57+
58+
| Target | dont-match-missing-tags | Matched metrics |
59+
|--------------------------|-------------------------|--------------------------------------------------------|
60+
| seriesByTag('dc!=mydc1') | false | metric.two;env=prod<br>metric.one;env=prod;dc=otherdc1 |
61+
| seriesByTag('dc!=mydc1') | true | metric.one;env=prod;dc=otherdc1 |
62+
| seriesByTag('dc!=~otherdc') | false | metric.two;env=prod<br>metric.one;env=stage;dc=mydc1 |
63+
| seriesByTag('dc!=~otherdc') | true | metric.one;env=stage;dc=mydc1 |
64+
3565
## ClickHouse `[clickhouse]`
3666

3767
### URL `url`
@@ -228,6 +258,12 @@ Only one tag used as filter for index field Tag1, see graphite_tagged table [str
228258
# offset beetween now and until for select short cache timeout
229259
short-offset = 0
230260

261+
[feature-flags]
262+
# if true, prefers carbon's behaviour on how tags are treated
263+
use-carbon-behaviour = false
264+
# if true, seriesByTag terms containing '!=' or '!=~' operators will not match metrics that don't have the tag at all
265+
dont-match-missing-tags = false
266+
231267
[metrics]
232268
# graphite relay address
233269
metric-endpoint = ""

finder/finder.go

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,16 @@ func newPlainFinder(ctx context.Context, config *config.Config, query string, fr
3838
var f Finder
3939

4040
if config.ClickHouse.TaggedTable != "" && strings.HasPrefix(strings.TrimSpace(query), "seriesByTag") {
41-
f = NewTagged(config.ClickHouse.URL, config.ClickHouse.TaggedTable, config.ClickHouse.TaggedUseDaily, false, opts, config.ClickHouse.TaggedCosts)
41+
f = NewTagged(
42+
config.ClickHouse.URL,
43+
config.ClickHouse.TaggedTable,
44+
config.ClickHouse.TaggedUseDaily,
45+
config.FeatureFlags.UseCarbonBehavior,
46+
config.FeatureFlags.DontMatchMissingTags,
47+
false,
48+
opts,
49+
config.ClickHouse.TaggedCosts,
50+
)
4251

4352
if len(config.Common.Blacklist) > 0 {
4453
f = WrapBlacklist(f, config.Common.Blacklist)
@@ -121,7 +130,16 @@ func FindTagged(ctx context.Context, config *config.Config, terms []TaggedTerm,
121130
return Result(plain), nil
122131
}
123132

124-
fnd := NewTagged(config.ClickHouse.URL, config.ClickHouse.TaggedTable, config.ClickHouse.TaggedUseDaily, true, opts, config.ClickHouse.TaggedCosts)
133+
fnd := NewTagged(
134+
config.ClickHouse.URL,
135+
config.ClickHouse.TaggedTable,
136+
config.ClickHouse.TaggedUseDaily,
137+
config.FeatureFlags.UseCarbonBehavior,
138+
config.FeatureFlags.DontMatchMissingTags,
139+
true,
140+
opts,
141+
config.ClickHouse.TaggedCosts,
142+
)
125143

126144
err := fnd.ExecutePrepared(ctx, terms, from, until, stat)
127145
if err != nil {

finder/index.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,11 @@ func (idx *IndexFinder) Abs(v []byte) []byte {
178178
}
179179

180180
func (idx *IndexFinder) bodySplit() {
181-
idx.rows = bytes.Split(idx.body, []byte{'\n'})
181+
if len(idx.body) == 0 {
182+
return
183+
}
184+
185+
idx.rows = bytes.Split(bytes.TrimSuffix(idx.body, []byte{'\n'}), []byte{'\n'})
182186

183187
if idx.useReverse("") {
184188
// rotate names for reduce

0 commit comments

Comments
 (0)