Skip to content

Commit

Permalink
move behaviour with '!=~' from one feature to another
Browse files Browse the repository at this point in the history
  • Loading branch information
mchrome committed Mar 12, 2024
1 parent c603956 commit d569edc
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 9 deletions.
2 changes: 1 addition & 1 deletion config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ type Common struct {

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 requests containing 'not equal' terms will not match metrics that don't have the tag at all"`
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
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
11 changes: 5 additions & 6 deletions doc/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,11 @@ findTimeoutSec = 600

`use-carbon-behaviour=true`.

- Tagged terms with `!=~` op only match metrics that have that tag.
- Tagged terms with `=` op and empty value (e.g. `t=`) match all metrics that don't have that tag.
- 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 `!=` op only match metrics that have that tag.
- Tagged terms with `!=`, `!=~` operators only match metrics that have that tag.

### Examples

Expand All @@ -55,13 +54,13 @@ metric.one;env=prod;dc=otherdc1
|-----------------------------|----------------------|---------------------------------------------------|
| seriesByTag('dc=') | false | - |
| seriesByTag('dc=') | true | metric.two;env=prod |
| 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 |

| 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]`

Expand Down Expand Up @@ -258,7 +257,7 @@ Only one tag used as filter for index field Tag1, see graphite_tagged table [str
[feature-flags]
# if true, prefers carbon's behaviour on how tags are treated
use-carbon-behaviour = false
# if true, seriesByTag requests containing 'not equal' terms will not match metrics that don't have the tag at all
# 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]
Expand Down
4 changes: 2 additions & 2 deletions finder/tagged.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ func TaggedTermWhere1(term *TaggedTerm, useCarbonBehaviour, dontMatchMissingTags
return where.Match("Tag1", term.Key, term.Value), nil
case TaggedTermNotMatch:
var whereLikeAnyVal string
if useCarbonBehaviour {
if dontMatchMissingTags {
whereLikeAnyVal = where.HasPrefix("Tag1", term.Key+"=") + " AND "
}
whereMatch := where.Match("x", term.Key, term.Value)
Expand Down Expand Up @@ -227,7 +227,7 @@ func TaggedTermWhereN(term *TaggedTerm, useCarbonBehaviour, dontMatchMissingTags
return fmt.Sprintf("arrayExists((x) -> %s, Tags)", where.Match("x", term.Key, term.Value)), nil
case TaggedTermNotMatch:
var whereLikeAnyVal string
if useCarbonBehaviour {
if dontMatchMissingTags {
whereLikeAnyVal = fmt.Sprintf("arrayExists((x) -> %s, Tags) AND ", where.HasPrefix("x", term.Key+"="))
}
whereMatch := where.Match("x", term.Key, term.Value)
Expand Down

0 comments on commit d569edc

Please sign in to comment.