Skip to content

Commit aee3fde

Browse files
authored
feat(clients): add usage client (#2960)
1 parent b1bb97e commit aee3fde

File tree

10 files changed

+170
-13
lines changed

10 files changed

+170
-13
lines changed

config/clients.config.json

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
"personalization",
1010
"query-suggestions",
1111
"recommend",
12-
"search"
12+
"search",
13+
"usage"
1314
],
1415
"folder": "clients/algoliasearch-client-csharp",
1516
"gitRepoId": "algoliasearch-client-csharp",
@@ -70,7 +71,8 @@
7071
"personalization",
7172
"query-suggestions",
7273
"recommend",
73-
"search"
74+
"search",
75+
"usage"
7476
],
7577
"folder": "clients/algoliasearch-client-go",
7678
"gitRepoId": "algoliasearch-client-go",
@@ -97,7 +99,8 @@
9799
"personalization",
98100
"query-suggestions",
99101
"recommend",
100-
"search"
102+
"search",
103+
"usage"
101104
],
102105
"folder": "clients/algoliasearch-client-java",
103106
"gitRepoId": "algoliasearch-client-java",
@@ -155,6 +158,10 @@
155158
{
156159
"name": "search",
157160
"output": "clients/algoliasearch-client-javascript/packages/client-search"
161+
},
162+
{
163+
"name": "usage",
164+
"output": "clients/algoliasearch-client-javascript/packages/client-usage"
158165
}
159166
],
160167
"folder": "clients/algoliasearch-client-javascript",
@@ -183,7 +190,8 @@
183190
"personalization",
184191
"query-suggestions",
185192
"recommend",
186-
"search"
193+
"search",
194+
"usage"
187195
],
188196
"folder": "clients/algoliasearch-client-kotlin",
189197
"gitRepoId": "algoliasearch-client-kotlin",
@@ -210,7 +218,8 @@
210218
"personalization",
211219
"query-suggestions",
212220
"recommend",
213-
"search"
221+
"search",
222+
"usage"
214223
],
215224
"folder": "clients/algoliasearch-client-php",
216225
"gitRepoId": "algoliasearch-client-php",
@@ -237,7 +246,8 @@
237246
"personalization",
238247
"query-suggestions",
239248
"recommend",
240-
"search"
249+
"search",
250+
"usage"
241251
],
242252
"folder": "clients/algoliasearch-client-python",
243253
"gitRepoId": "algoliasearch-client-python",
@@ -264,7 +274,8 @@
264274
"personalization",
265275
"query-suggestions",
266276
"recommend",
267-
"search"
277+
"search",
278+
"usage"
268279
],
269280
"folder": "clients/algoliasearch-client-ruby",
270281
"gitRepoId": "algoliasearch-client-ruby",
@@ -291,7 +302,8 @@
291302
"personalization",
292303
"query-suggestions",
293304
"recommend",
294-
"search"
305+
"search",
306+
"usage"
295307
],
296308
"folder": "clients/algoliasearch-client-scala",
297309
"gitRepoId": "algoliasearch-client-scala",
@@ -318,7 +330,8 @@
318330
"personalization",
319331
"query-suggestions",
320332
"recommend",
321-
"search"
333+
"search",
334+
"usage"
322335
],
323336
"folder": "clients/algoliasearch-client-swift",
324337
"gitRepoId": "algoliasearch-client-swift",

generators/src/main/java/com/algolia/codegen/AlgoliaJavaGenerator.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,10 @@ public String toEnumVarName(String value, String datatype) {
121121
return "GREATER_THAN";
122122
case ">=":
123123
return "GREATER_EQUALS";
124+
case "90p_processing_time":
125+
return "NINETY_P_PROCESSING_TIME";
126+
case "99p_processing_time":
127+
return "NINETY_NINE_P_PROCESSING_TIME";
124128
case "mappingkit/v1":
125129
return "MAPPINGKIT_V1";
126130
}

generators/src/main/java/com/algolia/codegen/AlgoliaKotlinGenerator.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,15 @@ public OperationsMap postProcessOperationsWithModels(OperationsMap objs, List<Mo
195195
@Override
196196
public String toEnumVarName(String value, String datatype) {
197197
if (!"String".equals(datatype)) return super.toEnumVarName(value, datatype);
198+
// In some cases, the API might accept characters instead of the textual notation, we will
199+
// replace it internally so that it doesn't output the character itself.
200+
switch (value) {
201+
case "90p_processing_time":
202+
return "NinetyPProcessingTime";
203+
case "99p_processing_time":
204+
return "NinetyNinePProcessingTime";
205+
}
206+
198207
String enumVarName = value.replace("-", "_");
199208
return super.toEnumVarName(enumVarName, datatype);
200209
}

scripts/pre-gen/removeExistingCodegen.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,14 +87,12 @@ export async function removeExistingCodegen({
8787
}
8888

8989
// Delete client model folder/file
90-
await run(`rm -rf ${path.join(baseModelFolder, clientModel)}`, {
91-
cwd: folder,
90+
await run(`rm -rf ${path.join(folder, baseModelFolder, clientModel)}`, {
9291
language,
9392
});
9493

9594
// Delete client api folder/file
96-
await run(`rm -rf ${path.join(baseApiFolder, clientApi)}`, {
97-
cwd: folder,
95+
await run(`rm -rf ${path.join(folder, baseApiFolder, clientApi)}`, {
9896
language,
9997
});
10098
}

snippets/javascript/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
"@algolia/client-personalization": "link:../../clients/algoliasearch-client-javascript/packages/client-personalization",
1010
"@algolia/client-query-suggestions": "link:../../clients/algoliasearch-client-javascript/packages/client-query-suggestions",
1111
"@algolia/client-search": "link:../../clients/algoliasearch-client-javascript/packages/client-search",
12+
"@algolia/client-usage": "link:../../clients/algoliasearch-client-javascript/packages/client-usage",
1213
"@algolia/ingestion": "link:../../clients/algoliasearch-client-javascript/packages/ingestion",
1314
"@algolia/monitoring": "link:../../clients/algoliasearch-client-javascript/packages/monitoring",
1415
"@algolia/recommend": "link:../../clients/algoliasearch-client-javascript/packages/recommend",

specs/usage/spec.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,15 @@ tags:
5656
x-displayName: Usage statistics
5757
description: Get various metrics related to the usage of your Algolia applications.
5858
paths:
59+
# ######################
60+
# ### Custom request ###
61+
# ######################
62+
/{path}:
63+
$ref: '../common/paths/customRequest.yml'
64+
65+
# ##################################
66+
# ######## Usage Endpoints ########
67+
# ##################################
5968
/1/usage/{statistic}:
6069
$ref: 'paths/statistic.yml'
6170
/1/usage/{statistic}/{indexName}:

tests/CTS/client/usage/api.json

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
[
2+
{
3+
"testName": "calls api with correct read host",
4+
"autoCreateClient": false,
5+
"steps": [
6+
{
7+
"type": "createClient",
8+
"parameters": {
9+
"appId": "test-app-id",
10+
"apiKey": "test-api-key"
11+
},
12+
"expected": {}
13+
},
14+
{
15+
"type": "method",
16+
"object": "$client",
17+
"path": "customGet",
18+
"parameters": {
19+
"path": "test"
20+
},
21+
"expected": {
22+
"type": "host",
23+
"match": "test-app-id-dsn.algolia.net"
24+
}
25+
}
26+
]
27+
},
28+
{
29+
"testName": "calls api with correct write host",
30+
"autoCreateClient": false,
31+
"steps": [
32+
{
33+
"type": "createClient",
34+
"parameters": {
35+
"appId": "test-app-id",
36+
"apiKey": "test-api-key"
37+
},
38+
"expected": {}
39+
},
40+
{
41+
"type": "method",
42+
"object": "$client",
43+
"path": "customPost",
44+
"parameters": {
45+
"path": "test"
46+
},
47+
"expected": {
48+
"type": "host",
49+
"match": "test-app-id.algolia.net"
50+
}
51+
}
52+
]
53+
}
54+
]
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
[
2+
{
3+
"testName": "client throws with invalid parameters",
4+
"autoCreateClient": false,
5+
"steps": [
6+
{
7+
"type": "createClient",
8+
"expected": {
9+
"error": "`appId` is missing."
10+
}
11+
},
12+
{
13+
"type": "createClient",
14+
"parameters": {
15+
"apiKey": "my-api-key"
16+
},
17+
"expected": {
18+
"error": "`appId` is missing."
19+
}
20+
},
21+
{
22+
"type": "createClient",
23+
"parameters": {
24+
"appId": "my-app-id"
25+
},
26+
"expected": {
27+
"error": "`apiKey` is missing."
28+
}
29+
}
30+
]
31+
}
32+
]
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
[
2+
{
3+
"testName": "getIndexUsage with minimal parameters",
4+
"parameters": {
5+
"statistic": "queries_operations",
6+
"indexName": "myIndexName",
7+
"startDate": "2024-04-03T12:46:43Z",
8+
"endDate": "2024-04-05T12:46:43Z"
9+
},
10+
"request": {
11+
"path": "/1/usage/queries_operations/myIndexName",
12+
"method": "GET",
13+
"queryParameters": {
14+
"startDate": "2024-04-03T12%3A46%3A43Z",
15+
"endDate": "2024-04-05T12%3A46%3A43Z"
16+
}
17+
}
18+
}
19+
]
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
[
2+
{
3+
"testName": "getUsage with minimal parameters",
4+
"parameters": {
5+
"statistic": "queries_operations",
6+
"startDate": "2024-04-03T12:46:43Z",
7+
"endDate": "2024-04-05T12:46:43Z"
8+
},
9+
"request": {
10+
"path": "/1/usage/queries_operations",
11+
"method": "GET",
12+
"queryParameters": {
13+
"startDate": "2024-04-03T12%3A46%3A43Z",
14+
"endDate": "2024-04-05T12%3A46%3A43Z"
15+
}
16+
}
17+
}
18+
]

0 commit comments

Comments
 (0)