APIGEE spike arrest

Is it possible to distribute spike arrest value based on different query parameters within same proxy?

Solved Solved
0 8 1,063
1 ACCEPTED SOLUTION

Yes, you can configure multiple spike arrest policies for different query parameters in Apigee Edge.

To do this, you would first create the spike arrest policies in the Apigee Edge UI or using the Apigee Edge API. Then you would apply the policies to the relevant API proxies or endpoints.

To add a spike arrest policy to a preflow, you would typically add it to the ProxyEndpoint or TargetEndpoint preflow section in the API proxy's XML configuration file. However, instead of adding a single spike arrest policy to the preflow, you can add multiple spike arrest policies by defining them with different names and referencing them in the flow section using a condition.

For example, suppose you have two spike arrest policies defined, "spike-arrest-1" and "spike-arrest-2", that limit the number of requests per minute for different query parameters. You could add them to a ProxyEndpoint preflow like this: 

<ProxyEndpoint name="my-proxy">
<PreFlow>
<Request>
<Step>
<Name>spike-arrest</Name>
<Condition>(request.queryparam.param1 != null)</Condition>
<Properties>
<Property name="identifier">param1</Property>
<Property name="rate">1pm</Property>
</Properties>
</Step>
<Step>
<Name>spike-arrest</Name>
<Condition>(request.queryparam.param2 != null)</Condition>
<Properties>
<Property name="identifier">param2</Property>
<Property name="rate">5pm</Property>
</Properties>
</Step>
</Request>
</PreFlow>
...
</ProxyEndpoint>

In this example, the first spike arrest policy ("spike-arrest-1") is applied when the "param1" query parameter is present in the request, and the second policy ("spike-arrest-2") is applied when the "param2" query parameter is present. The "identifier" property specifies the query parameter to track, and the "rate" property specifies the maximum number of requests per minute.

You can adjust the conditions, identifier values, and rate limits to fit your specific use case.

View solution in original post

8 REPLIES 8

Hi there,

I'm not sure if I fully understand the question, but I think you're asking how to use flow variables such as request query parameters as SpikeArrest policy child element values. If this is the case, then you're in luck. All child elements besides DisplayName are able to use flow variables as values. Here's an example SpikeArrest policy where I use a different query parameter for each child element:

<SpikeArrest name="Spike-Arrest-Ex">
  <Rate ref="request.queryparam.param0" />
  <Identifier ref="request.queryparam.param1" />
  <MessageWeight ref="request.queryparam.param2" />
  <UseEffectiveCount ref="request.queryparam.param3" />
</SpikeArrest>

 

May be yes. But the main query I have is that for supposing I want to throttle the request by 60 pm and I have two operations in my one proxy both are POST operations (P1, P1).
And the resource path is same (/abc), and again both operations having different query parameters.
So, based on this both operation should have 60 request pm, not combined 60pm request.

Operation 1 : p1/abc?pqr should have 60pm request.   

Operation 2 : p1/abc?xyz should have 60pm request. 

So, how can I distribute them? 

You could use an assign message policy to combine the desired query parameters into a single flow variable. You could then use this as the identifier in your Spike Arrest policy.

Yes, it is possible to distribute spike arrest value based on different query parameters within the same proxy.

Spike arrest is a feature commonly used in API gateways to protect backend services from excessive traffic. It limits the number of requests that can be made to the backend service within a certain time period. When the limit is exceeded, the API gateway will block further requests from the client for a specified amount of time.

In some cases, it may be necessary to apply different spike arrest values based on different query parameters. For example, if you have an API endpoint that accepts different types of queries, you may want to apply a different spike arrest value for each query type.

Most API gateways allow you to configure spike arrest values based on various criteria, such as client IP address, HTTP method, request path, and query parameters. You can define multiple spike arrest policies with different values for each criterion and apply them to specific routes or endpoints within the same proxy.

Therefore, you can create separate spike arrest policies for different query parameters and apply them to the relevant routes or endpoints within the same proxy. This will allow you to fine-tune your API traffic management strategy and protect your backend services from different types of traffic spikes.

Thanks for your reply.
I got the point that we can route spike arrest policy with respective to the query parameters, but my concern is that usually we add a spike arrest policy to preflow of proxy endpoint which is used as common for API endpoint. But, you are suggesting to configure different policies. Can I see were exactly we can add multiple policies and how can we route them. 

Yes, you can configure multiple spike arrest policies for different query parameters in Apigee Edge.

To do this, you would first create the spike arrest policies in the Apigee Edge UI or using the Apigee Edge API. Then you would apply the policies to the relevant API proxies or endpoints.

To add a spike arrest policy to a preflow, you would typically add it to the ProxyEndpoint or TargetEndpoint preflow section in the API proxy's XML configuration file. However, instead of adding a single spike arrest policy to the preflow, you can add multiple spike arrest policies by defining them with different names and referencing them in the flow section using a condition.

For example, suppose you have two spike arrest policies defined, "spike-arrest-1" and "spike-arrest-2", that limit the number of requests per minute for different query parameters. You could add them to a ProxyEndpoint preflow like this: 

<ProxyEndpoint name="my-proxy">
<PreFlow>
<Request>
<Step>
<Name>spike-arrest</Name>
<Condition>(request.queryparam.param1 != null)</Condition>
<Properties>
<Property name="identifier">param1</Property>
<Property name="rate">1pm</Property>
</Properties>
</Step>
<Step>
<Name>spike-arrest</Name>
<Condition>(request.queryparam.param2 != null)</Condition>
<Properties>
<Property name="identifier">param2</Property>
<Property name="rate">5pm</Property>
</Properties>
</Step>
</Request>
</PreFlow>
...
</ProxyEndpoint>

In this example, the first spike arrest policy ("spike-arrest-1") is applied when the "param1" query parameter is present in the request, and the second policy ("spike-arrest-2") is applied when the "param2" query parameter is present. The "identifier" property specifies the query parameter to track, and the "rate" property specifies the maximum number of requests per minute.

You can adjust the conditions, identifier values, and rate limits to fit your specific use case.

Thank you! I am able to solve my query using this solution.

 

Thanks for the solution.

But how do I create a spike arrest policy based on the query params value so if the value of query param id is equal to developers then assign rate as 60 per minutes and if id is equal testers then assign rate as 2 per minutes ?