@@ -124,6 +124,8 @@ func NewServer(config *Config, opts []grpc.ServerOption) (*Server, error) {
124
124
return nil , errors .New ("config not provided" )
125
125
}
126
126
127
+ common_utils .InitCounters ()
128
+
127
129
s := grpc .NewServer (opts ... )
128
130
reflection .Register (s )
129
131
@@ -274,26 +276,32 @@ func (s *Server) checkEncodingAndModel(encoding gnmipb.Encoding, models []*gnmip
274
276
275
277
// Get implements the Get RPC in gNMI spec.
276
278
func (s * Server ) Get (ctx context.Context , req * gnmipb.GetRequest ) (* gnmipb.GetResponse , error ) {
279
+ common_utils .IncCounter (common_utils .GNMI_GET )
277
280
ctx , err := authenticate (s .config .UserAuth , ctx )
278
281
if err != nil {
282
+ common_utils .IncCounter (common_utils .GNMI_GET_FAIL )
279
283
return nil , err
280
284
}
281
285
282
286
if req .GetType () != gnmipb .GetRequest_ALL {
287
+ common_utils .IncCounter (common_utils .GNMI_GET_FAIL )
283
288
return nil , status .Errorf (codes .Unimplemented , "unsupported request type: %s" , gnmipb .GetRequest_DataType_name [int32 (req .GetType ())])
284
289
}
285
290
286
291
if err = s .checkEncodingAndModel (req .GetEncoding (), req .GetUseModels ()); err != nil {
292
+ common_utils .IncCounter (common_utils .GNMI_GET_FAIL )
287
293
return nil , status .Error (codes .Unimplemented , err .Error ())
288
294
}
289
295
290
296
var target string
291
297
prefix := req .GetPrefix ()
292
298
if prefix == nil {
299
+ common_utils .IncCounter (common_utils .GNMI_GET_FAIL )
293
300
return nil , status .Error (codes .Unimplemented , "No target specified in prefix" )
294
301
} else {
295
302
target = prefix .GetTarget ()
296
303
if target == "" {
304
+ common_utils .IncCounter (common_utils .GNMI_GET_FAIL )
297
305
return nil , status .Error (codes .Unimplemented , "Empty target data not supported yet" )
298
306
}
299
307
}
@@ -315,11 +323,13 @@ func (s *Server) Get(ctx context.Context, req *gnmipb.GetRequest) (*gnmipb.GetRe
315
323
}
316
324
317
325
if err != nil {
326
+ common_utils .IncCounter (common_utils .GNMI_GET_FAIL )
318
327
return nil , status .Error (codes .NotFound , err .Error ())
319
328
}
320
329
notifications := make ([]* gnmipb.Notification , len (paths ))
321
330
spbValues , err := dc .Get (nil )
322
331
if err != nil {
332
+ common_utils .IncCounter (common_utils .GNMI_GET_FAIL )
323
333
return nil , status .Error (codes .NotFound , err .Error ())
324
334
}
325
335
@@ -339,8 +349,14 @@ func (s *Server) Get(ctx context.Context, req *gnmipb.GetRequest) (*gnmipb.GetRe
339
349
}
340
350
341
351
func (s * Server ) Set (ctx context.Context , req * gnmipb.SetRequest ) (* gnmipb.SetResponse , error ) {
352
+ common_utils .IncCounter (common_utils .GNMI_SET )
353
+ if s .config .EnableTranslibWrite == false {
354
+ common_utils .IncCounter (common_utils .GNMI_SET_FAIL )
355
+ return nil , grpc .Errorf (codes .Unimplemented , "GNMI is in read-only mode" )
356
+ }
342
357
ctx , err := authenticate (s .config .UserAuth , ctx )
343
358
if err != nil {
359
+ common_utils .IncCounter (common_utils .GNMI_SET_FAIL )
344
360
return nil , err
345
361
}
346
362
var results []* gnmipb.UpdateResult
@@ -388,13 +404,11 @@ func (s *Server) Set(ctx context.Context, req *gnmipb.SetRequest) (*gnmipb.SetRe
388
404
/* Add to Set response results. */
389
405
results = append (results , & res )
390
406
}
391
- if s .config .EnableTranslibWrite {
392
- err = dc .Set (req .GetDelete (), req .GetReplace (), req .GetUpdate ())
393
- } else {
394
- return nil , grpc .Errorf (codes .Unimplemented , "Telemetry is in read-only mode" )
407
+ err = dc .Set (req .GetDelete (), req .GetReplace (), req .GetUpdate ())
408
+ if err != nil {
409
+ common_utils .IncCounter (common_utils .GNMI_SET_FAIL )
395
410
}
396
411
397
-
398
412
return & gnmipb.SetResponse {
399
413
Prefix : req .GetPrefix (),
400
414
Response : results ,
0 commit comments