Skip to content

Commit

Permalink
fixup! rollup: split plain/tagged rules
Browse files Browse the repository at this point in the history
  • Loading branch information
msaf1980 committed Apr 25, 2024
1 parent 28a70b1 commit b108315
Show file tree
Hide file tree
Showing 5 changed files with 470 additions and 9 deletions.
2 changes: 1 addition & 1 deletion helper/rollup/remote.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ func remoteLoad(addr string, tlsConf *tls.Config, table string) (*Rules, error)
},
nil,
)
if err != nil {
if err != nil && strings.Contains(err.Error(), " Missing columns: 'rule_type' ") {
// for old version
query = `SELECT
regexp,
Expand Down
2 changes: 1 addition & 1 deletion helper/rollup/remote_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ func TestParseJsonTyped(t *testing.T) {
}`

expected := &Rules{
Splitted: true,
Separated: true,
Pattern: []Pattern{
{
Regexp: "^hourly",
Expand Down
12 changes: 6 additions & 6 deletions helper/rollup/rules.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ type Pattern struct {
type Rules struct {
Pattern []Pattern `json:"pattern"`
Updated int64 `json:"updated"`
Splitted bool `json:"-"`
Separated bool `json:"-"`
PatternPlain []Pattern `json:"-"`
PatternTagged []Pattern `json:"-"`
}
Expand Down Expand Up @@ -211,17 +211,17 @@ func (r *Rules) compile() (*Rules, error) {
r.PatternPlain = make([]Pattern, 0)
r.PatternTagged = make([]Pattern, 0)

r.Splitted = false
r.Separated = false
for i := range r.Pattern {
if err := r.Pattern[i].compile(); err != nil {
return r, err
}
if !r.Splitted && r.Pattern[i].RuleType != RuleAll {
r.Splitted = true
if !r.Separated && r.Pattern[i].RuleType != RuleAll {
r.Separated = true
}
}

if r.Splitted {
if r.Separated {
for i := range r.Pattern {
switch r.Pattern[i].RuleType {
case RulePlain:
Expand Down Expand Up @@ -275,7 +275,7 @@ func (r *Rules) withSuperDefault() *Rules {

// Lookup returns precision and aggregate function for metric name and age
func (r *Rules) Lookup(metric string, age uint32, verbose bool) (precision uint32, ag *Aggr, aggrPattern, retentionPattern *Pattern) {
if r.Splitted {
if r.Separated {
if strings.Contains(metric, "?") {
return lookup(metric, age, r.PatternTagged, verbose)
}
Expand Down
Loading

0 comments on commit b108315

Please sign in to comment.