From 7f5229450a382bda0032e038c52c53c88dca358c Mon Sep 17 00:00:00 2001 From: Chetan Banavikalmutt Date: Thu, 9 May 2024 17:24:57 +0530 Subject: [PATCH] Make monitoring interval configurable Signed-off-by: Chetan Banavikalmutt --- controller/cache/cache.go | 24 +++++++++++++++--------- go.mod | 2 +- go.sum | 8 ++++++-- 3 files changed, 22 insertions(+), 12 deletions(-) diff --git a/controller/cache/cache.go b/controller/cache/cache.go index d7fb86bf782d47..ef8bd237cdd581 100644 --- a/controller/cache/cache.go +++ b/controller/cache/cache.go @@ -67,6 +67,9 @@ const ( // EnvClusterCacheRetryUseBackoff is the env variable to control whether to use a backoff strategy with the retry during cluster cache sync EnvClusterCacheRetryUseBackoff = "ARGOCD_CLUSTER_CACHE_RETRY_USE_BACKOFF" + + // EnvClusterConnectionMonitoringInterval is the env variable to configure the cluster status monitoring interval. + EnvClusterConnectionMonitoringInterval = "ARGOCD_CLUSTER_STATUS_MONITORING_INTERVAL" ) // GitOps engine cluster cache tuning options @@ -98,6 +101,9 @@ var ( // clusterCacheRetryUseBackoff specifies whether to use a backoff strategy on cluster cache sync, if retry is enabled clusterCacheRetryUseBackoff bool = false + + // clusterStatusMonitoringInterval specifies the interval used by Argo CD to monitor the cluster connection status. + clusterStatusMonitoringInterval = 10 * time.Second ) func init() { @@ -109,6 +115,7 @@ func init() { clusterCacheListSemaphoreSize = env.ParseInt64FromEnv(EnvClusterCacheListSemaphore, clusterCacheListSemaphoreSize, 0, math.MaxInt64) clusterCacheAttemptLimit = int32(env.ParseNumFromEnv(EnvClusterCacheAttemptLimit, int(clusterCacheAttemptLimit), 1, math.MaxInt32)) clusterCacheRetryUseBackoff = env.ParseBoolFromEnv(EnvClusterCacheRetryUseBackoff, false) + clusterStatusMonitoringInterval = env.ParseDurationFromEnv(EnvClusterConnectionMonitoringInterval, clusterStatusMonitoringInterval, 0, math.MaxInt64) } type LiveStateCache interface { @@ -183,7 +190,6 @@ func NewLiveStateCache( settingsMgr: settingsMgr, metricsServer: metricsServer, clusterSharding: clusterSharding, - clusterFilter: clusterFilter, resourceTracking: resourceTracking, } } @@ -517,19 +523,19 @@ func (c *liveStateCache) getCluster(server string) (clustercache.ClusterCache, e clustercache.SetRetryOptions(clusterCacheAttemptLimit, clusterCacheRetryUseBackoff, isRetryableError), clustercache.SetRespectRBAC(respectRBAC), clustercache.SetClusterStatusRetryFunc(isTransientNetworkErr), - clustercache.SetClusterConnectionInterval(10 * time.Second), + clustercache.SetClusterConnectionInterval(clusterStatusMonitoringInterval), } clusterCache = clustercache.NewClusterCache(clusterCacheConfig, clusterCacheOpts...) - // Make sure to check if the monitoring interval is disabled - - ctx, cancel := context.WithCancel(context.Background()) - if c.clusterStatusCancel == nil { - c.clusterStatusCancel = make(map[string]context.CancelFunc) + if clusterStatusMonitoringInterval != 0 { + ctx, cancel := context.WithCancel(context.Background()) + if c.clusterStatusCancel == nil { + c.clusterStatusCancel = make(map[string]context.CancelFunc) + } + c.clusterStatusCancel[server] = cancel + clusterCache.StartClusterConnectionStatusMonitoring(ctx) } - c.clusterStatusCancel[server] = cancel - clusterCache.StartClusterConnectionStatusMonitoring(ctx) _ = clusterCache.OnResourceUpdated(func(newRes *clustercache.Resource, oldRes *clustercache.Resource, namespaceResources map[kube.ResourceKey]*clustercache.Resource) { toNotify := make(map[string]bool) diff --git a/go.mod b/go.mod index bfbc2d01e4ead8..63c97b0a15a430 100644 --- a/go.mod +++ b/go.mod @@ -295,7 +295,7 @@ require ( ) replace ( - github.com/argoproj/gitops-engine => ../gitops-engine + github.com/argoproj/gitops-engine => github.com/chetan-rns/gitops-engine v0.1.3-0.20240404103429-cea6dcc9ec66 // https://github.com/golang/go/issues/33546#issuecomment-519656923 github.com/go-check/check => github.com/go-check/check v0.0.0-20180628173108-788fd7840127 diff --git a/go.sum b/go.sum index b3a3358db6ffbf..02c5775adb7eb2 100644 --- a/go.sum +++ b/go.sum @@ -695,8 +695,8 @@ github.com/apache/thrift v0.12.0/go.mod h1:cp2SuWMxlEZw2r+iP2GNCdIi4C1qmUzdZFSVb github.com/apache/thrift v0.13.0/go.mod h1:cp2SuWMxlEZw2r+iP2GNCdIi4C1qmUzdZFSVb+bacwQ= github.com/apache/thrift v0.16.0/go.mod h1:PHK3hniurgQaNMZYaCLEqXKsYK8upmhPbmdP2FXSqgU= github.com/appscode/go v0.0.0-20191119085241-0887d8ec2ecc/go.mod h1:OawnOmAL4ZX3YaPdN+8HTNwBveT1jMsqP74moa9XUbE= -github.com/argoproj/notifications-engine v0.4.1-0.20230905144632-9dcecdc3eebf h1:4wliaBwd6iKvT/5huDTJntaYtTSdwPLs00SOQwDSK6A= -github.com/argoproj/notifications-engine v0.4.1-0.20230905144632-9dcecdc3eebf/go.mod h1:TuK0BNKo34DIUOyCCGOB9ij+smGCxeCgt9ZB+0fMWno= +github.com/argoproj/notifications-engine v0.4.1-0.20240403133627-f48567108f01 h1:/V8+HM0VPPTrdjTwUrkIj5a+SjaU//tJwfIXJ1QAOvg= +github.com/argoproj/notifications-engine v0.4.1-0.20240403133627-f48567108f01/go.mod h1:N0A4sEws2soZjEpY4hgZpQS8mRIEw6otzwfkgc3g9uQ= github.com/argoproj/pkg v0.13.7-0.20230626144333-d56162821bd1 h1:qsHwwOJ21K2Ao0xPju1sNuqphyMnMYkyB3ZLoLtxWpo= github.com/argoproj/pkg v0.13.7-0.20230626144333-d56162821bd1/go.mod h1:CZHlkyAD1/+FbEn6cB2DQTj48IoLGvEYsWEvtzP3238= github.com/armon/circbuf v0.0.0-20150827004946-bbbad097214e/go.mod h1:3U/XgcO3hCbHZ8TKRvWD2dDTCfh9M9ya+I9JpbB7O8o= @@ -786,6 +786,8 @@ github.com/chai2010/gettext-go v1.0.2 h1:1Lwwip6Q2QGsAdl/ZKPCwTe9fe0CjlUbqj5bFNS github.com/chai2010/gettext-go v1.0.2/go.mod h1:y+wnP2cHYaVj19NZhYKAwEMH2CI1gNHeQQ+5AjwawxA= github.com/chainguard-dev/git-urls v1.0.2 h1:pSpT7ifrpc5X55n4aTTm7FFUE+ZQHKiqpiwNkJrVcKQ= github.com/chainguard-dev/git-urls v1.0.2/go.mod h1:rbGgj10OS7UgZlbzdUQIQpT0k/D4+An04HJY7Ol+Y/o= +github.com/chetan-rns/gitops-engine v0.1.3-0.20240404103429-cea6dcc9ec66 h1:BOFozSr3QU9BpcC91A9bNLo2CQjpig0Yf65cg8dyO6w= +github.com/chetan-rns/gitops-engine v0.1.3-0.20240404103429-cea6dcc9ec66/go.mod h1:gWE8uROi7hIkWGNAVM+8FWkMfo0vZ03SLx/aFw/DBzg= github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI= github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI= github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU= @@ -1101,6 +1103,8 @@ github.com/google/btree v1.0.1/go.mod h1:xXMiIv4Fb/0kKde4SpL7qlzvu5cMJDRkFDxJfI9 github.com/google/btree v1.1.2 h1:xf4v41cLI2Z6FxbKm+8Bu+m8ifhj15JuZ9sa0jZCMUU= github.com/google/btree v1.1.2/go.mod h1:qOPhT0dTNdNzV6Z/lhRX0YXUafgPLFUh+gZMl761Gm4= github.com/google/flatbuffers v2.0.8+incompatible/go.mod h1:1AeVuKshWv4vARoZatz6mlQ0JxURH0Kv5+zNeJKJCa8= +github.com/google/gnostic v0.6.9 h1:ZK/5VhkoX835RikCHpSUJV9a+S3e1zLh59YnyWeBW+0= +github.com/google/gnostic v0.6.9/go.mod h1:Nm8234We1lq6iB9OmlgNv3nH91XLLVZHCDayfA3xq+E= github.com/google/gnostic-models v0.6.8 h1:yo/ABAfM5IMRsS1VnXjTBvUb61tFIHozhlYvRgGre9I= github.com/google/gnostic-models v0.6.8/go.mod h1:5n7qKqH0f5wFt+aWF8CW6pZLLNOfYuF5OpfBSENuI8U= github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=