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

[extension/k8s leader elector] Initial implementation for the extension leader elector - basic structure #37266

Conversation

rakesh-garimella
Copy link
Contributor

@rakesh-garimella rakesh-garimella commented Jan 16, 2025

Description

This extension could be used to run multiple receivers in HA mode. The receiver which has successfully acquired the lease becomes active and thus becomes leader.

The extension uses k8s.io/client-go/tools/leaderelection to perform leader election. The component that owns the lease becomes the leader and runs the function defined in onStartedLeading. If the leader loses the lease, it runs the function defined in onStoppedLeading, stops its operation, and waits to acquire the lease again.

The config would like this:

receivers:
  my_awesome_reciever:
    leader_elector: k8s_leader_elector
exporters:
  debug:
    verbosity: detailed
extensions:
  k8s_leader_elector:
    auth_type: kubeConfig
    lease_name: foo
    lease_namespace: default

service:
  extensions: [k8s_leader_elector]
  pipelines:
    metrics:
      receivers: [my_awesome_receiver]
      exporters: [debug]
  telemetry:
    logs:
      level: debug

Link to tracking issue

Fixes
#34460

Testing

unit tests have been added

Documentation

README file has been added

@rakesh-garimella rakesh-garimella changed the title [extension/leader elector] Initial implementation for the extension leader elector - basic structure [extension/k8s leader elector] Initial implementation for the extension leader elector - basic structure Feb 4, 2025
@dmitryax dmitryax added the Skip Changelog PRs that do not require a CHANGELOG.md entry label Feb 7, 2025
return nil, errors.New("failed to create k8s client")
}

leaseHolderID, err := os.Hostname()
Copy link
Member

Choose a reason for hiding this comment

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

Can we always rely on this to be unique within the cluster? Probably not. I think this should be a configurable option with this value as a default.

@dmitryax dmitryax closed this Feb 11, 2025
@dmitryax dmitryax reopened this Feb 11, 2025
Copy link

codecov bot commented Feb 11, 2025

Codecov Report

Attention: Patch coverage is 53.84615% with 24 lines in your changes missing coverage. Please review.

Project coverage is 79.65%. Comparing base (499df64) to head (a654357).
Report is 23 commits behind head on main.

Files with missing lines Patch % Lines
extension/k8sleaderelector/factory.go 74.28% 6 Missing and 3 partials ⚠️
extension/k8sleaderelector/config.go 20.00% 7 Missing and 1 partial ⚠️
extension/k8sleaderelector/extension.go 0.00% 7 Missing ⚠️

❌ Your patch status has failed because the patch coverage (53.84%) is below the target coverage (95.00%). You can increase the patch coverage or adjust the target coverage.
❌ Your project status has failed because the head coverage (79.65%) is below the target coverage (85.00%). You can increase the head coverage or adjust the target coverage.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #37266      +/-   ##
==========================================
+ Coverage   79.60%   79.65%   +0.05%     
==========================================
  Files        2308     2315       +7     
  Lines      216392   217241     +849     
==========================================
+ Hits       172253   173051     +798     
- Misses      38381    38414      +33     
- Partials     5758     5776      +18     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@dmitryax dmitryax merged commit 6a40c64 into open-telemetry:main Feb 11, 2025
323 of 325 checks passed
@github-actions github-actions bot added this to the next release milestone Feb 11, 2025
dmitryax pushed a commit that referenced this pull request Feb 27, 2025
…on (#38015)

<!--Ex. Fixing a bug - Describe the bug and how this fixes the issue.
Ex. Adding a feature - Explain what this achieves.-->
#### Description
Added the actual implementation for leader election

Initial structure was added here: [basic
structure](#37266)

<!-- Issue number (e.g. #1234) or full URL to issue, if applicable. -->
#### Link to tracking issue
Fixes

#34460
<!--Describe what testing was performed and which tests were added.-->
#### Testing
unit tests added
<!--Describe the documentation added.-->
#### Documentation
documentation is provided
<!--Please delete paragraphs that you did not use before submitting.-->
dmitryax pushed a commit that referenced this pull request Mar 7, 2025
…elog (#38426)

<!--Ex. Fixing a bug - Describe the bug and how this fixes the issue.
Ex. Adding a feature - Explain what this achieves.-->
#### Description
- Change the stability level to alpha and allow print it in the change
log.
- Also adjust the documentation

PR for
[Implementation](#38015)
Pr for [Basic
structure](#37266)

<!-- Issue number (e.g. #1234) or full URL to issue, if applicable. -->
#### Link to tracking issue
Fixes

#34460
<!--Describe what testing was performed and which tests were added.-->
#### Testing

<!--Describe the documentation added.-->
#### Documentation
provided
<!--Please delete paragraphs that you did not use before submitting.-->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Accepted Component New component has been sponsored Skip Changelog PRs that do not require a CHANGELOG.md entry
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants