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

fix: handled quota index key in rest template with tests #3128

Merged
merged 2 commits into from
Sep 2, 2024
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
3 changes: 2 additions & 1 deletion cmd/collectors/rest/plugins/quota/quota.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ func (q *Quota) handlingQuotaMetrics(instanceMap map[string]*matrix.Instance, me
continue
}
index := quota.GetLabel("index")
volumeUUID := quota.GetLabel("volume_uuid")
uName := quota.GetLabel("userName")
uid := quota.GetLabel("userId")
group := quota.GetLabel("groupName")
Expand All @@ -93,7 +94,7 @@ func (q *Quota) handlingQuotaMetrics(instanceMap map[string]*matrix.Instance, me
for metricName, m := range metricMap {
// set -1 for unlimited
value := -1.0
quotaInstanceKey := index + metricName
quotaInstanceKey := index + volumeUUID + metricName
quotaInstance, err := data.NewInstance(quotaInstanceKey)
if err != nil {
q.Logger.Debug().Msgf("add (%s) instance: %v", metricName, err)
Expand Down
40 changes: 36 additions & 4 deletions cmd/collectors/rest/rest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/netapp/harvest/v2/cmd/poller/options"
"github.com/netapp/harvest/v2/pkg/conf"
"github.com/netapp/harvest/v2/pkg/matrix"
"github.com/netapp/harvest/v2/pkg/util"
"github.com/tidwall/gjson"
"os"
"strings"
Expand Down Expand Up @@ -70,7 +71,7 @@ var (
func TestMain(m *testing.M) {
conf.TestLoadHarvestConfig("testdata/config.yml")

benchRest = newRest("Volume", "volume.yaml")
benchRest = newRest("Volume", "volume.yaml", "testdata/conf")
fullPollData = collectors.JSONToGson("testdata/volume-1.json.gz", true)
now := time.Now().Truncate(time.Second)
_, _ = benchRest.pollData(now, fullPollData, volumeEndpoints)
Expand Down Expand Up @@ -119,7 +120,7 @@ func Test_pollDataVolume(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {

r := newRest("Volume", "volume.yaml")
r := newRest("Volume", "volume.yaml", "testdata/conf")
now := time.Now().Truncate(time.Second)
pollData := collectors.JSONToGson(tt.pollDataPath1, true)

Expand Down Expand Up @@ -148,9 +149,9 @@ func volumeEndpoints(e *EndPoint) ([]gjson.Result, time.Duration, error) {
return gson, 0, nil
}

func newRest(object string, path string) *Rest {
func newRest(object string, path string, confPath string) *Rest {
var err error
opts := options.New(options.WithConfPath("testdata/conf"))
opts := options.New(options.WithConfPath(confPath))
opts.Poller = pollerName
opts.HomePath = "testdata"
opts.IsTest = true
Expand Down Expand Up @@ -438,3 +439,34 @@ func TestFields(t *testing.T) {
})
}
}

func TestQuotas(t *testing.T) {
r := newRest("Quota", "quota.yaml", "../../../conf")
var instanceKeys []string
result, err := collectors.InvokeRestCallWithTestFile(r.Client, "", r.Logger, "testdata/quota.json")
if err != nil {
t.Errorf("Error while invoking quota rest api call")
}

for _, quotaInstanceData := range result {
var instanceKey string
if len(r.Prop.InstanceKeys) != 0 {
// extract instance key(s)
for _, k := range r.Prop.InstanceKeys {
value := quotaInstanceData.Get(k)
if value.Exists() {
instanceKey += value.String()
}
}

if instanceKey == "" {
continue
}
instanceKeys = append(instanceKeys, instanceKey)
}
}

if util.HasDuplicates(instanceKeys) {
t.Errorf("Duplicate instanceKeys found for quota rest api")
}
}
Loading
Loading