-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
bugfix loading config & test code (#20)
- Loading branch information
Showing
15 changed files
with
117 additions
and
102 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,7 @@ | ||
# queryTimeOut: 30 | ||
datasources: | ||
- name: Prometheus | ||
type: prometheus | ||
url: http://prometheus:9090 | ||
# basicAuth: true | ||
# basicAuthUser: Aladdin | ||
# basicAuthPassword: openSesame | ||
- name: Lethe | ||
type: lethe | ||
url: http://lethe:3100 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package store | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
"os" | ||
"path/filepath" | ||
|
||
"github.com/prometheus/prometheus/model/rulefmt" | ||
) | ||
|
||
type AlertRuleStore struct { | ||
ruleGroupsList []rulefmt.RuleGroups | ||
} | ||
|
||
func NewAlertRuleStore(pattern string) (*AlertRuleStore, error) { | ||
log.Println("Loading alertRules...") | ||
files, err := filepath.Glob("etc/alertrules/*.yaml") | ||
if err != nil { | ||
return nil, err | ||
} | ||
var ruleGroupsList []rulefmt.RuleGroups | ||
for _, filename := range files { | ||
log.Printf("alertRule file: %s\n", filename) | ||
f, err := os.Open(filename) | ||
if err != nil { | ||
return nil, fmt.Errorf("error on Open: %w", err) | ||
} | ||
var ruleGroups *rulefmt.RuleGroups | ||
err = loadYaml(f, &ruleGroups) | ||
if err != nil { | ||
return nil, fmt.Errorf("error on loadYaml: %w", err) | ||
} | ||
ruleGroupsList = append(ruleGroupsList, *ruleGroups) | ||
} | ||
return &AlertRuleStore{ruleGroupsList: ruleGroupsList}, nil | ||
} | ||
|
||
func (ars *AlertRuleStore) RuleGroupsList() []rulefmt.RuleGroups { | ||
return ars.ruleGroupsList | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package store | ||
|
||
import ( | ||
"os" | ||
"testing" | ||
|
||
"github.com/prometheus/prometheus/model/rulefmt" | ||
"github.com/stretchr/testify/assert" | ||
"gopkg.in/yaml.v3" | ||
) | ||
|
||
func init() { | ||
_ = os.Chdir("../..") | ||
} | ||
|
||
func TestNewAlertRuleStore(t *testing.T) { | ||
ars, err := NewAlertRuleStore("") | ||
assert.Nil(t, err) | ||
assert.Equal(t, ars, &AlertRuleStore{ruleGroupsList: []rulefmt.RuleGroups{rulefmt.RuleGroups{Groups: []rulefmt.RuleGroup{rulefmt.RuleGroup{Name: "sample", Interval: 0, Limit: 0, Rules: []rulefmt.RuleNode{rulefmt.RuleNode{Record: yaml.Node{Kind: 0x0, Style: 0x0, Tag: "", Value: "", Anchor: "", Alias: (*yaml.Node)(nil), Content: []*yaml.Node(nil), HeadComment: "", LineComment: "", FootComment: "", Line: 0, Column: 0}, Alert: yaml.Node{Kind: 0x8, Style: 0x0, Tag: "!!str", Value: "S00-AlwaysOn", Anchor: "", Alias: (*yaml.Node)(nil), Content: []*yaml.Node(nil), HeadComment: "", LineComment: "", FootComment: "", Line: 7, Column: 12}, Expr: yaml.Node{Kind: 0x8, Style: 0x0, Tag: "!!str", Value: "vector(1234)", Anchor: "", Alias: (*yaml.Node)(nil), Content: []*yaml.Node(nil), HeadComment: "", LineComment: "", FootComment: "", Line: 8, Column: 11}, For: 0, Labels: map[string]string(nil), Annotations: map[string]string{"summary": "AlwaysOn value={{ $value }}"}}, rulefmt.RuleNode{Record: yaml.Node{Kind: 0x0, Style: 0x0, Tag: "", Value: "", Anchor: "", Alias: (*yaml.Node)(nil), Content: []*yaml.Node(nil), HeadComment: "", LineComment: "", FootComment: "", Line: 0, Column: 0}, Alert: yaml.Node{Kind: 0x8, Style: 0x0, Tag: "!!str", Value: "S01-Monday", Anchor: "", Alias: (*yaml.Node)(nil), Content: []*yaml.Node(nil), HeadComment: "", LineComment: "", FootComment: "", Line: 12, Column: 12}, Expr: yaml.Node{Kind: 0x8, Style: 0x0, Tag: "!!str", Value: "day_of_week() == 1 and hour() < 2", Anchor: "", Alias: (*yaml.Node)(nil), Content: []*yaml.Node(nil), HeadComment: "", LineComment: "", FootComment: "", Line: 13, Column: 11}, For: 0, Labels: map[string]string(nil), Annotations: map[string]string{"summary": "Monday"}}, rulefmt.RuleNode{Record: yaml.Node{Kind: 0x0, Style: 0x0, Tag: "", Value: "", Anchor: "", Alias: (*yaml.Node)(nil), Content: []*yaml.Node(nil), HeadComment: "", LineComment: "", FootComment: "", Line: 0, Column: 0}, Alert: yaml.Node{Kind: 0x8, Style: 0x0, Tag: "!!str", Value: "S02-NewNamespace", Anchor: "", Alias: (*yaml.Node)(nil), Content: []*yaml.Node(nil), HeadComment: "", LineComment: "", FootComment: "", Line: 17, Column: 12}, Expr: yaml.Node{Kind: 0x8, Style: 0x0, Tag: "!!str", Value: "time() - kube_namespace_created < 120", Anchor: "", Alias: (*yaml.Node)(nil), Content: []*yaml.Node(nil), HeadComment: "", LineComment: "", FootComment: "", Line: 18, Column: 11}, For: 0, Labels: map[string]string(nil), Annotations: map[string]string{"summary": "labels={{ $labels }} namespace={{ $labels.namespace }} value={{ $value }}"}}}}}}}}) | ||
} | ||
|
||
func TestRuleGroupsList(t *testing.T) { | ||
ars, err := NewAlertRuleStore("") | ||
assert.Nil(t, err) | ||
assert.Equal(t, ars.RuleGroupsList(), []rulefmt.RuleGroups{rulefmt.RuleGroups{Groups: []rulefmt.RuleGroup{rulefmt.RuleGroup{Name: "sample", Interval: 0, Limit: 0, Rules: []rulefmt.RuleNode{rulefmt.RuleNode{Record: yaml.Node{Kind: 0x0, Style: 0x0, Tag: "", Value: "", Anchor: "", Alias: (*yaml.Node)(nil), Content: []*yaml.Node(nil), HeadComment: "", LineComment: "", FootComment: "", Line: 0, Column: 0}, Alert: yaml.Node{Kind: 0x8, Style: 0x0, Tag: "!!str", Value: "S00-AlwaysOn", Anchor: "", Alias: (*yaml.Node)(nil), Content: []*yaml.Node(nil), HeadComment: "", LineComment: "", FootComment: "", Line: 7, Column: 12}, Expr: yaml.Node{Kind: 0x8, Style: 0x0, Tag: "!!str", Value: "vector(1234)", Anchor: "", Alias: (*yaml.Node)(nil), Content: []*yaml.Node(nil), HeadComment: "", LineComment: "", FootComment: "", Line: 8, Column: 11}, For: 0, Labels: map[string]string(nil), Annotations: map[string]string{"summary": "AlwaysOn value={{ $value }}"}}, rulefmt.RuleNode{Record: yaml.Node{Kind: 0x0, Style: 0x0, Tag: "", Value: "", Anchor: "", Alias: (*yaml.Node)(nil), Content: []*yaml.Node(nil), HeadComment: "", LineComment: "", FootComment: "", Line: 0, Column: 0}, Alert: yaml.Node{Kind: 0x8, Style: 0x0, Tag: "!!str", Value: "S01-Monday", Anchor: "", Alias: (*yaml.Node)(nil), Content: []*yaml.Node(nil), HeadComment: "", LineComment: "", FootComment: "", Line: 12, Column: 12}, Expr: yaml.Node{Kind: 0x8, Style: 0x0, Tag: "!!str", Value: "day_of_week() == 1 and hour() < 2", Anchor: "", Alias: (*yaml.Node)(nil), Content: []*yaml.Node(nil), HeadComment: "", LineComment: "", FootComment: "", Line: 13, Column: 11}, For: 0, Labels: map[string]string(nil), Annotations: map[string]string{"summary": "Monday"}}, rulefmt.RuleNode{Record: yaml.Node{Kind: 0x0, Style: 0x0, Tag: "", Value: "", Anchor: "", Alias: (*yaml.Node)(nil), Content: []*yaml.Node(nil), HeadComment: "", LineComment: "", FootComment: "", Line: 0, Column: 0}, Alert: yaml.Node{Kind: 0x8, Style: 0x0, Tag: "!!str", Value: "S02-NewNamespace", Anchor: "", Alias: (*yaml.Node)(nil), Content: []*yaml.Node(nil), HeadComment: "", LineComment: "", FootComment: "", Line: 17, Column: 12}, Expr: yaml.Node{Kind: 0x8, Style: 0x0, Tag: "!!str", Value: "time() - kube_namespace_created < 120", Anchor: "", Alias: (*yaml.Node)(nil), Content: []*yaml.Node(nil), HeadComment: "", LineComment: "", FootComment: "", Line: 18, Column: 11}, For: 0, Labels: map[string]string(nil), Annotations: map[string]string{"summary": "labels={{ $labels }} namespace={{ $labels.namespace }} value={{ $value }}"}}}}}}}) | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#!/bin/bash | ||
cd $(dirname $0)/.. | ||
|
||
set -xeuo pipefail | ||
go fmt ./... | ||
go vet ./... | ||
staticcheck ./... | ||
golangci-lint run --timeout 5m | ||
./scripts/test-cover.sh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters