Skip to content

Commit ae10732

Browse files
committed
Make monitoring interval configurable
Signed-off-by: Chetan Banavikalmutt <[email protected]>
1 parent 040dd12 commit ae10732

File tree

3 files changed

+18
-11
lines changed

3 files changed

+18
-11
lines changed

controller/cache/cache.go

+15-9
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,9 @@ const (
6969

7070
// EnvClusterCacheRetryUseBackoff is the env variable to control whether to use a backoff strategy with the retry during cluster cache sync
7171
EnvClusterCacheRetryUseBackoff = "ARGOCD_CLUSTER_CACHE_RETRY_USE_BACKOFF"
72+
73+
// EnvClusterConnectionMonitoringInterval is the env variable to configure the cluster status monitoring interval.
74+
EnvClusterConnectionMonitoringInterval = "ARGOCD_CLUSTER_STATUS_MONITORING_INTERVAL"
7275
)
7376

7477
// GitOps engine cluster cache tuning options
@@ -100,6 +103,9 @@ var (
100103

101104
// clusterCacheRetryUseBackoff specifies whether to use a backoff strategy on cluster cache sync, if retry is enabled
102105
clusterCacheRetryUseBackoff bool = false
106+
107+
// clusterStatusMonitoringInterval specifies the interval used by Argo CD to monitor the cluster connection status.
108+
clusterStatusMonitoringInterval = 10 * time.Second
103109
)
104110

105111
func init() {
@@ -111,6 +117,7 @@ func init() {
111117
clusterCacheListSemaphoreSize = env.ParseInt64FromEnv(EnvClusterCacheListSemaphore, clusterCacheListSemaphoreSize, 0, math.MaxInt64)
112118
clusterCacheAttemptLimit = int32(env.ParseNumFromEnv(EnvClusterCacheAttemptLimit, int(clusterCacheAttemptLimit), 1, math.MaxInt32))
113119
clusterCacheRetryUseBackoff = env.ParseBoolFromEnv(EnvClusterCacheRetryUseBackoff, false)
120+
clusterStatusMonitoringInterval = env.ParseDurationFromEnv(EnvClusterConnectionMonitoringInterval, clusterStatusMonitoringInterval, 0, math.MaxInt64)
114121
}
115122

116123
type LiveStateCache interface {
@@ -185,7 +192,6 @@ func NewLiveStateCache(
185192
settingsMgr: settingsMgr,
186193
metricsServer: metricsServer,
187194
clusterSharding: clusterSharding,
188-
clusterFilter: clusterFilter,
189195
resourceTracking: resourceTracking,
190196
}
191197
}
@@ -524,19 +530,19 @@ func (c *liveStateCache) getCluster(server string) (clustercache.ClusterCache, e
524530
clustercache.SetRetryOptions(clusterCacheAttemptLimit, clusterCacheRetryUseBackoff, isRetryableError),
525531
clustercache.SetRespectRBAC(respectRBAC),
526532
clustercache.SetClusterStatusRetryFunc(isTransientNetworkErr),
527-
clustercache.SetClusterConnectionInterval(10 * time.Second),
533+
clustercache.SetClusterConnectionInterval(clusterStatusMonitoringInterval),
528534
}
529535

530536
clusterCache = clustercache.NewClusterCache(clusterCacheConfig, clusterCacheOpts...)
531537

532-
// Make sure to check if the monitoring interval is disabled
533-
534-
ctx, cancel := context.WithCancel(context.Background())
535-
if c.clusterStatusCancel == nil {
536-
c.clusterStatusCancel = make(map[string]context.CancelFunc)
538+
if clusterStatusMonitoringInterval != 0 {
539+
ctx, cancel := context.WithCancel(context.Background())
540+
if c.clusterStatusCancel == nil {
541+
c.clusterStatusCancel = make(map[string]context.CancelFunc)
542+
}
543+
c.clusterStatusCancel[server] = cancel
544+
clusterCache.StartClusterConnectionStatusMonitoring(ctx)
537545
}
538-
c.clusterStatusCancel[server] = cancel
539-
clusterCache.StartClusterConnectionStatusMonitoring(ctx)
540546

541547
_ = clusterCache.OnResourceUpdated(func(newRes *clustercache.Resource, oldRes *clustercache.Resource, namespaceResources map[kube.ResourceKey]*clustercache.Resource) {
542548
toNotify := make(map[string]bool)

go.mod

+1
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,7 @@ require (
295295
)
296296

297297
replace (
298+
github.com/argoproj/gitops-engine => github.com/chetan-rns/gitops-engine v0.1.3-0.20240509130717-b3e1c67fec67
298299
// https://github.com/golang/go/issues/33546#issuecomment-519656923
299300
github.com/go-check/check => github.com/go-check/check v0.0.0-20180628173108-788fd7840127
300301

go.sum

+2-2
Original file line numberDiff line numberDiff line change
@@ -695,8 +695,6 @@ github.com/apache/thrift v0.12.0/go.mod h1:cp2SuWMxlEZw2r+iP2GNCdIi4C1qmUzdZFSVb
695695
github.com/apache/thrift v0.13.0/go.mod h1:cp2SuWMxlEZw2r+iP2GNCdIi4C1qmUzdZFSVb+bacwQ=
696696
github.com/apache/thrift v0.16.0/go.mod h1:PHK3hniurgQaNMZYaCLEqXKsYK8upmhPbmdP2FXSqgU=
697697
github.com/appscode/go v0.0.0-20191119085241-0887d8ec2ecc/go.mod h1:OawnOmAL4ZX3YaPdN+8HTNwBveT1jMsqP74moa9XUbE=
698-
github.com/argoproj/gitops-engine v0.7.1-0.20240514190100-8a3ce6d85caa h1:RcIYoAbkaGA7yzpY1YItaTLgKYABDfkITyQ4jUl3Y6c=
699-
github.com/argoproj/gitops-engine v0.7.1-0.20240514190100-8a3ce6d85caa/go.mod h1:Vet2xN0akQpggQJZGmThA8Lozpn26RLagZFmLXw/oSI=
700698
github.com/argoproj/notifications-engine v0.4.1-0.20240403133627-f48567108f01 h1:/V8+HM0VPPTrdjTwUrkIj5a+SjaU//tJwfIXJ1QAOvg=
701699
github.com/argoproj/notifications-engine v0.4.1-0.20240403133627-f48567108f01/go.mod h1:N0A4sEws2soZjEpY4hgZpQS8mRIEw6otzwfkgc3g9uQ=
702700
github.com/argoproj/pkg v0.13.7-0.20230626144333-d56162821bd1 h1:qsHwwOJ21K2Ao0xPju1sNuqphyMnMYkyB3ZLoLtxWpo=
@@ -788,6 +786,8 @@ github.com/chai2010/gettext-go v1.0.2 h1:1Lwwip6Q2QGsAdl/ZKPCwTe9fe0CjlUbqj5bFNS
788786
github.com/chai2010/gettext-go v1.0.2/go.mod h1:y+wnP2cHYaVj19NZhYKAwEMH2CI1gNHeQQ+5AjwawxA=
789787
github.com/chainguard-dev/git-urls v1.0.2 h1:pSpT7ifrpc5X55n4aTTm7FFUE+ZQHKiqpiwNkJrVcKQ=
790788
github.com/chainguard-dev/git-urls v1.0.2/go.mod h1:rbGgj10OS7UgZlbzdUQIQpT0k/D4+An04HJY7Ol+Y/o=
789+
github.com/chetan-rns/gitops-engine v0.1.3-0.20240509130717-b3e1c67fec67 h1:MTqQCeBINPIXxuhynmozQA6Y3Ijv59TemYmImd3UFy8=
790+
github.com/chetan-rns/gitops-engine v0.1.3-0.20240509130717-b3e1c67fec67/go.mod h1:Vet2xN0akQpggQJZGmThA8Lozpn26RLagZFmLXw/oSI=
791791
github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI=
792792
github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI=
793793
github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU=

0 commit comments

Comments
 (0)