plugin/kubernetes: Fix dns programming duration metric (#4255)
* get data reqd to record latency before calling toFuncs * refactor out unnecessary toFunc wrappers * remove latency metric unit tests per PR feedback Signed-off-by: Chris O'Haver <cohaver@infoblox.com>
This commit is contained in:
parent
56eea6e609
commit
9121e78496
9 changed files with 166 additions and 196 deletions
|
@ -4,6 +4,7 @@ import (
|
|||
"fmt"
|
||||
|
||||
api "k8s.io/api/core/v1"
|
||||
meta "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/runtime"
|
||||
)
|
||||
|
||||
|
@ -28,18 +29,12 @@ type Service struct {
|
|||
// ServiceKey returns a string using for the index.
|
||||
func ServiceKey(name, namespace string) string { return name + "." + namespace }
|
||||
|
||||
// ToService returns a function that converts an api.Service to a *Service.
|
||||
func ToService(skipCleanup bool) ToFunc {
|
||||
return func(obj interface{}) (interface{}, error) {
|
||||
svc, ok := obj.(*api.Service)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("unexpected object %v", obj)
|
||||
}
|
||||
return toService(skipCleanup, svc), nil
|
||||
// ToService converts an api.Service to a *Service.
|
||||
func ToService(obj meta.Object) (meta.Object, error) {
|
||||
svc, ok := obj.(*api.Service)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("unexpected object %v", obj)
|
||||
}
|
||||
}
|
||||
|
||||
func toService(skipCleanup bool, svc *api.Service) *Service {
|
||||
s := &Service{
|
||||
Version: svc.GetResourceVersion(),
|
||||
Name: svc.GetName(),
|
||||
|
@ -70,11 +65,9 @@ func toService(skipCleanup bool, svc *api.Service) *Service {
|
|||
|
||||
}
|
||||
|
||||
if !skipCleanup {
|
||||
*svc = api.Service{}
|
||||
}
|
||||
*svc = api.Service{}
|
||||
|
||||
return s
|
||||
return s, nil
|
||||
}
|
||||
|
||||
var _ runtime.Object = &Service{}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue