Skip to content

Commit

Permalink
fix: handled quota index key in rest template with tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Hardikl committed Aug 30, 2024
1 parent f9fc0ec commit 1e68385
Show file tree
Hide file tree
Showing 4 changed files with 608 additions and 0 deletions.
32 changes: 32 additions & 0 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 @@ -438,3 +439,34 @@ func TestFields(t *testing.T) {
})
}
}

func TestQuotas(t *testing.T) {
r := newRest("Quota", "quota.yaml")
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")
}
}
42 changes: 42 additions & 0 deletions cmd/collectors/rest/testdata/conf/rest/9.12.1/quota.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: Quota
query: api/storage/quota/reports
object: quota

client_timeout: 2m

counters:
- ^^index => index
- ^^volume.uuid => volume_uuid
- ^group.name => groupName
- ^qtree.name => qtree
- ^svm.name => svm
- ^type => type
- ^users.0.id => userId
- ^users.0.name => userName
- ^volume.name => volume
- files.hard_limit => file_limit
- files.soft_limit => soft_file_limit
- files.used.hard_limit_percent => files_used_pct_file_limit
- files.used.soft_limit_percent => files_used_pct_soft_file_limit
- files.used.total => files_used
- space.hard_limit => disk_limit
- space.soft_limit => soft_disk_limit
- space.used.hard_limit_percent => disk_used_pct_disk_limit
- space.used.soft_limit_percent => disk_used_pct_soft_disk_limit
- space.used.total => disk_used
- filter:
- show_default_records=false
- type=tree #|user|group

plugins:
- Quota:

export_options:
instance_keys:
- group
- qtree
- svm
- type
- unit
- user
- volume
Loading

0 comments on commit 1e68385

Please sign in to comment.