Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
languagejava
titleClient Quota Callback
/**
 * Quota callback interface for brokers that enables customization of client quota computation.
 */
public interface ClientQuotaCallback extends Configurable {

    /**
     * Quota callback invoked to determine the quota limitmetric tags to be applied for a request.
     *
 Quota limits are associated *with @paramquota principalmetrics Theand user principal of the connection forall clients which quotause isthe requestedsame
     * metric @paramtags clientIdshare the Thequota clientlimit.
 id associated with the request*
     * @param quotaType Type of quota requested
     * @return@param theprincipal quotaThe includinguser principal of the limit and connection for which quota is requested
     * @param clientId  The client id associated with the request
     * @return quota metric tags that indicate which other clients share this quota
     */
    Map<String, ClientQuotaString> quotaquotaMetricTags(KafkaPrincipalClientQuotaType principalquotaType, StringKafkaPrincipal clientIdprincipal, ClientQuotaTypeString quotaTypeclientId);

    /**
     * Returns the quota limit associated with the provided metric tags. These tags were returned from
     * a previous call to {@link #quota#quotaMetricTags(ClientQuotaType, KafkaPrincipal, String, ClientQuotaType)}. This method is invoked
     * invoked by quota managers to obtain the current quota limit applied to a metric afterwhen athe quotafirst update orrequest
     * using clusterthese tags metadatais changeprocessed. IfIt theis tagsalso areinvoked noafter longera inquota useupdate afteror thecluster update, metadata change.
     * If the tags are no longer in use after the update, (e.g. this is a
     * {user, client-id} quota metric
     * and the quota now in use is a {user} quota), null is returned.
     *
     * @param metricTagsquotaType Metric tagsType for aof quota metricrequested
 of type `quotaType`
  * @param metricTags Metric *tags @paramfor quotaTypea quota Typemetric of quotatype requested`quotaType`
     * @return the quota limit for the provided metric tags or null if the metric tags are no longer in use
     */
    Double quotaLimit(ClientQuotaType quotaType, Map<String, String> metricTags, ClientQuotaType quotaType);

    /**
     * Quota Metadataconfiguration update callback that is invoked wheneverwhen quota UpdateMetadataconfiguration requestfor isan receivedentity fromis
     * updated thein controllerZooKeeper. This is useful ifto quotatrack computationconfigured takesquotas partitions into account.if built-in quota configuration
     * Topics thattools are beingused deletedfor will not be included in `cluster`quota management.
     *
     * @param clusterquotaType Cluster metadata includingType partitionsof andquota their leaders if knownbeing updated
     * @return@param truequotaEntity ifThe quotasquota haveentity changedfor andwhich metric configs may need to be updatedquota is being updated
     * @param newValue    The new quota value
     */
    booleanvoid updateClusterMetadata(Cluster clusterupdateQuota(ClientQuotaType quotaType, ClientQuotaEntity quotaEntity, double newValue);

    /**
     * Quota configuration updateremoval callback that is invoked when quota configuration for an entity is
     * updatedremoved in ZooKeeper. This is useful to track configured quotas if built-in quota configuration
     * tools are used for quota management.
     *
     * @param quotaEntityquotaType The quota entityType for whichof quota is being updated
     * @param quotaTypequotaEntity The quota entity Typefor ofwhich quota is being updated
     */
    @paramvoid newValueremoveQuota(ClientQuotaType quotaType, ClientQuotaEntity quotaEntity);

 The new quota value/**
     * @returnReturns true if quotasany haveof changedthe andexisting metricquota configs may needhave to bebeen updated
 since the last  */call
    boolean updateQuota(ClientQuotaEntity quotaEntity, ClientQuotaType quotaType, double newValue);

    /**
     * Quota configuration removal callback that is invoked when quota configuration for an entity is* to this method for the provided quota type. Quota updates as a result of calls to
     * {@link #updateClusterMetadata(Cluster)}, {@link #updateQuota(ClientQuotaType, ClientQuotaEntity, double)}
     * removed in ZooKeeper. This is useful to track configured quotas if and {@link #removeQuota(ClientQuotaType, ClientQuotaEntity)} are automatically processed.
     * So callbacks that rely only on built-in quota configuration
 tools always return false. *Quota toolscallbacks
 are used for quota management.
     *
 with external quota configuration *or @paramcustom quotaEntity Thereconfigurable quota entityconfigs forthat whichaffect quota is being updated.limits must
     * return true @paramif quotaTypeexisting metric configs Typemay ofneed quotato beingbe updated.
 This method is invoked *on @returnevery truerequest
  if quotas have changed* and metrichence configsis may needexpected to be updated
handled by callbacks as a */
simple flag that is booleanupdated removeQuota(ClientQuotaEntity quotaEntity, ClientQuotaType quotaType);

when quotas change.
     /**
     * @param quotaType ClosesType thisof instance.quota
     */
    voidboolean closequotaResetRequired(ClientQuotaType quotaType);
}

 

The quota returned by the callback should include the quota limit as well the metric tags to be used. These tags determine which entities share the quota.

By default the tags "user" and "client-id" will be used for all quota metrics. When <user, client-id> quota config is used, user tag is set to user principal of the session and client-id tag is set to the client-id of the request. If <user> quota config is used, user tag is set to user principal of the session and client-id tag is set to empty string. Similarly, if <client-id> quota config is used, the user tag is set to empty string. This ensures that the same quota sensors and metrics are shared by all requests that match each quota config.

Code Block
languagejava
titleClientQuota
/**
 * Client quota returned by {@link ClientQuotaCallback} that includes the quota bound
 * as well as the metric tags that indicate which other clients share this quota.
 */
public class ClientQuota {
    private final double quotaLimit;
    private final Map<String, String> metricTags;

    /**
     * Constructs an instance of ClientQuota.
     *
     * @param quotaLimit The quota bound to be applied
     * @param metricTags The tags to be added to the quota metric for this request. All
     *                   entities which have the same `metricTags` share the `quotaLimit`
     */
    public ClientQuota(double quotaLimit, Map<String, String> metricTags) {
        this.quotaLimit = quotaLimit;
        this.metricTags = metricTags;
    }

    /**
     * Returns the quota bound.
     */
    public double quotaLimit() {
        return quotaLimit;
    }

    /**
     * Returns the tags to be added to the quota metric for this request. All
     * entities which have the same `metricTags` share a quota.
     */
    public Map<String, String> metricTags() {
        return metricTags;
    }
}


    /**
     * Metadata update callback that is invoked whenever UpdateMetadata request is received from
     * the controller. This is useful if quota computation takes partitions into account.
     * Topics that are being deleted will not be included in `cluster`.
     *
     * @param cluster Cluster metadata including partitions and their leaders if known
     * @return true if quotas have changed and metric configs may need to be updated
     */
    boolean updateClusterMetadata(Cluster cluster);

    /**
     * Closes this instance.
     */
    void close();
}

 

The callback is invoked to obtain the quota limit as well the metric tags to be used. These metric tags determine which entities share the quota.

By default the tags "user" and "client-id" will be used for all quota metrics. When <user, client-id> quota config is used, user tag is set to user principal of the session and client-id tag is set to the client-id of the request. If <user> quota config is used, user tag is set to user principal of the session and client-id tag is set to empty string. Similarly, if <client-id> quota config is used, the user tag is set to empty string. This ensures that the same quota sensors and metrics are shared by all requests that match each quota config. 

When quota configuration is updated in ZooKeeper, quota callbacks are notified of configuration changes. Quota configuration entities can be combined to define quotas at different levels.

...