Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handling removing of existing quota in API #438

Closed
gcornacchia opened this issue Sep 5, 2023 · 4 comments
Closed

Handling removing of existing quota in API #438

gcornacchia opened this issue Sep 5, 2023 · 4 comments
Assignees
Labels
bug Something isn't working

Comments

@gcornacchia
Copy link
Contributor

APIM-CLI version

1.14.2

API-Management version

7.7.20211130

Bug description

After testing different scenarios in adding/removing quotas on APIs I've found a strange behavior that I describe below.

Steps to reproduce

STEP 1) Consider an API with already 2 application default quotas and 2 system quotas as in this config file

...
 "applicationQuota": {
    "restrictions": [
      {
        "method": "*",
        "type": "throttle",
        "config": {
          "messages": "1000",
          "period": "second",
          "per": "1"
        }
      },
      {
        "method": "method1",
        "type": "throttle",
        "config": {
          "messages": "500",
          "period": "second",
          "per": "1"
        }
      }
    ]
  },
  "systemQuota": {
    "restrictions": [
      {
        "method": "method1",
        "type": "throttle",
        "config": {
          "messages": "9000",
          "period": "second",
          "per": "2"
        }
      },
      {
        "method": "method2",
        "type": "throttlemb",
        "config": {
          "mb": 8000,
          "period": "second",
          "per": "1"
        }
      }
    ]
  }
...

STEP 2) Remove one application default quota and one system quota

   ...
   "applicationQuota": {
    "restrictions": [
      {
        "method": "*",
        "type": "throttle",
        "config": {
          "messages": "1000",
          "period": "second",
          "per": "1"
        }
      }
    ]
  },
  "systemQuota": {
    "restrictions": [
      {
        "method": "method1",
        "type": "throttle",
        "config": {
          "messages": "9000",
          "period": "second",
          "per": "2"
        }
      }
    ]
  }
 ....

When importing this config file with quotaMode=replace the existing quotas on API Manager are correctly removed. OK

2023-09-05 15:23:24,258 [APIQuotaManager] INFO : Updating System default quota for API: PublicAPI_v1
2023-09-05 15:23:24,260 [APIQuotaManager] INFO : Removing existing Quotas for API: PublicAPI_v1 as quotaMode is set to replace.
2023-09-05 15:23:25,306 [APIQuotaManager] INFO : Updating Application default quota for API: PublicAPI_v1
2023-09-05 15:23:25,306 [APIQuotaManager] INFO : Removing existing Quotas for API: PublicAPI_v1 as quotaMode is set to replace.

STEP 3) I try to remove all quotas not serializing applicationQuota and systemQuota field in json but no differences are found

No changes detected between Import- and API-Manager-API

But...

STEP 4.1) I try to remove only the application quota

...
"systemQuota": {
    "restrictions": [
      {
        "method": "method1",
        "type": "throttle",
        "config": {
          "messages": "9000",
          "period": "second",
          "per": "2"
        }
      }
    ]
  }
...

The application quota is correctly removed from API Manager but I don't understand the first two lines of log (as system quotas are untouched)

2023-09-05 15:30:16,648 [APIQuotaManager] INFO : Updating System default quota for API: PublicAPI_v1
2023-09-05 15:30:16,649 [APIQuotaManager] INFO : Removing existing Quotas for API: PublicAPI_v1 as quotaMode is set to replace.
2023-09-05 15:30:17,093 [APIQuotaManager] INFO : Updating Application default quota for API: PublicAPI_v1
2023-09-05 15:30:17,094 [APIQuotaManager] INFO : Removing existing Quotas for API: PublicAPI_v1 as quotaMode is set to replace.

BUT...

STEP 4.1) After step 3 if I try to remove only the system quota instead of application quota.

 ...
 "applicationQuota": {
    "restrictions": [
      {
        "method": "*",
        "type": "throttle",
        "config": {
          "messages": "1000",
          "period": "second",
          "per": "1"
        }
      }
    ]
  } 
 ...

the system quota is not removed from API Manager

No changes detected between Import- and API-Manager-API

Maybe there's a need for uniformity in handling the semantics of null fields (not existent in JSON input file) or fields with empty values for "applicationQuota" and "systemQuota" fields.

"applicationQuota": {
restrictions: []
}

@rathnapandi what do you think?

Relevant log output

No response

@gcornacchia gcornacchia added the bug Something isn't working label Sep 5, 2023
@rathnapandi rathnapandi self-assigned this Sep 5, 2023
@rathnapandi
Copy link
Member

Hi @gcornacchia,
Thanks for reporting, looks like a defect to me. I will get back to you with more details.

rathnapandi added a commit that referenced this issue Sep 14, 2023
@rathnapandi
Copy link
Member

Hi @gcornacchia,

I have added some Junit test cases and existing code is working as expected. The only place I might see the issue is

the source contains

 "applicationQuota": {
    "restrictions": [
    ]
  }

and destination contains

 "applicationQuota": {

  }

it throws exception. Do you see anything different?

Please review the code 730a52f and let me know if i miss anything?

@lturricchia
Copy link

Hello about this problem in removing existing quotas on a specific API, we see Apim-cli is working.
we see the problem still occurs in removing GLOBAL quotas for ALL API, as in #442

@rathnapandi
Copy link
Member

Fixed as part of 1.14.3 release

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants