Skip to content

Commit

Permalink
feat(clients): add usage client (#2960)
Browse files Browse the repository at this point in the history
  • Loading branch information
shortcuts authored Apr 5, 2024
1 parent b1bb97e commit aee3fde
Show file tree
Hide file tree
Showing 10 changed files with 170 additions and 13 deletions.
31 changes: 22 additions & 9 deletions config/clients.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
"personalization",
"query-suggestions",
"recommend",
"search"
"search",
"usage"
],
"folder": "clients/algoliasearch-client-csharp",
"gitRepoId": "algoliasearch-client-csharp",
Expand Down Expand Up @@ -70,7 +71,8 @@
"personalization",
"query-suggestions",
"recommend",
"search"
"search",
"usage"
],
"folder": "clients/algoliasearch-client-go",
"gitRepoId": "algoliasearch-client-go",
Expand All @@ -97,7 +99,8 @@
"personalization",
"query-suggestions",
"recommend",
"search"
"search",
"usage"
],
"folder": "clients/algoliasearch-client-java",
"gitRepoId": "algoliasearch-client-java",
Expand Down Expand Up @@ -155,6 +158,10 @@
{
"name": "search",
"output": "clients/algoliasearch-client-javascript/packages/client-search"
},
{
"name": "usage",
"output": "clients/algoliasearch-client-javascript/packages/client-usage"
}
],
"folder": "clients/algoliasearch-client-javascript",
Expand Down Expand Up @@ -183,7 +190,8 @@
"personalization",
"query-suggestions",
"recommend",
"search"
"search",
"usage"
],
"folder": "clients/algoliasearch-client-kotlin",
"gitRepoId": "algoliasearch-client-kotlin",
Expand All @@ -210,7 +218,8 @@
"personalization",
"query-suggestions",
"recommend",
"search"
"search",
"usage"
],
"folder": "clients/algoliasearch-client-php",
"gitRepoId": "algoliasearch-client-php",
Expand All @@ -237,7 +246,8 @@
"personalization",
"query-suggestions",
"recommend",
"search"
"search",
"usage"
],
"folder": "clients/algoliasearch-client-python",
"gitRepoId": "algoliasearch-client-python",
Expand All @@ -264,7 +274,8 @@
"personalization",
"query-suggestions",
"recommend",
"search"
"search",
"usage"
],
"folder": "clients/algoliasearch-client-ruby",
"gitRepoId": "algoliasearch-client-ruby",
Expand All @@ -291,7 +302,8 @@
"personalization",
"query-suggestions",
"recommend",
"search"
"search",
"usage"
],
"folder": "clients/algoliasearch-client-scala",
"gitRepoId": "algoliasearch-client-scala",
Expand All @@ -318,7 +330,8 @@
"personalization",
"query-suggestions",
"recommend",
"search"
"search",
"usage"
],
"folder": "clients/algoliasearch-client-swift",
"gitRepoId": "algoliasearch-client-swift",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,10 @@ public String toEnumVarName(String value, String datatype) {
return "GREATER_THAN";
case ">=":
return "GREATER_EQUALS";
case "90p_processing_time":
return "NINETY_P_PROCESSING_TIME";
case "99p_processing_time":
return "NINETY_NINE_P_PROCESSING_TIME";
case "mappingkit/v1":
return "MAPPINGKIT_V1";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,15 @@ public OperationsMap postProcessOperationsWithModels(OperationsMap objs, List<Mo
@Override
public String toEnumVarName(String value, String datatype) {
if (!"String".equals(datatype)) return super.toEnumVarName(value, datatype);
// In some cases, the API might accept characters instead of the textual notation, we will
// replace it internally so that it doesn't output the character itself.
switch (value) {
case "90p_processing_time":
return "NinetyPProcessingTime";
case "99p_processing_time":
return "NinetyNinePProcessingTime";
}

String enumVarName = value.replace("-", "_");
return super.toEnumVarName(enumVarName, datatype);
}
Expand Down
6 changes: 2 additions & 4 deletions scripts/pre-gen/removeExistingCodegen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,12 @@ export async function removeExistingCodegen({
}

// Delete client model folder/file
await run(`rm -rf ${path.join(baseModelFolder, clientModel)}`, {
cwd: folder,
await run(`rm -rf ${path.join(folder, baseModelFolder, clientModel)}`, {
language,
});

// Delete client api folder/file
await run(`rm -rf ${path.join(baseApiFolder, clientApi)}`, {
cwd: folder,
await run(`rm -rf ${path.join(folder, baseApiFolder, clientApi)}`, {
language,
});
}
1 change: 1 addition & 0 deletions snippets/javascript/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"@algolia/client-personalization": "link:../../clients/algoliasearch-client-javascript/packages/client-personalization",
"@algolia/client-query-suggestions": "link:../../clients/algoliasearch-client-javascript/packages/client-query-suggestions",
"@algolia/client-search": "link:../../clients/algoliasearch-client-javascript/packages/client-search",
"@algolia/client-usage": "link:../../clients/algoliasearch-client-javascript/packages/client-usage",
"@algolia/ingestion": "link:../../clients/algoliasearch-client-javascript/packages/ingestion",
"@algolia/monitoring": "link:../../clients/algoliasearch-client-javascript/packages/monitoring",
"@algolia/recommend": "link:../../clients/algoliasearch-client-javascript/packages/recommend",
Expand Down
9 changes: 9 additions & 0 deletions specs/usage/spec.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,15 @@ tags:
x-displayName: Usage statistics
description: Get various metrics related to the usage of your Algolia applications.
paths:
# ######################
# ### Custom request ###
# ######################
/{path}:
$ref: '../common/paths/customRequest.yml'

# ##################################
# ######## Usage Endpoints ########
# ##################################
/1/usage/{statistic}:
$ref: 'paths/statistic.yml'
/1/usage/{statistic}/{indexName}:
Expand Down
54 changes: 54 additions & 0 deletions tests/CTS/client/usage/api.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
[
{
"testName": "calls api with correct read host",
"autoCreateClient": false,
"steps": [
{
"type": "createClient",
"parameters": {
"appId": "test-app-id",
"apiKey": "test-api-key"
},
"expected": {}
},
{
"type": "method",
"object": "$client",
"path": "customGet",
"parameters": {
"path": "test"
},
"expected": {
"type": "host",
"match": "test-app-id-dsn.algolia.net"
}
}
]
},
{
"testName": "calls api with correct write host",
"autoCreateClient": false,
"steps": [
{
"type": "createClient",
"parameters": {
"appId": "test-app-id",
"apiKey": "test-api-key"
},
"expected": {}
},
{
"type": "method",
"object": "$client",
"path": "customPost",
"parameters": {
"path": "test"
},
"expected": {
"type": "host",
"match": "test-app-id.algolia.net"
}
}
]
}
]
32 changes: 32 additions & 0 deletions tests/CTS/client/usage/parameters.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
[
{
"testName": "client throws with invalid parameters",
"autoCreateClient": false,
"steps": [
{
"type": "createClient",
"expected": {
"error": "`appId` is missing."
}
},
{
"type": "createClient",
"parameters": {
"apiKey": "my-api-key"
},
"expected": {
"error": "`appId` is missing."
}
},
{
"type": "createClient",
"parameters": {
"appId": "my-app-id"
},
"expected": {
"error": "`apiKey` is missing."
}
}
]
}
]
19 changes: 19 additions & 0 deletions tests/CTS/requests/usage/getIndexUsage.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
[
{
"testName": "getIndexUsage with minimal parameters",
"parameters": {
"statistic": "queries_operations",
"indexName": "myIndexName",
"startDate": "2024-04-03T12:46:43Z",
"endDate": "2024-04-05T12:46:43Z"
},
"request": {
"path": "/1/usage/queries_operations/myIndexName",
"method": "GET",
"queryParameters": {
"startDate": "2024-04-03T12%3A46%3A43Z",
"endDate": "2024-04-05T12%3A46%3A43Z"
}
}
}
]
18 changes: 18 additions & 0 deletions tests/CTS/requests/usage/getUsage.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[
{
"testName": "getUsage with minimal parameters",
"parameters": {
"statistic": "queries_operations",
"startDate": "2024-04-03T12:46:43Z",
"endDate": "2024-04-05T12:46:43Z"
},
"request": {
"path": "/1/usage/queries_operations",
"method": "GET",
"queryParameters": {
"startDate": "2024-04-03T12%3A46%3A43Z",
"endDate": "2024-04-05T12%3A46%3A43Z"
}
}
}
]

1 comment on commit aee3fde

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.