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

Add kafka client pool #3493

Merged

Conversation

Cali0707
Copy link
Member

@Cali0707 Cali0707 commented Nov 29, 2023

Fixes #3397 , #3139

Proposed Changes

  • Create a client pool to use to get clients and cluster admins for the ekb control plane
  • Use an LRU eviction method to ensure that there are never more than a max number of connections being made

Release Note

Kafka control plane connections are now pooled, rather than recreated.

Docs

Signed-off-by: Calum Murray <cmurray@redhat.com>
Copy link

knative-prow bot commented Nov 29, 2023

Skipping CI for Draft Pull Request.
If you want CI signal for your change, please convert it to an actual PR.
You can still manually trigger a test run with /test all

@knative-prow knative-prow bot added do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. area/control-plane approved Indicates a PR has been approved by an approver from all required OWNERS files. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Nov 29, 2023
Copy link

codecov bot commented Nov 29, 2023

Codecov Report

Attention: Patch coverage is 45.91837% with 212 lines in your changes are missing coverage. Please review.

Project coverage is 48.41%. Comparing base (73c369e) to head (d317978).
Report is 37 commits behind head on main.

Files Patch % Lines
control-plane/pkg/kafka/clientpool/client.go 8.69% 124 Missing and 2 partials ⚠️
control-plane/pkg/kafka/clientpool/clientpool.go 50.00% 39 Missing and 6 partials ⚠️
...ontrol-plane/pkg/kafka/sarama/batch_get_offsets.go 0.00% 14 Missing ⚠️
control-plane/pkg/kafka/testing/client_mock.go 0.00% 11 Missing ⚠️
control-plane/pkg/kafka/testing/admin_mock.go 62.50% 2 Missing and 1 partial ⚠️
...ane/pkg/reconciler/broker/namespaced_controller.go 0.00% 3 Missing ⚠️
...lane/pkg/reconciler/consumergroup/consumergroup.go 57.14% 2 Missing and 1 partial ⚠️
control-plane/pkg/prober/async_prober.go 60.00% 2 Missing ⚠️
control-plane/pkg/reconciler/broker/broker.go 66.66% 2 Missing ⚠️
control-plane/cmd/kafka-controller/main.go 0.00% 1 Missing ⚠️
... and 2 more
Additional details and impacted files
@@              Coverage Diff              @@
##               main    #3493       +/-   ##
=============================================
- Coverage     62.18%   48.41%   -13.77%     
=============================================
  Files           188      243       +55     
  Lines         12690    18017     +5327     
  Branches        273        0      -273     
=============================================
+ Hits           7891     8723      +832     
- Misses         4187     8560     +4373     
- Partials        612      734      +122     
Flag Coverage Δ
java-unittests ?

Flags with carried forward coverage won't be shown. Click here to find out more.

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

Signed-off-by: Calum Murray <cmurray@redhat.com>
Signed-off-by: Calum Murray <cmurray@redhat.com>
… properly enforced

Signed-off-by: Calum Murray <cmurray@redhat.com>
Signed-off-by: Calum Murray <cmurray@redhat.com>
…es to use the clientpool

Signed-off-by: Calum Murray <cmurray@redhat.com>
@knative-prow knative-prow bot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Dec 1, 2023
Signed-off-by: Calum Murray <cmurray@redhat.com>
Signed-off-by: Calum Murray <cmurray@redhat.com>
Signed-off-by: Calum Murray <cmurray@redhat.com>
Signed-off-by: Calum Murray <cmurray@redhat.com>
@knative-prow knative-prow bot added size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. and removed size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Dec 5, 2023
Signed-off-by: Calum Murray <cmurray@redhat.com>
Signed-off-by: Calum Murray <cmurray@redhat.com>
Signed-off-by: Calum Murray <cmurray@redhat.com>
@Cali0707 Cali0707 marked this pull request as ready for review December 5, 2023 19:43
@knative-prow knative-prow bot requested a review from aliok December 5, 2023 19:43
@Cali0707
Copy link
Member Author

Cali0707 commented Dec 5, 2023

/hold
While I debug the tests

@knative-prow knative-prow bot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Dec 5, 2023
Signed-off-by: Calum Murray <cmurray@redhat.com>
Signed-off-by: Calum Murray <cmurray@redhat.com>
Signed-off-by: Calum Murray <cmurray@redhat.com>
Signed-off-by: Calum Murray <cmurray@redhat.com>
Signed-off-by: Calum Murray <cmurray@redhat.com>
Signed-off-by: Calum Murray <cmurray@redhat.com>
@Cali0707
Copy link
Member Author

/unhold
/cc @pierDipi @creydr @matzew

@knative-prow knative-prow bot requested a review from matzew January 31, 2024 20:15
@knative-prow knative-prow bot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Jan 31, 2024
@knative-prow-robot knative-prow-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jan 31, 2024
@knative-prow-robot knative-prow-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jan 31, 2024
@Cali0707
Copy link
Member Author

Cali0707 commented Feb 1, 2024

/retest-required

1 similar comment
@Cali0707
Copy link
Member Author

/retest-required

Signed-off-by: Calum Murray <cmurray@redhat.com>
@Cali0707
Copy link
Member Author

/cc @pierDipi

Signed-off-by: Calum Murray <cmurray@redhat.com>
Signed-off-by: Calum Murray <cmurray@redhat.com>
Signed-off-by: Calum Murray <cmurray@redhat.com>
Comment on lines 207 to 210
// guard against panic, this makes it easier to defer client.Close() on the caller side
if c == nil {
return nil
}
Copy link
Member

Choose a reason for hiding this comment

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

When does this case happen?

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh I've fixed this now, we can probably remove it. Basically, if you do something like:

client, err := r.GetKafkaClient(...)
defer client.Close()
if err != nil {
   ...
}

Here, if err is not nil, the deferred client.Close() method panics.

I fixed all the instances where this was happening, so I don't think we actually need this now

Comment on lines 63 to 64
// Keys returns all of the keys currently in the cache that have not expired
Keys() []K
Copy link
Member

Choose a reason for hiding this comment

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

This is unused, why do we need this method?

Copy link
Member Author

Choose a reason for hiding this comment

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

Good catch, this was from an earlier version of the PR. Let me remove it

Signed-off-by: Calum Murray <cmurray@redhat.com>
Copy link
Member

@pierDipi pierDipi left a comment

Choose a reason for hiding this comment

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

/lgtm
/approve

@knative-prow knative-prow bot added the lgtm Indicates that a PR is ready to be merged. label Feb 27, 2024
Copy link

knative-prow bot commented Feb 27, 2024

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: Cali0707, pierDipi

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@pierDipi
Copy link
Member

/retest-required

@Cali0707 Cali0707 linked an issue Feb 27, 2024 that may be closed by this pull request
@knative-prow knative-prow bot merged commit bd4ecfa into knative-extensions:main Feb 27, 2024
33 of 37 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. area/control-plane lgtm Indicates that a PR is ready to be merged. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Optimize Kafka cluster connections kafka-controller Kafka connections pooling
4 participants