diff --git a/test/cucumber-tests/CRs/artifacts.yaml b/test/cucumber-tests/CRs/artifacts.yaml index 56e41d317..2bbeb801a 100644 --- a/test/cucumber-tests/CRs/artifacts.yaml +++ b/test/cucumber-tests/CRs/artifacts.yaml @@ -1777,3 +1777,25 @@ spec: cpu: 10m --- +apiVersion: dp.wso2.com/v1alpha3 +kind: AIProvider +metadata: + name: llm-provider-1 + namespace: apk-integration-test +spec: + providerName : "AzureAI" + providerAPIVersion : "2024-06-01" + organization : "default" + model: + in: "Body" + value: "model" + rateLimitFields: + promptTokens: + in: "Body" + value: "usage.prompt_tokens" + completionToken: + in: "Body" + value: "usage.completion_tokens" + totalToken: + in: "Body" + value: "usage.total_tokens" diff --git a/test/cucumber-tests/src/test/resources/artifacts/apk-confs/backend_based_airl_conf.yaml b/test/cucumber-tests/src/test/resources/artifacts/apk-confs/backend_based_airl_conf.yaml new file mode 100644 index 000000000..ffa4a2078 --- /dev/null +++ b/test/cucumber-tests/src/test/resources/artifacts/apk-confs/backend_based_airl_conf.yaml @@ -0,0 +1,41 @@ +--- +name: "BackendBasedAIRL" +basePath: "/backend-based-airl" +id: "backend-based-airl" +version: "1.0.0" +type: "REST" +defaultVersion: false +subscriptionValidation: false +aiProvider: + name: llm-provider-1 + apiVersion: “2024.06.01” +endpointConfigurations: + production: + endpoint: "http://llm-service:80" + aiRatelimit: + enabled: true + token: + promptLimit: 5000 + completionLimit: 10000 + totalLimit: 15000 + unit: Minute + request: + requestLimit: 6000 + unit: Minute +operations: +- target: "/employee" + verb: "GET" + secured: true + scopes: [] +- target: "/employee" + verb: "POST" + secured: true + scopes: [] +- target: "/employee/{employeeId}" + verb: "PUT" + secured: true + scopes: [] +- target: "/employee/{employeeId}" + verb: "DELETE" + secured: true + scopes: [] diff --git a/test/cucumber-tests/src/test/resources/tests/api/APIBackendBasedAIRatelimit.feature b/test/cucumber-tests/src/test/resources/tests/api/APIBackendBasedAIRatelimit.feature index 2ad7bebe3..13fb3c024 100644 --- a/test/cucumber-tests/src/test/resources/tests/api/APIBackendBasedAIRatelimit.feature +++ b/test/cucumber-tests/src/test/resources/tests/api/APIBackendBasedAIRatelimit.feature @@ -1,24 +1,25 @@ Feature: API backend based AI ratelimit Feature + Scenario: backend based AI ratelimit token detail comes in the body. Given The system is ready And I have a valid subscription Then I set headers - |Authorization|bearer ${accessToken}| + | Authorization | bearer ${accessToken} | And I wait for next minute strictly And I send "GET" request to "https://default.gw.wso2.com:9095/llm-api/v1.0.0/3.14/employee?send=body" with body "" Then the response status code should be 200 And the response headers should contain - | x-ratelimit-remaining | 4999 | + | x-ratelimit-remaining | 4999 | And I wait for 3 seconds And I send "GET" request to "https://default.gw.wso2.com:9095/llm-api/v1.0.0/3.14/employee?send=body" with body "" Then the response status code should be 200 And the response headers should contain - | x-ratelimit-remaining | 4699 | + | x-ratelimit-remaining | 4699 | And I wait for 3 seconds And I send "GET" request to "https://default.gw.wso2.com:9095/llm-api/v1.0.0/3.14/employee?send=body&prompt_tokens=40000" with body "" Then the response status code should be 200 And the response headers should contain - | x-ratelimit-remaining | 4399 | + | x-ratelimit-remaining | 4399 | And I wait for 3 seconds And I send "GET" request to "https://default.gw.wso2.com:9095/llm-api/v1.0.0/3.14/employee?send=body&prompt_tokens=40000" with body "" Then the response status code should be 429 @@ -34,26 +35,27 @@ Feature: API backend based AI ratelimit Feature And I wait for 3 seconds And I send "GET" request to "https://default.gw.wso2.com:9095/llm-api/v1.0.0/3.14/employee?send=body" with body "" Then the response status code should be 429 + Scenario: backend based AI ratelimit token detail comes in the header. Given The system is ready And I have a valid subscription Then I set headers - |Authorization|bearer ${accessToken}| + | Authorization | bearer ${accessToken} | And I wait for next minute strictly And I send "GET" request to "https://default.gw.wso2.com:9095/llm-api-header/v1.0.0/3.14/employee?send=header" with body "" Then the response status code should be 200 And the response headers should contain - | x-ratelimit-remaining | 4999 | + | x-ratelimit-remaining | 4999 | And I wait for 3 seconds And I send "GET" request to "https://default.gw.wso2.com:9095/llm-api-header/v1.0.0/3.14/employee?send=header" with body "" Then the response status code should be 200 And the response headers should contain - | x-ratelimit-remaining | 4699 | + | x-ratelimit-remaining | 4699 | And I wait for 3 seconds And I send "GET" request to "https://default.gw.wso2.com:9095/llm-api-header/v1.0.0/3.14/employee?send=header&prompt_tokens=40000" with body "" Then the response status code should be 200 And the response headers should contain - | x-ratelimit-remaining | 4399 | + | x-ratelimit-remaining | 4399 | And I wait for 3 seconds And I send "GET" request to "https://default.gw.wso2.com:9095/llm-api-header/v1.0.0/3.14/employee?send=header&prompt_tokens=40000" with body "" Then the response status code should be 429 @@ -69,18 +71,69 @@ Feature: API backend based AI ratelimit Feature And I wait for 3 seconds And I send "GET" request to "https://default.gw.wso2.com:9095/llm-api-header/v1.0.0/3.14/employee?send=header" with body "" Then the response status code should be 429 + Scenario: backend based AI ratelimit token detail comes in the header but a body configured api checked. Given The system is ready And I have a valid subscription Then I set headers - |Authorization|bearer ${accessToken}| + | Authorization | bearer ${accessToken} | And I wait for next minute strictly And I send "GET" request to "https://default.gw.wso2.com:9095/llm-api/v1.0.0/3.14/employee?send=header" with body "" Then the response status code should be 200 And the response headers should contain - | x-ratelimit-remaining | 4999 | + | x-ratelimit-remaining | 4999 | And I wait for 3 seconds And I send "GET" request to "https://default.gw.wso2.com:9095/llm-api/v1.0.0/3.14/employee?send=header" with body "" Then the response status code should be 200 And the response headers should contain - | x-ratelimit-remaining | 4998 | \ No newline at end of file + | x-ratelimit-remaining | 4998 | + + Scenario: apk conf backend based AI ratelimit token detail comes in the body. + Given The system is ready + And I have a valid subscription + When I use the APK Conf file "artifacts/apk-confs/backend_based_airl_conf.yaml" + And the definition file "artifacts/definitions/employees_api.json" + And make the API deployment request + Then the response status code should be 200 + Then I set headers + | Authorization | bearer ${accessToken} | + And I wait for next minute strictly + And I send "GET" request to "https://default.gw.wso2.com:9095/backend-based-airl/1.0.0/employee?send=body" with body "" + Then the response status code should be 200 + And the response headers should contain + | x-ratelimit-remaining | 4999 | + And I wait for 3 seconds + And I send "GET" request to "https://default.gw.wso2.com:9095/backend-based-airl/1.0.0/employee?send=body" with body "" + Then the response status code should be 200 + And the response headers should contain + | x-ratelimit-remaining | 4699 | + And I wait for 3 seconds + And I send "GET" request to "https://default.gw.wso2.com:9095/backend-based-airl/1.0.0/employee?send=body&prompt_tokens=40000" with body "" + Then the response status code should be 200 + And the response headers should contain + | x-ratelimit-remaining | 4399 | + And I wait for 3 seconds + And I send "GET" request to "https://default.gw.wso2.com:9095/backend-based-airl/1.0.0/employee?send=body&prompt_tokens=40000" with body "" + Then the response status code should be 429 + And I wait for next minute strictly + And I send "GET" request to "https://default.gw.wso2.com:9095/backend-based-airl/1.0.0/employee?send=body&completion_tokens=40000" with body "" + Then the response status code should be 200 + And I wait for 3 seconds + And I send "GET" request to "https://default.gw.wso2.com:9095/backend-based-airl/1.0.0/employee?send=body" with body "" + Then the response status code should be 429 + And I wait for next minute strictly + And I send "GET" request to "https://default.gw.wso2.com:9095/backend-based-airl/1.0.0/employee?send=body&total_tokens=40000" with body "" + Then the response status code should be 200 + And I wait for 3 seconds + And I send "GET" request to "https://default.gw.wso2.com:9095/backend-based-airl/1.0.0/employee?send=body" with body "" + Then the response status code should be 429 + + Scenario Outline: Undeploy API + Given The system is ready + And I have a valid subscription + When I undeploy the API whose ID is "" + Then the response status code should be + + Examples: + | apiID | expectedStatusCode | + | backend-based-airl | 202 |