Send Docs Feedback

Reset Quota policy

  About | Samples | Element reference | Error codes | Schemas | Related topics

What

Use to dynamically modify the remaining number of requests allowed by the target Quota policy. You typically use this policy to decrease the current quota count of the target Quota policy rather than waiting for the quota count to reset. 

For example, the target Quota policy limits a developer to 1000 requests per week. By the second day of the week, the developer has already reached this limit. Use the Reset Quota policy to subtract 500 from their quota counter to allow an additional 500 requests for the remainder of the week. At the end of the week, the Quota policy resets, and the developer is back to 1000 requests for the week.

See Quota policy for more on the Quota policy.

Where

This policy can be attached in the following locations.

ProxyEndpoint TargetEndpoint
    PreFlow Flow PostFlow PreFlow Flow PostFlow    
Request    
    Response
    PostFlow Flow PreFlow PostFlow Flow PreFlow    

Samples

These policy code samples illustrate how to reset quota counters:

<ResetQuota name="resetQuota">
   <Quota name="MyQuotaPolicy">
      <Identifier name="_default">
         <Allow>100</Allow>
      </Identifier>
   </Quota>
</ResetQuota>

The Reset Quota policy specifies the target Quota policy by using the name attribute of the <Quota> tag. In the example above, the MyQuotaPolicy policy is the target.

All Reset Quota policies require the <Identifier> tag to specify the counter in the Quota policy to update. By default, a Quota policy has a single counter, unless the Quota policy also includes the <Identifier> tag. In this example, the target Quota policy does not use the <Identifier> tag, so you specify the name attribute as _default.

The <Allow> element specifies the value used to decrease the current quota count on the target policy. In this example, the quota count is decreased by 100, to allow 100 more requests to the target Quota policy. When the target Quota policy resets, this change is discarded.

Shown below is the definition of the target Quota policy:

<Quota name="MyQuotaPolicy">
  <Interval>5</Interval>
  <TimeUnit>hour</TimeUnit>
  <Allow count="100"/>
</Quota>
<ResetQuota name="resetQuota">
   <Quota ref="request.header.quotapolicy">
      <Identifier name="_default">
         <Allow ref="request.header.allowquota" />
      </Identifier>
   </Quota>
</ResetQuota>

In this example, you pass the name of the target Quota policy, and the change to its quota count, as headers in the request. You can then reference the flow variables containing these values in the Reset Quota policy.  

<ResetQuota name="resetQuota">
   <Quota name="QuotaPolicy">
      <Identifier ref="request.header.clientId">
         <Allow>100</Allow>
      </Identifier>
   </Quota>
</ResetQuota>

If the target Quota policy specifies the <Identifier> tag, then you can specify the same value to the <Identifier> tag of the Reset Quota policy to update a specific quota count. Notice how the <Identifier> tag in the target Quota policy below matches the value specified to the Reset Quota policy: 

<Quota name="QuotaPolicy">
  <Identifier ref="request.header.clientId"/> 
  <Interval>5</Interval>
  <TimeUnit>hour</TimeUnit>
  <Allow count="100"/>
</Quota>

Element reference

The element reference describes the elements and attributes of the Reset Quota policy.

<ResetQuota async="false" continueOnError="false" enabled="true" name="Reset-Quota-1">
   <DisplayName>Reset Quota 1</DisplayName>
   <Quota name="quotaName" ref="request.header.quotapolicy">
      <Identifier name="identifierName" ref="request.header.identifier">
         <Class ref="request.header.classIdentifier" />
         <Allow>100</Allow>
      </Identifier>
   </Quota>
</ResetQuota>

<ResetQuota> attributes

<ResetQuota async="false" continueOnError="false" enabled="true" name="Reset-Quota-1"> 

The following attributes are common to all policy parent elements.

Attribute Description Default Presence
name

The internal name of the policy. Characters you can use in the name are restricted to: A-Z0-9._\-$ %. However, the Edge management UI enforces additional restrictions, such as automatically removing characters that are not alphanumeric.

Optionally, use the <DisplayName> element to label the policy in the management UI proxy editor with a different, natural-language name.

N/A Required
continueOnError

Set to false to return an error when a policy fails. This is expected behavior for most policies.

Set to true to have flow execution continue even after a policy fails.

false Optional
enabled

Set to true to enforce the policy.

Set to false to "turn off" the policy. The policy will not be enforced even if it remains attached to a flow.

true Optional
async

This attribute is deprecated.

false Deprecated

<DisplayName> element

Use in addition to the name attribute to label the policy in the management UI proxy editor with a different, natural-language name.

<DisplayName>Policy Display Name</DisplayName>
Default:

N/A

If you omit this element, the the value of the policy's name attribute is used.

Presence: Optional
Type: String

 

<Quota> element

Identifies the target Quota policy whose counter should be updated.

<Quota name="quotaName"  ref="request.header.quotapolicy">
   <Identifier name="identifierName" ref="request.header.identifier">
      <Allow>100</Allow>
   </Identifier>
</Quota>
Default: N/A
Presence: Required
Type: N/A

Attributes

Attribute Description Default Presence
name

Specifies the name of the target Quota policy. 

N/A Optional
ref A flow variable that contains the name of the target Quota policy. If both ref and name are specified, then ref gets priority. If ref does not resolve at runtime, then name is used. N/A Optional

<Quota>/<Identifier> element

Variable used to uniquely identify the counter if the target Quota policy specifies the <Identifier> tag. 

<Quota name="quotaName">
   <Identifier name="identifierName" ref="request.header.identifier">
      <Allow>100</Allow>
   </Identifier>
</Quota>
Default: N/A
Presence: Required
Type: String

Attributes

Attribute Description Default Presence
name

Specifies the name of the count identifier in the target Quota policy. For a Quota policy that does not use the <Identifier> tag, specify _default.

N/A Optional
ref

A flow variable that contains the name of the count identifier in the target Quota policy. If both ref and name are specified, then ref gets priority. If ref does not resolve at runtime, then name is used.

N/A Optional

<Quota>/<Identifier>/<Allow> element

Specifies the amount to decrease the quota counter. You must specify <Allow>, otherwise, the policy does not modify the quota.

<Identifier name="identifierName" ref="request.header.identifier">
   <Allow>100</Allow>
</Identifier>
Default: N/A
Presence: Required
Type: Integer

<Quota>/<Identifier>/<Class> element

Specifies the class for which the Quota counter is updated. For more on using class with the Quota policy, see Quota policy

<Identifier name="_default">
   <Class ref="request.header.classIdentifier" />
   <Allow>200</Allow>
</Identifier>
Default: N/A
Presence: Optional
Type: N/A

Attributes

Attribute Description Default Presence
ref

Reference to the flow variable that contains the quota class to update.

N/A Optional

Error codes

The default format for error codes returned by policies is:

{
  "code" : " {ErrorCode} ",
  "message" : " {Error message} ",
  "contexts" : [ ]
}

The Reset Quota policy type defines the following error codes. For guidance on handling errors, see Fault handling.

Error Code Message
InvalidRLPolicyDefinition Invalid rate limit policy {0}
NoRLPolicy Quota policy {0} is not attached.
InvalidCount Invalid count value {0} for identifier {1} in {2}
FailedToResolveAllowCountRef Failed to resolve allow count reference {0} for identifier {1} in {2}

Schemas

See our Github repository samples for the most recent schemas.

Related topics

Quota policy

 

Help or comments?