Skip to content

Commit 7c9959e

Browse files
review comments
1 parent f123649 commit 7c9959e

File tree

2 files changed

+15
-17
lines changed

2 files changed

+15
-17
lines changed

gnmi_server/client_subscribe.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ func (c *Client) recv(stream gnmipb.GNMI_SubscribeServer) {
249249
// send runs until process Queue returns an error.
250250
func (c *Client) send(stream gnmipb.GNMI_SubscribeServer, dc sdc.Client) error {
251251
for {
252-
var val *sdc.Value
252+
var val *sdc.Value
253253
items, err := c.q.Get(1)
254254

255255
if items == nil {
@@ -264,13 +264,13 @@ func (c *Client) send(stream gnmipb.GNMI_SubscribeServer, dc sdc.Client) error {
264264

265265
var resp *gnmipb.SubscribeResponse
266266

267-
switch v := items[0].(type) {
267+
switch v := items[0].(type) {
268268
case sdc.Value:
269-
if resp, err = sdc.ValToResp(v); err != nil {
269+
if resp, err = sdc.ValToResp(v); err != nil {
270270
c.errors++
271271
return err
272272
}
273-
val = &v;
273+
val = &v;
274274
default:
275275
log.V(1).Infof("Unknown data type %v for %s in queue", items[0], c)
276276
c.errors++

sonic_data_client/events_client.go

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,9 @@ func compute_latency(evtc *EventClient) {
141141
cnt += 1
142142
}
143143
}
144-
evtc.counters[LATENCY] = (uint64) (total/cnt/1000/1000)
144+
if (cnt > 0) {
145+
evtc.counters[LATENCY] = (uint64) (total/cnt/1000/1000)
146+
}
145147
}
146148
}
147149

@@ -151,6 +153,11 @@ func update_stats(evtc *EventClient) {
151153
var wr_counters *map[string]uint64 = nil
152154
var rclient *redis.Client
153155

156+
/*
157+
* This loop pauses until at least one non zero counter.
158+
* This helps add some initial pause before accessing DB
159+
* for existing values.
160+
*/
154161
for evtc.stopped == 0 {
155162
var val uint64
156163

@@ -166,6 +173,7 @@ func update_stats(evtc *EventClient) {
166173
time.Sleep(time.Second)
167174
}
168175

176+
/* Populate counters from DB for cumulative counters. */
169177
if evtc.stopped == 0 {
170178
ns := sdcfg.GetDbDefaultNamespace()
171179

@@ -193,22 +201,12 @@ func update_stats(evtc *EventClient) {
193201
}
194202
}
195203

204+
/* Main running loop that updates DB */
196205
for evtc.stopped == 0 {
197206
tmp_counters := make(map[string]uint64)
198207

199208
// compute latency
200-
if evtc.last_latency_full {
201-
var total uint64 = 0
202-
var cnt uint64 = 0
203-
204-
for _, v := range evtc.last_latencies {
205-
if v > 0 {
206-
total += v
207-
cnt += 1
208-
}
209-
}
210-
evtc.counters[LATENCY] = (uint64) (total/cnt/1000/1000)
211-
}
209+
compute_latency(evtc)
212210

213211
for key, val := range evtc.counters {
214212
tmp_counters[key] = val + db_counters[key]

0 commit comments

Comments
 (0)