@@ -382,45 +382,57 @@ func (pm *PluginManager) podUnlock(fullPodName string) {
382
382
383
383
// recordOperation records operation and duration
384
384
func recordOperation (operation string , start time.Time ) {
385
+ metrics .NetworkPluginOperations .WithLabelValues (operation ).Inc ()
385
386
metrics .NetworkPluginOperationsLatency .WithLabelValues (operation ).Observe (metrics .SinceInSeconds (start ))
386
387
}
387
388
389
+ // recordError records errors for metric.
390
+ func recordError (operation string ) {
391
+ metrics .NetworkPluginOperationsErrors .WithLabelValues (operation ).Inc ()
392
+ }
393
+
388
394
func (pm * PluginManager ) GetPodNetworkStatus (podNamespace , podName string , id kubecontainer.ContainerID ) (* PodNetworkStatus , error ) {
389
- defer recordOperation ("get_pod_network_status" , time .Now ())
395
+ const operation = "get_pod_network_status"
396
+ defer recordOperation (operation , time .Now ())
390
397
fullPodName := kubecontainer .BuildPodFullName (podName , podNamespace )
391
398
pm .podLock (fullPodName ).Lock ()
392
399
defer pm .podUnlock (fullPodName )
393
400
394
401
netStatus , err := pm .plugin .GetPodNetworkStatus (podNamespace , podName , id )
395
402
if err != nil {
403
+ recordError (operation )
396
404
return nil , fmt .Errorf ("networkPlugin %s failed on the status hook for pod %q: %v" , pm .plugin .Name (), fullPodName , err )
397
405
}
398
406
399
407
return netStatus , nil
400
408
}
401
409
402
410
func (pm * PluginManager ) SetUpPod (podNamespace , podName string , id kubecontainer.ContainerID , annotations , options map [string ]string ) error {
403
- defer recordOperation ("set_up_pod" , time .Now ())
411
+ const operation = "set_up_pod"
412
+ defer recordOperation (operation , time .Now ())
404
413
fullPodName := kubecontainer .BuildPodFullName (podName , podNamespace )
405
414
pm .podLock (fullPodName ).Lock ()
406
415
defer pm .podUnlock (fullPodName )
407
416
408
417
klog .V (3 ).Infof ("Calling network plugin %s to set up pod %q" , pm .plugin .Name (), fullPodName )
409
418
if err := pm .plugin .SetUpPod (podNamespace , podName , id , annotations , options ); err != nil {
419
+ recordError (operation )
410
420
return fmt .Errorf ("networkPlugin %s failed to set up pod %q network: %v" , pm .plugin .Name (), fullPodName , err )
411
421
}
412
422
413
423
return nil
414
424
}
415
425
416
426
func (pm * PluginManager ) TearDownPod (podNamespace , podName string , id kubecontainer.ContainerID ) error {
417
- defer recordOperation ("tear_down_pod" , time .Now ())
427
+ const operation = "tear_down_pod"
428
+ defer recordOperation (operation , time .Now ())
418
429
fullPodName := kubecontainer .BuildPodFullName (podName , podNamespace )
419
430
pm .podLock (fullPodName ).Lock ()
420
431
defer pm .podUnlock (fullPodName )
421
432
422
433
klog .V (3 ).Infof ("Calling network plugin %s to tear down pod %q" , pm .plugin .Name (), fullPodName )
423
434
if err := pm .plugin .TearDownPod (podNamespace , podName , id ); err != nil {
435
+ recordError (operation )
424
436
return fmt .Errorf ("networkPlugin %s failed to teardown pod %q network: %v" , pm .plugin .Name (), fullPodName , err )
425
437
}
426
438
0 commit comments