Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reorder ServiceEntry writes. Add execution time and informer event logs. #202

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
d457913
Bootstrapping admiral
aattuluri Sep 19, 2019
7b9a2ff
Add circle ci config
aattuluri Sep 19, 2019
c9e80a5
Fix the working directory for builds
aattuluri Sep 19, 2019
76b9561
Bootstrapping admiral
aattuluri Sep 19, 2019
85aeeaa
Add circle ci config
aattuluri Sep 19, 2019
fe313cc
Fix the working directory for builds
aattuluri Sep 19, 2019
306ad93
Merge branch 'master' of https://github.com/aattuluri/admiral
aattuluri Sep 19, 2019
a9fa409
Add build status badge.
aattuluri Sep 19, 2019
4ae717d
Revert "Add build status badge."
aattuluri Sep 19, 2019
ff09cfb
Merge remote-tracking branch 'upstream/master'
aattuluri Sep 19, 2019
eb51849
Merge remote-tracking branch 'upstream/master'
aattuluri Sep 20, 2019
928c0d2
Merge remote-tracking branch 'upstream/master'
aattuluri Sep 20, 2019
2fb3364
Merge remote-tracking branch 'upstream/master'
aattuluri Sep 23, 2019
ea3ed61
Merge remote-tracking branch 'upstream/master'
aattuluri Sep 23, 2019
15e7845
Merge remote-tracking branch 'upstream/master'
aattuluri Sep 24, 2019
3b34036
Merge remote-tracking branch 'upstream/master'
aattuluri Sep 29, 2019
656bf71
Merge remote-tracking branch 'upstream/master'
aattuluri Sep 29, 2019
0245314
Merge remote-tracking branch 'upstream/master'
aattuluri Sep 29, 2019
111c3de
Merge remote-tracking branch 'upstream/master'
aattuluri Oct 4, 2019
e39651c
Merge remote-tracking branch 'upstream/master'
aattuluri Oct 4, 2019
b280c0b
Merge remote-tracking branch 'upstream/master'
aattuluri Oct 6, 2019
4b74679
Merge remote-tracking branch 'upstream/master'
aattuluri Oct 16, 2019
09b8a5b
Merge remote-tracking branch 'upstream/master'
aattuluri Oct 30, 2019
6546170
Merge remote-tracking branch 'upstream/master'
aattuluri Dec 27, 2019
1b0dfeb
Merge remote-tracking branch 'upstream/master'
aattuluri Jan 2, 2020
9b0010b
Merge remote-tracking branch 'upstream/master'
aattuluri Jan 9, 2020
7b68379
Merge remote-tracking branch 'upstream/master'
aattuluri Jan 21, 2020
5ae2f4c
Merge remote-tracking branch 'upstream/master'
aattuluri Jan 24, 2020
6e297db
Publish images: i) latest from master, ii) TAG if its set and iii) co…
aattuluri Jan 24, 2020
d6674b9
Merge remote-tracking branch 'upstream/master'
aattuluri Feb 19, 2020
e45ef03
Merge remote-tracking branch 'upstream/master'
aattuluri Feb 26, 2020
9096f16
Merge remote-tracking branch 'upstream/master'
aattuluri Feb 27, 2020
1e7a3d5
Merge remote-tracking branch 'upstream/master'
aattuluri Mar 8, 2020
a9e55b3
Merge remote-tracking branch 'upstream/master'
aattuluri Mar 20, 2020
c40a8be
Merge remote-tracking branch 'upstream/master'
aattuluri Mar 27, 2020
798b06a
Merge remote-tracking branch 'upstream/master'
aattuluri Apr 6, 2020
f028e1e
Merge remote-tracking branch 'upstream/master'
aattuluri Apr 16, 2020
0956d03
Merge remote-tracking branch 'upstream/master'
aattuluri Apr 27, 2020
cecd2ca
Merge remote-tracking branch 'upstream/master'
aattuluri May 13, 2020
b46682c
Merge remote-tracking branch 'upstream/master'
aattuluri May 14, 2020
2d3460c
Merge remote-tracking branch 'upstream/master'
aattuluri May 26, 2020
77c46e0
Merge remote-tracking branch 'upstream/master'
aattuluri Jun 15, 2020
82a4223
Merge remote-tracking branch 'upstream/master'
aattuluri Jul 24, 2020
065b6d4
Merge remote-tracking branch 'upstream/master'
aattuluri Aug 26, 2020
933650b
Merge remote-tracking branch 'upstream/master'
aattuluri Sep 20, 2020
d2e76cb
Merge remote-tracking branch 'upstream/master'
aattuluri Nov 2, 2020
63b4c60
Merge remote-tracking branch 'upstream/master'
aattuluri Nov 6, 2020
7b6626f
Merge remote-tracking branch 'upstream/master'
aattuluri Nov 12, 2020
0631dce
Merge remote-tracking branch 'upstream/master'
aattuluri Nov 13, 2020
51a27da
Merge remote-tracking branch 'upstream/master'
aattuluri Jan 21, 2021
8683c4e
Merge remote-tracking branch 'upstream/master'
aattuluri Apr 23, 2021
e05e909
Merge remote-tracking branch 'upstream/master'
aattuluri Jun 3, 2021
85a586e
Merge remote-tracking branch 'upstream/master'
aattuluri Jan 30, 2022
5a3d36f
Merge remote-tracking branch 'upstream/master'
aattuluri Feb 4, 2022
0f387e1
Merge remote-tracking branch 'upstream/master'
aattuluri Feb 10, 2022
cf0996e
Do not do destructive updates during bootup time
aattuluri Feb 10, 2022
accf659
Merge remote-tracking branch 'upstream/master'
aattuluri Mar 2, 2022
0ef1a24
Merge remote-tracking branch 'upstream/master'
aattuluri Mar 22, 2022
f85d4b0
Merge remote-tracking branch 'upstream/master'
aattuluri Apr 8, 2022
a9b8aee
Merge remote-tracking branch 'upstream/master'
aattuluri Apr 12, 2022
5f48dc6
Reorder ServiceEntry writes. Add execution time and informer event logs.
aattuluri Apr 12, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 31 additions & 11 deletions admiral/pkg/clusters/serviceentry.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ func createServiceEntry(event admiral.EventType, rc *RemoteController, admiralCa
}

func modifyServiceEntryForNewServiceOrPod(event admiral.EventType, env string, sourceIdentity string, remoteRegistry *RemoteRegistry) map[string]*networking.ServiceEntry {

defer util.LogElapsedTime("modifyServiceEntryForNewServiceOrPod", sourceIdentity, env, "")()

//create a service entry, destination rule and virtual service in the local cluster
sourceServices := make(map[string]*k8sV1.Service)
sourceDeployments := make(map[string]*k8sAppsV1.Deployment)
Expand All @@ -67,6 +70,7 @@ func modifyServiceEntryForNewServiceOrPod(event admiral.EventType, env string, s
var weightedServices map[string]*WeightedService
var rollout *admiral.RolloutClusterEntry

start := time.Now()
for _, rc := range remoteRegistry.RemoteControllers {

deployment := rc.DeploymentController.Cache.Get(sourceIdentity)
Expand Down Expand Up @@ -118,18 +122,15 @@ func modifyServiceEntryForNewServiceOrPod(event admiral.EventType, env string, s
sourceServices[rc.ClusterID] = serviceInstance
}

dependents := remoteRegistry.AdmiralCache.IdentityDependencyCache.Get(sourceIdentity).Copy()
util.LogElapsedTimeSince("BuildServiceEntry", sourceIdentity, env, "", start)

dependentClusters := getDependentClusters(dependents, remoteRegistry.AdmiralCache.IdentityClusterCache, sourceServices)
dependents := remoteRegistry.AdmiralCache.IdentityDependencyCache.Get(sourceIdentity).Copy()

//update cname dependent cluster cache
for clusterId := range dependentClusters {
remoteRegistry.AdmiralCache.CnameDependentClusterCache.Put(cname, clusterId, clusterId)
}
//handle local updates (source clusters first)
//update the address to local fqdn for service entry in a cluster local to the service instance

AddServiceEntriesWithDr(remoteRegistry.AdmiralCache, dependentClusters, remoteRegistry.RemoteControllers, serviceEntries)
start = time.Now()

//update the address to local fqdn for service entry in a cluster local to the service instance
for sourceCluster, serviceInstance := range sourceServices {
localFqdn := serviceInstance.Name + common.Sep + serviceInstance.Namespace + common.DotLocalDomainSuffix
rc := remoteRegistry.RemoteControllers[sourceCluster]
Expand Down Expand Up @@ -186,14 +187,33 @@ func modifyServiceEntryForNewServiceOrPod(event admiral.EventType, env string, s
}
}

if common.GetWorkloadSidecarUpdate() == "enabled" {
modifySidecarForLocalClusterCommunication(serviceInstance.Namespace, remoteRegistry.AdmiralCache.DependencyNamespaceCache.Get(sourceIdentity), rc)
}

for _, val := range dependents {
remoteRegistry.AdmiralCache.DependencyNamespaceCache.Put(val, serviceInstance.Namespace, localFqdn, cnames)
}

if common.GetWorkloadSidecarUpdate() == "enabled" {
modifySidecarForLocalClusterCommunication(serviceInstance.Namespace, remoteRegistry.AdmiralCache.DependencyNamespaceCache.Get(sourceIdentity), rc)
}
}

util.LogElapsedTimeSince("WriteServiceEntryToSourceClusters", sourceIdentity, env, "", start)

//Write to dependent clusters

start = time.Now()

dependentClusters := getDependentClusters(dependents, remoteRegistry.AdmiralCache.IdentityClusterCache, sourceServices)

//update cname dependent cluster cache
for clusterId := range dependentClusters {
remoteRegistry.AdmiralCache.CnameDependentClusterCache.Put(cname, clusterId, clusterId)
}

AddServiceEntriesWithDr(remoteRegistry.AdmiralCache, dependentClusters, remoteRegistry.RemoteControllers, serviceEntries)

util.LogElapsedTimeSince("WriteServiceEntryToDependentClusters", sourceIdentity, env, "", start)

return serviceEntries
}

Expand Down
19 changes: 10 additions & 9 deletions admiral/pkg/controller/admiral/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,40 +39,41 @@ type InformerCacheObj struct {
}

type Controller struct {
name string
delegator Delegator
queue workqueue.RateLimitingInterface
informer cache.SharedIndexInformer
}

func NewController(stopCh <-chan struct{}, delegator Delegator, informer cache.SharedIndexInformer) Controller {
func NewController(name string, stopCh <-chan struct{}, delegator Delegator, informer cache.SharedIndexInformer) Controller {

controller := Controller{
name: name,
informer: informer,
delegator: delegator,
queue: workqueue.NewRateLimitingQueue(workqueue.DefaultControllerRateLimiter()),
}

controller.informer.AddEventHandler(cache.ResourceEventHandlerFuncs{
AddFunc: func(obj interface{}) {
log.Debugf("Informer: add : %v", obj)
key, err := cache.MetaNamespaceKeyFunc(obj)

if err == nil {
log.Infof("Informer Add controller=%v obj=%v", controller.name, key)
controller.queue.Add(InformerCacheObj{key: key, eventType: Add, obj: obj})
}

},
UpdateFunc: func(oldObj, newObj interface{}) {
log.Debugf("Informer Update: %v", newObj)
key, err := cache.MetaNamespaceKeyFunc(newObj)
if err == nil {
log.Infof("Informer Update controller=%v obj=%v", controller.name, key)
controller.queue.Add(InformerCacheObj{key: key, eventType: Update, obj: newObj, oldObj: oldObj})
}
},
DeleteFunc: func(obj interface{}) {
log.Debugf("Informer Delete: %v", obj)
key, err := cache.DeletionHandlingMetaNamespaceKeyFunc(obj)
if err == nil {
log.Infof("Informer Delete controller=%v obj=%v", controller.name, key)
controller.queue.Add(InformerCacheObj{key: key, eventType: Delete, obj: obj})
}
},
Expand All @@ -88,18 +89,18 @@ func (c *Controller) Run(stopCh <-chan struct{}) {
defer utilruntime.HandleCrash()
defer c.queue.ShutDown()

log.Info("Starting controller")
log.Infof("Starting controller=%v", c.name)

go c.informer.Run(stopCh)

// Wait for the caches to be synced before starting workers
log.Info(" Waiting for informer caches to sync")
log.Infof(" Waiting for informer caches to sync for controller=%v", c.name)
if !cache.WaitForCacheSync(stopCh, c.informer.HasSynced) {
utilruntime.HandleError(fmt.Errorf(" timed out waiting for caches to sync"))
utilruntime.HandleError(fmt.Errorf(" timed out waiting for caches to sync for controller=%v", c.name))
return
}

log.Info("informer caches synced")
log.Infof("Informer caches synced for controller=%v, current keys=%v", c.name, c.informer.GetStore().ListKeys())
wait.Until(c.runWorker, 5*time.Second, stopCh)
}

Expand Down
2 changes: 1 addition & 1 deletion admiral/pkg/controller/admiral/dependency.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ func NewDependencyController(stopCh <-chan struct{}, handler DepHandler, configP
cache.Indexers{},
)

NewController(stopCh, &depController, depController.informer)
NewController("dependency-ctrl-" + namespace, stopCh, &depController, depController.informer)

return &depController, nil
}
Expand Down
2 changes: 1 addition & 1 deletion admiral/pkg/controller/admiral/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ func NewDeploymentController(stopCh <-chan struct{}, handler DeploymentHandler,
cache.Indexers{},
)

NewController(stopCh, &deploymentController, deploymentController.informer)
NewController("deployment-ctrl-" + config.Host, stopCh, &deploymentController, deploymentController.informer)

return &deploymentController, nil
}
Expand Down
2 changes: 1 addition & 1 deletion admiral/pkg/controller/admiral/globaltraffic.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func NewGlobalTrafficController(stopCh <-chan struct{}, handler GlobalTrafficHan
cache.Indexers{},
)

NewController(stopCh, &globalTrafficController, globalTrafficController.informer)
NewController("gtp-ctrl-" + configPath.Host, stopCh, &globalTrafficController, globalTrafficController.informer)

return &globalTrafficController, nil
}
Expand Down
2 changes: 1 addition & 1 deletion admiral/pkg/controller/admiral/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func NewNodeController(stopCh <-chan struct{}, handler NodeHandler, config *rest
cache.Indexers{},
)

NewController(stopCh, &nodeController, nodeController.informer)
NewController("node-ctrl-" + config.Host, stopCh, &nodeController, nodeController.informer)

return &nodeController, nil
}
Expand Down
2 changes: 1 addition & 1 deletion admiral/pkg/controller/admiral/rollouts.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ func NewRolloutsController(stopCh <-chan struct{}, handler RolloutHandler, confi
//Initialize informer
roController.informer = argoRolloutsInformerFactory.Argoproj().V1alpha1().Rollouts().Informer()

NewController(stopCh, &roController, roController.informer)
NewController("rollouts-ctrl-" + config.Host , stopCh, &roController, roController.informer)
return &roController, nil
}

Expand Down
2 changes: 1 addition & 1 deletion admiral/pkg/controller/admiral/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ func NewServiceController(stopCh <-chan struct{}, handler ServiceHandler, config
&k8sV1.Service{}, resyncPeriod, cache.Indexers{},
)

NewController(stopCh, &serviceController, serviceController.informer)
NewController("service-ctrl-" + config.Host , stopCh, &serviceController, serviceController.informer)

return &serviceController, nil
}
Expand Down
2 changes: 1 addition & 1 deletion admiral/pkg/controller/istio/destinationrule.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func NewDestinationRuleController(stopCh <-chan struct{}, handler DestinationRul

drController.informer = informers.NewDestinationRuleInformer(ic, k8sV1.NamespaceAll, resyncPeriod, cache.Indexers{})

admiral.NewController(stopCh, &drController, drController.informer)
admiral.NewController("destinationrule-ctrl-" + config.Host, stopCh, &drController, drController.informer)

return &drController, nil
}
Expand Down
2 changes: 1 addition & 1 deletion admiral/pkg/controller/istio/serviceentry.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func NewServiceEntryController(stopCh <-chan struct{}, handler ServiceEntryHandl

seController.informer = informers.NewServiceEntryInformer(ic, k8sV1.NamespaceAll, resyncPeriod, cache.Indexers{})

admiral.NewController(stopCh, &seController, seController.informer)
admiral.NewController("serviceentry-ctrl-" + config.Host, stopCh, &seController, seController.informer)

return &seController, nil
}
Expand Down
2 changes: 1 addition & 1 deletion admiral/pkg/controller/istio/sidecar.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func NewSidecarController(stopCh <-chan struct{}, handler SidecarHandler, config

sidecarController.informer = informers.NewSidecarInformer(ic, k8sV1.NamespaceAll, resyncPeriod, cache.Indexers{})

admiral.NewController(stopCh, &sidecarController, sidecarController.informer)
admiral.NewController("sidecar-ctrl-" + config.Host, stopCh, &sidecarController, sidecarController.informer)

return &sidecarController, nil
}
Expand Down
2 changes: 1 addition & 1 deletion admiral/pkg/controller/istio/virtualservice.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func NewVirtualServiceController(stopCh <-chan struct{}, handler VirtualServiceH

drController.informer = informers.NewVirtualServiceInformer(ic, k8sV1.NamespaceAll, resyncPeriod, cache.Indexers{})

admiral.NewController(stopCh, &drController, drController.informer)
admiral.NewController("virtualservice-ctrl-" + config.Host, stopCh, &drController, drController.informer)

return &drController, nil
}
Expand Down
6 changes: 3 additions & 3 deletions admiral/pkg/controller/secret/secretcontroller.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,21 +141,21 @@ func NewController(
secretsInformer.AddEventHandler(cache.ResourceEventHandlerFuncs{
AddFunc: func(obj interface{}) {
key, err := cache.MetaNamespaceKeyFunc(obj)
log.Infof("Processing add: %s", key)
log.Infof("Processing cluster add: %s", key)
if err == nil {
queue.Add(key)
}
},
UpdateFunc: func(oldObj interface{}, newObj interface{}) {
key, err := cache.MetaNamespaceKeyFunc(newObj)
log.Infof("Processing update: %s", key)
log.Infof("Processing cluster update: %s", key)
if err == nil {
queue.Add(key)
}
},
DeleteFunc: func(obj interface{}) {
key, err := cache.DeletionHandlingMetaNamespaceKeyFunc(obj)
log.Infof("Processing delete: %s", key)
log.Infof("Processing cluster delete: %s", key)
if err == nil {
queue.Add(key)
}
Expand Down
13 changes: 13 additions & 0 deletions admiral/pkg/controller/util/util.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package util

import (
log "github.com/sirupsen/logrus"
"reflect"
"time"
)

func MapCopy(dst, src interface{}) {
Expand Down Expand Up @@ -36,3 +38,14 @@ func Contains(vs []string, t string) bool {
}
return false
}

func LogElapsedTime(op, identity, env, clusterId string) func() {
start := time.Now()
return func() {
LogElapsedTimeSince(op, identity, env, clusterId, start)
}
}

func LogElapsedTimeSince(op, identity, env, clusterId string, start time.Time) {
log.Infof("op=%s identity=%s env=%s cluster=%s time=%v\n", op, identity, env, clusterId, time.Since(start).Milliseconds())
}