how to set periodStartTime in quota-by-key policy in API management service?

Stoklas, Nac 1 Reputation point
2022-01-05T07:02:35.95+00:00

I prepared a quota-by-key subscription ID limit in policies and set it to a large number (in seconds). I ran into a problem when I checked for when the periodStartTime is set (via REST API ApiManagementGetQuotaCounterKeys). The date is very far in the past.
For example I set the following policy for 30 days renewal period:

    <quota-by-key calls="100" renewal-period="2592000" counter-key="@(context.Subscription?.Id ?? "anonymous")" />

I made a few API calls and the counter worked well but it set periodStartTime to 2021-12-13. This is a huge problem as it means when a new user would subscribe their subscription wouldn't start on the day they applied for it but from some random date in the past. I've tried different large renewal periods and the start date was always weird. Keep in mind that if I use 1 day or 2 as renewal period (60s*60min*24h) it works fine and sets the date of subscription application as start.

Quota by subscripton response:
{'value': [{'counterKey': '61d44b58279af5d6adc735b0', 'periodKey': '0_2419200', 'periodStartTime': '2021-12-13T00:00:00Z', 'periodEndTime': '2022-01-10T00:00:00Z', 'value': {'callsCount': 1, 'kbTransferred': 2.2353515625}}], 'count': 1, 'nextLink': None}

Can I affect the start date somehow, anyhow? Why does this happen?

Thank you for your help!

Azure API Management
Azure API Management
An Azure service that provides a hybrid, multi-cloud management platform for APIs.
2,078 questions
{count} votes

1 answer

Sort by: Most helpful
  1. MayankBargali-MSFT 70,221 Reputation points
    2022-01-17T06:00:10.98+00:00

    @Stoklas, Nac Apology for the delay. I have got the update from my team by default quota by key policy uses 0001-01-01T00:00:00 as a start point, not the date you set up the policy, to calculate the period and advances forward until it hits period containing current data - this is the current interval. You can see that interval between start and end times always matches the interval you set to policy.

    We can override that behavior by setting first-period-start attribute to desired start time. As of now this is not documented and we will be updating our document to update first-period-start attribute for quota-by-key policy.

    You can leverage the policy as below:

    <quota-by-key calls="100" first-period-start="2022-01-14T12:00:00+00:00" renewal-period="2419200" counter-key="testkey" />  
    

    Once you saved the policy it may not show the first-period-start in the portal and there is still discussion on the expected behavior but the policy will set the start date correctly. Feel free to get back to me if you have any queries or concerns.

    1 person found this answer helpful.

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.