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

feat(clients): add usage client #2960

Merged
merged 6 commits into from
Apr 5, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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";
shortcuts marked this conversation as resolved.
Show resolved Hide resolved
case "99p_processing_time":
return "NinetyNinepProcessingTime";
}

String enumVarName = value.replace("-", "_");
return super.toEnumVarName(enumVarName, datatype);
}
Expand Down
14 changes: 7 additions & 7 deletions scripts/pre-gen/removeExistingCodegen.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import fsp from 'fs/promises';
import path from 'path';

import { createClientName, run, toAbsolutePath, toSnakeCase } from '../common.js';
import { createClientName, toAbsolutePath, toSnakeCase } from '../common.js';
import { getLanguageApiFolder, getLanguageFolder, getLanguageModelFolder } from '../config.js';
import type { Generator } from '../types.js';

Expand Down Expand Up @@ -87,14 +87,14 @@ export async function removeExistingCodegen({
}

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

// Delete client api folder/file
await run(`rm -rf ${path.join(baseApiFolder, clientApi)}`, {
cwd: folder,
language,
await fsp.rm(path.join(folder, path.join(baseApiFolder, clientApi)), {
force: true,
recursive: true,
shortcuts marked this conversation as resolved.
Show resolved Hide resolved
});
}
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"
}
}
}
]
Loading