forked from apache/kafka
-
Notifications
You must be signed in to change notification settings - Fork 12
Broker support for QuotaRecord and DescribeClientQuotas #477
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
Merged
Colin Patrick McCabe (cmccabe)
merged 16 commits into
kip-500
from
kip-500-quota-processor-2
Jan 29, 2021
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
8ef5a1a
Broker support for QuotaRecord and DescribeClientQuotas
mumrah 2a1e7d9
Restructure the cache logic a bit
mumrah 1bdb82a
Small bit of cleanup
mumrah e3fa08f
PR feedback
mumrah 13bb515
Add some comments, cleanup a few things
mumrah fc9cc3d
Merge remote-tracking branch 'confluentinc/kip-500' into kip-500-quot…
mumrah 8ad11d4
Fix imports
mumrah b81b4c0
Merge remote-tracking branch 'confluentinc/kip-500' into kip-500-quot…
mumrah 25f96ae
Add an end to end integration test for client quotas
mumrah a07cceb
Add more cases to the integration test
mumrah 4503dc4
PR feedback
mumrah b441431
Merge remote-tracking branch 'confluentinc/kip-500' into kip-500-quot…
mumrah 81c46f3
Indent fix
mumrah 3efd9b9
Remove unused arg
mumrah d0390b0
Rename some things
mumrah 0f3f8f3
Merge remote-tracking branch 'confluentinc/kip-500' into kip-500-quot…
mumrah File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -87,9 +87,10 @@ import scala.collection.mutable.ArrayBuffer | |
| import scala.collection.{Map, Seq, Set, immutable, mutable} | ||
| import scala.util.{Failure, Success, Try} | ||
| import kafka.coordinator.group.GroupOverview | ||
| import kafka.server.metadata.ConfigRepository | ||
| import kafka.server.metadata.{ConfigRepository, ClientQuotaCache} | ||
| import org.apache.kafka.clients.ClientResponse | ||
| import org.apache.kafka.common.message.DescribeConfigsRequestData.DescribeConfigsResource | ||
| import org.apache.kafka.common.quota.ClientQuotaEntity | ||
| import org.apache.kafka.common.requests.DescribeConfigsResponse.ConfigSource | ||
|
|
||
| import scala.annotation.nowarn | ||
|
|
@@ -118,7 +119,8 @@ class KafkaApis(val requestChannel: RequestChannel, | |
| val tokenManager: DelegationTokenManager, | ||
| val brokerFeatures: BrokerFeatures, | ||
| val finalizedFeatureCache: FinalizedFeatureCache, | ||
| val configRepository: ConfigRepository) extends ApiRequestHandler with Logging { | ||
| val configRepository: ConfigRepository, | ||
| val quotaCache: Option[ClientQuotaCache]) extends ApiRequestHandler with Logging { | ||
|
|
||
| type FetchResponseStats = Map[TopicPartition, RecordConversionStats] | ||
| this.logIdent = "[KafkaApi-%d] ".format(brokerId) | ||
|
|
@@ -247,7 +249,7 @@ class KafkaApis(val requestChannel: RequestChannel, | |
| case ApiKeys.ALTER_PARTITION_REASSIGNMENTS => maybeForward(request, handleAlterPartitionReassignmentsRequest) | ||
| case ApiKeys.LIST_PARTITION_REASSIGNMENTS => handleListPartitionReassignmentsRequest(request) | ||
| case ApiKeys.OFFSET_DELETE => handleOffsetDeleteRequest(request) | ||
| case ApiKeys.DESCRIBE_CLIENT_QUOTAS => maybeForward(request, handleDescribeClientQuotasRequest) | ||
| case ApiKeys.DESCRIBE_CLIENT_QUOTAS => handleDescribeClientQuotasRequest(request) | ||
| case ApiKeys.ALTER_CLIENT_QUOTAS => maybeForward(request, handleAlterClientQuotasRequest) | ||
| case ApiKeys.DESCRIBE_USER_SCRAM_CREDENTIALS => handleDescribeUserScramCredentialsRequest(request) | ||
| case ApiKeys.ALTER_USER_SCRAM_CREDENTIALS => maybeForward(request, handleAlterUserScramCredentialsRequest) | ||
|
|
@@ -3201,7 +3203,10 @@ class KafkaApis(val requestChannel: RequestChannel, | |
| def handleDescribeClientQuotasRequest(request: RequestChannel.Request): Unit = { | ||
| val describeClientQuotasRequest = request.body[DescribeClientQuotasRequest] | ||
|
|
||
| if (adminManager != null && authHelper.authorize(request.context, DESCRIBE_CONFIGS, CLUSTER, CLUSTER_NAME)) { | ||
| if (!authHelper.authorize(request.context, DESCRIBE_CONFIGS, CLUSTER, CLUSTER_NAME)) { | ||
| requestHelper.sendResponseMaybeThrottle(request, requestThrottleMs => | ||
| describeClientQuotasRequest.getErrorResponse(requestThrottleMs, Errors.CLUSTER_AUTHORIZATION_FAILED.exception)) | ||
| } else if (adminManager != null) { | ||
| val result = adminManager.describeClientQuotas(describeClientQuotasRequest.filter) | ||
|
|
||
| val entriesData = result.iterator.map { case (quotaEntity, quotaValues) => | ||
|
|
@@ -3226,9 +3231,23 @@ class KafkaApis(val requestChannel: RequestChannel, | |
| new DescribeClientQuotasResponse(new DescribeClientQuotasResponseData() | ||
| .setThrottleTimeMs(requestThrottleMs) | ||
| .setEntries(entriesData.asJava))) | ||
| } else if (quotaCache.isDefined) { | ||
| val result = quotaCache.get.describeClientQuotas( | ||
| describeClientQuotasRequest.filter().components().asScala.toSeq, | ||
| describeClientQuotasRequest.filter().strict()) | ||
| val resultAsJava = new util.HashMap[ClientQuotaEntity, util.Map[String, java.lang.Double]](result.size) | ||
| result.foreach { case (entity, quotas) => | ||
| resultAsJava.put(entity, quotas.map { case (key, quota) => key -> Double.box(quota)}.asJava) | ||
| } | ||
| requestHelper.sendResponseMaybeThrottle(request, requestThrottleMs => | ||
| DescribeClientQuotasResponse.fromQuotaEntities(resultAsJava, requestThrottleMs) | ||
| ) | ||
| } else { | ||
| requestHelper.sendResponseMaybeThrottle(request, requestThrottleMs => | ||
| describeClientQuotasRequest.getErrorResponse(requestThrottleMs, Errors.CLUSTER_AUTHORIZATION_FAILED.exception)) | ||
| warn("Neither LegacyAdminManager nor QuotaCache were defined") | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ERROR level since this should never happen? |
||
| requestHelper.sendResponseMaybeThrottle(request, requestThrottleMs => | ||
| describeClientQuotasRequest.getErrorResponse(requestThrottleMs, Errors.UNKNOWN_SERVER_ERROR.exception)) | ||
| } | ||
| } | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These conversions are annoying, but I don't know how to avoid them (unless we just use Java classes in the QuotaCache code)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not a hot path, so I personally don't see a real need to change the
QuotaCacheclass -- though others may differ.