openconfig / gnmic

gNMIc is a gNMI CLI client and collector
https://gnmic.openconfig.net
Apache License 2.0
190 stars 57 forks source link

gnmic is displaying response in order different than it receives them. #273

Closed ngniksnikhil closed 1 year ago

ngniksnikhil commented 1 year ago

gnmic is displaying sync_response before the actual data received for path.

Command used : gnmic subscribe -a ip:port -p PWD -u USERNAME --stream-mode sample --sample-interval 10s --skip-verify --path /sample_path --format prototext

sync_response: true update: { timestamp: 662261525310000000 update: { path: { elem:{
name: "sample_path"
} } val: { json_val: "sample_value" } } }

If we run this command in debug mode we can see that data has come before sync_response.

gnmic subscribe -a ip:port -p PWD -u USERNAME --stream-mode sample --sample-interval 10s --skip-verify --path /sample_path --format prototext --debug ` 2023/11/01 16:14:43.632950 /home/runner/work/gnmic/gnmic/app/collector.go:70: [gnmic] target "ip:port": gNMI Subscribe Response: &{SubscriptionName:default-1698835473 SubscriptionConfig:{"name":"default-1698835473","paths":["/sample_path"],"mode":"stream","stream-mode":"sample","encoding":"json","sample-interval":10000000000}Response:update:{timestamp:662261979310000000 update:{path:{elem:{name:"sample_path"}}] val:{json_val:"sample_value"}}}}

2023/11/01 16:14:43.633120 /home/runner/work/gnmic/gnmic/app/collector.go:70: [gnmic] target "ip:port": gNMI Subscribe Response: &{SubscriptionName:default-1698835473 SubscriptionConfig:{"name":"default-1698835473","paths":["/sample_path"],"mode":"stream","stream-mode":"sample","encoding":"json","sample-interval":10000000000} Response:sync_response:true}

`

As we can see data came at 16:14:43.632950 and sync_response at 16:14:43.633120, But while displaying this output it shows sync_response before the data itself.

karimra commented 1 year ago

This is probably due to concurrent writes to stdout. The sync_response takes less time to parse so it gets written first. I will change the default output to have a single writer.