ResetQuota ポリシー

概要

ターゲットの Quota ポリシーで許可されている残りのリクエスト数を動的に変更します。このポリシーは通常、割り当てカウントのリセットを待たずに、ターゲットの Quota ポリシーの現在の割り当てカウントを減らす場合に使用します。

たとえば、ターゲットの Quota ポリシーで 1 週間のリクエスト数が 1,000 件に制限されているときに、週の 2 日目に、デベロッパーがこの上限に達したとします。Reset Quota ポリシーを使用して、割り当てカウンタから 500 を引き、週の残りの日数に追加で 500 件のリクエストを許可します。週末に Quota ポリシーがリセットされるので、デベロッパーの週のリクエスト数は 1,000 件に戻ります。

Quota ポリシーの詳細については、Quota ポリシーをご覧ください。また、Reset Quota ポリシーの使用方法については、こちらのコミュニティ投稿をご覧ください。

サンプル

次のポリシーコードのサンプルでは、割り当てカウンタのリセット方法を説明します。

デフォルト カウンタをリセットする

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

Reset Quota ポリシーでは、<Quota> タグの name 属性を使用して、ターゲット Quota ポリシーを指定します。上の例では、MyQuotaPolicy ポリシーがターゲットです。

すべての Reset Quota ポリシーで、更新する Quota ポリシーのカウンタを指定するために <Identifier> タグが必要です。デフォルトでは、Quota ポリシーに <Identifier> タグも含まれていない限り、Quota ポリシーにはカウンタが 1 つあります。この例では、ターゲットの Quota ポリシーで <Identifier> タグを使用しないため、name 属性を _default として指定します。

<Allow> 要素では、ターゲット ポリシーの現在の割り当て数を減らすために使用される値を指定します。この例では、割り当てカウントを 100 減らしているので、ターゲットの Quota ポリシーに追加で 100 件のリクエストが許可されます。ターゲットの Quota ポリシーがリセットされると、この変更は破棄されます。

以下に、ターゲットの Quota ポリシーの定義を示します。

<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>

この例では、リクエストのヘッダーでターゲットの Quota ポリシーの名前を渡し、割り当てカウントを変更しています。これらの値を含むフロー変数を Reset Quota ポリシーで参照できます。

ID を指定する

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

ターゲット Quota ポリシーで <Identifier> タグを指定する場合は、Reset Quota ポリシーの <Identifier> タグに同じ値を指定して、特定の割り当て数を更新できます。以下のターゲット Quota ポリシーの <Identifier> タグが、Reset Quota ポリシーに指定された値とどの程度一致しているかを確認します。

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

要素リファレンス

この要素リファレンスでは、Reset Quota ポリシーの要素と属性について説明します。

<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> 属性

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

The following table describes attributes that are common to all policy parent elements:

Attribute Description Default Presence
name

The internal name of the policy. The value of the name attribute can contain letters, numbers, spaces, hyphens, underscores, and periods. This value cannot exceed 255 characters.

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 value of the policy's name attribute is used.

Presence Optional
Type String

<Quota> 要素

カウンタを更新するターゲット Quota ポリシーを指定します。

<Quota name="quotaName"  ref="request.header.quotapolicy">
   <Identifier name="identifierName" ref="request.header.identifier">
      <Allow>100</Allow>
   </Identifier>
</Quota>
デフォルト: なし
要否: 必須
型: なし

属性

属性 説明 デフォルト 要否
name

ターゲット Quota ポリシーの名前を指定します。

なし 省略可
ref ターゲット Quota ポリシーの名前を含むフロー変数。refname の両方が指定されている場合は、ref が優先されます。 ランタイムに ref が解決されない場合は、name が使用されます。 なし 省略可

<Quota> / <Identifier> 要素

ターゲット Quota ポリシーで <Identifier> タグが指定されている場合に、カウンタを一意に識別するために使用される変数。

<Quota name="quotaName">
   <Identifier name="identifierName" ref="request.header.identifier">
      <Allow>100</Allow>
   </Identifier>
</Quota>
デフォルト: なし
要否: 必須
型: 文字列

属性

属性 説明 デフォルト 要否
name

ターゲット Quota ポリシーのカウント ID の名前を指定します。<Identifier> タグを使用しない Quota ポリシーの場合は、_default を指定します。

なし 省略可
ref

ターゲット Quota ポリシーのカウント ID の名前を含むフロー変数。refname の両方が指定されている場合は、refが優先されます。ランタイムに ref が解決されない場合は、name が使用されます。

なし 省略可

<Quota> / <Identifier> / <Allow> 要素

割り当てカウンタを減らす量を指定します。<Allow> を指定する必要があります。指定しない場合、ポリシーで割り当てが変更されません。

<Identifier name="identifierName" ref="request.header.identifier">
   <Allow ref="request.header.allowquota">100</Allow>
</Identifier>
デフォルト: なし
要否: 必須
型: 整数

属性

属性 説明 デフォルト 要否
ref

ターゲット Quota ポリシーの割り当て数の変更が含まれたフロー変数。

なし 省略可

<Quota> / <Identifier> / <Class> 要素

割り当てカウンタを更新するクラスを指定します。Quota ポリシーでクラスを使用する方法の詳細については、Quota ポリシーをご覧ください。

<Identifier name="_default">
   <Class ref="request.header.classIdentifier">
     <Allow>200</Allow>
   </Class>
</Identifier>
デフォルト: なし
要否: 省略可
型: なし

属性

属性 説明 デフォルト 要否
ref

更新する割り当てクラスを含むフロー変数を参照します。

なし 省略可

エラー リファレンス

This section describes the fault codes and error messages that are returned and fault variables that are set by Edge when this policy triggers an error. This information is important to know if you are developing fault rules to handle faults. To learn more, see What you need to know about policy errors and Handling faults.

Runtime errors

These errors can occur when the policy executes.

Fault code HTTP status Cause Fix
policies.resetquota.InvalidRLPolicy 500 The Quota policy specified in the <Quota> element of the Reset Quota policy is not defined in the API proxy and thus is not available during the flow. The <Quota> element is mandatory and identifies the target Quota policy whose counter should be updated through the Reset Quota policy.
policies.resetquota.FailedToResolveAllowCountRef N/A The reference to the variable containing the allow count in the <Allow> element of the policy cannot be resolved to a value. This element is mandatory and specifies the amount to decrease the quota counter.
policies.resetquota.FailedToResolveRLPolicy 500 The variable referenced by the ref attribute in the <Quota> element cannot be resolved.

Deployment errors

These errors can occur when you deploy a proxy containing this policy.

Error name Cause Fix
InvalidCount If the count value specified in the <Allow> element of the Reset Quota Policy is not an integer, then the deployment of the API proxy fails.

スキーマ

関連トピック

Quota ポリシー