Skip to content

Commit 3a166e3

Browse files
api-clients-generation-pipeline[bot]therveci.datadog-api-spec
authored
Add a test for group_by in AggregateLogs (#545)
* Be more strict in the serializer to better match oneOf * Regenerate client from commit fea6d10 of spec repo Co-authored-by: Thomas Hervé <[email protected]> Co-authored-by: api-clients-generation-pipeline[bot] <54105614+api-clients-generation-pipeline[bot]@users.noreply.github.com> Co-authored-by: ci.datadog-api-spec <[email protected]>
1 parent cfd4296 commit 3a166e3

File tree

8 files changed

+153
-20
lines changed

8 files changed

+153
-20
lines changed

.apigentools-info

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44
"spec_versions": {
55
"v1": {
66
"apigentools_version": "1.6.2",
7-
"regenerated": "2022-02-23 10:10:02.745830",
8-
"spec_repo_commit": "cf974e8"
7+
"regenerated": "2022-02-25 21:39:20.090294",
8+
"spec_repo_commit": "fea6d10"
99
},
1010
"v2": {
1111
"apigentools_version": "1.6.2",
12-
"regenerated": "2022-02-23 10:10:02.762812",
13-
"spec_repo_commit": "cf974e8"
12+
"regenerated": "2022-02-25 21:39:20.107720",
13+
"spec_repo_commit": "fea6d10"
1414
}
1515
}
1616
}

.generator/templates/model/ObjectSerializer.mustache

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@ const primitives = [
1212
"integer",
1313
"long",
1414
"float",
15-
"number",
16-
"any"
15+
"number"
1716
];
1817

1918
const ARRAY_PREFIX = "Array<";
@@ -61,9 +60,9 @@ const oneOfMap: {[index: string]: string[]} = {
6160

6261
export class ObjectSerializer {
6362
public static serialize(data: any, type: string, format: string): any {
64-
if (data == undefined) {
63+
if (data == undefined || type == "any") {
6564
return data;
66-
} else if (primitives.includes(type.toLowerCase())) {
65+
} else if (primitives.includes(type.toLowerCase()) && typeof data == type.toLowerCase()) {
6766
return data;
6867
} else if (type.startsWith(ARRAY_PREFIX)) {
6968
// Array<Type> => Type
@@ -146,9 +145,9 @@ export class ObjectSerializer {
146145
}
147146

148147
public static deserialize(data: any, type: string, format: string = ""): any {
149-
if (data == undefined) {
148+
if (data == undefined || type == "any") {
150149
return data;
151-
} else if (primitives.includes(type.toLowerCase())) {
150+
} else if (primitives.includes(type.toLowerCase()) && typeof data == type.toLowerCase()) {
152151
return data;
153152
} else if (type.startsWith(ARRAY_PREFIX)) {
154153
// Array<Type> => Type
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
"2022-02-23T10:58:05.766Z"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
{
2+
"log": {
3+
"_recordingName": "Logs/Aggregate compute events with group by returns \"OK\" response",
4+
"creator": {
5+
"comment": "persister:fs",
6+
"name": "Polly.JS",
7+
"version": "6.0.4"
8+
},
9+
"entries": [
10+
{
11+
"_id": "1eef1be924c87eb2f7227ce2a5cf1bca",
12+
"_order": 0,
13+
"cache": {},
14+
"request": {
15+
"bodySize": 289,
16+
"cookies": [],
17+
"headers": [
18+
{
19+
"_fromType": "array",
20+
"name": "accept",
21+
"value": "application/json"
22+
},
23+
{
24+
"_fromType": "array",
25+
"name": "content-type",
26+
"value": "application/json"
27+
}
28+
],
29+
"headersSize": 572,
30+
"httpVersion": "HTTP/1.1",
31+
"method": "POST",
32+
"postData": {
33+
"mimeType": "application/json",
34+
"params": [],
35+
"text": "{\"compute\":[{\"aggregation\":\"count\",\"interval\":\"5m\",\"type\":\"timeseries\"}],\"filter\":{\"from\":\"now-15m\",\"indexes\":[\"main\"],\"query\":\"*\",\"to\":\"now\"},\"group_by\":[{\"facet\":\"host\",\"missing\":\"miss\",\"sort\":{\"aggregation\":\"pc90\",\"metric\":\"@duration\",\"order\":\"asc\",\"type\":\"measure\"},\"total\":\"recall\"}]}"
36+
},
37+
"queryString": [],
38+
"url": "https://api.datadoghq.com/api/v2/logs/analytics/aggregate"
39+
},
40+
"response": {
41+
"bodySize": 2962,
42+
"content": {
43+
"mimeType": "application/json",
44+
"size": 2962,
45+
"text": "{\"meta\":{\"status\":\"done\",\"request_id\":\"pddv1ChZjajVGdnloOFRydURjT01RakZPRGJRIiwKHAubHcvWGIRKaJwUb1Qgc-peEYojhMk6Z3opAHYSDOMLcdT0IUoqNWaYdA\",\"elapsed\":10},\"data\":{\"buckets\":[{\"computes\":{\"c0\":[{\"value\":28,\"time\":\"2022-02-23T10:40:00.000Z\"},{\"value\":80,\"time\":\"2022-02-23T10:45:00.000Z\"},{\"value\":80,\"time\":\"2022-02-23T10:50:00.000Z\"},{\"value\":42,\"time\":\"2022-02-23T10:55:00.000Z\"}]},\"by\":{\"host\":\"07266d86-ec5b-40cb-4060-e4d9\"}},{\"computes\":{\"c0\":[{\"value\":32,\"time\":\"2022-02-23T10:40:00.000Z\"},{\"value\":80,\"time\":\"2022-02-23T10:45:00.000Z\"},{\"value\":80,\"time\":\"2022-02-23T10:50:00.000Z\"},{\"value\":40,\"time\":\"2022-02-23T10:55:00.000Z\"}]},\"by\":{\"host\":\"4a5a50c3-5d34-4009-74aa-38d8\"}},{\"computes\":{\"c0\":[{\"value\":28,\"time\":\"2022-02-23T10:40:00.000Z\"},{\"value\":80,\"time\":\"2022-02-23T10:45:00.000Z\"},{\"value\":80,\"time\":\"2022-02-23T10:50:00.000Z\"},{\"value\":44,\"time\":\"2022-02-23T10:55:00.000Z\"}]},\"by\":{\"host\":\"3a1410f9-5b3b-44a8-52bc-5269\"}},{\"computes\":{\"c0\":[{\"value\":32,\"time\":\"2022-02-23T10:40:00.000Z\"},{\"value\":80,\"time\":\"2022-02-23T10:45:00.000Z\"},{\"value\":80,\"time\":\"2022-02-23T10:50:00.000Z\"},{\"value\":42,\"time\":\"2022-02-23T10:55:00.000Z\"}]},\"by\":{\"host\":\"e17b600e-a2cf-4d23-4eb2-e648\"}},{\"computes\":{\"c0\":[{\"value\":28,\"time\":\"2022-02-23T10:40:00.000Z\"},{\"value\":80,\"time\":\"2022-02-23T10:45:00.000Z\"},{\"value\":80,\"time\":\"2022-02-23T10:50:00.000Z\"},{\"value\":44,\"time\":\"2022-02-23T10:55:00.000Z\"}]},\"by\":{\"host\":\"3a6c8709-df68-49b2-5992-351d\"}},{\"computes\":{\"c0\":[{\"value\":28,\"time\":\"2022-02-23T10:40:00.000Z\"},{\"value\":80,\"time\":\"2022-02-23T10:45:00.000Z\"},{\"value\":80,\"time\":\"2022-02-23T10:50:00.000Z\"},{\"value\":42,\"time\":\"2022-02-23T10:55:00.000Z\"}]},\"by\":{\"host\":\"f301493f-d994-4237-4a99-b382\"}},{\"computes\":{\"c0\":[{\"value\":28,\"time\":\"2022-02-23T10:40:00.000Z\"},{\"value\":80,\"time\":\"2022-02-23T10:45:00.000Z\"},{\"value\":80,\"time\":\"2022-02-23T10:50:00.000Z\"},{\"value\":42,\"time\":\"2022-02-23T10:55:00.000Z\"}]},\"by\":{\"host\":\"4d77dd12-b3be-41fd-753b-fcbb\"}},{\"computes\":{\"c0\":[{\"value\":32,\"time\":\"2022-02-23T10:40:00.000Z\"},{\"value\":80,\"time\":\"2022-02-23T10:45:00.000Z\"},{\"value\":80,\"time\":\"2022-02-23T10:50:00.000Z\"},{\"value\":40,\"time\":\"2022-02-23T10:55:00.000Z\"}]},\"by\":{\"host\":\"2961e831-36b5-4c2b-5853-b6d5\"}},{\"computes\":{\"c0\":[{\"value\":32,\"time\":\"2022-02-23T10:40:00.000Z\"},{\"value\":80,\"time\":\"2022-02-23T10:45:00.000Z\"},{\"value\":80,\"time\":\"2022-02-23T10:50:00.000Z\"},{\"value\":42,\"time\":\"2022-02-23T10:55:00.000Z\"}]},\"by\":{\"host\":\"cec04667-4f47-4d64-4bf1-b449\"}},{\"computes\":{\"c0\":[{\"value\":32,\"time\":\"2022-02-23T10:40:00.000Z\"},{\"value\":80,\"time\":\"2022-02-23T10:45:00.000Z\"},{\"value\":80,\"time\":\"2022-02-23T10:50:00.000Z\"},{\"value\":42,\"time\":\"2022-02-23T10:55:00.000Z\"}]},\"by\":{\"host\":\"352e5c4f-9d7d-4b5e-414f-4199\"}},{\"computes\":{\"c0\":[{\"value\":332,\"time\":\"2022-02-23T10:40:00.000Z\"},{\"value\":880,\"time\":\"2022-02-23T10:45:00.000Z\"},{\"value\":880,\"time\":\"2022-02-23T10:50:00.000Z\"},{\"value\":460,\"time\":\"2022-02-23T10:55:00.000Z\"}]},\"by\":{\"host\":\"recall\"}}]}}"
46+
},
47+
"cookies": [],
48+
"headers": [
49+
{
50+
"name": "content-type",
51+
"value": "application/json"
52+
}
53+
],
54+
"headersSize": 686,
55+
"httpVersion": "HTTP/1.1",
56+
"redirectURL": "",
57+
"status": 200,
58+
"statusText": "OK"
59+
},
60+
"startedDateTime": "2022-02-23T10:58:05.787Z",
61+
"time": 516
62+
}
63+
],
64+
"pages": [],
65+
"version": "1.2"
66+
}
67+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/**
2+
* Aggregate compute events with group by returns "OK" response
3+
*/
4+
5+
import { v2 } from "@datadog/datadog-api-client";
6+
7+
const configuration = v2.createConfiguration();
8+
const apiInstance = new v2.LogsApi(configuration);
9+
10+
let params: v2.LogsApiAggregateLogsRequest = {
11+
body: {
12+
compute: [
13+
{
14+
aggregation: "count",
15+
interval: "5m",
16+
type: "timeseries",
17+
},
18+
],
19+
filter: {
20+
from: "now-15m",
21+
indexes: ["main"],
22+
query: "*",
23+
to: "now",
24+
},
25+
groupBy: [
26+
{
27+
facet: "host",
28+
missing: "miss",
29+
sort: {
30+
type: "measure",
31+
order: "asc",
32+
aggregation: "pc90",
33+
metric: "@duration",
34+
},
35+
total: "recall",
36+
},
37+
],
38+
},
39+
};
40+
41+
apiInstance
42+
.aggregateLogs(params)
43+
.then((data: v2.LogsAggregateResponse) => {
44+
console.log(
45+
"API called successfully. Returned data: " + JSON.stringify(data)
46+
);
47+
})
48+
.catch((error: any) => console.error(error));

features/v2/logs.feature

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,14 @@ Feature: Logs
1414
When the request is sent
1515
Then the response status is 200 OK
1616

17+
@team:DataDog/logs-app
18+
Scenario: Aggregate compute events with group by returns "OK" response
19+
Given a valid "appKeyAuth" key in the system
20+
And new "AggregateLogs" request
21+
And body with value {"compute": [{"aggregation": "count", "interval": "5m", "type": "timeseries"}], "filter": {"from": "now-15m", "indexes": ["main"], "query": "*", "to": "now"}, "group_by": [{"facet": "host", "missing": "miss", "sort": {"type": "measure", "order": "asc", "aggregation": "pc90", "metric": "@duration"}, "total": "recall"}]}
22+
When the request is sent
23+
Then the response status is 200 OK
24+
1725
@generated @skip @team:DataDog/logs-app
1826
Scenario: Aggregate events returns "Bad Request" response
1927
Given a valid "appKeyAuth" key in the system

packages/datadog-api-client-v1/models/ObjectSerializer.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -505,7 +505,6 @@ const primitives = [
505505
"long",
506506
"float",
507507
"number",
508-
"any",
509508
];
510509

511510
const ARRAY_PREFIX = "Array<";
@@ -1799,9 +1798,12 @@ const oneOfMap: { [index: string]: string[] } = {
17991798

18001799
export class ObjectSerializer {
18011800
public static serialize(data: any, type: string, format: string): any {
1802-
if (data == undefined) {
1801+
if (data == undefined || type == "any") {
18031802
return data;
1804-
} else if (primitives.includes(type.toLowerCase())) {
1803+
} else if (
1804+
primitives.includes(type.toLowerCase()) &&
1805+
typeof data == type.toLowerCase()
1806+
) {
18051807
return data;
18061808
} else if (type.startsWith(ARRAY_PREFIX)) {
18071809
// Array<Type> => Type
@@ -1913,9 +1915,12 @@ export class ObjectSerializer {
19131915
}
19141916

19151917
public static deserialize(data: any, type: string, format = ""): any {
1916-
if (data == undefined) {
1918+
if (data == undefined || type == "any") {
19171919
return data;
1918-
} else if (primitives.includes(type.toLowerCase())) {
1920+
} else if (
1921+
primitives.includes(type.toLowerCase()) &&
1922+
typeof data == type.toLowerCase()
1923+
) {
19191924
return data;
19201925
} else if (type.startsWith(ARRAY_PREFIX)) {
19211926
// Array<Type> => Type

packages/datadog-api-client-v2/models/ObjectSerializer.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,6 @@ const primitives = [
307307
"long",
308308
"float",
309309
"number",
310-
"any",
311310
];
312311

313312
const ARRAY_PREFIX = "Array<";
@@ -832,9 +831,12 @@ const oneOfMap: { [index: string]: string[] } = {
832831

833832
export class ObjectSerializer {
834833
public static serialize(data: any, type: string, format: string): any {
835-
if (data == undefined) {
834+
if (data == undefined || type == "any") {
836835
return data;
837-
} else if (primitives.includes(type.toLowerCase())) {
836+
} else if (
837+
primitives.includes(type.toLowerCase()) &&
838+
typeof data == type.toLowerCase()
839+
) {
838840
return data;
839841
} else if (type.startsWith(ARRAY_PREFIX)) {
840842
// Array<Type> => Type
@@ -946,9 +948,12 @@ export class ObjectSerializer {
946948
}
947949

948950
public static deserialize(data: any, type: string, format = ""): any {
949-
if (data == undefined) {
951+
if (data == undefined || type == "any") {
950952
return data;
951-
} else if (primitives.includes(type.toLowerCase())) {
953+
} else if (
954+
primitives.includes(type.toLowerCase()) &&
955+
typeof data == type.toLowerCase()
956+
) {
952957
return data;
953958
} else if (type.startsWith(ARRAY_PREFIX)) {
954959
// Array<Type> => Type

0 commit comments

Comments
 (0)