Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resolve all existing lint issues #1030

Merged
merged 3 commits into from
Feb 7, 2023
Merged
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: 2 additions & 0 deletions .drone.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ platform:
os: linux
arch: amd64
steps:
- name: lint
image: rancher/drone-golangci-lint:latest
- name: build-and-package
image: docker
environment: &dagger_env
Expand Down
2 changes: 1 addition & 1 deletion .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ linters-settings:
- name: error-return
- name: error-strings
- name: imports-blacklist
arguments: ["crypto/md5", "crypto/sha1", "grpc.go4.org/**", "github.com/gogo/status","github.com/gogo/codes"]
arguments: ["grpc.go4.org/**", "github.com/gogo/status","github.com/gogo/codes"]
- name: increment-decrement
- name: indent-error-flow
- name: package-comments
Expand Down
8 changes: 4 additions & 4 deletions infra/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,13 @@ func run(ctx *Context) (runErr error) {
}

var id StringOutput
if rand, err := random.NewRandomId(ctx, "id", &random.RandomIdArgs{
rand, err := random.NewRandomId(ctx, "id", &random.RandomIdArgs{
ByteLength: Int(4),
}); err != nil {
})
if err != nil {
return errors.WithStack(err)
} else {
id = rand.Hex
}
id = rand.Hex

tags := map[string]string{}
for k, v := range conf.Tags {
Expand Down
4 changes: 2 additions & 2 deletions internal/bench/query_runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,8 +217,8 @@ func (q *QueryRunner) ExecuteQuery(ctx context.Context, queryReq Query) error {
now := time.Now()

var (
queryType string = "instant"
status string = "success"
queryType = "instant"
status = "success"
)
if queryReq.TimeRange > 0 {
queryType = "range"
Expand Down
2 changes: 1 addition & 1 deletion internal/bench/write_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ type WriteClient struct {
}

// NewWriteClient creates a new client for remote write.
func NewWriteClient(name string, tenantName string, conf *remote.ClientConfig, logger log.Logger, requestHistogram *prometheus.HistogramVec) (*WriteClient, error) {
func NewWriteClient(name string, tenantName string, conf *remote.ClientConfig, _ log.Logger, requestHistogram *prometheus.HistogramVec) (*WriteClient, error) {
httpClient, err := config_util.NewClientFromConfig(conf.HTTPClientConfig, "bench_write_client", config_util.WithHTTP2Disabled())
if err != nil {
return nil, err
Expand Down
4 changes: 2 additions & 2 deletions internal/cortex/cortex_main.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,10 @@ func Main(args []string) {
}
//////////////////////////////////////////////////////////////////////////////

if close, err := tracing.SetupTracing(ctx, name, cfg.Tracing); err != nil {
if closeTracing, err := tracing.SetupTracing(ctx, name, cfg.Tracing); err != nil {
level.Error(util_log.Logger).Log("msg", "Failed to setup tracing", "err", err.Error())
} else {
defer close(ctx) // nolint:errcheck
defer closeTracing(ctx) // nolint:errcheck
}

//////////////////////////////////////////////////////////////////////////////
Expand Down
34 changes: 16 additions & 18 deletions pkg/alerting/backend/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,17 +189,16 @@ func (a *AlertManagerAPI) DoRequest() error {
lastRetrierError := fmt.Errorf("unknwon error")
numRetries := 0
for backoffv2.Continue(b) {
if err := a.doRequest(); err == nil {
err := a.doRequest()
if err == nil {
return nil
} else {
lastRetrierError = err
}
numRetries += 1
lastRetrierError = err
numRetries++
}
return fmt.Errorf("failed to complete request after retrier timeout (%d retries) : %s", numRetries, lastRetrierError)
} else {
return a.doRequest()
}
return a.doRequest()
}

func (a *AlertManagerAPI) doRequest() error {
Expand Down Expand Up @@ -457,20 +456,19 @@ func NewExpectConfigEqual(expectedConfig string) func(*http.Response) error {
func NewApiPipline(ctx context.Context, apis []*AlertManagerAPI, chainRetrier *backoffv2.Policy) error {
if chainRetrier == nil {
return newApiPipeline(apis)
} else {
b := (*chainRetrier).Start(ctx)
lastRetrierError := fmt.Errorf("unkown error")
numRetries := 0
for backoffv2.Continue(b) {
if err := newApiPipeline(apis); err == nil {
return nil
} else {
lastRetrierError = err
}
numRetries += 1
}
b := (*chainRetrier).Start(ctx)
lastRetrierError := fmt.Errorf("unkown error")
numRetries := 0
for backoffv2.Continue(b) {
err := newApiPipeline(apis)
if err == nil {
return nil
}
return fmt.Errorf("api pipeline failed with backoff retrier timeout (%d retries) : %s", numRetries, lastRetrierError)
lastRetrierError = err
numRetries++
}
return fmt.Errorf("api pipeline failed with backoff retrier timeout (%d retries) : %s", numRetries, lastRetrierError)
}

func newApiPipeline(apis []*AlertManagerAPI) error {
Expand Down
4 changes: 2 additions & 2 deletions pkg/alerting/condition/condition.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func ParseAlertManagerWebhookPayload(annotations []gjson.Result) ([]*alertingv1.
}
anyFailed := false
res := &alertingv1.TriggerAlertsRequest{}

IDENTIFIERS:
for _, identifier := range RequiredCortexWebhookAnnotationIdentifiers {
if _, ok := result[identifier]; !ok {
errors = append(errors, fmt.Errorf(
Expand All @@ -95,7 +95,7 @@ func ParseAlertManagerWebhookPayload(annotations []gjson.Result) ([]*alertingv1.
errors = append(errors, fmt.Errorf("unhandled opni identifier %s", identifier))
opniRequests = append(opniRequests, nil)
anyFailed = true
break
kralicky marked this conversation as resolved.
Show resolved Hide resolved
break IDENTIFIERS
}
}
delete(result, identifier)
Expand Down
4 changes: 2 additions & 2 deletions pkg/alerting/metrics/construct.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,12 +182,12 @@ func (a *AlertingRule) Or(other *AlertingRule) AlertRuleBuilder {
}
}

func (a *AlertingRule) IfForSecondsThen(other *AlertingRule, seconds time.Duration) AlertRuleBuilder {
func (a *AlertingRule) IfForSecondsThen(_ *AlertingRule, _ time.Duration) AlertRuleBuilder {
//TODO : implement
return nil
}

func (a *AlertingRule) IfNotForSecondsThen(other *AlertingRule, seconds time.Duration) AlertRuleBuilder {
func (a *AlertingRule) IfNotForSecondsThen(_ *AlertingRule, _ time.Duration) AlertRuleBuilder {
//TODO: implement
return nil
}
Expand Down
36 changes: 17 additions & 19 deletions pkg/alerting/metrics/opts.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@ import (
_ "embed"
"fmt"
"reflect"
"time"

corev1 "github.com/rancher/opni/pkg/apis/core/v1"
"github.com/rancher/opni/pkg/validation"
"github.com/rancher/opni/plugins/metrics/pkg/apis/cortexadmin"
)
Expand All @@ -33,44 +31,44 @@ type MetricOpts interface {
// Iterates over the field values of the MetricOpts struct
// - Fetches labels and annotations from the field tags
// - Returns a map of options to their list of values
func FetchAlertConditionValues(m *MetricOpts, client *cortexadmin.CortexAdminClient) (interface{}, error) {
func FetchAlertConditionValues(m *MetricOpts, _ *cortexadmin.CortexAdminClient) (interface{}, error) {
values := make(map[string][]string)
t := reflect.TypeOf(m)

for i := 0; i < t.NumField(); i++ {
field := t.Field(i)
labelTag := field.Tag.Get(labelTag)
metricTag := field.Tag.Get(metricTag)
jobExtractorTag := field.Tag.Get(jobExtractorTag)
//jobExtractorTag := field.Tag.Get(jobExtractorTag)
if labelTag != "" {
if metricTag == "" {
panic(fmt.Sprintf("invalid struct declaration for : %s, missing metric tag %s on field", t.Kind(), field.Type.String()))
}
// fetch label values of on metric
}

if field.Tag.Get(jobExtractorTag) != "" {
// get all metric names matching regex expr
}
// if field.Tag.Get(jobExtractorTag) != "" {
// get all metric names matching regex expr
// }

if field.Tag.Get(rangeTag) != "" {
// translate rage to an array
}
// if field.Tag.Get(rangeTag) != "" {
// translate rage to an array
// }

// comparison operator choices
if reflect.TypeOf(field) == reflect.TypeOf(ComparisonOperator{}) {
// // comparison operator choices
// if reflect.TypeOf(field) == reflect.TypeOf(ComparisonOperator{}) {

}
// }

// list clusters on which the metrics are defined
if reflect.TypeOf(field) == reflect.TypeOf(corev1.Cluster{}) {
// // list clusters on which the metrics are defined
// if reflect.TypeOf(field) == reflect.TypeOf(corev1.Cluster{}) {

}
// }

// list multiples of time.Duration
if reflect.TypeOf(field) == reflect.TypeOf(time.Duration(0)) {
// // list multiples of time.Duration
// if reflect.TypeOf(field) == reflect.TypeOf(time.Duration(0)) {

}
// }
}
return values, nil
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/alerting/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ func IsNil(p *Provider) bool {
}

func DoCreate(
p Provider,
ctx context.Context,
p Provider,
req *alertingv1.AlertCondition,
) (*corev1.Reference, error) {
alertingMutex.Lock()
Expand All @@ -42,8 +42,8 @@ func DoCreate(
}

func DoDelete(
p Provider,
ctx context.Context,
p Provider,
req *corev1.Reference,
) (*emptypb.Empty, error) {
alertingMutex.Lock()
Expand All @@ -52,8 +52,8 @@ func DoDelete(
}

func DoTrigger(
p Provider,
ctx context.Context,
p Provider,
req *alertingv1.TriggerAlertsRequest,
) (*alertingv1.TriggerAlertsResponse, error) {
alertingMutex.Lock()
Expand Down
6 changes: 3 additions & 3 deletions pkg/alerting/routing/api_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,12 @@ func (r *Receiver) Equal(other *Receiver) (bool, string) {
return receiversAreEqual(r, other)
}

func (c *Receiver) UnmarshalYAML(unmarshal func(interface{}) error) error {
func (r *Receiver) UnmarshalYAML(unmarshal func(interface{}) error) error {
type plain Receiver
if err := unmarshal((*plain)(c)); err != nil {
if err := unmarshal((*plain)(r)); err != nil {
return err
}
if c.Name == "" {
if r.Name == "" {
return fmt.Errorf("missing name in receiver")
}
return nil
Expand Down
43 changes: 21 additions & 22 deletions pkg/alerting/routing/data.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,23 +184,23 @@ func (r *RoutingTree) Equal(input any) (equal bool, reason string) {
selfReceiverIndex := r.indexOpniReceivers()
otherReceiverIndex := other.indexOpniReceivers()
for id, r1 := range selfReceiverIndex {
if r2, ok := otherReceiverIndex[id]; !ok {
r2, ok := otherReceiverIndex[id]
if !ok {
return false, fmt.Sprintf("configurations do not have matching receiver : %s", id)
} else {
if equal, reason := r1.Equal(r2); !equal {
return false, fmt.Sprintf("configurations do not have equal receivers '%s' : %s", id, reason)
}
}
if equal, reason := r1.Equal(r2); !equal {
return false, fmt.Sprintf("configurations do not have equal receivers '%s' : %s", id, reason)
}
}
selfRoutingIndex := r.indexOpniRoutes()
otherRoutingIndex := other.indexOpniRoutes()
for id, r1 := range selfRoutingIndex {
if r2, ok := otherRoutingIndex[id]; !ok {
r2, ok := otherRoutingIndex[id]
if !ok {
return false, fmt.Sprintf("configurations do not have matching route : %s", id)
} else {
if equal, reason := routesAreEqual(r1, r2); !equal {
return false, fmt.Sprintf("configurations do not have equal route '%s' : %s", id, reason)
}
}
if equal, reason := routesAreEqual(r1, r2); !equal {
return false, fmt.Sprintf("configurations do not have equal route '%s' : %s", id, reason)
}
}
return true, ""
Expand Down Expand Up @@ -294,23 +294,23 @@ func (o *OpniInternalRouting) Add(
}

func (o *OpniInternalRouting) GetFromCondition(conditionId string) (map[string]*OpniRoutingMetadata, error) {
if res, ok := o.Content[conditionId]; !ok {
res, ok := o.Content[conditionId]
if !ok {
return nil, shared.WithNotFoundError("existing condition id that is expected to exist not found in internal routing ids")
} else {
return res, nil
}
return res, nil
}

func (o *OpniInternalRouting) Get(conditionId, endpointId string) (*OpniRoutingMetadata, error) {
if condition, ok := o.Content[conditionId]; !ok {
condition, ok := o.Content[conditionId]
if !ok {
return nil, shared.WithNotFoundError("existing condition id that is expected to exist not found in internal routing ids")
} else {
if metadata, ok := condition[endpointId]; !ok {
return nil, shared.WithNotFoundError("existing condition/endpoint id pair that is expected to exist not found in internal routing ids")
} else {
return metadata, nil
}
}
metadata, ok := condition[endpointId]
if !ok {
return nil, shared.WithNotFoundError("existing condition/endpoint id pair that is expected to exist not found in internal routing ids")
}
return metadata, nil
}

func (o *OpniInternalRouting) UpdateEndpoint(conditionId, notificationId string, metadata OpniRoutingMetadata) error {
Expand Down Expand Up @@ -347,8 +347,7 @@ func (o *OpniInternalRouting) RemoveEndpoint(conditionId string, endpointId stri
func (o *OpniInternalRouting) RemoveCondition(conditionId string) error {
if _, ok := o.Content[conditionId]; !ok {
return shared.WithNotFoundError("existing condition id that is expected to exist not found in internal routing ids")
} else {
delete(o.Content, conditionId)
}
delete(o.Content, conditionId)
return nil
}
4 changes: 2 additions & 2 deletions pkg/alerting/routing/ops.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ func (r *RoutingTree) UpdateIndividualEndpointNode(
}
for _, metadata := range internalRouting.Content[toTraverseItem.conditionId] {
if metadata.EndpointType == toTraverseItem.endpointType && *metadata.Position > toTraverseItem.position {
*metadata.Position -= 1
*metadata.Position--
}
}
// add with correct config while updating internal routing
Expand Down Expand Up @@ -269,7 +269,7 @@ func (r *RoutingTree) DeleteIndividualEndpointNode(
}
for _, metadata := range internalRouting.Content[toTraverseItem.conditionId] {
if metadata.EndpointType == toTraverseItem.endpointType && *metadata.Position > toTraverseItem.position {
*metadata.Position -= 1
*metadata.Position--
}
}
// add with correct config while updating internal routing
Expand Down
2 changes: 1 addition & 1 deletion pkg/alerting/routing/pagerduty.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ func (c *PagerdutyConfig) Default() OpniConfig {
}
}

func (p *PagerdutyConfig) InternalId() string {
func (c *PagerdutyConfig) InternalId() string {
return "pagerduty"
}

Expand Down
6 changes: 3 additions & 3 deletions pkg/apis/capability/v1/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ func (d *Duration) UnmarshalJSON(b []byte) error {
}
switch value := value.(type) {
case string:
if parsed, err := time.ParseDuration(value); err != nil {
parsed, err := time.ParseDuration(value)
if err != nil {
return err
} else {
*d = Duration(parsed)
}
*d = Duration(parsed)
case float64:
*d = Duration(time.Duration(value))
default:
Expand Down
Loading