Skip to content

Commit

Permalink
fix: moved test to ci
Browse files Browse the repository at this point in the history
  • Loading branch information
Hardikl committed Sep 19, 2024
1 parent 23c18c0 commit 805cdfe
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 37 deletions.
31 changes: 0 additions & 31 deletions cmd/collectors/commonutils.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"github.com/netapp/harvest/v2/pkg/util"
"github.com/tidwall/gjson"
"os"
"regexp"
"sort"
"strconv"
"strings"
Expand All @@ -21,8 +20,6 @@ const (
MaxAllowedTimeDrift = 10 * time.Second
)

var isStringAlphabetic = regexp.MustCompile(`^[a-zA-Z0-9_]*$`).MatchString

var validUnits = map[string]bool{
"mW": true,
"W": true,
Expand Down Expand Up @@ -517,31 +514,3 @@ func PopulateIfgroupMetrics(portIfgroupMap map[string]string, portDataMap map[st
}
return nil
}

func FindStringBetweenTwoChar(stringValue string, startChar string, endChar string) []string {
var counters = make([]string, 0)
firstSet := strings.Split(stringValue, startChar)
for _, actualString := range firstSet {
counterArray := strings.Split(actualString, endChar)
switch {
case strings.Contains(actualString, ")"): // check for inner expression such as top:
counterArray = strings.Split(actualString, ")")
case strings.Contains(actualString, "+"): // check for inner expression such as top:
counterArray = strings.Split(actualString, "+")
case strings.Contains(actualString, "/"): // check for inner expression such as top:
counterArray = strings.Split(actualString, "/")
case strings.Contains(actualString, ","): // check for inner expression such as top:
counterArray = strings.Split(actualString, ",")
}
counter := strings.TrimSpace(counterArray[len(counterArray)-1])
counterArray = strings.Split(counter, endChar)
counter = strings.TrimSpace(counterArray[len(counterArray)-1])
if _, err := strconv.Atoi(counter); err == nil {
continue
}
if isStringAlphabetic(counter) && counter != "" {
counters = append(counters, counter)
}
}
return counters
}
4 changes: 2 additions & 2 deletions cmd/tools/generate/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -676,11 +676,11 @@ func init() {
fFlags := fullCmd.PersistentFlags()

flags := metricCmd.PersistentFlags()
flags.StringVarP(&opts.Poller, "poller", "p", "sar", "name of poller, e.g. 10.193.48.154")
flags.StringVarP(&opts.Poller, "poller", "p", "dc1", "name of poller, e.g. 10.193.48.154")
_ = metricCmd.MarkPersistentFlagRequired("poller")

flag := descCmd.PersistentFlags()
flag.StringVarP(&opts.Poller, "poller", "p", "sar", "name of poller, e.g. 10.193.48.154")
flag.StringVarP(&opts.Poller, "poller", "p", "dc1", "name of poller, e.g. 10.193.48.154")
_ = descCmd.MarkPersistentFlagRequired("poller")

dFlags.IntVarP(&opts.loglevel, "loglevel", "l", 2,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package collectors
package main

import (
"fmt"
"github.com/Netapp/harvest-automation/test/utils"
"github.com/netapp/harvest/v2/cmd/tools/generate"
"github.com/netapp/harvest/v2/pkg/tree"
"github.com/netapp/harvest/v2/pkg/tree/node"
Expand Down Expand Up @@ -29,6 +30,7 @@ var exceptionMetrics = []string{
}

func TestAlertRules(t *testing.T) {
utils.SkipIfMissing(t, utils.Regression)
metrics, _ := generate.GeneratedMetrics("../../", "harvest.yml", "dc1")
for pluginMetric, pluginLabels := range pluginGeneratedMetric {
metrics[pluginMetric] = generate.Counter{Name: pluginMetric, Labels: pluginLabels}
Expand Down Expand Up @@ -57,6 +59,7 @@ func TestAlertRules(t *testing.T) {
}

func TestEmsAlertRules(t *testing.T) {
utils.SkipIfMissing(t, utils.Regression)
templateEmsLabels := getEmsLabels("../../conf/ems/9.6.0/ems.yaml")
emsAlertRules := GetAllAlertRules("../../container/prometheus/", "ems_alert_rules.yml", true)
for _, alertRule := range emsAlertRules {
Expand Down
37 changes: 34 additions & 3 deletions integration/test/dashboard_json_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@ import (
"fmt"
"github.com/Netapp/harvest-automation/test/dashboard"
"github.com/Netapp/harvest-automation/test/utils"
"github.com/netapp/harvest/v2/cmd/collectors"
"github.com/tidwall/gjson"
"golang.org/x/text/cases"
"golang.org/x/text/language"
"log/slog"
"os"
"path/filepath"
"regexp"
"strconv"
"strings"
"testing"
"time"
Expand All @@ -23,6 +24,8 @@ const (

var restDataCollectors = []string{"Rest"}

var isStringAlphabetic = regexp.MustCompile(`^[a-zA-Z0-9_]*$`).MatchString

var fileSet []string

// zapiCounterMap are additional counters, above and beyond the ones from counterMap, which should be excluded from Zapi
Expand Down Expand Up @@ -340,7 +343,7 @@ func getAllExpr(record gjson.Result) []string {
}

func getAllCounters(expression string) []string {
all := collectors.FindStringBetweenTwoChar(expression, "{", "(")
all := FindStringBetweenTwoChar(expression, "{", "(")
var filtered []string

allLoop:
Expand All @@ -361,7 +364,7 @@ allLoop:

func validateExpr(expression string) (bool, string) {
if expression != "" {
counters := collectors.FindStringBetweenTwoChar(expression, "{", "(")
counters := FindStringBetweenTwoChar(expression, "{", "(")
newExpression := expression
if len(counters) > 0 {
for _, counter := range counters {
Expand Down Expand Up @@ -395,6 +398,34 @@ func GetAllJsons(dir string) []string {
return fileSet
}

func FindStringBetweenTwoChar(stringValue string, startChar string, endChar string) []string {
var counters = make([]string, 0)
firstSet := strings.Split(stringValue, startChar)
for _, actualString := range firstSet {
counterArray := strings.Split(actualString, endChar)
switch {
case strings.Contains(actualString, ")"): // check for inner expression such as top:
counterArray = strings.Split(actualString, ")")
case strings.Contains(actualString, "+"): // check for inner expression such as top:
counterArray = strings.Split(actualString, "+")
case strings.Contains(actualString, "/"): // check for inner expression such as top:
counterArray = strings.Split(actualString, "/")
case strings.Contains(actualString, ","): // check for inner expression such as top:
counterArray = strings.Split(actualString, ",")
}
counter := strings.TrimSpace(counterArray[len(counterArray)-1])
counterArray = strings.Split(counter, endChar)
counter = strings.TrimSpace(counterArray[len(counterArray)-1])
if _, err := strconv.Atoi(counter); err == nil {
continue
}
if isStringAlphabetic(counter) && counter != "" {
counters = append(counters, counter)
}
}
return counters
}

func hasDataInDB(query string, waitFor time.Duration) bool {
now := time.Now()
for {
Expand Down

0 comments on commit 805cdfe

Please sign in to comment.