Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
- name: Build UI
run: make ui
- name: golangci-lint
uses: golangci/golangci-lint-action@v6.2.0
uses: golangci/golangci-lint-action@v8.0.0
with:
args: --timeout=10m
version: 'latest'
47 changes: 42 additions & 5 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
version: "2"

run:
deadline: 10m
go: 1.23

output:
formats:
- format: colored-line-number
format: colored-line-number

linters:
settings:
errcheck:
exclude-functions:
- "(github.com/go-kit/log.Logger).Log"
enable:
- depguard
- godot
- whitespace
formatters:
- gofumpt
- goimports
- revive
- whitespace

issues:
exclude-dirs:
Expand All @@ -22,11 +26,40 @@ issues:
- path: _test.go
linters:
- errcheck
- linters:
- revive
text: "exported:"

linters-settings:
depguard:
rules:
Main:
list-mode: lax
allow:
- $gostd
- github.com/alecthomas/kong
- github.com/bufbuild/connect-go
- github.com/fsnotify/fsnotify
- github.com/go-kit/log
- github.com/go-kit/log/...
- github.com/oklog/run
- github.com/polarsignals/connect-go-prometheus
- github.com/prometheus-operator/prometheus-operator/...
- github.com/prometheus/alertmanager/...
- github.com/prometheus/client_golang/...
- github.com/prometheus/common/...
- github.com/prometheus/prometheus/...
- github.com/pyrra-dev/pyrra/...
- github.com/rs/cors
- github.com/spf13/viper
- github.com/stretchr/testify/...
- github.com/thanos-io/objstore/...
- github.com/urfave/negroni
- golang.org/x/...
- google.golang.org/...
- gopkg.in/yaml.v3
- k8s.io/...
- sigs.k8s.io/...
deny:
- pkg: sync/atomic
desc: "Use go.uber.org/atomic instead of sync/atomic"
Expand All @@ -51,3 +84,7 @@ linters-settings:
extra-rules: true
misspell:
locale: US
revive:
rules:
- name: exported
disabled: true
4 changes: 2 additions & 2 deletions kubernetes/api/v1alpha1/servicelevelobjective_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -356,11 +356,11 @@ func (in *ServiceLevelObjective) validate() (admission.Warnings, error) {

if in.Spec.ServiceLevelIndicator.BoolGauge != nil {
boolGauge := in.Spec.ServiceLevelIndicator.BoolGauge
if boolGauge.Query.Metric == "" {
if boolGauge.Metric == "" {
return warnings, fmt.Errorf("boolGauge metric must be set")
}

if _, err := parser.ParseExpr(boolGauge.Query.Metric); err != nil {
if _, err := parser.ParseExpr(boolGauge.Metric); err != nil {
return warnings, fmt.Errorf("failed to parse boolGauge metric: %w", err)
}
}
Expand Down
10 changes: 5 additions & 5 deletions kubernetes/api/v1alpha1/servicelevelobjective_types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -701,30 +701,30 @@ func TestServiceLevelObjective_Validate(t *testing.T) {

t.Run("empty", func(t *testing.T) {
bg := boolGauge()
bg.Spec.ServiceLevelIndicator.BoolGauge.Query.Metric = ""
bg.Spec.ServiceLevelIndicator.BoolGauge.Metric = ""
warn, err := bg.ValidateCreate(ctx, bg)
require.EqualError(t, err, "boolGauge metric must be set")
require.Nil(t, warn)
})

t.Run("invalidMetric", func(t *testing.T) {
bg := boolGauge()
bg.Spec.ServiceLevelIndicator.BoolGauge.Query.Metric = "foo{"
bg.Spec.ServiceLevelIndicator.BoolGauge.Metric = "foo{"
warn, err := bg.ValidateCreate(ctx, bg)
require.EqualError(t, err, "failed to parse boolGauge metric: 1:5: parse error: unexpected end of input inside braces")
require.Nil(t, warn)

bg.Spec.ServiceLevelIndicator.BoolGauge.Query.Metric = "foo}"
bg.Spec.ServiceLevelIndicator.BoolGauge.Metric = "foo}"
warn, err = bg.ValidateCreate(ctx, bg)
require.EqualError(t, err, "failed to parse boolGauge metric: 1:4: parse error: unexpected character: '}'")
require.Nil(t, warn)

bg.Spec.ServiceLevelIndicator.BoolGauge.Query.Metric = "$$$"
bg.Spec.ServiceLevelIndicator.BoolGauge.Metric = "$$$"
warn, err = bg.ValidateCreate(ctx, bg)
require.EqualError(t, err, "failed to parse boolGauge metric: 1:1: parse error: unexpected character: '$'")
require.Nil(t, warn)

bg.Spec.ServiceLevelIndicator.BoolGauge.Query.Metric = `foo{foo="bar'}`
bg.Spec.ServiceLevelIndicator.BoolGauge.Metric = `foo{foo="bar'}`
warn, err = bg.ValidateCreate(ctx, bg)
require.EqualError(t, err, "failed to parse boolGauge metric: 1:9: parse error: unterminated quoted string")
require.Nil(t, warn)
Expand Down
2 changes: 1 addition & 1 deletion kubernetes/controllers/servicelevelobjective.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func (r *ServiceLevelObjectiveReconciler) Reconcile(ctx context.Context, req ctr

if r.MimirClient != nil {
mimirFinalizer := "mimir.servicelevelobjective.pyrra.dev/finalizer"
if slo.ObjectMeta.DeletionTimestamp.IsZero() {
if slo.DeletionTimestamp.IsZero() {
// slo is not being deleted, add our finalizer if not already present
if !controllerutil.ContainsFinalizer(&slo, mimirFinalizer) {
controllerutil.AddFinalizer(&slo, mimirFinalizer)
Expand Down
2 changes: 1 addition & 1 deletion mimir/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func (c *Client) Ready(ctx context.Context) error {
return err
}

defer resp.Body.Close()
defer func() { _ = resp.Body.Close() }()

if resp.StatusCode != http.StatusOK {
return fmt.Errorf("mimir not ready, unexpected status code: %d, expected %d", resp.StatusCode, http.StatusOK)
Expand Down
4 changes: 2 additions & 2 deletions mimir/rulegroup.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func (c *Client) SetRuleGroup(ctx context.Context, namespace string, ruleGroup r
return err
}

defer resp.Body.Close()
defer func() { _ = resp.Body.Close() }()

if resp.StatusCode != http.StatusAccepted {
return fmt.Errorf("unexpected status code: %d, expected %d", resp.StatusCode, http.StatusAccepted)
Expand All @@ -54,7 +54,7 @@ func (c *Client) DeleteNamespace(ctx context.Context, namespace string) error {
return err
}

defer resp.Body.Close()
defer func() { _ = resp.Body.Close() }()

if resp.StatusCode != http.StatusAccepted {
return fmt.Errorf("unexpected status code: %d, expected %d", resp.StatusCode, http.StatusAccepted)
Expand Down
16 changes: 8 additions & 8 deletions proto/objectives/v1alpha1/objectives.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,11 +124,11 @@ func FromInternal(o slo.Objective) *Objective {
Grouping: o.Grouping(),
Errors: &Query{
Name: r.Errors.Name,
Metric: r.Errors.Metric(),
Metric: r.Errors.String(),
},
Total: &Query{
Name: r.Total.Name,
Metric: r.Total.Metric(),
Metric: r.Total.String(),
},
}
for _, m := range r.Total.LabelMatchers {
Expand All @@ -153,11 +153,11 @@ func FromInternal(o slo.Objective) *Objective {
Grouping: o.Grouping(),
Success: &Query{
Name: l.Success.Name,
Metric: l.Success.Metric(),
Metric: l.Success.String(),
},
Total: &Query{
Name: l.Total.Name,
Metric: l.Total.Metric(),
Metric: l.Total.String(),
},
}
for _, m := range l.Total.LabelMatchers {
Expand All @@ -181,7 +181,7 @@ func FromInternal(o slo.Objective) *Objective {
Grouping: o.Grouping(),
Total: &Query{
Name: l.Total.Name,
Metric: l.Total.Metric(),
Metric: l.Total.String(),
},
Latency: l.Latency.String(),
}
Expand All @@ -199,11 +199,11 @@ func FromInternal(o slo.Objective) *Objective {
boolGauge = &BoolGauge{
Grouping: o.Grouping(),
BoolGauge: &Query{
Name: b.Metric.Name,
Metric: b.Metric.Metric(),
Name: b.Name,
Metric: b.String(),
},
}
for _, m := range b.Metric.LabelMatchers {
for _, m := range b.LabelMatchers {
boolGauge.BoolGauge.Matchers = append(boolGauge.BoolGauge.Matchers, &LabelMatcher{
Type: LabelMatcher_Type(m.Type),
Name: m.Name,
Expand Down
4 changes: 2 additions & 2 deletions slo/promql_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ var (
}
o := objectiveUpTargets()
o.Indicator.BoolGauge.Grouping = []string{"job", "instance"}
o.Indicator.BoolGauge.Metric.LabelMatchers = append(o.Indicator.BoolGauge.LabelMatchers, matcher)
o.Indicator.BoolGauge.LabelMatchers = append(o.Indicator.BoolGauge.LabelMatchers, matcher)
return o
}
)
Expand Down Expand Up @@ -1025,7 +1025,7 @@ func TestObjective_Immutable(t *testing.T) {
objective.QueryErrorBudget()
objective.QueryTotal(model.Duration(2 * time.Hour))
objective.QueryErrors(model.Duration(2 * time.Hour))
objective.QueryBurnrate(2*time.Hour, nil)
_, _ = objective.QueryBurnrate(2*time.Hour, nil)
require.Equal(t, tc(), objective)
})
}
Expand Down
8 changes: 4 additions & 4 deletions slo/rules.go
Original file line number Diff line number Diff line change
Expand Up @@ -1421,8 +1421,8 @@ func (o Objective) GenericRules() (monitoringv1.RuleGroup, error) {
return monitoringv1.RuleGroup{}, ErrGroupingUnsupported
}

totalMetric := countName(o.Indicator.BoolGauge.Metric.Name, o.Window)
totalMatchers := cloneMatchers(o.Indicator.BoolGauge.Metric.LabelMatchers)
totalMetric := countName(o.Indicator.BoolGauge.Name, o.Window)
totalMatchers := cloneMatchers(o.Indicator.BoolGauge.LabelMatchers)
for _, m := range totalMatchers {
if m.Name == labels.MetricName {
m.Value = totalMetric
Expand All @@ -1435,8 +1435,8 @@ func (o Objective) GenericRules() (monitoringv1.RuleGroup, error) {
Value: o.Name(),
})

successMetric := sumName(o.Indicator.BoolGauge.Metric.Name, o.Window)
successMatchers := cloneMatchers(o.Indicator.BoolGauge.Metric.LabelMatchers)
successMetric := sumName(o.Indicator.BoolGauge.Name, o.Window)
successMatchers := cloneMatchers(o.Indicator.BoolGauge.LabelMatchers)
for _, m := range successMatchers {
if m.Name == labels.MetricName {
m.Value = successMetric
Expand Down
2 changes: 1 addition & 1 deletion slo/slo.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ type Metric struct {
LabelMatchers []*labels.Matcher
}

func (m Metric) Metric() string {
func (m Metric) String() string {
v := parser.VectorSelector{Name: m.Name, LabelMatchers: m.LabelMatchers}
return v.String()
}
Loading