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: handle array as comma separated value in zapi #1810

Merged
merged 10 commits into from
Mar 20, 2023
Merged

Conversation

Hardikl
Copy link
Contributor

@Hardikl Hardikl commented Mar 10, 2023

Tested with Volume and NetworkInterface object.

For Volume, with changes:

hardikl@hardikl-mac-2 ~ % curl -s 'http://localhost:13001/metrics'  | grep volume_labels | grep aggr | wc -l
     164
hardikl@hardikl-mac-2 ~ % curl -s 'http://localhost:13001/metrics'  | grep volume_labels | grep flexvol | grep aggr | wc -l
     163
hardikl@hardikl-mac-2 ~ % curl -s 'http://localhost:13001/metrics'  |grep volume_labels | grep flexvol | grep aggr     
volume_labels{aggr="umeng_aff300_aggr2",cluster="umeng-aff300-01-02",datacenter="u2",isEncrypted="false",isHardwareEncrypted="false",is_sis_volume="true",node="umeng-aff300-01",node_root="false",root_volume="No",snapshot_policy="none",state="online",style="flexvol",svm="astra_300",svm_root="false",type="rw",volume="trident_pvc_4e7e77ff_39a3_43e2_b4c8_69e31ce90b93"} 1.0
volume_labels{aggr="umeng_aff300_aggr2",cluster="umeng-aff300-01-02",datacenter="u2",isEncrypted="false",isHardwareEncrypted="false",is_sis_volume="true",node="umeng-aff300-01",node_root="false",root_volume="No",snapshot_policy="none",state="online",style="flexvol",svm="astra_300",svm_root="false",type="rw",volume="trident_pvc_9b4f1397_106d_4359_8076_2f3d89ba447f"} 1.0
volume_labels{aggr="umeng_aff300_aggr2",cluster="umeng-aff300-01-02",datacenter="u2",isEncrypted="false",isHardwareEncrypted="false",is_sis_volume="true",node="umeng-aff300-01",node_root="false",root_volume="No",snapshot_policy="none",state="online",style="flexvol",svm="astra_300",svm_root="false",type="rw",volume="trident_pvc_c37ce9f9_2b8d_406a_8610_2f511868882c"} 1.0
volume_labels{aggr="test",cluster="umeng-aff300-01-02",datacenter="u2",isEncrypted="false",isHardwareEncrypted="false",is_sis_volume="true",node="umeng-aff300-02",node_root="false",root_volume="No",snapshot_policy="default",state="online",style="flexvol",svm="astra_304",svm_root="false",type="rw",volume="dummy"} 1.0
volume_labels{aggr="test",cluster="umeng-aff300-01-02",datacenter="u2",isEncrypted="false",isHardwareEncrypted="false",is_sis_volume="true",node="umeng-aff300-02",node_root="false",root_volume="No",snapshot_policy="none",state="online",style="flexvol",svm="astra_304",svm_root="false",type="rw",volume="trident_pvc_ce04e59a_9073_407c_bbce_c149b0e6a32c"} 1.0
volume_labels{aggr="test",cluster="umeng-aff300-01-02",datacenter="u2",isEncrypted="false",isHardwareEncrypted="false",is_sis_volume="false",node="umeng-aff300-02",node_root="false",root_volume="Yes",snapshot_policy="default",state="online",style="flexvol",svm="test_banner_154_1",svm_root="true",type="rw",volume="test_banner_154_1_root"} 1.0
...
hardikl@hardikl-mac-2 ~ % curl -s 'http://localhost:13001/metrics'  | grep volume_labels | grep flexgroup | grep aggr | wc -l
       1
hardikl@hardikl-mac-2 ~ % curl -s 'http://localhost:13001/metrics'  |grep volume_labels | grep flexgroup | grep aggr        
volume_labels{aggr="test,umeng_aff300_aggr2",cluster="umeng-aff300-01-02",datacenter="u2",isEncrypted="false",isHardwareEncrypted="false",is_sis_volume="true",node="",node_root="false",root_volume="No",snapshot_policy="none",state="online",style="flexgroup",svm="osc",svm_root="false",type="rw",volume="RahulTest"} 1.0

For NetworkInterface, custom Rest:

name:               networkinterface
query:              api/private/cli/network/interface
object:             netint

counters:
  - ^^data_protocol => data_protocol
  - ^address        => address
  - ^^lif           => interface

plugins:
  LabelAgent:
    value_to_num:
      - test_status status ok ok 1

export_options:
  include_all_labels: true

image

For NetworkInterface, custom zapi, with changes,

name: networkinterface
query: net-interface-get-iter
object: netint

collect_only_labels: true

counters:
  net-interface-info:
    - ^address
    - ^^interface-name => interface
    - data-protocols:
      - ^data-protocol => data_protocol

plugins:
  LabelAgent:
    value_to_num:
      - test_status status ok ok 1

export_options:
  include_all_labels: true

image

  • code changes
  • unit test case for array

@Hardikl
Copy link
Contributor Author

Hardikl commented Mar 10, 2023

Fix #1360

@Hardikl
Copy link
Contributor Author

Hardikl commented Mar 13, 2023

As no extra symbol for array handling in Zapi, we don't need any documentation change for this.

@Hardikl
Copy link
Contributor Author

Hardikl commented Mar 13, 2023

For Array case, response would be something like this:

printed as {{node name}} - {{node value}} : {{child names list}}

2023-03-13T16:03:09+05:30 INF collector/zapi.go:306 > volume-id-attributes - <aggr-list><aggr-name>Ak_Aggregate</aggr-name><aggr-name>Ak_Aggregate_HE</aggr-name><aggr-name>puk_aggr2_on_154</aggr-name><aggr-name>puk_aggr3_on_154</aggr-name></aggr-list><instance-uuid>ce6d03e9-be1c-11eb-b50d-00a098d7b0b9</instance-uuid><name>test_flexgroup_dont_delete_1</name><owning-vserver-name>svm_workload_dont_delete_1622024777713</owning-vserver-name><style-extended>flexgroup</style-extended><type>rw</type> : [aggr-list instance-uuid name owning-vserver-name style-extended type] Poller=cluster-01 collector=Zapi:Volume

2023-03-13T16:03:09+05:30 INF collector/zapi.go:306 > aggr-list - <aggr-name>Ak_Aggregate</aggr-name><aggr-name>Ak_Aggregate_HE</aggr-name><aggr-name>puk_aggr2_on_154</aggr-name><aggr-name>puk_aggr3_on_154</aggr-name> : [aggr-name aggr-name aggr-name aggr-name] Poller=cluster-01 collector=Zapi:Volume

@@ -279,7 +287,13 @@ func (z *Zapi) PollData() (map[string]*matrix.Matrix, error) {
}

for _, child := range node.GetChildren() {
fetch(instance, child, newpath)
uniqueNames := util.RemoveDuplicateStr(child.GetAllChildNamesS())
if len(child.GetAllChildNamesS()) > 1 && len(uniqueNames) < len(child.GetAllChildNamesS()) && len(uniqueNames) == 1 {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since child.GetAllChildNamesS() does work and allocations, better to calculate once

also not sure I completely understand this logic - an array is defined as:

  • multiple child elements (makes sense)
  • where those children have duplicates (why can an array have duplicates?)
  • where those duplicates unique to a single item (why?)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is one of the response o/p:

<volume-id-attributes>
<aggr-list>
<aggr-name>Ak_Aggregate</aggr-name>
<aggr-name>Ak_Aggregate_HE</aggr-name>
<aggr-name>puk_aggr2_on_154</aggr-name>
<aggr-name>puk_aggr3_on_154</aggr-name>
</aggr-list>
<instance-uuid>ce6d03e9-be1c-11eb-b50d-00a098d7b0b9</instance-uuid>
<name>test_flexgroup_dont_delete_1</name>
<owning-vserver-name>svm_workload_dont_delete_1622024777713</owning-vserver-name>
<style-extended>flexgroup</style-extended>
<type>rw</type> 
</volume-id-attributes>

For node volume-id-attributes, child elements are : [aggr-list instance-uuid name owning-vserver-name style-extended type]
Whereas for node aggr-list, child elements are: [aggr-name aggr-name aggr-name aggr-name]

From Zapidoc,
image

image

So,
Case 1: Parent node have multiple different child elements Ex. volume-id-attributes
Case 2: Parent node may have few duplicates and few unique child elements (I am not much sure about this case)
Case 3: Parent node have multiple same child elements Ex. aggr-list, which eventually only 1 child with array case.

cmd/collectors/zapi/collector/zapi.go Outdated Show resolved Hide resolved
cmd/collectors/zapi/collector/zapi.go Outdated Show resolved Hide resolved
pkg/util/util.go Outdated Show resolved Hide resolved
pkg/util/util.go Outdated Show resolved Hide resolved
cgrinds
cgrinds previously approved these changes Mar 15, 2023
conf/zapi/cdot/9.8.0/volume.yaml Show resolved Hide resolved
cmd/collectors/zapi/collector/zapi.go Outdated Show resolved Hide resolved
// Handling array with comma separated values
previousValue := instance.GetLabel(label)
if isAppend && previousValue != "" {
instance.SetLabel(label, previousValue+","+value)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In past we have been setting empty for array elements. That needs to be fixed as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Out of 4 volume plugin(zapi, zapiperf, rest, restperf),

  • zapiperf and restperf are exact same and handling aggr, node as perf call don't have this array in response. --> no changes required.
  • zapi don't have any handling for flexgroup.
  • rest has this below handling for aggruuid and it still holds true as zapi don't handle aggruuid for flexgroup.

image

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How is isHardwareEncrypted handled for flexgroup if aggruuid is always empty for it? Also comment about aggrUUid in code doesn't match if Zapi doesn't do it this way.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, Zapi would handle this way,
First populate aggrsDisksMap and then populate aggrsMap.
For flexgroup, which span across multiple aggregates, it can't be part of any map.
So for them label isHardwareEncrypted alway be false.

for _, aggrDiskData := range result {
		aggrUUID := aggrDiskData.GetChildContentS("aggregate-uuid")
		aggrName := aggrDiskData.GetChildContentS("aggregate")
		aggrDiskList := aggrDiskData.GetChildS("aggr-plex-list").GetChildS("aggr-plex-info").GetChildS("aggr-raidgroup-list").GetChildS("aggr-raidgroup-info").GetChildS("aggr-disk-list").GetChildren()
		for _, aggrDisk := range aggrDiskList {
			diskName = aggrDisk.GetChildContentS("disk")
			aggrsDisksMap[diskName] = aggrData{aggrUUID: aggrUUID, aggrName: aggrName}
		}
	}
	return aggrsDisksMap, nil
func (my *Volume) updateAggrMap(disks []string, aggrDiskMap map[string]aggrData) {
	if disks != nil && aggrDiskMap != nil {
		// Clean aggrsMap map
		my.aggrsMap = make(map[string]string)

		for _, disk := range disks {
			aggr := aggrDiskMap[disk]
			my.aggrsMap[aggr.aggrUUID] = aggr.aggrName
		}
	}
}

image

image

- ^owning-vserver-name => svm
- ^containing-aggregate-name => aggr
- aggr-list:
- ^aggr-name => aggr
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should revisit added metrics volume_aggr_labels which were added last release. Let's discuss if it is safe to remove them or we want to keep publishing them.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for now, I don't change it and based on our discussion we will take call on volume_aggr_labels.

// Handling array with comma separated values
previousValue := instance.GetLabel(label)
if isAppend && previousValue != "" {
instance.SetLabel(label, previousValue+","+value)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How is isHardwareEncrypted handled for flexgroup if aggruuid is always empty for it? Also comment about aggrUUid in code doesn't match if Zapi doesn't do it this way.

pkg/util/util.go Outdated Show resolved Hide resolved
@rahulguptajss
Copy link
Contributor

looks good. Completes Zapi gap with Rest 💯

@cgrinds cgrinds merged commit 372a8b1 into main Mar 20, 2023
@cgrinds cgrinds deleted the zapi_array_handle branch March 20, 2023 14:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants