Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into rg2-qos-fix
Browse files Browse the repository at this point in the history
  • Loading branch information
rahulguptajss committed Aug 22, 2023
2 parents c6c63b5 + 9c00fb8 commit f830348
Show file tree
Hide file tree
Showing 61 changed files with 540 additions and 647 deletions.
18 changes: 18 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,29 +1,44 @@
linters:
disable-all: true
enable:
- asasalint
- bidichk
- bodyclose
- contextcheck
- dogsled
- dupword
- durationcheck
- errcheck
- errchkjson
- errname
- errorlint
- exhaustive
- exportloopref
- gocheckcompilerdirectives
- gosec
- gosimple
- govet
- ineffassign
- makezero
- mirror
- nilerr
- nolintlint
- nonamedreturns
- nosprintfhostport
- reassign
- revive
- staticcheck
- stylecheck
- tenv
- thelper
- testableexamples
- typecheck
- unconvert
- unparam
- unused
- usestdlibvars
- wastedassign
- zerologlint

issues:
max-issues-per-linter: 0
Expand All @@ -38,3 +53,6 @@ linters-settings:
thelper:
test:
begin: false
gocritic:
disabled-tags:
- style
12 changes: 6 additions & 6 deletions cmd/admin/admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,19 +98,19 @@ func (a *Admin) APISD(w http.ResponseWriter, r *http.Request) {
return
}
}
if r.Method == "PUT" {
if r.Method == http.MethodPut {
a.apiPublish(w, r)
} else if r.Method == "GET" {
w.WriteHeader(200)
} else if r.Method == http.MethodGet {
w.WriteHeader(http.StatusOK)
_, _ = w.Write(a.makeTargets())
} else {
w.WriteHeader(400)
w.WriteHeader(http.StatusBadRequest)
}
}

func (a *Admin) setupLogger() {
zerolog.SetGlobalLevel(zerolog.InfoLevel)
zerolog.ErrorStackMarshaler = logging.MarshalStack
zerolog.ErrorStackMarshaler = logging.MarshalStack //nolint:reassign

a.logger = zerolog.New(zerolog.ConsoleWriter{Out: os.Stderr}).
With().Caller().Timestamp().Logger()
Expand All @@ -128,7 +128,7 @@ func (a *Admin) apiPublish(w http.ResponseWriter, r *http.Request) {
err := decoder.Decode(&publish)
if err != nil {
a.logger.Err(err).Msg("Unable to parse publish json")
w.WriteHeader(400)
w.WriteHeader(http.StatusBadRequest)
return
}
a.pollerToPromAddr.Set(publish.Name, publish, a.expireAfter)
Expand Down
72 changes: 18 additions & 54 deletions cmd/collectors/commonutils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,7 @@ func testWithoutGroupType(t *testing.T, instance *matrix.Instance) {
instance.SetLabel("group_type", "")
UpdateProtectedFields(instance)

if instance.GetLabel("protectedBy") == "" && instance.GetLabel("protectionSourceType") == "" {
// OK
} else {
if instance.GetLabel("protectedBy") != "" || instance.GetLabel("protectionSourceType") != "" {
t.Errorf("Labels protectedBy= %s, expected empty and protectionSourceType= %s, expected empty", instance.GetLabel("protectedBy"), instance.GetLabel("protectionSourceType"))
}
}
Expand All @@ -57,9 +55,7 @@ func testSvmdr(t *testing.T, instance *matrix.Instance) {
instance.SetLabel("source_volume", "")
UpdateProtectedFields(instance)

if instance.GetLabel("protectedBy") == "storage_vm" && instance.GetLabel("protectionSourceType") == "storage_vm" {
// OK
} else {
if instance.GetLabel("protectedBy") != "storage_vm" || instance.GetLabel("protectionSourceType") != "storage_vm" {
t.Errorf("Labels protectedBy= %s, expected: storage_vm and protectionSourceType= %s, expected: storage_vm", instance.GetLabel("protectedBy"), instance.GetLabel("protectionSourceType"))
}
}
Expand All @@ -71,9 +67,7 @@ func testConstituentVolumeWithinSvmdr(t *testing.T, instance *matrix.Instance) {
instance.SetLabel("destination_location", "test1")
UpdateProtectedFields(instance)

if instance.GetLabel("protectedBy") == "storage_vm" && instance.GetLabel("protectionSourceType") == "volume" {
// OK
} else {
if instance.GetLabel("protectedBy") != "storage_vm" || instance.GetLabel("protectionSourceType") != "volume" {
t.Errorf("Labels protectedBy= %s, expected: storage_vm and protectionSourceType= %s, expected: volume", instance.GetLabel("protectedBy"), instance.GetLabel("protectionSourceType"))
}
}
Expand All @@ -83,9 +77,7 @@ func testCg(t *testing.T, instance *matrix.Instance) {
instance.SetLabel("destination_location", "test123:/cg/")
UpdateProtectedFields(instance)

if instance.GetLabel("protectedBy") == "cg" && instance.GetLabel("protectionSourceType") == "cg" {
// OK
} else {
if instance.GetLabel("protectedBy") != "cg" || instance.GetLabel("protectionSourceType") != "cg" {
t.Errorf("Labels protectedBy= %s, expected: cg and protectionSourceType= %s, expected: cg", instance.GetLabel("protectedBy"), instance.GetLabel("protectionSourceType"))
}
}
Expand All @@ -95,9 +87,7 @@ func testConstituentVolumeWithinCg(t *testing.T, instance *matrix.Instance) {
instance.SetLabel("destination_location", "test123")
UpdateProtectedFields(instance)

if instance.GetLabel("protectedBy") == "cg" && instance.GetLabel("protectionSourceType") == "volume" {
// OK
} else {
if instance.GetLabel("protectedBy") != "cg" || instance.GetLabel("protectionSourceType") != "volume" {
t.Errorf("Labels protectedBy= %s, expected: cg and protectionSourceType= %s, expected: volume", instance.GetLabel("protectedBy"), instance.GetLabel("protectionSourceType"))
}
}
Expand All @@ -106,9 +96,7 @@ func testNegativeCase1(t *testing.T, instance *matrix.Instance) {
instance.SetLabel("group_type", "infinitevol")
UpdateProtectedFields(instance)

if instance.GetLabel("protectedBy") == "volume" && instance.GetLabel("protectionSourceType") == "not_mapped" {
// OK
} else {
if instance.GetLabel("protectedBy") != "volume" || instance.GetLabel("protectionSourceType") != "not_mapped" {
t.Errorf("Labels protectedBy= %s, expected: volume and protectionSourceType= %s, expected: not_mapped", instance.GetLabel("protectedBy"), instance.GetLabel("protectionSourceType"))
}
}
Expand All @@ -120,9 +108,7 @@ func testNegativeCase2(t *testing.T, instance *matrix.Instance) {
instance.SetLabel("destination_location", "test123:")
UpdateProtectedFields(instance)

if instance.GetLabel("protectedBy") == "volume" && instance.GetLabel("protectionSourceType") == "not_mapped" {
// OK
} else {
if instance.GetLabel("protectedBy") != "volume" || instance.GetLabel("protectionSourceType") != "not_mapped" {
t.Errorf("Labels protectedBy= %s, expected: volume and protectionSourceType= %s, expected: not_mapped", instance.GetLabel("protectedBy"), instance.GetLabel("protectionSourceType"))
}
}
Expand All @@ -131,9 +117,7 @@ func testGroupTypeNone(t *testing.T, instance *matrix.Instance) {
instance.SetLabel("group_type", "none")
UpdateProtectedFields(instance)

if instance.GetLabel("protectedBy") == "volume" && instance.GetLabel("protectionSourceType") == "volume" {
// OK
} else {
if instance.GetLabel("protectedBy") != "volume" || instance.GetLabel("protectionSourceType") != "volume" {
t.Errorf("Labels protectedBy= %s, expected: volume and protectionSourceType= %s, expected: volume", instance.GetLabel("protectedBy"), instance.GetLabel("protectionSourceType"))
}
}
Expand All @@ -142,9 +126,7 @@ func testGroupTypeFlexgroup(t *testing.T, instance *matrix.Instance) {
instance.SetLabel("group_type", "flexgroup")
UpdateProtectedFields(instance)

if instance.GetLabel("protectedBy") == "volume" && instance.GetLabel("protectionSourceType") == "volume" {
// OK
} else {
if instance.GetLabel("protectedBy") != "volume" || instance.GetLabel("protectionSourceType") != "volume" {
t.Errorf("Labels protectedBy= %s, expected: volume and protectionSourceType= %s, expected: volume", instance.GetLabel("protectedBy"), instance.GetLabel("protectionSourceType"))
}
}
Expand All @@ -155,9 +137,7 @@ func testStrictSyncMirror(t *testing.T, instance *matrix.Instance) {
instance.SetLabel("policy_type", "strict_sync_mirror")
UpdateProtectedFields(instance)

if instance.GetLabel("derived_relationship_type") == "sync_mirror_strict" {
// OK
} else {
if instance.GetLabel("derived_relationship_type") != "sync_mirror_strict" {
t.Errorf("Labels derived_relationship_type= %s, expected: sync_mirror_strict", instance.GetLabel("derived_relationship_type"))
}
}
Expand All @@ -167,9 +147,7 @@ func testSyncMirror(t *testing.T, instance *matrix.Instance) {
instance.SetLabel("policy_type", "sync_mirror")
UpdateProtectedFields(instance)

if instance.GetLabel("derived_relationship_type") == "sync_mirror" {
// OK
} else {
if instance.GetLabel("derived_relationship_type") != "sync_mirror" {
t.Errorf("Labels derived_relationship_type= %s, expected: sync_mirror", instance.GetLabel("derived_relationship_type"))
}
}
Expand All @@ -179,9 +157,7 @@ func testMirrorVault(t *testing.T, instance *matrix.Instance) {
instance.SetLabel("policy_type", "mirror_vault")
UpdateProtectedFields(instance)

if instance.GetLabel("derived_relationship_type") == "mirror_vault" {
// OK
} else {
if instance.GetLabel("derived_relationship_type") != "mirror_vault" {
t.Errorf("Labels derived_relationship_type= %s, expected: mirror_vault", instance.GetLabel("derived_relationship_type"))
}
}
Expand All @@ -191,9 +167,7 @@ func testAutomatedFailover(t *testing.T, instance *matrix.Instance) {
instance.SetLabel("policy_type", "automated_failover")
UpdateProtectedFields(instance)

if instance.GetLabel("derived_relationship_type") == "sync_mirror" {
// OK
} else {
if instance.GetLabel("derived_relationship_type") != "sync_mirror" {
t.Errorf("Labels derived_relationship_type= %s, expected: sync_mirror", instance.GetLabel("derived_relationship_type"))
}
}
Expand All @@ -203,9 +177,7 @@ func testOtherPolicyType(t *testing.T, instance *matrix.Instance) {
instance.SetLabel("policy_type", "vault")
UpdateProtectedFields(instance)

if instance.GetLabel("derived_relationship_type") == "vault" {
// OK
} else {
if instance.GetLabel("derived_relationship_type") != "vault" {
t.Errorf("Labels derived_relationship_type= %s, expected: vault", instance.GetLabel("derived_relationship_type"))
}
}
Expand All @@ -215,9 +187,7 @@ func testWithNoPolicyType(t *testing.T, instance *matrix.Instance) {
instance.SetLabel("policy_type", "")
UpdateProtectedFields(instance)

if instance.GetLabel("derived_relationship_type") == "extended_data_protection" {
// OK
} else {
if instance.GetLabel("derived_relationship_type") != "extended_data_protection" {
t.Errorf("Labels derived_relationship_type= %s, expected: extended_data_protection", instance.GetLabel("derived_relationship_type"))
}
}
Expand All @@ -227,9 +197,7 @@ func testWithNoPolicyTypeNoRelationshipType(t *testing.T, instance *matrix.Insta
instance.SetLabel("policy_type", "")
UpdateProtectedFields(instance)

if instance.GetLabel("derived_relationship_type") == "" {
// OK
} else {
if instance.GetLabel("derived_relationship_type") != "" {
t.Errorf("Labels derived_relationship_type= %s, expected: \"\"(empty)", instance.GetLabel("derived_relationship_type"))
}
}
Expand All @@ -240,9 +208,7 @@ func testOlderTimestampThanDuration(t *testing.T) {
duration := 5 * time.Minute
isOlder := IsTimestampOlderThanDuration(time.Now(), timestamp, duration)

if isOlder {
// OK
} else {
if !isOlder {
t.Errorf("timestamp= %f is older than duration %s", timestamp, duration.String())
}
}
Expand All @@ -252,9 +218,7 @@ func testNewerTimestampThanDuration(t *testing.T) {
duration := 2 * time.Hour
isOlder := IsTimestampOlderThanDuration(time.Now(), timestamp, duration)

if !isOlder {
// OK
} else {
if isOlder {
t.Errorf("timestamp= %f is newer than duration %s", timestamp, duration.String())
}
}
Expand Down
16 changes: 6 additions & 10 deletions cmd/collectors/ems/ems.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,7 @@ func (e *Ems) Init(a *collector.AbstractCollector) error {
return err
}

if err = e.InitMatrix(); err != nil {
return err
}

return nil
return e.InitMatrix()
}

func (e *Ems) InitMatrix() error {
Expand Down Expand Up @@ -359,7 +355,8 @@ func (e *Ems) PollData() (map[string]*matrix.Matrix, error) {
}
toTime := clusterTime.Unix()
timeFilter := e.getTimeStampFilter(clusterTime)
filter := append(e.Filter, timeFilter)
filter := e.Filter
filter = append(filter, timeFilter)

// build hrefs up to maxURLSize
var hrefs []string
Expand Down Expand Up @@ -534,13 +531,13 @@ func (e *Ems) HandleResults(result []gjson.Result, prop map[string][]*emsProp) (
}

// Check matches at all same name ems
isMatch := false
var isMatch bool
// Check matches at each ems
isMatchPs := false
var isMatchPs bool
// Check instance count at all same name ems
instanceLabelCount := uint64(0)
// Check instance count at each ems
instanceLabelCountPs := uint64(0)
var instanceLabelCountPs uint64

// parse ems properties for the instance
if ps, ok := prop[msgName]; ok {
Expand Down Expand Up @@ -609,7 +606,6 @@ func (e *Ems) HandleResults(result []gjson.Result, prop map[string][]*emsProp) (
}
}
if !isMatchPs {
instanceLabelCountPs = 0
continue
}

Expand Down
10 changes: 3 additions & 7 deletions cmd/collectors/ems/ems_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func NewEms() *Ems {
ac := collector.New("Ems", "Ems", &opts, emsParams(emsConfgPath), nil)
e := &Ems{}
if err := e.Init(ac); err != nil {
log.Fatal().Err(err)
log.Fatal().Err(err).Send()
}
// Changed the resolve_after for 2 issuing ems for auto resolve testing
e.resolveAfter["LUN.offline"] = 1 * time.Second
Expand Down Expand Up @@ -102,9 +102,7 @@ func (e *Ems) testBookendIssuingEms(t *testing.T, path string) {
}
// Test for matches - filter
if generatedEmsName == "hm.alert.raised" {
if instance.GetLabel("alert_id") == "RaidLeftBehindAggrAlert" {
// OK
} else {
if instance.GetLabel("alert_id") != "RaidLeftBehindAggrAlert" {
t.Errorf("Labels alert_id= %s, expected: RaidLeftBehindAggrAlert", instance.GetLabel("alert_id"))
}
}
Expand Down Expand Up @@ -142,9 +140,7 @@ func (e *Ems) testBookendResolvingEms(t *testing.T, path string) {
}
// Test for matches - filter
if generatedEmsName == "hm.alert.raised" {
if instance.GetLabel("alert_id") == "RaidLeftBehindAggrAlert" && ok && val == 0.0 {
// OK
} else {
if instance.GetLabel("alert_id") != "RaidLeftBehindAggrAlert" || !ok || val != 0.0 {
t.Errorf("Labels alert_id= %s, expected: RaidLeftBehindAggrAlert, metric value = %f, expected: 0.0", instance.GetLabel("alert_id"), val)
}
}
Expand Down
5 changes: 2 additions & 3 deletions cmd/collectors/rest/plugins/disk/disk.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/*
* Copyright NetApp Inc, 2021 All rights reserved
*/
// Copyright NetApp Inc, 2021 All rights reserved

package disk

import (
Expand Down
9 changes: 2 additions & 7 deletions cmd/collectors/rest/plugins/health/health.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,7 @@ func (h *Health) Init() error {
return err
}

if err = h.client.Init(5); err != nil {
return err
}

return nil
return h.client.Init(5)
}

func (h *Health) initAllMatrix() error {
Expand Down Expand Up @@ -457,8 +453,7 @@ func (h *Health) collectSupportAlerts() {
}
toTime := clusterTime.Unix()
timeFilter := h.getTimeStampFilter(clusterTime)
addFilter := []string{"suppress=false"}
filter := append(addFilter, timeFilter)
filter := append([]string{"suppress=false"}, timeFilter)

records, err := h.getSupportAlerts(filter)
if err != nil {
Expand Down
Loading

0 comments on commit f830348

Please sign in to comment.