Skip to content

Commit bb5de53

Browse files
authored
Adding config variables to leader_election provider (#3625)
* Adding config variables to leader election process * Adding Debug message info * Adding Changelog fragment
1 parent 3155ea9 commit bb5de53

3 files changed

Lines changed: 44 additions & 3 deletions

File tree

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Kind can be one of:
2+
# - breaking-change: a change to previously-documented behavior
3+
# - deprecation: functionality that is being removed in a later release
4+
# - bug-fix: fixes a problem in a previous version
5+
# - enhancement: extends functionality but does not break or fix existing behavior
6+
# - feature: new functionality
7+
# - known-issue: problems that we are aware of in a given version
8+
# - security: impacts on the security of a product or a user’s deployment.
9+
# - upgrade: important information for someone upgrading from a prior version
10+
# - other: does not fit into any of the other categories
11+
kind: enhancement
12+
13+
# Change summary; a 80ish characters long description of the change.
14+
summary: Added Kubernetes leader_election provider configuration parameters
15+
16+
# Long description; in case the summary is not enough to describe the change
17+
# this field accommodate a description without length limits.
18+
# NOTE: This field will be rendered only for breaking-change and known-issue kinds at the moment.
19+
#description:
20+
21+
# Affected component; usually one of "elastic-agent", "fleet-server", "filebeat", "metricbeat", "auditbeat", "all", etc.
22+
component: elastic-agent
23+
24+
# PR URL; optional; the PR number that added the changeset.
25+
# If not present is automatically filled by the tooling finding the PR where this changelog fragment has been added.
26+
# NOTE: the tooling supports backports, so it's able to fill the original PR number instead of the backport PR number.
27+
# Please provide it if you are adding a fragment for a different PR.
28+
#pr: https://github.com/owner/repo/1234
29+
30+
# Issue URL; optional; the GitHub issue related to this changeset (either closes or is part of).
31+
# If not present is automatically filled by the tooling with the issue linked to the PR number.
32+
#issue: https://github.com/owner/repo/1234

internal/pkg/composable/providers/kubernetesleaderelection/config.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,18 @@ type Config struct {
1313
// Name of the leaderelection lease
1414
LeaderLease string `config:"leader_lease"`
1515

16+
//Parameters to configure election process
17+
LeaseDuration int `config:"leader_leaseduration"`
18+
RenewDeadline int `config:"leader_renewdeadline"`
19+
RetryPeriod int `config:"leader_retryperiod"`
20+
1621
KubeClientOptions kubernetes.KubeClientOptions `config:"kube_client_options"`
1722
}
1823

1924
// InitDefaults initializes the default values for the config.
2025
func (c *Config) InitDefaults() {
2126
c.LeaderLease = "elastic-agent-cluster-leader"
27+
c.LeaseDuration = 15
28+
c.RenewDeadline = 10
29+
c.RetryPeriod = 2
2230
}

internal/pkg/composable/providers/kubernetesleaderelection/kubernetes_leaderelection.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,12 +83,13 @@ func (p *contextProvider) Run(ctx context.Context, comm corecomp.ContextProvider
8383
},
8484
},
8585
ReleaseOnCancel: true,
86-
LeaseDuration: 15 * time.Second,
87-
RenewDeadline: 10 * time.Second,
88-
RetryPeriod: 2 * time.Second,
86+
LeaseDuration: time.Duration(p.config.LeaseDuration) * time.Second,
87+
RenewDeadline: time.Duration(p.config.RenewDeadline) * time.Second,
88+
RetryPeriod: time.Duration(p.config.RetryPeriod) * time.Second,
8989
Callbacks: leaderelection.LeaderCallbacks{
9090
OnStartedLeading: func(ctx context.Context) {
9191
p.logger.Debugf("leader election lock GAINED, id %v", id)
92+
p.logger.Debugf("leader configuration timings: LeaseDuration: %v , RenewDeadline: %v, RetryPeriod: %v", p.leaderElection.LeaseDuration, p.leaderElection.RenewDeadline, p.leaderElection.RetryPeriod)
9293
p.startLeading(comm)
9394
},
9495
OnStoppedLeading: func() {

0 commit comments

Comments
 (0)