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

Adding config variables to leader_election provider #3625

Merged
merged 4 commits into from
Nov 13, 2023
Merged

Conversation

gizas
Copy link
Contributor

@gizas gizas commented Oct 18, 2023

  • Enhancement

What does this PR do?

WHAT: Adding config options for the kubernetes provider leader_election
WHY: We need to make the values configurable in order to adjust the number of API calls we need for the Leader Election process

Why is it important?

In big Kubernetes cluster, the number of API calls is proportional to number of agents that take part in the leader election. We have seen that this number of API calls towards kubernetes control API can be significant. With this effort we can offer to our users the ability to increase the period of leader election requests

Checklist

  • My code follows the style guidelines of this project
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • I have made corresponding change to the default configuration files
  • I have added tests that prove my fix is effective or that my feature works
  • I have added an entry in ./changelog/fragments using the changelog tool
  • I have added an integration test or an E2E test

How to test this PR locally

  1. Checkout this PR
  2. Build you custom agent image by following https://github.com/elastic/elastic-agent#testing-elastic-agent-on-kubernetes
  3. Sample standalone agent.yml config to provide:
providers.kubernetes_leaderelection:
      enabled: true
      leader_retryperiod: 15
      leader_leaseduration: 20
      leader_renewdeadline: 19

Related issues

Screenshot

With retry period every 15 sec
Screenshot 2023-10-31 at 5 20 19 PM

The kube-state-metrics processing every 10 sec works as expected:

Screenshot 2023-10-31 at 5 25 16 PM

Logs

kubectl logs -n kube-system elastic-agent-gj7zt | grep leader

I1101 14:29:15.495697      11 leaderelection.go:258] successfully acquired lease kube-system/agent-k8s-leader-lock2
{"log.level":"debug","@timestamp":"2023-11-01T14:29:15.495Z","log.logger":"composable","log.origin":{"file.name":"kubernetesleaderelection/kubernetes_leaderelection.go","file.line":91},"message":"leader election lock GAINED, id elastic-agent-leader-elastic-agent-gj7zt","log":{"source":"elastic-agent"},"ecs.version":"1.6.0"}
{"log.level":"debug","@timestamp":"2023-11-01T14:29:15.496Z","log.logger":"composable","log.origin":{"file.name":"kubernetesleaderelection/kubernetes_leaderelection.go","file.line":92},"message":"leader configuration timings: LeaseDuration: 20s , RenewDeadline: 19s, RetryPeriod: 15s","log":{"source":"elastic-agent"},"ecs.version":"1.6.0"}

@mergify mergify bot assigned gizas Oct 18, 2023
@mergify
Copy link
Contributor

mergify bot commented Oct 18, 2023

This pull request does not have a backport label. Could you fix it @gizas? 🙏
To fixup this pull request, you need to add the backport labels for the needed
branches, such as:

  • backport-v./d./d./d is the label to automatically backport to the 8./d branch. /d is the digit

NOTE: backport-skip has been added to this pull request.

@elasticmachine
Copy link
Contributor

elasticmachine commented Oct 18, 2023

💚 Build Succeeded

the below badges are clickable and redirect to their specific view in the CI or DOCS
Pipeline View Test View Changes Artifacts preview preview

Expand to view the summary

Build stats

  • Start Time: 2023-11-03T11:24:22.344+0000

  • Duration: 17 min 21 sec

❕ Flaky test report

No test was executed to be analysed.

🤖 GitHub comments

Expand to view the GitHub comments

To re-run your PR in the CI, just comment with:

  • /test : Re-trigger the build.

  • /package : Generate the packages.

  • run integration tests : Run the Elastic Agent Integration tests.

  • run end-to-end tests : Generate the packages and run the E2E Tests.

  • run elasticsearch-ci/docs : Re-trigger the docs validation. (use unformatted text in the comment!)

@elasticmachine
Copy link
Contributor

🌐 Coverage report

Name Metrics % (covered/total) Diff
Packages 98.81% (83/84) 👍
Files 67.105% (204/304) 👍
Classes 65.719% (370/563) 👍
Methods 53.043% (1168/2202) 👍
Lines 39.333% (13632/34658) 👎 -0.029
Conditionals 100.0% (0/0) 💚

@gizas
Copy link
Contributor Author

gizas commented Oct 30, 2023

Sample manifest used:

data:
  agent.yml: |-
   
    providers.kubernetes_leaderelection:
      enabled: true
      leader_lease: agent-k8s-leader-lock3
      leader_retryperiod: 15
      leader_leaseduration: 20
      leader_renewdeadline: 19

Verification:

kubectl describe leases -n kube-system agent-k8s-leader-lock3
Name:         agent-k8s-leader-lock3
Namespace:    kube-system
Labels:       <none>
Annotations:  <none>
API Version:  coordination.k8s.io/v1
Kind:         Lease
Metadata:
  Creation Timestamp:  2023-10-30T14:42:38Z
  Managed Fields:
    API Version:  coordination.k8s.io/v1
    Fields Type:  FieldsV1
    fieldsV1:
      f:spec:
        f:acquireTime:
        f:holderIdentity:
        f:leaseDurationSeconds:
        f:leaseTransitions:
        f:renewTime:
    Manager:         elastic-agent
    Operation:       Update
    Time:            2023-10-30T14:42:38Z
  Resource Version:  70559
  UID:               a024c0c4-8d90-4776-81a2-a37b1c768b7a
Spec:
  Acquire Time:            2023-10-30T14:42:38.346903Z
  Holder Identity:         elastic-agent-leader-elastic-agent-7nh9q
  Lease Duration Seconds:  20
  Lease Transitions:       0
  Renew Time:              2023-10-30T14:42:38.372912Z
Events:                    <none>

@gizas gizas marked this pull request as ready for review October 31, 2023 11:55
@gizas gizas requested a review from a team as a code owner October 31, 2023 11:55
@gizas gizas requested review from michalpristas, blakerouse, a team, MichaelKatsoulis, constanca-m and tetianakravchenko and removed request for a team October 31, 2023 11:55
@gizas gizas added the backport-v8.11.0 Automated backport with mergify label Oct 31, 2023
@mergify mergify bot removed the backport-skip label Oct 31, 2023
@gizas
Copy link
Contributor Author

gizas commented Nov 2, 2023

@elastic/elastic-agent-control-plane team can I have a review here please?

@gizas gizas added the backport-v8.10.0 Automated backport with mergify label Nov 2, 2023
Copy link
Contributor

@tetianakravchenko tetianakravchenko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gizas I think you need to add changelog record for this changes - https://github.com/elastic/elastic-agent#changelog?

@gizas
Copy link
Contributor Author

gizas commented Nov 3, 2023

@gizas I think you need to add changelog record for this changes - https://github.com/elastic/elastic-agent#changelog?

Thanks added one Tania (had the impression that we add it only for customer phasing issues, bugs or features. Does not harm to have it :))

Copy link

@gizas gizas merged commit bb5de53 into main Nov 13, 2023
13 checks passed
@gizas gizas deleted the leaderelection_config branch November 13, 2023 09:18
mergify bot pushed a commit that referenced this pull request Nov 13, 2023
* Adding config variables to leader election process

* Adding Debug message info

* Adding Changelog fragment

(cherry picked from commit bb5de53)
mergify bot pushed a commit that referenced this pull request Nov 13, 2023
* Adding config variables to leader election process

* Adding Debug message info

* Adding Changelog fragment

(cherry picked from commit bb5de53)
gizas added a commit that referenced this pull request Nov 13, 2023
* Adding config variables to leader election process

* Adding Debug message info

* Adding Changelog fragment

(cherry picked from commit bb5de53)

Co-authored-by: Andrew Gizas <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport-v8.10.0 Automated backport with mergify backport-v8.11.0 Automated backport with mergify
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants