Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
ecce8c1
fix several cases where gch behavior is different from carbon
mchrome Mar 6, 2024
a5d354a
add feature flags
mchrome Mar 11, 2024
ab4a665
cleanup
mchrome Mar 11, 2024
e9c5b9f
change e2e test directory name
mchrome Mar 11, 2024
79c318b
remove unnecessary space characters in sql queries
mchrome Mar 11, 2024
7d4ddc1
only escape regex that contains '|'
mchrome Mar 11, 2024
2b3d4a3
add detailed description of feature flags in doc/config.md
mchrome Mar 12, 2024
c603956
build same sql query for first tag term when op is not match
mchrome Mar 12, 2024
d569edc
move behaviour with '!=~' from one feature to another
mchrome Mar 12, 2024
e6e5995
split tests to check flags correctness individually
mchrome Mar 12, 2024
c3685df
add some unit tests
mchrome Mar 24, 2024
8a74c71
add e2e tests with both feature flags enabled
mchrome Mar 25, 2024
0876b24
add a comment explaining FeatureFlags struct
mchrome Mar 25, 2024
1747465
rerun tests
mchrome Mar 25, 2024
4fa4d24
Merge branch 'master' into fix/seriesByTag-inconsistency-with-carbon
mchrome Apr 8, 2024
cfc11d5
bump ruby version from 2.7 to 3.3
mchrome Apr 8, 2024
1839390
change clickhouse latest to 23.12
mchrome Apr 8, 2024
dd95a5a
Merge branch 'deps/bump-ruby-version' into fix/seriesByTag-inconsiste…
mchrome Apr 8, 2024
46d2313
change clickhouse version from 23.12 to 24.2 (#272)
mchrome Apr 24, 2024
f023894
Update Prometheus to v.0.51.1 / v2.51.1 (#269)
Hedius Apr 24, 2024
cd89065
Fixed incorrect finder behaviour with extra-prefix specified (#243)
lexx-bright Apr 24, 2024
3926f04
Merge branch 'master' into fix/seriesByTag-inconsistency-with-carbon
mchrome Apr 24, 2024
d50d657
change clickhouse version in new tests to 24.2
mchrome Apr 24, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: '2.7' # Version range or exact version of a Ruby version to use, using semvers version range syntax.
ruby-version: '3.3' # Version range or exact version of a Ruby version to use, using semvers version range syntax.
- name: Install packaging dependencies
run: |
gem install fpm package_cloud
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -93,14 +93,14 @@ jobs:
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: '2.7' # Version range or exact version of a Ruby version to use, using semvers version range syntax.
ruby-version: '3.3' # Version range or exact version of a Ruby version to use, using semvers version range syntax.

# gem install dotenv -v 2.8.1 # workaroaund for ruby version 2.7.8.225
- name: Install packaging dependencies
run: |
gem install dotenv -v 2.8.1 # workaroaund for ruby version 2.7.8.225
gem install fpm package_cloud
go install github.com/mitchellh/gox@latest

- name: Check packaging
run: |
make DEVEL=1 gox-build fpm-deb fpm-rpm
Expand Down
2 changes: 1 addition & 1 deletion autocomplete/autocomplete.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ func (h *Handler) requestExpr(r *http.Request) (*where.Where, *where.Where, map[
return wr, pw, usedTags, err
}

wr, pw, err = finder.TaggedWhere(terms)
wr, pw, err = finder.TaggedWhere(terms, h.config.FeatureFlags.UseCarbonBehavior, h.config.FeatureFlags.DontMatchMissingTags)
if err != nil {
return wr, pw, usedTags, err
}
Expand Down
25 changes: 16 additions & 9 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,12 @@ type Common struct {
FindCache cache.BytesCache `toml:"-" json:"-"`
}

// FeatureFlags contains feature flags that significantly change how gch responds to some requests
type FeatureFlags struct {
UseCarbonBehavior bool `toml:"use-carbon-behaviour" json:"use-carbon-behaviour" comment:"if true, prefers carbon's behaviour on how tags are treated"`
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"`
}

// IndexReverseRule contains rules to use direct or reversed request to index table
type IndexReverseRule struct {
Suffix string `toml:"suffix,omitempty" json:"suffix" comment:"rule is used when the target suffix is matched"`
Expand Down Expand Up @@ -341,15 +347,16 @@ type Debug struct {

// Config is the daemon configuration
type Config struct {
Common Common `toml:"common" json:"common"`
Metrics metrics.Config `toml:"metrics" json:"metrics"`
ClickHouse ClickHouse `toml:"clickhouse" json:"clickhouse"`
DataTable []DataTable `toml:"data-table" json:"data-table" comment:"data tables, see doc/config.md for additional info"`
Tags Tags `toml:"tags" json:"tags" comment:"is not recommended to use, https://github.com/lomik/graphite-clickhouse/wiki/TagsRU" commented:"true"`
Carbonlink Carbonlink `toml:"carbonlink" json:"carbonlink"`
Prometheus Prometheus `toml:"prometheus" json:"prometheus"`
Debug Debug `toml:"debug" json:"debug" comment:"see doc/debugging.md"`
Logging []zapwriter.Config `toml:"logging" json:"logging"`
Common Common `toml:"common" json:"common"`
FeatureFlags FeatureFlags `toml:"feature-flags" json:"feature-flags"`
Metrics metrics.Config `toml:"metrics" json:"metrics"`
ClickHouse ClickHouse `toml:"clickhouse" json:"clickhouse"`
DataTable []DataTable `toml:"data-table" json:"data-table" comment:"data tables, see doc/config.md for additional info"`
Tags Tags `toml:"tags" json:"tags" comment:"is not recommended to use, https://github.com/lomik/graphite-clickhouse/wiki/TagsRU" commented:"true"`
Carbonlink Carbonlink `toml:"carbonlink" json:"carbonlink"`
Prometheus Prometheus `toml:"prometheus" json:"prometheus"`
Debug Debug `toml:"debug" json:"debug" comment:"see doc/debugging.md"`
Logging []zapwriter.Config `toml:"logging" json:"logging"`
}

// New returns *Config with default values
Expand Down
30 changes: 30 additions & 0 deletions deploy/doc/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,36 @@ shortTimeoutSec = 300
findTimeoutSec = 600
```

## Feature flags `[feature-flags]`

`use-carbon-behaviour=true`.

- Tagged terms with `=` operator and empty value (e.g. `t=`) match all metrics that don't have that tag.

`dont-match-missing-tags=true`.

- Tagged terms with `!=`, `!=~` operators only match metrics that have that tag.

### Examples

Given tagged metrics:
```
metric.two;env=prod
metric.one;env=stage;dc=mydc1
metric.one;env=prod;dc=otherdc1
```
| Target | use-carbon-behaviour | Matched metrics |
|-----------------------------|----------------------|---------------------------------------------------|
| seriesByTag('dc=') | false | - |
| seriesByTag('dc=') | true | metric.two;env=prod |

| Target | dont-match-missing-tags | Matched metrics |
|--------------------------|-------------------------|--------------------------------------------------------|
| seriesByTag('dc!=mydc1') | false | metric.two;env=prod<br>metric.one;env=prod;dc=otherdc1 |
| seriesByTag('dc!=mydc1') | true | metric.one;env=prod;dc=otherdc1 |
| seriesByTag('dc!=~otherdc') | false | metric.two;env=prod<br>metric.one;env=stage;dc=mydc1 |
| seriesByTag('dc!=~otherdc') | true | metric.one;env=stage;dc=mydc1 |

## ClickHouse `[clickhouse]`

### URL `url`
Expand Down
36 changes: 36 additions & 0 deletions doc/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,36 @@ shortTimeoutSec = 300
findTimeoutSec = 600
```

## Feature flags `[feature-flags]`

`use-carbon-behaviour=true`.

- Tagged terms with `=` operator and empty value (e.g. `t=`) match all metrics that don't have that tag.

`dont-match-missing-tags=true`.

- Tagged terms with `!=`, `!=~` operators only match metrics that have that tag.

### Examples

Given tagged metrics:
```
metric.two;env=prod
metric.one;env=stage;dc=mydc1
metric.one;env=prod;dc=otherdc1
```
| Target | use-carbon-behaviour | Matched metrics |
|-----------------------------|----------------------|---------------------------------------------------|
| seriesByTag('dc=') | false | - |
| seriesByTag('dc=') | true | metric.two;env=prod |

| Target | dont-match-missing-tags | Matched metrics |
|--------------------------|-------------------------|--------------------------------------------------------|
| seriesByTag('dc!=mydc1') | false | metric.two;env=prod<br>metric.one;env=prod;dc=otherdc1 |
| seriesByTag('dc!=mydc1') | true | metric.one;env=prod;dc=otherdc1 |
| seriesByTag('dc!=~otherdc') | false | metric.two;env=prod<br>metric.one;env=stage;dc=mydc1 |
| seriesByTag('dc!=~otherdc') | true | metric.one;env=stage;dc=mydc1 |

## ClickHouse `[clickhouse]`

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

[feature-flags]
# if true, prefers carbon's behaviour on how tags are treated
use-carbon-behaviour = false
# if true, seriesByTag terms containing '!=' or '!=~' operators will not match metrics that don't have the tag at all
dont-match-missing-tags = false

[metrics]
# graphite relay address
metric-endpoint = ""
Expand Down
22 changes: 20 additions & 2 deletions finder/finder.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,16 @@ func newPlainFinder(ctx context.Context, config *config.Config, query string, fr
var f Finder

if config.ClickHouse.TaggedTable != "" && strings.HasPrefix(strings.TrimSpace(query), "seriesByTag") {
f = NewTagged(config.ClickHouse.URL, config.ClickHouse.TaggedTable, config.ClickHouse.TaggedUseDaily, false, opts, config.ClickHouse.TaggedCosts)
f = NewTagged(
config.ClickHouse.URL,
config.ClickHouse.TaggedTable,
config.ClickHouse.TaggedUseDaily,
config.FeatureFlags.UseCarbonBehavior,
config.FeatureFlags.DontMatchMissingTags,
false,
opts,
config.ClickHouse.TaggedCosts,
)

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

fnd := NewTagged(config.ClickHouse.URL, config.ClickHouse.TaggedTable, config.ClickHouse.TaggedUseDaily, true, opts, config.ClickHouse.TaggedCosts)
fnd := NewTagged(
config.ClickHouse.URL,
config.ClickHouse.TaggedTable,
config.ClickHouse.TaggedUseDaily,
config.FeatureFlags.UseCarbonBehavior,
config.FeatureFlags.DontMatchMissingTags,
true,
opts,
config.ClickHouse.TaggedCosts,
)

err := fnd.ExecutePrepared(ctx, terms, from, until, stat)
if err != nil {
Expand Down
6 changes: 5 additions & 1 deletion finder/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,11 @@ func (idx *IndexFinder) Abs(v []byte) []byte {
}

func (idx *IndexFinder) bodySplit() {
idx.rows = bytes.Split(idx.body, []byte{'\n'})
if len(idx.body) == 0 {
return
}

idx.rows = bytes.Split(bytes.TrimSuffix(idx.body, []byte{'\n'}), []byte{'\n'})

if idx.useReverse("") {
// rotate names for reduce
Expand Down
Loading