-
Notifications
You must be signed in to change notification settings - Fork 40
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
feat: Harvest should collect QOS policy groups #1831
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
52 changes: 52 additions & 0 deletions
52
cmd/collectors/rest/plugins/qospolicyfixed/qospolicyfixed.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package qospolicyfixed | ||
|
||
import ( | ||
"github.com/netapp/harvest/v2/cmd/collectors/zapi/plugins/qospolicyfixed" | ||
"github.com/netapp/harvest/v2/cmd/poller/plugin" | ||
"github.com/netapp/harvest/v2/pkg/matrix" | ||
"strings" | ||
) | ||
|
||
type QosPolicyFixed struct { | ||
*plugin.AbstractPlugin | ||
} | ||
|
||
func New(p *plugin.AbstractPlugin) plugin.Plugin { | ||
return &QosPolicyFixed{AbstractPlugin: p} | ||
} | ||
|
||
func (p *QosPolicyFixed) Run(dataMap map[string]*matrix.Matrix) ([]*matrix.Matrix, error) { | ||
data := dataMap[p.Object] | ||
|
||
for _, instance := range data.GetInstances() { | ||
p.setFixed(instance) | ||
} | ||
|
||
return nil, nil | ||
} | ||
|
||
func (p *QosPolicyFixed) setFixed(instance *matrix.Instance) { | ||
label := instance.GetLabel("throughput_policy") | ||
if label == "" { | ||
return | ||
} | ||
before, after, found := strings.Cut(label, "-") | ||
if !found { | ||
p.Logger.Warn().Str("label", label).Msg("Unable to parse fixed xput label") | ||
return | ||
} | ||
min, err := qospolicyfixed.ZapiXputToRest(before) | ||
if err != nil { | ||
p.Logger.Error().Err(err).Str("label", before).Msg("Failed to parse fixed xput label") | ||
return | ||
} | ||
max, err := qospolicyfixed.ZapiXputToRest(after) | ||
if err != nil { | ||
p.Logger.Error().Err(err).Str("label", after).Msg("Failed to parse fixed xput label") | ||
return | ||
} | ||
instance.SetLabel("min_throughput_iops", min.IOPS) | ||
instance.SetLabel("max_throughput_iops", max.IOPS) | ||
instance.SetLabel("min_throughput_mbps", min.Mbps) | ||
instance.SetLabel("max_throughput_mbps", max.Mbps) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
111 changes: 111 additions & 0 deletions
111
cmd/collectors/zapi/plugins/qospolicyfixed/qospolicyfixed.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
package qospolicyfixed | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
"github.com/netapp/harvest/v2/cmd/poller/plugin" | ||
"github.com/netapp/harvest/v2/pkg/matrix" | ||
"regexp" | ||
"strconv" | ||
"strings" | ||
) | ||
|
||
type QosPolicyFixed struct { | ||
*plugin.AbstractPlugin | ||
} | ||
|
||
func New(p *plugin.AbstractPlugin) plugin.Plugin { | ||
return &QosPolicyFixed{AbstractPlugin: p} | ||
} | ||
|
||
func (p *QosPolicyFixed) Run(dataMap map[string]*matrix.Matrix) ([]*matrix.Matrix, error) { | ||
// Change ZAPI max-throughput/min-throughput to match what REST publishes | ||
|
||
data := dataMap[p.Object] | ||
for _, instance := range data.GetInstances() { | ||
policyClass := instance.GetLabel("class") | ||
if policyClass != "user_defined" { | ||
// Only export user_defined policy classes - ignore all others | ||
// REST only returns user_defined while ZAPI returns all | ||
instance.SetExportable(false) | ||
continue | ||
} | ||
p.setThroughput(instance, "max_xput", "max_throughput_iops", "max_throughput_mbps") | ||
p.setThroughput(instance, "min_xput", "min_throughput_iops", "min_throughput_mbps") | ||
} | ||
|
||
return nil, nil | ||
} | ||
|
||
func (p *QosPolicyFixed) setThroughput(instance *matrix.Instance, labelName string, iopLabel string, mbpsLabel string) { | ||
val := instance.GetLabel(labelName) | ||
xput, err := ZapiXputToRest(val) | ||
if err != nil { | ||
p.Logger.Warn().Str(labelName, val).Msg("Unable to convert label, skipping") | ||
return | ||
} | ||
instance.SetLabel(iopLabel, xput.IOPS) | ||
instance.SetLabel(mbpsLabel, xput.Mbps) | ||
} | ||
|
||
var iopsRe = regexp.MustCompile(`(\d+)iops`) | ||
var bpsRe = regexp.MustCompile(`(\d+(\.\d+)?)(\w+)/s`) | ||
|
||
var unitToMb = map[string]float32{ | ||
"b": 1 / float32(1024*1024), | ||
"kb": 1 / float32(1024), | ||
"mb": 1, | ||
"gb": 1024, | ||
"tb": 1024 * 1024, | ||
} | ||
|
||
type MaxXput struct { | ||
IOPS string | ||
Mbps string | ||
} | ||
|
||
func ZapiXputToRest(zapi string) (MaxXput, error) { | ||
lower := strings.ToLower(zapi) | ||
empty := MaxXput{IOPS: "0", Mbps: "0"} | ||
if lower == "inf" || lower == "0" { | ||
return empty, nil | ||
} | ||
|
||
// check for a combination | ||
before, after, found := strings.Cut(lower, ",") | ||
if found { | ||
l, err1 := ZapiXputToRest(before) | ||
r, err2 := ZapiXputToRest(after) | ||
if err1 != nil || err2 != nil { | ||
return empty, errors.Join(err1, err2) | ||
} | ||
return MaxXput{ | ||
IOPS: l.IOPS, | ||
Mbps: r.Mbps, | ||
}, nil | ||
} | ||
|
||
// check for iops | ||
matches := iopsRe.FindStringSubmatch(lower) | ||
if len(matches) == 2 { | ||
return MaxXput{IOPS: matches[1], Mbps: "0"}, nil | ||
} | ||
|
||
// check for bps and normalize units to Mbps | ||
matches = bpsRe.FindStringSubmatch(lower) | ||
if len(matches) != 4 { | ||
return empty, fmt.Errorf("unknown qos-policy format [%s]", zapi) | ||
} | ||
numStr := matches[1] | ||
unit := matches[3] | ||
multiple, ok := unitToMb[unit] | ||
if !ok { | ||
return empty, fmt.Errorf("unknown qos-policy unit [%s] of [%s]", unit, zapi) | ||
} | ||
num, err := strconv.ParseFloat(numStr, 32) | ||
if err != nil { | ||
return empty, fmt.Errorf("failed to convert qos-policy unit [%s] of [%s]", numStr, zapi) | ||
} | ||
mbps := float32(num) * multiple | ||
return MaxXput{Mbps: strconv.Itoa(int(mbps)), IOPS: "0"}, nil | ||
} |
43 changes: 43 additions & 0 deletions
43
cmd/collectors/zapi/plugins/qospolicyfixed/qospolicyfixed_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package qospolicyfixed | ||
|
||
import ( | ||
"strconv" | ||
"testing" | ||
) | ||
|
||
func Test_zapiXputToRest(t *testing.T) { | ||
tests := []struct { | ||
zapi string | ||
want MaxXput | ||
isErr bool | ||
}{ | ||
{zapi: "100IOPS", want: MaxXput{IOPS: "100", Mbps: "0"}}, | ||
{zapi: "100iops", want: MaxXput{IOPS: "100", Mbps: "0"}}, | ||
{zapi: "111111IOPS", want: MaxXput{IOPS: "111111", Mbps: "0"}}, | ||
{zapi: "0", want: MaxXput{IOPS: "0", Mbps: "0"}}, | ||
{zapi: "INF", want: MaxXput{IOPS: "0", Mbps: "0"}}, | ||
|
||
{zapi: "1GB/s", want: MaxXput{IOPS: "0", Mbps: "1024"}}, | ||
{zapi: "100B/s", want: MaxXput{IOPS: "0", Mbps: "0"}}, | ||
{zapi: "10KB/s", want: MaxXput{IOPS: "0", Mbps: "0"}}, | ||
{zapi: "1mb/s", want: MaxXput{IOPS: "0", Mbps: "1"}}, | ||
{zapi: "1tb/s", want: MaxXput{IOPS: "0", Mbps: "1048576"}}, | ||
{zapi: "1000KB/s", want: MaxXput{IOPS: "0", Mbps: "0"}}, | ||
{zapi: "15000IOPS,468.8MB/s", want: MaxXput{IOPS: "15000", Mbps: "468"}}, | ||
{zapi: "50000IOPS,1.53GB/s", want: MaxXput{IOPS: "50000", Mbps: "1566"}}, | ||
|
||
{zapi: "1 foople/s", want: MaxXput{IOPS: "0", Mbps: "0"}, isErr: true}, | ||
} | ||
for i, tt := range tests { | ||
t.Run(strconv.Itoa(i), func(t *testing.T) { | ||
got, err := ZapiXputToRest(tt.zapi) | ||
if tt.isErr && err == nil { | ||
t.Errorf("ZapiXputToRest(%s) got=%+v, want err but got err=%s", tt.zapi, got, err) | ||
return | ||
} | ||
if got.IOPS != tt.want.IOPS || got.Mbps != tt.want.Mbps { | ||
t.Errorf("ZapiXputToRest(%s) got=%+v, want=%+v", tt.zapi, got, tt.want) | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
|
||
name: QosPolicyFixed | ||
query: api/private/cli/qos/policy-group | ||
object: qos_policy_fixed | ||
|
||
counters: | ||
- ^^uuid => uuid | ||
- ^policy_group => name | ||
- ^vserver => svm | ||
- ^class => class | ||
- ^num_workloads => object_count | ||
- ^is_shared => capacity_shared | ||
- ^throughput_policy => throughput_policy | ||
- filter: | ||
- class=user_defined | ||
|
||
plugins: | ||
- QosPolicyFixed | ||
|
||
export_options: | ||
instance_keys: | ||
- svm | ||
instance_labels: | ||
- name | ||
- capacity_shared | ||
- max_throughput_iops | ||
- max_throughput_mbps | ||
- min_throughput_iops | ||
- min_throughput_mbps | ||
- object_count | ||
- class |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
|
||
name: QosPolicyFixed | ||
query: qos-policy-group-get-iter | ||
object: qos_policy_fixed | ||
|
||
counters: | ||
qos-policy-group-info: | ||
- ^^uuid => uuid | ||
- ^policy-group => name | ||
- ^vserver => svm | ||
- ^is-shared => capacity_shared | ||
- ^max-throughput => max_xput | ||
- ^min-throughput => min_xput | ||
- ^num-workloads => object_count | ||
- ^policy-group-class => class | ||
|
||
collect_only_labels: true | ||
|
||
plugins: | ||
- QosPolicyFixed | ||
|
||
export_options: | ||
instance_keys: | ||
- svm | ||
instance_labels: | ||
- name | ||
- capacity_shared | ||
- max_throughput_iops | ||
- max_throughput_mbps | ||
- min_throughput_iops | ||
- min_throughput_mbps | ||
- object_count | ||
- class |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should the label be absent/empty instead of having 0 values. For example if qos policy is
19.07MB/s-4.55TB/s
then bothmin_throughput_iops
andmax_throughput_iops
should not be published for that qos policy.