Skip to content

Commit

Permalink
Prepare 0.8.0 release (#19)
Browse files Browse the repository at this point in the history
  • Loading branch information
jpreese authored Nov 25, 2021
1 parent 4aa4314 commit 762277e
Show file tree
Hide file tree
Showing 5 changed files with 515 additions and 122 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
- name: setup go
uses: actions/setup-go@v1
with:
go-version: '1.14'
go-version: '1.17'

- name: build
run: make build
Expand Down
8 changes: 5 additions & 3 deletions generate/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"path/filepath"
"regexp"
"sort"
"strings"
)

// Generate finds all rules at the given path and its
Expand All @@ -30,17 +31,18 @@ func getRuleGroups(path string, input string) ([]ruleGroup, error) {
}

var alertGroups []ruleGroup
if input == "kubernetes" {
if strings.EqualFold(input, "kubernetes") {
alertGroups, err = getKubernetesRuleGroups(files)
if err != nil {
return nil, err
return nil, fmt.Errorf("get kubernetes rule groups: %w", err)
}
} else {
alertGroups, err = getMixinRuleGroups(files)
if err != nil {
return nil, err
return nil, fmt.Errorf("get mixin rule groups: %w", err)
}
}

sort.Slice(alertGroups, func(i int, j int) bool {
return alertGroups[i].Name < alertGroups[j].Name
})
Expand Down
26 changes: 16 additions & 10 deletions generate/prometheus.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,25 +33,27 @@ type rule struct {
}

func splitYAML(resources []byte) ([][]byte, error) {

dec := yaml.NewDecoder(bytes.NewReader(resources))

var res [][]byte
for {
var value interface{}
err := dec.Decode(&value)
if err == io.EOF {
break
}
if err != nil {
return nil, err
if err := dec.Decode(&value); err != nil {
if err == io.EOF {
break
}

return nil, fmt.Errorf("decode: %w", err)
}

valueBytes, err := yaml.Marshal(value)
if err != nil {
return nil, err
return nil, fmt.Errorf("marshal: %w", err)
}

res = append(res, valueBytes)
}

return res, nil
}

Expand Down Expand Up @@ -79,12 +81,14 @@ func getMixinRuleGroups(files []string) ([]ruleGroup, error) {
for _, group := range groups.Groups {
alertGroup, err := extractGroupAlerts(group)
if err != nil {
return nil, err
return nil, fmt.Errorf("extract group alerts: %w", err)
}

alertGroups = append(alertGroups, *alertGroup)
}
}
}

return alertGroups, nil
}

Expand Down Expand Up @@ -119,8 +123,9 @@ func getKubernetesRuleGroups(files []string) ([]ruleGroup, error) {
for _, group := range prometheusRule.Spec.Groups {
alertGroup, err := extractGroupAlerts(group)
if err != nil {
return nil, err
return nil, fmt.Errorf("extract group alerts: %w", err)
}

if alertGroup != nil {
alertGroups = append(alertGroups, *alertGroup)
}
Expand Down Expand Up @@ -149,5 +154,6 @@ func extractGroupAlerts(group ruleGroup) (*ruleGroup, error) {
Name: group.Name,
Rules: alertRules,
}

return &alertGroup, nil
}
23 changes: 20 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,9 +1,26 @@
module github.com/plexsystems/promdoc

go 1.15
go 1.17

require (
github.com/spf13/cobra v1.0.0
github.com/spf13/viper v1.7.1
github.com/spf13/cobra v1.2.1
github.com/spf13/viper v1.9.0
gopkg.in/yaml.v2 v2.4.0
)

require (
github.com/fsnotify/fsnotify v1.5.1 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/inconshreveable/mousetrap v1.0.0 // indirect
github.com/magiconair/properties v1.8.5 // indirect
github.com/mitchellh/mapstructure v1.4.2 // indirect
github.com/pelletier/go-toml v1.9.4 // indirect
github.com/spf13/afero v1.6.0 // indirect
github.com/spf13/cast v1.4.1 // indirect
github.com/spf13/jwalterweatherman v1.1.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/subosito/gotenv v1.2.0 // indirect
golang.org/x/sys v0.0.0-20210823070655-63515b42dcdf // indirect
golang.org/x/text v0.3.6 // indirect
gopkg.in/ini.v1 v1.63.2 // indirect
)
Loading

0 comments on commit 762277e

Please sign in to comment.