From 487aa9db3914448d9fd7f99bce8e48c3da242289 Mon Sep 17 00:00:00 2001 From: Adil Fulara Date: Wed, 4 May 2022 20:22:18 -0700 Subject: [PATCH 1/3] Prometheus Counters - add counter. rework tests - add support for labels - move metrics to metrics.go - update metrics tests with labels - use a dedicated delegator to capture metrics - renamed to MonitoredDelegator Signed-off-by: Adil Fulara --- admiral/pkg/clusters/handler_test.go | 10 +- admiral/pkg/clusters/registry.go | 19 ++- admiral/pkg/clusters/registry_test.go | 12 +- admiral/pkg/clusters/serviceentry_test.go | 83 ++++++------ admiral/pkg/controller/admiral/controller.go | 34 ++++- admiral/pkg/controller/admiral/dependency.go | 3 +- admiral/pkg/controller/admiral/deployment.go | 7 +- .../pkg/controller/admiral/deployment_test.go | 20 +-- .../pkg/controller/admiral/globaltraffic.go | 25 ++-- .../controller/admiral/globaltraffic_test.go | 107 ++++++++-------- admiral/pkg/controller/admiral/node.go | 5 +- admiral/pkg/controller/admiral/node_test.go | 4 +- admiral/pkg/controller/admiral/rollouts.go | 12 +- .../pkg/controller/admiral/rollouts_test.go | 20 +-- admiral/pkg/controller/admiral/service.go | 5 +- .../pkg/controller/admiral/service_test.go | 2 +- admiral/pkg/controller/common/config.go | 1 + admiral/pkg/controller/common/metrics.go | 89 +++++++++++-- admiral/pkg/controller/common/metrics_test.go | 121 ++++++++++++++++-- .../pkg/controller/istio/destinationrule.go | 5 +- .../controller/istio/destinationrule_test.go | 2 +- admiral/pkg/controller/istio/serviceentry.go | 6 +- .../pkg/controller/istio/serviceentry_test.go | 2 +- admiral/pkg/controller/istio/sidecar.go | 5 +- admiral/pkg/controller/istio/sidecar_test.go | 2 +- .../pkg/controller/istio/virtualservice.go | 5 +- .../controller/istio/virtualservice_test.go | 2 +- .../pkg/controller/secret/secretcontroller.go | 8 +- .../sample/overlays/deployment/greeting.yaml | 1 + install/sample/overlays/grpc/grpc-server.yaml | 1 + .../overlays/rollout-bluegreen/greeting.yaml | 1 + .../overlays/rollout-canary/greeting.yaml | 1 + 32 files changed, 405 insertions(+), 215 deletions(-) diff --git a/admiral/pkg/clusters/handler_test.go b/admiral/pkg/clusters/handler_test.go index 5a5ce133..f6202dee 100644 --- a/admiral/pkg/clusters/handler_test.go +++ b/admiral/pkg/clusters/handler_test.go @@ -671,8 +671,8 @@ func TestGetServiceForRolloutCanary(t *testing.T) { } stop := make(chan struct{}) - s, e := admiral.NewServiceController(stop, &test.MockServiceHandler{}, &config, time.Second*time.Duration(300)) - r, e := admiral.NewRolloutsController(stop, &test.MockRolloutHandler{}, &config, time.Second*time.Duration(300)) + s, e := admiral.NewServiceController("test", stop, &test.MockServiceHandler{}, &config, time.Second*time.Duration(300)) + r, e := admiral.NewRolloutsController("test", stop, &test.MockRolloutHandler{}, &config, time.Second*time.Duration(300)) fakeIstioClient := istiofake.NewSimpleClientset() @@ -1058,10 +1058,10 @@ func TestGetServiceForRolloutBlueGreen(t *testing.T) { } stop := make(chan struct{}) - s, e := admiral.NewServiceController(stop, &test.MockServiceHandler{}, &config, time.Second*time.Duration(300)) - r, e := admiral.NewRolloutsController(stop, &test.MockRolloutHandler{}, &config, time.Second*time.Duration(300)) + s, e := admiral.NewServiceController("test", stop, &test.MockServiceHandler{}, &config, time.Second*time.Duration(300)) + r, e := admiral.NewRolloutsController("test", stop, &test.MockRolloutHandler{}, &config, time.Second*time.Duration(300)) - emptyCacheService, e := admiral.NewServiceController(stop, &test.MockServiceHandler{}, &config, time.Second*time.Duration(300)) + emptyCacheService, e := admiral.NewServiceController("test", stop, &test.MockServiceHandler{}, &config, time.Second*time.Duration(300)) if e != nil { t.Fatalf("Inititalization failed") diff --git a/admiral/pkg/clusters/registry.go b/admiral/pkg/clusters/registry.go index 8d8561c9..540b7c84 100644 --- a/admiral/pkg/clusters/registry.go +++ b/admiral/pkg/clusters/registry.go @@ -25,7 +25,6 @@ func InitAdmiral(ctx context.Context, params common.AdmiralParams) (*RemoteRegis log.Infof("Initializing Admiral with params: %v", params) common.InitializeConfig(params) - w := RemoteRegistry{ ctx: ctx, } @@ -123,14 +122,14 @@ func (r *RemoteRegistry) createCacheController(clientConfig *rest.Config, cluste log.Infof("starting global traffic policy controller custerID: %v", clusterID) - rc.GlobalTraffic, err = admiral.NewGlobalTrafficController(stop, &GlobalTrafficHandler{RemoteRegistry: r, ClusterID: clusterID}, clientConfig, resyncPeriod) + rc.GlobalTraffic, err = admiral.NewGlobalTrafficController(clusterID, stop, &GlobalTrafficHandler{RemoteRegistry: r, ClusterID: clusterID}, clientConfig, resyncPeriod) if err != nil { return fmt.Errorf(" Error with GlobalTrafficController controller init: %v", err) } log.Infof("starting deployment controller clusterID: %v", clusterID) - rc.DeploymentController, err = admiral.NewDeploymentController(stop, &DeploymentHandler{RemoteRegistry: r, ClusterID: clusterID}, clientConfig, resyncPeriod) + rc.DeploymentController, err = admiral.NewDeploymentController(clusterID, stop, &DeploymentHandler{RemoteRegistry: r, ClusterID: clusterID}, clientConfig, resyncPeriod) if err != nil { return fmt.Errorf(" Error with DeploymentController controller init: %v", err) @@ -140,7 +139,7 @@ func (r *RemoteRegistry) createCacheController(clientConfig *rest.Config, cluste log.Warn("admiral cache was nil!") } else if r.AdmiralCache.argoRolloutsEnabled { log.Infof("starting rollout controller clusterID: %v", clusterID) - rc.RolloutController, err = admiral.NewRolloutsController(stop, &RolloutHandler{RemoteRegistry: r, ClusterID: clusterID}, clientConfig, resyncPeriod) + rc.RolloutController, err = admiral.NewRolloutsController(clusterID, stop, &RolloutHandler{RemoteRegistry: r, ClusterID: clusterID}, clientConfig, resyncPeriod) if err != nil { return fmt.Errorf(" Error with Rollout controller init: %v", err) @@ -148,41 +147,41 @@ func (r *RemoteRegistry) createCacheController(clientConfig *rest.Config, cluste } log.Infof("starting node controller clusterID: %v", clusterID) - rc.NodeController, err = admiral.NewNodeController(stop, &NodeHandler{RemoteRegistry: r, ClusterID: clusterID}, clientConfig) + rc.NodeController, err = admiral.NewNodeController(clusterID, stop, &NodeHandler{RemoteRegistry: r, ClusterID: clusterID}, clientConfig) if err != nil { return fmt.Errorf(" Error with NodeController controller init: %v", err) } log.Infof("starting service controller clusterID: %v", clusterID) - rc.ServiceController, err = admiral.NewServiceController(stop, &ServiceHandler{RemoteRegistry: r, ClusterID: clusterID}, clientConfig, resyncPeriod) + rc.ServiceController, err = admiral.NewServiceController(clusterID, stop, &ServiceHandler{RemoteRegistry: r, ClusterID: clusterID}, clientConfig, resyncPeriod) if err != nil { return fmt.Errorf(" Error with ServiceController controller init: %v", err) } log.Infof("starting service entry controller for custerID: %v", clusterID) - rc.ServiceEntryController, err = istio.NewServiceEntryController(stop, &ServiceEntryHandler{RemoteRegistry: r, ClusterID: clusterID}, clientConfig, resyncPeriod) + rc.ServiceEntryController, err = istio.NewServiceEntryController(clusterID, stop, &ServiceEntryHandler{RemoteRegistry: r, ClusterID: clusterID}, clientConfig, resyncPeriod) if err != nil { return fmt.Errorf(" Error with ServiceEntryController init: %v", err) } log.Infof("starting destination rule controller for custerID: %v", clusterID) - rc.DestinationRuleController, err = istio.NewDestinationRuleController(stop, &DestinationRuleHandler{RemoteRegistry: r, ClusterID: clusterID}, clientConfig, resyncPeriod) + rc.DestinationRuleController, err = istio.NewDestinationRuleController(clusterID, stop, &DestinationRuleHandler{RemoteRegistry: r, ClusterID: clusterID}, clientConfig, resyncPeriod) if err != nil { return fmt.Errorf(" Error with DestinationRuleController init: %v", err) } log.Infof("starting virtual service controller for custerID: %v", clusterID) - rc.VirtualServiceController, err = istio.NewVirtualServiceController(stop, &VirtualServiceHandler{RemoteRegistry: r, ClusterID: clusterID}, clientConfig, resyncPeriod) + rc.VirtualServiceController, err = istio.NewVirtualServiceController(clusterID, stop, &VirtualServiceHandler{RemoteRegistry: r, ClusterID: clusterID}, clientConfig, resyncPeriod) if err != nil { return fmt.Errorf(" Error with VirtualServiceController init: %v", err) } - rc.SidecarController, err = istio.NewSidecarController(stop, &SidecarHandler{RemoteRegistry: r, ClusterID: clusterID}, clientConfig, resyncPeriod) + rc.SidecarController, err = istio.NewSidecarController(clusterID, stop, &SidecarHandler{RemoteRegistry: r, ClusterID: clusterID}, clientConfig, resyncPeriod) if err != nil { return fmt.Errorf(" Error with DestinationRuleController init: %v", err) diff --git a/admiral/pkg/clusters/registry_test.go b/admiral/pkg/clusters/registry_test.go index e05fa775..e263fb6b 100644 --- a/admiral/pkg/clusters/registry_test.go +++ b/admiral/pkg/clusters/registry_test.go @@ -136,7 +136,7 @@ func TestCreateDestinationRuleForLocalNoDeployLabel(t *testing.T) { Host: "localhost", } - d, e := admiral.NewDeploymentController(make(chan struct{}), &test.MockDeploymentHandler{}, &config, time.Second*time.Duration(300)) + d, e := admiral.NewDeploymentController("", make(chan struct{}), &test.MockDeploymentHandler{}, &config, time.Second*time.Duration(300)) if e != nil { t.Fail() @@ -184,10 +184,10 @@ func createMockRemoteController(f func(interface{})) (*RemoteController, error) Host: "localhost", } stop := make(chan struct{}) - d, e := admiral.NewDeploymentController(stop, &test.MockDeploymentHandler{}, &config, time.Second*time.Duration(300)) - s, e := admiral.NewServiceController(stop, &test.MockServiceHandler{}, &config, time.Second*time.Duration(300)) - n, e := admiral.NewNodeController(stop, &test.MockNodeHandler{}, &config) - r, e := admiral.NewRolloutsController(stop, &test.MockRolloutHandler{}, &config, time.Second*time.Duration(300)) + d, e := admiral.NewDeploymentController("", stop, &test.MockDeploymentHandler{}, &config, time.Second*time.Duration(300)) + s, e := admiral.NewServiceController("test", stop, &test.MockServiceHandler{}, &config, time.Second*time.Duration(300)) + n, e := admiral.NewNodeController("", stop, &test.MockNodeHandler{}, &config) + r, e := admiral.NewRolloutsController("test", stop, &test.MockRolloutHandler{}, &config, time.Second*time.Duration(300)) if e != nil { return nil, e @@ -444,7 +444,7 @@ func TestUpdateCacheController(t *testing.T) { t.Run(c.name, func(t *testing.T) { hook := logTest.NewGlobal() rr.RemoteControllers[c.clusterId].ApiServer = c.oldConfig.Host - d, err := admiral.NewDeploymentController(make(chan struct{}), &test.MockDeploymentHandler{}, c.oldConfig, time.Second*time.Duration(300)) + d, err := admiral.NewDeploymentController("", make(chan struct{}), &test.MockDeploymentHandler{}, c.oldConfig, time.Second*time.Duration(300)) if err != nil { t.Fatalf("Unexpected error creating controller %v", err) } diff --git a/admiral/pkg/clusters/serviceentry_test.go b/admiral/pkg/clusters/serviceentry_test.go index 40dee1a8..7b8e0c18 100644 --- a/admiral/pkg/clusters/serviceentry_test.go +++ b/admiral/pkg/clusters/serviceentry_test.go @@ -294,9 +294,9 @@ func TestCreateServiceEntryForNewServiceOrPod(t *testing.T) { Host: "localhost", } - d, e := admiral.NewDeploymentController(make(chan struct{}), &test.MockDeploymentHandler{}, &config, time.Second*time.Duration(300)) + d, e := admiral.NewDeploymentController("", make(chan struct{}), &test.MockDeploymentHandler{}, &config, time.Second*time.Duration(300)) - r, e := admiral.NewRolloutsController(make(chan struct{}), &test.MockRolloutHandler{}, &config, time.Second*time.Duration(300)) + r, e := admiral.NewRolloutsController("test", make(chan struct{}), &test.MockRolloutHandler{}, &config, time.Second*time.Duration(300)) if e != nil { t.Fail() @@ -594,7 +594,7 @@ func TestCreateServiceEntry(t *testing.T) { Host: "localhost", } stop := make(chan struct{}) - s, e := admiral.NewServiceController(stop, &test.MockServiceHandler{}, &config, time.Second*time.Duration(300)) + s, e := admiral.NewServiceController("test", stop, &test.MockServiceHandler{}, &config, time.Second*time.Duration(300)) if e != nil { t.Fatalf("%v", e) @@ -879,17 +879,17 @@ func TestCreateServiceEntryForNewServiceOrPodRolloutsUsecase(t *testing.T) { Host: "localhost", } - d, e := admiral.NewDeploymentController(make(chan struct{}), &test.MockDeploymentHandler{}, &config, time.Second*time.Duration(300)) + d, e := admiral.NewDeploymentController("", make(chan struct{}), &test.MockDeploymentHandler{}, &config, time.Second*time.Duration(300)) - r, e := admiral.NewRolloutsController(make(chan struct{}), &test.MockRolloutHandler{}, &config, time.Second*time.Duration(300)) - v, e := istio.NewVirtualServiceController(make(chan struct{}), &test.MockVirtualServiceHandler{}, &config, time.Second*time.Duration(300)) + r, e := admiral.NewRolloutsController("test", make(chan struct{}), &test.MockRolloutHandler{}, &config, time.Second*time.Duration(300)) + v, e := istio.NewVirtualServiceController("", make(chan struct{}), &test.MockVirtualServiceHandler{}, &config, time.Second*time.Duration(300)) if e != nil { t.Fail() } - s, e := admiral.NewServiceController(make(chan struct{}), &test.MockServiceHandler{}, &config, time.Second*time.Duration(300)) + s, e := admiral.NewServiceController("test", make(chan struct{}), &test.MockServiceHandler{}, &config, time.Second*time.Duration(300)) - gtpc, e := admiral.NewGlobalTrafficController(make(chan struct{}), &test.MockGlobalTrafficHandler{}, &config, time.Second*time.Duration(300)) + gtpc, e := admiral.NewGlobalTrafficController("", make(chan struct{}), &test.MockGlobalTrafficHandler{}, &config, time.Second*time.Duration(300)) cacheWithEntry := ServiceEntryAddressStore{ EntryAddresses: map[string]string{"test.test.mesh-se": common.LocalAddressPrefix + ".10.1"}, @@ -913,7 +913,7 @@ func TestCreateServiceEntryForNewServiceOrPodRolloutsUsecase(t *testing.T) { RolloutController: r, ServiceController: s, VirtualServiceController: v, - GlobalTraffic: gtpc, + GlobalTraffic: gtpc, } rc.ClusterID = "test.cluster" rr.RemoteControllers["test.cluster"] = rc @@ -1012,16 +1012,16 @@ func TestCreateServiceEntryForBlueGreenRolloutsUsecase(t *testing.T) { Host: "localhost", } - d, e := admiral.NewDeploymentController(make(chan struct{}), &test.MockDeploymentHandler{}, &config, time.Second*time.Duration(300)) + d, e := admiral.NewDeploymentController("", make(chan struct{}), &test.MockDeploymentHandler{}, &config, time.Second*time.Duration(300)) - r, e := admiral.NewRolloutsController(make(chan struct{}), &test.MockRolloutHandler{}, &config, time.Second*time.Duration(300)) - v, e := istio.NewVirtualServiceController(make(chan struct{}), &test.MockVirtualServiceHandler{}, &config, time.Second*time.Duration(300)) + r, e := admiral.NewRolloutsController("test", make(chan struct{}), &test.MockRolloutHandler{}, &config, time.Second*time.Duration(300)) + v, e := istio.NewVirtualServiceController("", make(chan struct{}), &test.MockVirtualServiceHandler{}, &config, time.Second*time.Duration(300)) if e != nil { t.Fail() } - s, e := admiral.NewServiceController(make(chan struct{}), &test.MockServiceHandler{}, &config, time.Second*time.Duration(300)) - gtpc, e := admiral.NewGlobalTrafficController(make(chan struct{}), &test.MockGlobalTrafficHandler{}, &config, time.Second*time.Duration(300)) + s, e := admiral.NewServiceController("test", make(chan struct{}), &test.MockServiceHandler{}, &config, time.Second*time.Duration(300)) + gtpc, e := admiral.NewGlobalTrafficController("", make(chan struct{}), &test.MockGlobalTrafficHandler{}, &config, time.Second*time.Duration(300)) cacheWithEntry := ServiceEntryAddressStore{ EntryAddresses: map[string]string{ @@ -1048,7 +1048,7 @@ func TestCreateServiceEntryForBlueGreenRolloutsUsecase(t *testing.T) { RolloutController: r, ServiceController: s, VirtualServiceController: v, - GlobalTraffic: gtpc, + GlobalTraffic: gtpc, } rc.ClusterID = "test.cluster" rr.RemoteControllers["test.cluster"] = rc @@ -1345,17 +1345,16 @@ func TestUpdateGlobalGtpCache(t *testing.T) { env_stage = "stage" gtp = &v13.GlobalTrafficPolicy{ObjectMeta: v12.ObjectMeta{Name: "gtp", Namespace: "namespace1", CreationTimestamp: v12.NewTime(time.Now().Add(time.Duration(-30))), Labels: map[string]string{"identity": identity1, "env": env_stage}}, Spec: model.GlobalTrafficPolicy{ - Policy: []*model.TrafficPolicy {{DnsPrefix: "hello"}}, - },} + Policy: []*model.TrafficPolicy{{DnsPrefix: "hello"}}, + }} gtp2 = &v13.GlobalTrafficPolicy{ObjectMeta: v12.ObjectMeta{Name: "gtp2", Namespace: "namespace1", CreationTimestamp: v12.NewTime(time.Now().Add(time.Duration(-15))), Labels: map[string]string{"identity": identity1, "env": env_stage}}, Spec: model.GlobalTrafficPolicy{ - Policy: []*model.TrafficPolicy {{DnsPrefix: "hellogtp2"}}, - },} - - gtp3 = &v13.GlobalTrafficPolicy{ObjectMeta: v12.ObjectMeta{Name: "gtp3", Namespace: "namespace2", CreationTimestamp: v12.NewTime(time.Now()), Labels: map[string]string{"identity": identity1, "env": env_stage}}, Spec: model.GlobalTrafficPolicy{ - Policy: []*model.TrafficPolicy {{DnsPrefix: "hellogtp3"}}, - },} + Policy: []*model.TrafficPolicy{{DnsPrefix: "hellogtp2"}}, + }} + gtp3 = &v13.GlobalTrafficPolicy{ObjectMeta: v12.ObjectMeta{Name: "gtp3", Namespace: "namespace2", CreationTimestamp: v12.NewTime(time.Now()), Labels: map[string]string{"identity": identity1, "env": env_stage}}, Spec: model.GlobalTrafficPolicy{ + Policy: []*model.TrafficPolicy{{DnsPrefix: "hellogtp3"}}, + }} ) testCases := []struct { @@ -1364,33 +1363,33 @@ func TestUpdateGlobalGtpCache(t *testing.T) { env string gtps map[string][]*v13.GlobalTrafficPolicy expectedGtp *v13.GlobalTrafficPolicy - }{ { - name: "Should return nil when no GTP present", - gtps: map[string][]*v13.GlobalTrafficPolicy{}, - identity: identity1, - env: env_stage, - expectedGtp: nil, - }, + }{{ + name: "Should return nil when no GTP present", + gtps: map[string][]*v13.GlobalTrafficPolicy{}, + identity: identity1, + env: env_stage, + expectedGtp: nil, + }, { name: "Should return the only existing gtp", - gtps: map[string][]*v13.GlobalTrafficPolicy{"c1": {gtp}}, - identity: identity1, - env: env_stage, - expectedGtp: gtp, + gtps: map[string][]*v13.GlobalTrafficPolicy{"c1": {gtp}}, + identity: identity1, + env: env_stage, + expectedGtp: gtp, }, { name: "Should return the gtp recently created within the cluster", - gtps: map[string][]*v13.GlobalTrafficPolicy{"c1": {gtp, gtp2}}, - identity: identity1, - env: env_stage, - expectedGtp: gtp2, + gtps: map[string][]*v13.GlobalTrafficPolicy{"c1": {gtp, gtp2}}, + identity: identity1, + env: env_stage, + expectedGtp: gtp2, }, { name: "Should return the gtp recently created from another cluster", - gtps: map[string][]*v13.GlobalTrafficPolicy{"c1": {gtp, gtp2}, "c2": {gtp3}}, - identity: identity1, - env: env_stage, - expectedGtp: gtp3, + gtps: map[string][]*v13.GlobalTrafficPolicy{"c1": {gtp, gtp2}, "c2": {gtp3}}, + identity: identity1, + env: env_stage, + expectedGtp: gtp3, }, } diff --git a/admiral/pkg/controller/admiral/controller.go b/admiral/pkg/controller/admiral/controller.go index b97b3f30..56d2db3c 100644 --- a/admiral/pkg/controller/admiral/controller.go +++ b/admiral/pkg/controller/admiral/controller.go @@ -2,14 +2,15 @@ package admiral import ( "fmt" + "github.com/istio-ecosystem/admiral/admiral/pkg/controller/common" log "github.com/sirupsen/logrus" + "time" utilruntime "k8s.io/apimachinery/pkg/util/runtime" "k8s.io/apimachinery/pkg/util/wait" "k8s.io/client-go/tools/cache" "k8s.io/client-go/util/workqueue" - "time" ) const ( @@ -48,7 +49,7 @@ type Controller struct { func NewController(name string, stopCh <-chan struct{}, delegator Delegator, informer cache.SharedIndexInformer) Controller { controller := Controller{ - name: name, + name: name, informer: informer, delegator: delegator, queue: workqueue.NewRateLimitingQueue(workqueue.DefaultControllerRateLimiter()), @@ -145,3 +146,32 @@ func (c *Controller) processItem(informerCacheObj InformerCacheObj) error { } return nil } + +type MonitoredDelegator struct { + clusterID string + objectType string + d Delegator +} + +func NewMonitoredDelegator(d Delegator, clusterID string, objectType string) *MonitoredDelegator { + return &MonitoredDelegator{ + clusterID: clusterID, + objectType: objectType, + d: d, + } +} + +func (s *MonitoredDelegator) Added(obj interface{}) { + common.EventsProcessed.With(s.clusterID, s.objectType, common.AddEventLabelValue).Inc() + s.d.Added(obj) +} + +func (s *MonitoredDelegator) Updated(obj interface{}, oldObj interface{}) { + common.EventsProcessed.With(s.clusterID, s.objectType, common.UpdateEventLabelValue).Inc() + s.d.Updated(obj, oldObj) +} + +func (s *MonitoredDelegator) Deleted(obj interface{}) { + common.EventsProcessed.With(s.clusterID, s.objectType, common.DeleteEventLabelValue).Inc() + s.d.Deleted(obj) +} diff --git a/admiral/pkg/controller/admiral/dependency.go b/admiral/pkg/controller/admiral/dependency.go index 77bd3848..5949f9bb 100644 --- a/admiral/pkg/controller/admiral/dependency.go +++ b/admiral/pkg/controller/admiral/dependency.go @@ -84,7 +84,8 @@ func NewDependencyController(stopCh <-chan struct{}, handler DepHandler, configP cache.Indexers{}, ) - NewController("dependency-ctrl-" + namespace, stopCh, &depController, depController.informer) + mcd := NewMonitoredDelegator(&depController, "primary", "dependency") + NewController("dependency-ctrl-"+namespace, stopCh, mcd, depController.informer) return &depController, nil } diff --git a/admiral/pkg/controller/admiral/deployment.go b/admiral/pkg/controller/admiral/deployment.go index 6a2b77c1..e1b5ec7c 100644 --- a/admiral/pkg/controller/admiral/deployment.go +++ b/admiral/pkg/controller/admiral/deployment.go @@ -117,7 +117,7 @@ func (d *DeploymentController) GetDeployments() ([]*k8sAppsV1.Deployment, error) return res, nil } -func NewDeploymentController(stopCh <-chan struct{}, handler DeploymentHandler, config *rest.Config, resyncPeriod time.Duration) (*DeploymentController, error) { +func NewDeploymentController(clusterID string, stopCh <-chan struct{}, handler DeploymentHandler, config *rest.Config, resyncPeriod time.Duration) (*DeploymentController, error) { deploymentController := DeploymentController{} deploymentController.DeploymentHandler = handler @@ -142,14 +142,15 @@ func NewDeploymentController(stopCh <-chan struct{}, handler DeploymentHandler, cache.Indexers{}, ) - NewController("deployment-ctrl-" + config.Host, stopCh, &deploymentController, deploymentController.informer) + wc := NewMonitoredDelegator(&deploymentController, clusterID, "deployment") + NewController("deployment-ctrl-"+config.Host, stopCh, wc, deploymentController.informer) return &deploymentController, nil } func NewDeploymentControllerWithLabelOverride(stopCh <-chan struct{}, handler DeploymentHandler, config *rest.Config, resyncPeriod time.Duration, labelSet *common.LabelSet) (*DeploymentController, error) { - dc, err := NewDeploymentController(stopCh, handler, config, resyncPeriod) + dc, err := NewDeploymentController("", stopCh, handler, config, resyncPeriod) dc.labelSet = labelSet return dc, err } diff --git a/admiral/pkg/controller/admiral/deployment_test.go b/admiral/pkg/controller/admiral/deployment_test.go index d01039c9..2046dc07 100644 --- a/admiral/pkg/controller/admiral/deployment_test.go +++ b/admiral/pkg/controller/admiral/deployment_test.go @@ -144,19 +144,19 @@ func TestDeploymentController_Deleted(t *testing.T) { deployment.Spec.Template.Annotations = map[string]string{"sidecar.istio.io/inject": "true"} testCases := []struct { - name string - deployment *k8sAppsV1.Deployment - expectedDeployment *k8sAppsV1.Deployment + name string + deployment *k8sAppsV1.Deployment + expectedDeployment *k8sAppsV1.Deployment }{ { - name: "Expects deployment to be deleted from the cache when the correct label is present", - deployment: &deployment, - expectedDeployment: nil, + name: "Expects deployment to be deleted from the cache when the correct label is present", + deployment: &deployment, + expectedDeployment: nil, }, { - name: "Expects no error thrown if calling delete on an deployment not exist in cache", - deployment: &deployment, - expectedDeployment: nil, + name: "Expects no error thrown if calling delete on an deployment not exist in cache", + deployment: &deployment, + expectedDeployment: nil, }, } @@ -248,7 +248,7 @@ func TestNewDeploymentController(t *testing.T) { stop := make(chan struct{}) depHandler := test.MockDeploymentHandler{} - depCon, err := NewDeploymentController(stop, &depHandler, config, time.Duration(1000)) + depCon, err := NewDeploymentController("", stop, &depHandler, config, time.Duration(1000)) if depCon == nil { t.Errorf("Deployment controller should not be nil") diff --git a/admiral/pkg/controller/admiral/globaltraffic.go b/admiral/pkg/controller/admiral/globaltraffic.go index d7c88d0a..d2b626b1 100644 --- a/admiral/pkg/controller/admiral/globaltraffic.go +++ b/admiral/pkg/controller/admiral/globaltraffic.go @@ -25,7 +25,7 @@ type GlobalTrafficHandler interface { type GlobalTrafficController struct { CrdClient clientset.Interface GlobalTrafficHandler GlobalTrafficHandler - Cache *gtpCache + Cache *gtpCache informer cache.SharedIndexInformer } @@ -47,7 +47,7 @@ func (p *gtpCache) Put(obj *v1.GlobalTrafficPolicy) { if namespaceGtps == nil { namespaceGtps = make(map[string]*v1.GlobalTrafficPolicy) } - if common.ShouldIgnoreResource(obj.ObjectMeta){ + if common.ShouldIgnoreResource(obj.ObjectMeta) { delete(namespaceGtps, obj.Name) } else { namespaceGtps[obj.Name] = obj @@ -84,18 +84,18 @@ func (p *gtpCache) Get(key, namespace string) []*v1.GlobalTrafficPolicy { namespacesWithGtp := p.cache[key] matchedGtps := make([]*v1.GlobalTrafficPolicy, 0) for ns, gtps := range namespacesWithGtp { - if namespace == ns { - for _, gtp := range gtps { - logrus.Debugf("GTP match for identity=%s, from namespace=%v", key, ns) - //make a copy for safer iterations elsewhere - matchedGtps = append(matchedGtps, gtp.DeepCopy()) - } - } + if namespace == ns { + for _, gtp := range gtps { + logrus.Debugf("GTP match for identity=%s, from namespace=%v", key, ns) + //make a copy for safer iterations elsewhere + matchedGtps = append(matchedGtps, gtp.DeepCopy()) + } + } } return matchedGtps } -func NewGlobalTrafficController(stopCh <-chan struct{}, handler GlobalTrafficHandler, configPath *rest.Config, resyncPeriod time.Duration) (*GlobalTrafficController, error) { +func NewGlobalTrafficController(clusterID string, stopCh <-chan struct{}, handler GlobalTrafficHandler, configPath *rest.Config, resyncPeriod time.Duration) (*GlobalTrafficController, error) { globalTrafficController := GlobalTrafficController{} @@ -121,7 +121,8 @@ func NewGlobalTrafficController(stopCh <-chan struct{}, handler GlobalTrafficHan cache.Indexers{}, ) - NewController("gtp-ctrl-" + configPath.Host, stopCh, &globalTrafficController, globalTrafficController.informer) + mcd := NewMonitoredDelegator(&globalTrafficController, clusterID, "globaltrafficpolicy") + NewController("gtp-ctrl-"+configPath.Host, stopCh, mcd, globalTrafficController.informer) return &globalTrafficController, nil } @@ -142,4 +143,4 @@ func (d *GlobalTrafficController) Deleted(ojb interface{}) { gtp := ojb.(*v1.GlobalTrafficPolicy) d.Cache.Delete(gtp) d.GlobalTrafficHandler.Deleted(gtp) -} \ No newline at end of file +} diff --git a/admiral/pkg/controller/admiral/globaltraffic_test.go b/admiral/pkg/controller/admiral/globaltraffic_test.go index 5799ad82..a0da26a8 100644 --- a/admiral/pkg/controller/admiral/globaltraffic_test.go +++ b/admiral/pkg/controller/admiral/globaltraffic_test.go @@ -22,7 +22,7 @@ func TestNewGlobalTrafficController(t *testing.T) { stop := make(chan struct{}) handler := test.MockGlobalTrafficHandler{} - globalTrafficController, err := NewGlobalTrafficController(stop, &handler, config, time.Duration(1000)) + globalTrafficController, err := NewGlobalTrafficController("", stop, &handler, config, time.Duration(1000)) if err != nil { t.Errorf("Unexpected err %v", err) @@ -41,7 +41,7 @@ func TestGlobalTrafficAddUpdateDelete(t *testing.T) { stop := make(chan struct{}) handler := test.MockGlobalTrafficHandler{} - globalTrafficController, err := NewGlobalTrafficController(stop, &handler, config, time.Duration(1000)) + globalTrafficController, err := NewGlobalTrafficController("", stop, &handler, config, time.Duration(1000)) if err != nil { t.Errorf("Unexpected err %v", err) @@ -80,43 +80,41 @@ func TestGlobalTrafficAddUpdateDelete(t *testing.T) { func TestGlobalTrafficController_Updated(t *testing.T) { var ( - - gth = test.MockGlobalTrafficHandler{} + gth = test.MockGlobalTrafficHandler{} cache = gtpCache{ cache: make(map[string]map[string]map[string]*v1.GlobalTrafficPolicy), mutex: &sync.Mutex{}, } gtpController = GlobalTrafficController{ GlobalTrafficHandler: >h, - Cache: &cache, + Cache: &cache, } gtp = v1.GlobalTrafficPolicy{ObjectMeta: v12.ObjectMeta{Name: "gtp", Namespace: "namespace1", Labels: map[string]string{"identity": "id", "admiral.io/env": "stage"}}, Spec: model.GlobalTrafficPolicy{ - Policy: []*model.TrafficPolicy {{DnsPrefix: "hello"}}, - },} + Policy: []*model.TrafficPolicy{{DnsPrefix: "hello"}}, + }} gtpUpdated = v1.GlobalTrafficPolicy{ObjectMeta: v12.ObjectMeta{Name: "gtp", Namespace: "namespace1", Labels: map[string]string{"identity": "id", "admiral.io/env": "stage"}}, Spec: model.GlobalTrafficPolicy{ - Policy: []*model.TrafficPolicy {{DnsPrefix: "helloUpdated"}}, - },} + Policy: []*model.TrafficPolicy{{DnsPrefix: "helloUpdated"}}, + }} gtpUpdatedToIgnore = v1.GlobalTrafficPolicy{ObjectMeta: v12.ObjectMeta{Name: "gtp", Namespace: "namespace1", Labels: map[string]string{"identity": "id", "admiral.io/env": "stage"}, Annotations: map[string]string{"admiral.io/ignore": "true"}}} - ) //add the base object to cache gtpController.Added(>p) testCases := []struct { - name string - gtp *v1.GlobalTrafficPolicy - expectedGtps []*v1.GlobalTrafficPolicy + name string + gtp *v1.GlobalTrafficPolicy + expectedGtps []*v1.GlobalTrafficPolicy }{ { - name: "Gtp with should be updated", - gtp: >pUpdated, - expectedGtps: []*v1.GlobalTrafficPolicy{>pUpdated}, + name: "Gtp with should be updated", + gtp: >pUpdated, + expectedGtps: []*v1.GlobalTrafficPolicy{>pUpdated}, }, { - name: "Should remove gtp from cache when update with Ignore annotation", - gtp: >pUpdatedToIgnore, - expectedGtps: []*v1.GlobalTrafficPolicy{}, + name: "Should remove gtp from cache when update with Ignore annotation", + gtp: >pUpdatedToIgnore, + expectedGtps: []*v1.GlobalTrafficPolicy{}, }, } for _, c := range testCases { @@ -134,26 +132,26 @@ func TestGlobalTrafficController_Updated(t *testing.T) { func TestGlobalTrafficController_Deleted(t *testing.T) { var ( - gth = test.MockGlobalTrafficHandler{} + gth = test.MockGlobalTrafficHandler{} cache = gtpCache{ cache: make(map[string]map[string]map[string]*v1.GlobalTrafficPolicy), mutex: &sync.Mutex{}, } gtpController = GlobalTrafficController{ GlobalTrafficHandler: >h, - Cache: &cache, + Cache: &cache, } gtp = v1.GlobalTrafficPolicy{ObjectMeta: v12.ObjectMeta{Name: "gtp", Namespace: "namespace1", Labels: map[string]string{"identity": "id", "admiral.io/env": "stage"}}, Spec: model.GlobalTrafficPolicy{ - Policy: []*model.TrafficPolicy {{DnsPrefix: "hello"}}, - },} + Policy: []*model.TrafficPolicy{{DnsPrefix: "hello"}}, + }} gtp2 = v1.GlobalTrafficPolicy{ObjectMeta: v12.ObjectMeta{Name: "gtp2", Namespace: "namespace1", Labels: map[string]string{"identity": "id", "admiral.io/env": "stage"}}, Spec: model.GlobalTrafficPolicy{ - Policy: []*model.TrafficPolicy {{DnsPrefix: "hellogtp2"}}, - },} + Policy: []*model.TrafficPolicy{{DnsPrefix: "hellogtp2"}}, + }} gtp3 = v1.GlobalTrafficPolicy{ObjectMeta: v12.ObjectMeta{Name: "gtp3", Namespace: "namespace2", Labels: map[string]string{"identity": "id2", "admiral.io/env": "stage"}}, Spec: model.GlobalTrafficPolicy{ - Policy: []*model.TrafficPolicy {{DnsPrefix: "hellogtp3"}}, - },} + Policy: []*model.TrafficPolicy{{DnsPrefix: "hellogtp3"}}, + }} ) //add the base object to cache @@ -161,19 +159,19 @@ func TestGlobalTrafficController_Deleted(t *testing.T) { gtpController.Added(>p2) testCases := []struct { - name string - gtp *v1.GlobalTrafficPolicy - expectedGtps []*v1.GlobalTrafficPolicy + name string + gtp *v1.GlobalTrafficPolicy + expectedGtps []*v1.GlobalTrafficPolicy }{ { - name: "Should delete gtp", - gtp: >p, - expectedGtps: []*v1.GlobalTrafficPolicy{>p2}, + name: "Should delete gtp", + gtp: >p, + expectedGtps: []*v1.GlobalTrafficPolicy{>p2}, }, { - name: "Deleting non existing gtp should be a no-op", - gtp: >p3, - expectedGtps: []*v1.GlobalTrafficPolicy{}, + name: "Deleting non existing gtp should be a no-op", + gtp: >p3, + expectedGtps: []*v1.GlobalTrafficPolicy{}, }, } for _, c := range testCases { @@ -191,17 +189,16 @@ func TestGlobalTrafficController_Deleted(t *testing.T) { func TestGlobalTrafficController_Added(t *testing.T) { var ( - - gth = test.MockGlobalTrafficHandler{} + gth = test.MockGlobalTrafficHandler{} cache = gtpCache{ cache: make(map[string]map[string]map[string]*v1.GlobalTrafficPolicy), mutex: &sync.Mutex{}, } gtpController = GlobalTrafficController{ GlobalTrafficHandler: >h, - Cache: &cache, + Cache: &cache, } - gtp = v1.GlobalTrafficPolicy{ObjectMeta: v12.ObjectMeta{Name: "gtp", Namespace: "namespace1", Labels: map[string]string{"identity": "id", "admiral.io/env": "stage"}},} + gtp = v1.GlobalTrafficPolicy{ObjectMeta: v12.ObjectMeta{Name: "gtp", Namespace: "namespace1", Labels: map[string]string{"identity": "id", "admiral.io/env": "stage"}}} gtpWithIgnoreLabels = v1.GlobalTrafficPolicy{ObjectMeta: v12.ObjectMeta{Name: "gtpWithIgnoreLabels", Namespace: "namespace2", Labels: map[string]string{"identity": "id2", "admiral.io/env": "stage"}, Annotations: map[string]string{"admiral.io/ignore": "true"}}} gtp2 = v1.GlobalTrafficPolicy{ObjectMeta: v12.ObjectMeta{Name: "gtp2", Namespace: "namespace1", Labels: map[string]string{"identity": "id", "admiral.io/env": "stage"}}} @@ -210,29 +207,29 @@ func TestGlobalTrafficController_Added(t *testing.T) { ) testCases := []struct { - name string - gtp *v1.GlobalTrafficPolicy - expectedGtps []*v1.GlobalTrafficPolicy + name string + gtp *v1.GlobalTrafficPolicy + expectedGtps []*v1.GlobalTrafficPolicy }{ { - name: "Gtp should be added to the cache", - gtp: >p, - expectedGtps: []*v1.GlobalTrafficPolicy{>p}, + name: "Gtp should be added to the cache", + gtp: >p, + expectedGtps: []*v1.GlobalTrafficPolicy{>p}, }, { - name: "Gtp with ignore annotation should not be added to the cache", - gtp: >pWithIgnoreLabels, - expectedGtps: []*v1.GlobalTrafficPolicy{}, + name: "Gtp with ignore annotation should not be added to the cache", + gtp: >pWithIgnoreLabels, + expectedGtps: []*v1.GlobalTrafficPolicy{}, }, { - name: "Should cache multiple gtps in a namespace", - gtp: >p2, - expectedGtps: []*v1.GlobalTrafficPolicy{>p, >p2}, + name: "Should cache multiple gtps in a namespace", + gtp: >p2, + expectedGtps: []*v1.GlobalTrafficPolicy{>p, >p2}, }, { - name: "Should cache gtps in from multiple namespaces", - gtp: >p3, - expectedGtps: []*v1.GlobalTrafficPolicy{>p3}, + name: "Should cache gtps in from multiple namespaces", + gtp: >p3, + expectedGtps: []*v1.GlobalTrafficPolicy{>p3}, }, } for _, c := range testCases { diff --git a/admiral/pkg/controller/admiral/node.go b/admiral/pkg/controller/admiral/node.go index 317c2a79..81479785 100644 --- a/admiral/pkg/controller/admiral/node.go +++ b/admiral/pkg/controller/admiral/node.go @@ -26,7 +26,7 @@ type Locality struct { Region string } -func NewNodeController(stopCh <-chan struct{}, handler NodeHandler, config *rest.Config) (*NodeController, error) { +func NewNodeController(clusterID string, stopCh <-chan struct{}, handler NodeHandler, config *rest.Config) (*NodeController, error) { nodeController := NodeController{} nodeController.NodeHandler = handler @@ -44,7 +44,8 @@ func NewNodeController(stopCh <-chan struct{}, handler NodeHandler, config *rest cache.Indexers{}, ) - NewController("node-ctrl-" + config.Host, stopCh, &nodeController, nodeController.informer) + mcd := NewMonitoredDelegator(&nodeController, clusterID, "node") + NewController("node-ctrl-"+config.Host, stopCh, mcd, nodeController.informer) return &nodeController, nil } diff --git a/admiral/pkg/controller/admiral/node_test.go b/admiral/pkg/controller/admiral/node_test.go index edc8fc2b..a1c9fa27 100644 --- a/admiral/pkg/controller/admiral/node_test.go +++ b/admiral/pkg/controller/admiral/node_test.go @@ -17,7 +17,7 @@ func TestNewNodeController(t *testing.T) { stop := make(chan struct{}) handler := test.MockNodeHandler{} - nodeController, err := NewNodeController(stop, &handler, config) + nodeController, err := NewNodeController("", stop, &handler, config) if err != nil { t.Errorf("Unexpected err %v", err) @@ -36,7 +36,7 @@ func TestNodeAddUpdateDelete(t *testing.T) { stop := make(chan struct{}) handler := test.MockNodeHandler{} - nodeController, err := NewNodeController(stop, &handler, config) + nodeController, err := NewNodeController("", stop, &handler, config) if err != nil { t.Errorf("Unexpected err %v", err) diff --git a/admiral/pkg/controller/admiral/rollouts.go b/admiral/pkg/controller/admiral/rollouts.go index c59ee71f..e2b0d69d 100644 --- a/admiral/pkg/controller/admiral/rollouts.go +++ b/admiral/pkg/controller/admiral/rollouts.go @@ -124,11 +124,10 @@ func (d *RolloutController) shouldIgnoreBasedOnLabelsForRollout(rollout *argo.Ro return false //labels are fine, we should not ignore } -func NewRolloutsController(stopCh <-chan struct{}, handler RolloutHandler, config *rest.Config, resyncPeriod time.Duration) (*RolloutController, error) { +func NewRolloutsController(clusterID string, stopCh <-chan struct{}, handler RolloutHandler, config *rest.Config, resyncPeriod time.Duration) (*RolloutController, error) { roController := RolloutController{} roController.RolloutHandler = handler - roController.labelSet = common.GetLabelSet() rolloutCache := rolloutCache{} rolloutCache.cache = make(map[string]*RolloutClusterEntry) @@ -157,16 +156,11 @@ func NewRolloutsController(stopCh <-chan struct{}, handler RolloutHandler, confi //Initialize informer roController.informer = argoRolloutsInformerFactory.Argoproj().V1alpha1().Rollouts().Informer() - NewController("rollouts-ctrl-" + config.Host , stopCh, &roController, roController.informer) + mcd := NewMonitoredDelegator(&roController, clusterID, "rollout") + NewController("rollouts-ctrl-"+config.Host, stopCh, mcd, roController.informer) return &roController, nil } -func NewRolloutsControllerWithLabelOverride(stopCh <-chan struct{}, handler RolloutHandler, config *rest.Config, resyncPeriod time.Duration, labelSet *common.LabelSet) (*RolloutController, error) { - rc, err := NewRolloutsController(stopCh, handler, config, resyncPeriod) - rc.labelSet = labelSet - return rc, err -} - func (roc *RolloutController) Added(ojb interface{}) { HandleAddUpdateRollout(ojb, roc) } diff --git a/admiral/pkg/controller/admiral/rollouts_test.go b/admiral/pkg/controller/admiral/rollouts_test.go index 022858e8..b0c8e14d 100644 --- a/admiral/pkg/controller/admiral/rollouts_test.go +++ b/admiral/pkg/controller/admiral/rollouts_test.go @@ -25,7 +25,7 @@ func TestNewRolloutController(t *testing.T) { stop := make(chan struct{}) rolHandler := test.MockRolloutHandler{} - depCon, err := NewRolloutsController(stop, &rolHandler, config, time.Duration(1000)) + depCon, err := NewRolloutsController("test", stop, &rolHandler, config, time.Duration(1000)) if depCon == nil { t.Errorf("Rollout controller should not be nil") @@ -155,19 +155,19 @@ func TestRolloutController_Deleted(t *testing.T) { rollout.Spec.Template.Annotations = map[string]string{"sidecar.istio.io/inject": "true"} testCases := []struct { - name string - rollout *argo.Rollout - expectedRollout *argo.Rollout + name string + rollout *argo.Rollout + expectedRollout *argo.Rollout }{ { - name: "Expects rollout to be deleted from the cache when the correct label is present", - rollout: &rollout, - expectedRollout: nil, + name: "Expects rollout to be deleted from the cache when the correct label is present", + rollout: &rollout, + expectedRollout: nil, }, { - name: "Expects no error thrown if calling delete on an rollout not exist in cache", - rollout: &rollout, - expectedRollout: nil, + name: "Expects no error thrown if calling delete on an rollout not exist in cache", + rollout: &rollout, + expectedRollout: nil, }, } diff --git a/admiral/pkg/controller/admiral/service.go b/admiral/pkg/controller/admiral/service.go index 2dc6a1e2..8d741e16 100644 --- a/admiral/pkg/controller/admiral/service.go +++ b/admiral/pkg/controller/admiral/service.go @@ -121,7 +121,7 @@ func (s *serviceCache) GetLoadBalancer(key string, namespace string) (string, in return lb, lbPort } -func NewServiceController(stopCh <-chan struct{}, handler ServiceHandler, config *rest.Config, resyncPeriod time.Duration) (*ServiceController, error) { +func NewServiceController(clusterID string, stopCh <-chan struct{}, handler ServiceHandler, config *rest.Config, resyncPeriod time.Duration) (*ServiceController, error) { serviceController := ServiceController{} serviceController.ServiceHandler = handler @@ -150,7 +150,8 @@ func NewServiceController(stopCh <-chan struct{}, handler ServiceHandler, config &k8sV1.Service{}, resyncPeriod, cache.Indexers{}, ) - NewController("service-ctrl-"+config.Host, stopCh, &serviceController, serviceController.informer) + mcd := NewMonitoredDelegator(&serviceController, clusterID, "service") + NewController("service-ctrl-"+config.Host, stopCh, mcd, serviceController.informer) return &serviceController, nil } diff --git a/admiral/pkg/controller/admiral/service_test.go b/admiral/pkg/controller/admiral/service_test.go index 01ee1f4c..b2b439b3 100644 --- a/admiral/pkg/controller/admiral/service_test.go +++ b/admiral/pkg/controller/admiral/service_test.go @@ -25,7 +25,7 @@ func TestNewServiceController(t *testing.T) { stop := make(chan struct{}) handler := test.MockServiceHandler{} - serviceController, err := NewServiceController(stop, &handler, config, time.Duration(1000)) + serviceController, err := NewServiceController("test", stop, &handler, config, time.Duration(1000)) if err != nil { t.Errorf("Unexpected err %v", err) diff --git a/admiral/pkg/controller/common/config.go b/admiral/pkg/controller/common/config.go index 94d22459..d3da3d44 100644 --- a/admiral/pkg/controller/common/config.go +++ b/admiral/pkg/controller/common/config.go @@ -17,6 +17,7 @@ func InitializeConfig(params AdmiralParams) { once.Do(func() { admiralParams = params initHappened = true + InitializeMetrics() }) if !initHappened { log.Warn("InitializeConfig was called but didn't take effect. It can only be called once, and thus has already been initialized. Please ensure you aren't re-initializing the config.") diff --git a/admiral/pkg/controller/common/metrics.go b/admiral/pkg/controller/common/metrics.go index 213ad99c..c022cfcf 100644 --- a/admiral/pkg/controller/common/metrics.go +++ b/admiral/pkg/controller/common/metrics.go @@ -1,31 +1,100 @@ package common -import "github.com/prometheus/client_golang/prometheus" +import ( + "github.com/prometheus/client_golang/prometheus" + "sync" +) -const ClustersMonitoredMetricName = "clusters_monitored" +const ( + ClustersMonitoredMetricName = "clusters_monitored" + EventsProcessedTotalMetricName = "events_processed_total" + + AddEventLabelValue = "add" + UpdateEventLabelValue = "update" + DeleteEventLabelValue = "delete" +) + +var ( + metricsOnce sync.Once + RemoteClustersMetric Gauge + EventsProcessed Counter +) type Gauge interface { + With(labelValues ...string) Gauge Set(value float64) } -func NewGaugeFrom(name string, help string) Gauge { +type Counter interface { + With(labelValues ...string) Counter + Inc() +} + +/* +InitializeMetrics depends on AdmiralParams for metrics enablement. +*/ +func InitializeMetrics() { + metricsOnce.Do(func() { + RemoteClustersMetric = NewGaugeFrom(ClustersMonitoredMetricName, "Gauge for the clusters monitored by Admiral", []string{}) + EventsProcessed = NewCounterFrom(EventsProcessedTotalMetricName, "Counter for the events processed by Admiral", []string{"cluster", "object_type", "event_type"}) + }) +} + +func NewGaugeFrom(name string, help string, labelNames []string) Gauge { if !GetMetricsEnabled() { - return &Noop{} + return &NoopGauge{} } opts := prometheus.GaugeOpts{Name: name, Help: help} - g := prometheus.NewGauge(opts) + g := prometheus.NewGaugeVec(opts, labelNames) prometheus.MustRegister(g) - return &PromGauge{g} + return &PromGauge{g, labelNames} } -type Noop struct{} +func NewCounterFrom(name string, help string, labelNames []string) Counter { + if !GetMetricsEnabled() { + return &NoopCounter{} + } + opts := prometheus.CounterOpts{Name: name, Help: help} + c := prometheus.NewCounterVec(opts, labelNames) + prometheus.MustRegister(c) + return &PromCounter{c, labelNames} +} + +type NoopGauge struct{} +type NoopCounter struct{} type PromGauge struct { - g prometheus.Gauge + g *prometheus.GaugeVec + lvs []string +} + +type PromCounter struct { + c *prometheus.CounterVec + lvs []string +} + +func (g *PromGauge) With(labelValues ...string) Gauge { + g.lvs = append([]string{}, labelValues...) + + return g } func (g *PromGauge) Set(value float64) { - g.g.Set(value) + g.g.WithLabelValues(g.lvs...).Set(value) +} + +func (c *PromCounter) With(labelValues ...string) Counter { + c.lvs = append([]string{}, labelValues...) + + return c } -func (g *Noop) Set(value float64) {} +func (c *PromCounter) Inc() { + c.c.WithLabelValues(c.lvs...).Inc() +} + +func (g *NoopGauge) Set(float64) {} +func (g *NoopGauge) With(...string) Gauge { return g } + +func (g *NoopCounter) Inc() {} +func (g *NoopCounter) With(...string) Counter { return g } diff --git a/admiral/pkg/controller/common/metrics_test.go b/admiral/pkg/controller/common/metrics_test.go index 081adc42..0f881246 100644 --- a/admiral/pkg/controller/common/metrics_test.go +++ b/admiral/pkg/controller/common/metrics_test.go @@ -2,38 +2,131 @@ package common import ( "github.com/prometheus/client_golang/prometheus" + "github.com/prometheus/client_golang/prometheus/promhttp" "github.com/stretchr/testify/assert" + "io/ioutil" + "net/http" + "net/http/httptest" + "regexp" + "strconv" "testing" ) func TestNewGaugeFrom(t *testing.T) { type args struct { - prom bool - Name string - Help string + prom bool + name string + help string + value int64 + labelNames []string + labelValues []string } tc := []struct { - name string - args args - want Gauge + name string + args args + wantMetric bool + wantValue int64 }{ { - "Should return a Prometheus gauge", - args{true, "gauge", ""}, - &PromGauge{prometheus.NewGauge(prometheus.GaugeOpts{Name: "gauge", Help: ""})}, + name: "Should return a Prometheus gauge", + args: args{true, "mygauge", "", 10, []string{"l1", "l2"}, []string{"v1", "v2"}}, + wantMetric: true, + wantValue: 10, }, { - "Should return a Noop gauge", - args{false, "gauge", ""}, - &Noop{}, + name: "Should return a Noop gauge", + args: args{false, "mygauge", "", 10, []string{}, []string{}}, + wantMetric: false, }, } for _, tt := range tc { t.Run(tt.name, func(t *testing.T) { SetEnablePrometheus(tt.args.prom) - actual := NewGaugeFrom(tt.args.Name, tt.args.Help) - assert.Equal(t, tt.want, actual, "want: %#v, got: %#v", tt.want, actual) + + // exercise metric + actual := NewGaugeFrom(tt.args.name, tt.args.help, tt.args.labelNames) + actual.With(tt.args.labelValues...).Set(float64(tt.args.value)) + + // query metrics endpoint + s := httptest.NewServer(promhttp.HandlerFor(prometheus.DefaultGatherer, promhttp.HandlerOpts{})) + defer s.Close() + + // parse response + resp, _ := http.Get(s.URL) + buf, _ := ioutil.ReadAll(resp.Body) + actualString := string(buf) + + // verify + if tt.wantMetric { + pattern := tt.args.name + `{l1="v1",l2="v2"} ([0-9]+)` + re := regexp.MustCompile(pattern) + matches := re.FindStringSubmatch(actualString) + f, _ := strconv.ParseInt(matches[1], 0, 64) + assert.Equal(t, tt.wantValue, f) + } + assert.Equal(t, 200, resp.StatusCode) + }) + } +} + +func TestNewCounterFrom(t *testing.T) { + type args struct { + prom bool + name string + help string + value int64 + labelNames []string + labelValues []string + } + tc := []struct { + name string + args args + wantMetric bool + wantValue int64 + }{ + { + name: "Should return a Noop counter", + args: args{false, "mycounter", "", 10, []string{}, []string{}}, + wantMetric: false, + }, + { + name: "Should return a Prometheus counter", + args: args{true, "mycounter", "", 1, []string{"l1", "l2"}, []string{"v1", "v2"}}, + wantMetric: true, + wantValue: 1, + }, + } + + for _, tt := range tc { + t.Run(tt.name, func(t *testing.T) { + SetEnablePrometheus(tt.args.prom) + + // exercise metric + actual := NewCounterFrom(tt.args.name, tt.args.help, tt.args.labelNames) + var i int64 + for i = 0; i < tt.args.value; i++ { + actual.With(tt.args.labelValues...).Inc() + } + + // query metrics endpoint + s := httptest.NewServer(promhttp.HandlerFor(prometheus.DefaultGatherer, promhttp.HandlerOpts{})) + defer s.Close() + + // parse response + resp, _ := http.Get(s.URL) + buf, _ := ioutil.ReadAll(resp.Body) + actualString := string(buf) + + // verify + if tt.wantMetric { + pattern := tt.args.name + `{l1="v1",l2="v2"} ([0-9]+)` + re := regexp.MustCompile(pattern) + s2 := re.FindStringSubmatch(actualString)[1] + f, _ := strconv.ParseInt(s2, 0, 64) + assert.Equal(t, tt.wantValue, f) + } + assert.Equal(t, 200, resp.StatusCode) }) } } diff --git a/admiral/pkg/controller/istio/destinationrule.go b/admiral/pkg/controller/istio/destinationrule.go index 0aa0b221..467f8e65 100644 --- a/admiral/pkg/controller/istio/destinationrule.go +++ b/admiral/pkg/controller/istio/destinationrule.go @@ -31,7 +31,7 @@ type DestinationRuleController struct { informer cache.SharedIndexInformer } -func NewDestinationRuleController(stopCh <-chan struct{}, handler DestinationRuleHandler, config *rest.Config, resyncPeriod time.Duration) (*DestinationRuleController, error) { +func NewDestinationRuleController(clusterID string, stopCh <-chan struct{}, handler DestinationRuleHandler, config *rest.Config, resyncPeriod time.Duration) (*DestinationRuleController, error) { drController := DestinationRuleController{} drController.DestinationRuleHandler = handler @@ -47,7 +47,8 @@ func NewDestinationRuleController(stopCh <-chan struct{}, handler DestinationRul drController.informer = informers.NewDestinationRuleInformer(ic, k8sV1.NamespaceAll, resyncPeriod, cache.Indexers{}) - admiral.NewController("destinationrule-ctrl-" + config.Host, stopCh, &drController, drController.informer) + mcd := admiral.NewMonitoredDelegator(&drController, clusterID, "destinationrule") + admiral.NewController("destinationrule-ctrl-"+config.Host, stopCh, mcd, drController.informer) return &drController, nil } diff --git a/admiral/pkg/controller/istio/destinationrule_test.go b/admiral/pkg/controller/istio/destinationrule_test.go index 8a79a41b..82e08c5e 100644 --- a/admiral/pkg/controller/istio/destinationrule_test.go +++ b/admiral/pkg/controller/istio/destinationrule_test.go @@ -19,7 +19,7 @@ func TestNewDestinationRuleController(t *testing.T) { stop := make(chan struct{}) handler := test.MockDestinationRuleHandler{} - destinationRuleController, err := NewDestinationRuleController(stop, &handler, config, time.Duration(1000)) + destinationRuleController, err := NewDestinationRuleController("", stop, &handler, config, time.Duration(1000)) if err != nil { t.Errorf("Unexpected err %v", err) diff --git a/admiral/pkg/controller/istio/serviceentry.go b/admiral/pkg/controller/istio/serviceentry.go index fd17dde0..7d98cf37 100644 --- a/admiral/pkg/controller/istio/serviceentry.go +++ b/admiral/pkg/controller/istio/serviceentry.go @@ -31,7 +31,7 @@ type ServiceEntryController struct { informer cache.SharedIndexInformer } -func NewServiceEntryController(stopCh <-chan struct{}, handler ServiceEntryHandler, config *rest.Config, resyncPeriod time.Duration) (*ServiceEntryController, error) { +func NewServiceEntryController(clusterID string, stopCh <-chan struct{}, handler ServiceEntryHandler, config *rest.Config, resyncPeriod time.Duration) (*ServiceEntryController, error) { seController := ServiceEntryController{} seController.ServiceEntryHandler = handler @@ -47,7 +47,8 @@ func NewServiceEntryController(stopCh <-chan struct{}, handler ServiceEntryHandl seController.informer = informers.NewServiceEntryInformer(ic, k8sV1.NamespaceAll, resyncPeriod, cache.Indexers{}) - admiral.NewController("serviceentry-ctrl-" + config.Host, stopCh, &seController, seController.informer) + mcd := admiral.NewMonitoredDelegator(&seController, clusterID, "serviceentry") + admiral.NewController("serviceentry-ctrl-"+config.Host, stopCh, mcd, seController.informer) return &seController, nil } @@ -65,5 +66,4 @@ func (sec *ServiceEntryController) Updated(ojb interface{}, oldObj interface{}) func (sec *ServiceEntryController) Deleted(ojb interface{}) { se := ojb.(*networking.ServiceEntry) sec.ServiceEntryHandler.Deleted(se) - } diff --git a/admiral/pkg/controller/istio/serviceentry_test.go b/admiral/pkg/controller/istio/serviceentry_test.go index f7567192..0b8c02e6 100644 --- a/admiral/pkg/controller/istio/serviceentry_test.go +++ b/admiral/pkg/controller/istio/serviceentry_test.go @@ -19,7 +19,7 @@ func TestNewServiceEntryController(t *testing.T) { stop := make(chan struct{}) handler := test.MockServiceEntryHandler{} - serviceEntryController, err := NewServiceEntryController(stop, &handler, config, time.Duration(1000)) + serviceEntryController, err := NewServiceEntryController("test", stop, &handler, config, time.Duration(1000)) if err != nil { t.Errorf("Unexpected err %v", err) diff --git a/admiral/pkg/controller/istio/sidecar.go b/admiral/pkg/controller/istio/sidecar.go index ee35997c..86068f04 100644 --- a/admiral/pkg/controller/istio/sidecar.go +++ b/admiral/pkg/controller/istio/sidecar.go @@ -31,7 +31,7 @@ type SidecarController struct { informer cache.SharedIndexInformer } -func NewSidecarController(stopCh <-chan struct{}, handler SidecarHandler, config *rest.Config, resyncPeriod time.Duration) (*SidecarController, error) { +func NewSidecarController(clusterID string, stopCh <-chan struct{}, handler SidecarHandler, config *rest.Config, resyncPeriod time.Duration) (*SidecarController, error) { sidecarController := SidecarController{} sidecarController.SidecarHandler = handler @@ -47,7 +47,8 @@ func NewSidecarController(stopCh <-chan struct{}, handler SidecarHandler, config sidecarController.informer = informers.NewSidecarInformer(ic, k8sV1.NamespaceAll, resyncPeriod, cache.Indexers{}) - admiral.NewController("sidecar-ctrl-" + config.Host, stopCh, &sidecarController, sidecarController.informer) + mcd := admiral.NewMonitoredDelegator(&sidecarController, clusterID, "sidecar") + admiral.NewController("sidecar-ctrl-"+config.Host, stopCh, mcd, sidecarController.informer) return &sidecarController, nil } diff --git a/admiral/pkg/controller/istio/sidecar_test.go b/admiral/pkg/controller/istio/sidecar_test.go index 40ae8eb7..09bb0509 100644 --- a/admiral/pkg/controller/istio/sidecar_test.go +++ b/admiral/pkg/controller/istio/sidecar_test.go @@ -19,7 +19,7 @@ func TestNewSidecarController(t *testing.T) { stop := make(chan struct{}) handler := test.MockSidecarHandler{} - sidecarController, err := NewSidecarController(stop, &handler, config, time.Duration(1000)) + sidecarController, err := NewSidecarController("", stop, &handler, config, time.Duration(1000)) if err != nil { t.Errorf("Unexpected err %v", err) diff --git a/admiral/pkg/controller/istio/virtualservice.go b/admiral/pkg/controller/istio/virtualservice.go index 1c8a8650..2e0fa2b8 100644 --- a/admiral/pkg/controller/istio/virtualservice.go +++ b/admiral/pkg/controller/istio/virtualservice.go @@ -26,7 +26,7 @@ type VirtualServiceController struct { informer cache.SharedIndexInformer } -func NewVirtualServiceController(stopCh <-chan struct{}, handler VirtualServiceHandler, config *rest.Config, resyncPeriod time.Duration) (*VirtualServiceController, error) { +func NewVirtualServiceController(clusterID string, stopCh <-chan struct{}, handler VirtualServiceHandler, config *rest.Config, resyncPeriod time.Duration) (*VirtualServiceController, error) { drController := VirtualServiceController{} drController.VirtualServiceHandler = handler @@ -42,7 +42,8 @@ func NewVirtualServiceController(stopCh <-chan struct{}, handler VirtualServiceH drController.informer = informers.NewVirtualServiceInformer(ic, k8sV1.NamespaceAll, resyncPeriod, cache.Indexers{}) - admiral.NewController("virtualservice-ctrl-" + config.Host, stopCh, &drController, drController.informer) + mcd := admiral.NewMonitoredDelegator(&drController, clusterID, "virtualservice") + admiral.NewController("virtualservice-ctrl-"+config.Host, stopCh, mcd, drController.informer) return &drController, nil } diff --git a/admiral/pkg/controller/istio/virtualservice_test.go b/admiral/pkg/controller/istio/virtualservice_test.go index 3352ba31..868e0af1 100644 --- a/admiral/pkg/controller/istio/virtualservice_test.go +++ b/admiral/pkg/controller/istio/virtualservice_test.go @@ -19,7 +19,7 @@ func TestNewVirtualServiceController(t *testing.T) { stop := make(chan struct{}) handler := test.MockVirtualServiceHandler{} - virtualServiceController, err := NewVirtualServiceController(stop, &handler, config, time.Duration(1000)) + virtualServiceController, err := NewVirtualServiceController("", stop, &handler, config, time.Duration(1000)) if err != nil { t.Errorf("Unexpected err %v", err) diff --git a/admiral/pkg/controller/secret/secretcontroller.go b/admiral/pkg/controller/secret/secretcontroller.go index a07a5f17..af97d794 100644 --- a/admiral/pkg/controller/secret/secretcontroller.go +++ b/admiral/pkg/controller/secret/secretcontroller.go @@ -45,8 +45,6 @@ const ( // DO NOT USE - TEST ONLY. var LoadKubeConfig = clientcmd.Load -var remoteClustersMetric common.Gauge - // addSecretCallback prototype for the add secret callback function. type addSecretCallback func(config *rest.Config, dataKey string, resyncPeriod time.Duration) error @@ -163,8 +161,6 @@ func NewController( } }, }) - - remoteClustersMetric = common.NewGaugeFrom(common.ClustersMonitoredMetricName, "Gauge for the clusters monitored by Admiral") return controller } @@ -337,7 +333,7 @@ func (c *Controller) addMemberCluster(secretName string, s *corev1.Secret) { } } - remoteClustersMetric.Set(float64(len(c.Cs.RemoteClusters))) + common.RemoteClustersMetric.Set(float64(len(c.Cs.RemoteClusters))) log.Infof("Number of remote clusters: %d", len(c.Cs.RemoteClusters)) } @@ -352,6 +348,6 @@ func (c *Controller) deleteMemberCluster(secretName string) { delete(c.Cs.RemoteClusters, clusterID) } } - remoteClustersMetric.Set(float64(len(c.Cs.RemoteClusters))) + common.RemoteClustersMetric.Set(float64(len(c.Cs.RemoteClusters))) log.Infof("Number of remote clusters: %d", len(c.Cs.RemoteClusters)) } diff --git a/install/sample/overlays/deployment/greeting.yaml b/install/sample/overlays/deployment/greeting.yaml index 2c8593d9..2a146fb1 100644 --- a/install/sample/overlays/deployment/greeting.yaml +++ b/install/sample/overlays/deployment/greeting.yaml @@ -22,6 +22,7 @@ spec: spec: containers: - image: nginx + imagePullPolicy: IfNotPresent name: greeting ports: - containerPort: 80 diff --git a/install/sample/overlays/grpc/grpc-server.yaml b/install/sample/overlays/grpc/grpc-server.yaml index 1a98fef1..cad92273 100644 --- a/install/sample/overlays/grpc/grpc-server.yaml +++ b/install/sample/overlays/grpc/grpc-server.yaml @@ -20,6 +20,7 @@ spec: containers: - name: grpc-server image: buoyantio/strest-grpc:latest + imagePullPolicy: IfNotPresent args: - "server" - "--address=:11111" diff --git a/install/sample/overlays/rollout-bluegreen/greeting.yaml b/install/sample/overlays/rollout-bluegreen/greeting.yaml index 4a340c2b..19622bd0 100644 --- a/install/sample/overlays/rollout-bluegreen/greeting.yaml +++ b/install/sample/overlays/rollout-bluegreen/greeting.yaml @@ -21,6 +21,7 @@ spec: spec: containers: - image: nginx + imagePullPolicy: IfNotPresent name: greeting ports: - containerPort: 80 diff --git a/install/sample/overlays/rollout-canary/greeting.yaml b/install/sample/overlays/rollout-canary/greeting.yaml index ab8987fb..cf9059fd 100644 --- a/install/sample/overlays/rollout-canary/greeting.yaml +++ b/install/sample/overlays/rollout-canary/greeting.yaml @@ -20,6 +20,7 @@ spec: spec: containers: - image: nginx + imagePullPolicy: IfNotPresent name: greeting ports: - containerPort: 80 From 8c62f683d010d8a7bf5bb1a0aa32a3a5461db592 Mon Sep 17 00:00:00 2001 From: Adil Fulara Date: Sun, 12 Jun 2022 12:42:28 -0700 Subject: [PATCH 2/3] add tests for monitored delegator Signed-off-by: Adil Fulara --- .../pkg/controller/admiral/controller_test.go | 54 +++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 admiral/pkg/controller/admiral/controller_test.go diff --git a/admiral/pkg/controller/admiral/controller_test.go b/admiral/pkg/controller/admiral/controller_test.go new file mode 100644 index 00000000..ff0e81ba --- /dev/null +++ b/admiral/pkg/controller/admiral/controller_test.go @@ -0,0 +1,54 @@ +package admiral + +import ( + "github.com/stretchr/testify/assert" + "testing" +) + +func TestMonitoredDelegator_Added(t *testing.T) { + td := &TestDelegator{} + d := NewMonitoredDelegator(td, "test", "test") + d.Added(nil) + + assert.True(t, td.AddedInvoked) + assert.False(t, td.DeleteInvoked) + assert.False(t, td.UpdatedInvoked) +} + +func TestMonitoredDelegator_Deleted(t *testing.T) { + td := &TestDelegator{} + d := NewMonitoredDelegator(td, "test", "test") + d.Deleted(nil) + + assert.False(t, td.AddedInvoked) + assert.True(t, td.DeleteInvoked) + assert.False(t, td.UpdatedInvoked) +} + +func TestMonitoredDelegator_Updated(t *testing.T) { + td := &TestDelegator{} + d := NewMonitoredDelegator(td, "test", "test") + d.Updated(nil, nil) + + assert.False(t, td.AddedInvoked) + assert.False(t, td.DeleteInvoked) + assert.True(t, td.UpdatedInvoked) +} + +type TestDelegator struct { + AddedInvoked bool + UpdatedInvoked bool + DeleteInvoked bool +} + +func (t *TestDelegator) Added(obj interface{}) { + t.AddedInvoked = true +} + +func (t *TestDelegator) Updated(obj interface{}, oldObj interface{}) { + t.UpdatedInvoked = true +} + +func (t *TestDelegator) Deleted(obj interface{}) { + t.DeleteInvoked = true +} From ecf2deaa69146e9617b91a26a99c625430fa6a92 Mon Sep 17 00:00:00 2001 From: Adil Fulara Date: Mon, 13 Jun 2022 11:30:57 -0700 Subject: [PATCH 3/3] Fix build error. Incorporate PR feedback Signed-off-by: Adil Fulara --- admiral/pkg/clusters/handler.go | 8 ++++---- admiral/pkg/controller/admiral/rollouts.go | 7 ++++--- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/admiral/pkg/clusters/handler.go b/admiral/pkg/clusters/handler.go index 0502203e..5dc67dda 100644 --- a/admiral/pkg/clusters/handler.go +++ b/admiral/pkg/clusters/handler.go @@ -327,13 +327,13 @@ func handleDestinationRuleEvent(obj *v1alpha3.DestinationRule, dh *DestinationRu if err != nil { log.Infof(LogFormat, "Delete", "DestinationRule", obj.Name, clusterId, "success") } else { - log.Error(LogFormat, err) + log.Errorf(LogErrFormat, "Delete", "DestinationRule", obj.Name, clusterId, err) } err = rc.ServiceEntryController.IstioClient.NetworkingV1alpha3().ServiceEntries(syncNamespace).Delete(seName, &v12.DeleteOptions{}) if err != nil { log.Infof(LogFormat, "Delete", "ServiceEntry", seName, clusterId, "success") } else { - log.Error(LogFormat, err) + log.Errorf(LogErrFormat, "Delete", "ServiceEntry", seName, clusterId, err) } for _, subset := range destinationRule.Subsets { sseName := seName + common.Dash + subset.Name @@ -341,14 +341,14 @@ func handleDestinationRuleEvent(obj *v1alpha3.DestinationRule, dh *DestinationRu if err != nil { log.Infof(LogFormat, "Delete", "ServiceEntry", sseName, clusterId, "success") } else { - log.Error(LogFormat, err) + log.Errorf(LogErrFormat, "Delete", "ServiceEntry", sseName, clusterId, err) } } err = rc.DestinationRuleController.IstioClient.NetworkingV1alpha3().DestinationRules(syncNamespace).Delete(localDrName, &v12.DeleteOptions{}) if err != nil { log.Infof(LogFormat, "Delete", "DestinationRule", localDrName, clusterId, "success") } else { - log.Error(LogFormat, err) + log.Errorf(LogErrFormat, "Delete", "DestinationRule", localDrName, clusterId, err) } } else { diff --git a/admiral/pkg/controller/admiral/rollouts.go b/admiral/pkg/controller/admiral/rollouts.go index e2b0d69d..52244fbb 100644 --- a/admiral/pkg/controller/admiral/rollouts.go +++ b/admiral/pkg/controller/admiral/rollouts.go @@ -2,6 +2,9 @@ package admiral import ( "fmt" + "sync" + "time" + argo "github.com/argoproj/argo-rollouts/pkg/apis/rollouts/v1alpha1" argoclientset "github.com/argoproj/argo-rollouts/pkg/client/clientset/versioned" argoprojv1alpha1 "github.com/argoproj/argo-rollouts/pkg/client/clientset/versioned/typed/rollouts/v1alpha1" @@ -13,8 +16,6 @@ import ( "k8s.io/client-go/kubernetes" "k8s.io/client-go/rest" "k8s.io/client-go/tools/cache" - "sync" - "time" ) // Handler interface contains the methods that are required @@ -157,7 +158,7 @@ func NewRolloutsController(clusterID string, stopCh <-chan struct{}, handler Rol roController.informer = argoRolloutsInformerFactory.Argoproj().V1alpha1().Rollouts().Informer() mcd := NewMonitoredDelegator(&roController, clusterID, "rollout") - NewController("rollouts-ctrl-"+config.Host, stopCh, mcd, roController.informer) + NewController("rollouts-ctrl-"+clusterID, stopCh, mcd, roController.informer) return &roController, nil }