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

fixes #issue 42. add num for each key and sort keys by num. make sure keys in map can be sorted. #50

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

pettershao-ragilenetworks
Copy link
Contributor

Why I did it

The path is not fixed due to the unordered property of the map,which may cause the resource to be unable to be found.
#42

How I did it

add num for each key and sort keys by num.

How to verify it

gnmi_get,gnmi_set's path has more than two keys.

Which release branch to backport (provide reason below if selected)

  • 201811
  • 201911
  • 202006
  • 202012
  • 202106
  • 202111

Description for the changelog

Link to config_db schema for YANG module changes

A picture of a cute animal (not mandatory but encouraged)

@@ -170,7 +172,10 @@
// Recover escaped '[' and ']'.
val = strings.Replace(val, `\]`, `]`, -1)
val = strings.Replace(val, `\[`, `[`, -1)
Copy link
Contributor

@renukamanavalan renukamanavalan Oct 25, 2022

Choose a reason for hiding this comment

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

Good find!
I meant the patch that orders the keys as present in path.

log.V(6).Infof("num_key_map : %#v", num_key_map)
log.V(6).Infof("key_val_map : %#v", key_val_map)

if num_key_map != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

Always return != nil, as you have made it with make. You can check len instead.

@@ -94,8 +98,32 @@ func ConvertToURI(prefix *gnmipb.Path, path *gnmipb.Path, req *string) error {
/* If keys are present , process the keys. */
if key != nil {
for k, v := range key {
log.V(6).Infof("elem : %#v %#v", k, v)
*req += "[" + k + "=" + v + "]"
//log.V(6).Infof("elem : %#v %#v", k, v)
Copy link
Contributor

Choose a reason for hiding this comment

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

Please remove commented lines.

log.V(6).Infof("num : %#v", num_str)
key_del_num := k[strings.Index(k, "]") + 1 : len(k)]
log.V(6).Infof("elem : %#v %#v", key_del_num, v)
num, err := strconv.Atoi(num_str)
Copy link
Contributor

Choose a reason for hiding this comment

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

You may remove these 2 log lines. Later log at 115 & 116 should be sufficient.

for num_key_map_k := range num_key_map {
num_list = append(num_list, num_key_map_k)
}
sort.Ints(num_list)
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't this be already sorted?
xPath patch uses it in sequence.

@pettershao-ragilenetworks
Copy link
Contributor Author

@renukamanavalan I fixed by suggestion fix, and add a cace when key has no tag for test module.

@renukamanavalan
Copy link
Contributor

@ganglyu & @zbud-msft - Please provide your review/approval.

// "[k1=v1][k2=v2]",
// this API returns
-// map[string]string{"k1": "v1", "k2": "v2"}.
+// map[string]string{"[0]k1": "v1", "[1]k2": "v2"}.
Copy link
Contributor

Choose a reason for hiding this comment

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

How about compatibility?
If we add num for each key, other GNMI client can't communicate with SONiC telemetry?

Copy link
Contributor

Choose a reason for hiding this comment

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

The scope of this numbering within parameters of a path element.

@pettershao-ragilenetworks -- please correct my statement if needed.

@pettershao-ragilenetworks
Copy link
Contributor Author

this bug cause by GNMI client, the client assign value to map with "keyValuePairs[key] = val", causes the k-vs ​​to be out of order in memory. I used the int(-9223372036854775808 ~ 9223372036854775807) type in c-s, but there are rarely more than 10 keys in practice. If key without tag, the request also can be accepted, but the order of map to path cannot be guaranteed, and the resource may not be found. see file transl_utils/transl_utils.go in line 101.
@ganglyu & @zbud-msft - Please provide your review/approval.

@ganglyu
Copy link
Contributor

ganglyu commented Nov 8, 2022

this bug cause by GNMI client, the client assign value to map with "keyValuePairs[key] = val", causes the k-vs ​​to be out of order in memory. I used the int(-9223372036854775808 ~ 9223372036854775807) type in c-s, but there are rarely more than 10 keys in practice. If key without tag, the request also can be accepted, but the order of map to path cannot be guaranteed, and the resource may not be found. see file transl_utils/transl_utils.go in line 101. @ganglyu & @zbud-msft - Please provide your review/approval.

I wonder if GNMI spec has any solution for this order issue.

@ganglyu
Copy link
Contributor

ganglyu commented Nov 8, 2022

https://github.com/openconfig/gnmi/blob/master/proto/gnmi/gnmi.proto#L153-L156
GNMI protobuf is using map for key, and map is ordered by key. That's why we can't get the expected order.
Translib is used to support openconfig yang, maybe we can restore the order from yang model?

@pettershao-ragilenetworks
Copy link
Contributor Author

I had try use list[map,map] struct replace map or add a list to record key in protobuf(modify protobuf defined message), but failed. Pkg YGOT relies on the structure generated by protobuf, cause can not use YGOT, so at last I gived up, and the code is more than now. @ganglyu

@ganglyu
Copy link
Contributor

ganglyu commented Nov 9, 2022

@seiferteric Would you please review this PR?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants