Skip to content

Commit b5e4e1d

Browse files
api-clients-generation-pipeline[bot]therveci.datadog-api-spec
authored
Add hourly usage v2 endpoint (#749)
* Handle multiple chars to escape in BDD parameters * Regenerate client from commit 448d6aae 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 4d73088 commit b5e4e1d

File tree

19 files changed

+954
-5
lines changed

19 files changed

+954
-5
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-07-19 15:15:39.466629",
8-
"spec_repo_commit": "d2c0157b"
7+
"regenerated": "2022-07-19 16:28:33.415866",
8+
"spec_repo_commit": "448d6aae"
99
},
1010
"v2": {
1111
"apigentools_version": "1.6.2",
12-
"regenerated": "2022-07-19 15:15:39.506219",
13-
"spec_repo_commit": "d2c0157b"
12+
"regenerated": "2022-07-19 16:28:33.428437",
13+
"spec_repo_commit": "448d6aae"
1414
}
1515
}
1616
}

.generator/schemas/v2/openapi.yaml

Lines changed: 192 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1683,6 +1683,84 @@ components:
16831683
required:
16841684
- message
16851685
type: object
1686+
HourlyUsage:
1687+
description: Hourly usage for a product family for an org.
1688+
properties:
1689+
attributes:
1690+
$ref: '#/components/schemas/HourlyUsageAttributes'
1691+
id:
1692+
description: Unique ID of the response.
1693+
type: string
1694+
type:
1695+
$ref: '#/components/schemas/UsageTimeSeriesType'
1696+
type: object
1697+
HourlyUsageAttributes:
1698+
description: Attributes of hourly usage for a product family for an org for
1699+
a time period.
1700+
properties:
1701+
measurements:
1702+
description: List of the measured usage values for the product family for
1703+
the org for the time period.
1704+
items:
1705+
$ref: '#/components/schemas/HourlyUsageMeasurement'
1706+
type: array
1707+
org_name:
1708+
description: The organization name.
1709+
type: string
1710+
product_family:
1711+
description: The product for which usage is being reported.
1712+
type: string
1713+
public_id:
1714+
description: The organization public ID.
1715+
type: string
1716+
region:
1717+
description: The region of the Datadog instance that the organization belongs
1718+
to.
1719+
type: string
1720+
timestamp:
1721+
description: Datetime in ISO-8601 format, UTC. The hour for the usage.
1722+
format: date-time
1723+
type: string
1724+
type: object
1725+
HourlyUsageMeasurement:
1726+
description: Usage amount for a given usage type.
1727+
properties:
1728+
usage_type:
1729+
description: Type of usage.
1730+
type: string
1731+
value:
1732+
description: Contains the number measured for the given usage_type during
1733+
the hour.
1734+
format: int64
1735+
nullable: true
1736+
type: integer
1737+
type: object
1738+
HourlyUsageMetadata:
1739+
description: The object containing document metadata.
1740+
properties:
1741+
pagination:
1742+
$ref: '#/components/schemas/HourlyUsagePagination'
1743+
type: object
1744+
HourlyUsagePagination:
1745+
description: The metadata for the current pagination.
1746+
properties:
1747+
next_record_id:
1748+
description: The cursor to get the next results (if any). To make the next
1749+
request, use the same parameters and add `next_record_id`.
1750+
nullable: true
1751+
type: string
1752+
type: object
1753+
HourlyUsageResponse:
1754+
description: Hourly usage response.
1755+
properties:
1756+
data:
1757+
description: Response containing hourly usage.
1758+
items:
1759+
$ref: '#/components/schemas/HourlyUsage'
1760+
type: array
1761+
meta:
1762+
$ref: '#/components/schemas/HourlyUsageMetadata'
1763+
type: object
16861764
HourlyUsageType:
16871765
description: Usage type that is being measured.
16881766
enum:
@@ -13382,6 +13460,120 @@ paths:
1338213460
x-menu-order: 39
1338313461
x-undo:
1338413462
type: safe
13463+
/api/v2/usage/hourly_usage:
13464+
get:
13465+
description: Get hourly usage by product family
13466+
operationId: GetHourlyUsage
13467+
parameters:
13468+
- description: 'Datetime in ISO-8601 format, UTC, precise to hour: [YYYY-MM-DDThh]
13469+
for usage beginning at this hour.'
13470+
in: query
13471+
name: filter[timestamp][start]
13472+
required: true
13473+
schema:
13474+
format: date-time
13475+
type: string
13476+
- description: 'Datetime in ISO-8601 format, UTC, precise to hour: [YYYY-MM-DDThh]
13477+
for usage ending **before** this hour.'
13478+
in: query
13479+
name: filter[timestamp][end]
13480+
required: false
13481+
schema:
13482+
format: date-time
13483+
type: string
13484+
- description: 'Comma separated list of product families to retrieve. Available
13485+
families are `all`, `analyzed_logs`,
13486+
13487+
`application_security`, `audit_logs`, `serverless`, `ci_app`, `cspm`, `cws`,
13488+
`dbm`, `fargate`,
13489+
13490+
`infra_hosts`, `incident_management`, `indexed_logs`, `indexed_spans`, `ingested_spans`,
13491+
`iot`,
13492+
13493+
`lambda_traced_invocations`, `logs`, `network_flows`, `network_hosts`, `observability_pipelines`,
13494+
13495+
`online_archive`, `profiling`, `rum`, `rum_browser_sessions`, `rum_mobile_sessions`,
13496+
`sds`, `snmp`,
13497+
13498+
`synthetics_api`, `synthetics_browser`, and `timeseries`.'
13499+
in: query
13500+
name: filter[product_families]
13501+
required: true
13502+
schema:
13503+
type: string
13504+
- description: Include child org usage in the response. Defaults to false.
13505+
in: query
13506+
name: filter[include_descendants]
13507+
required: false
13508+
schema:
13509+
default: false
13510+
type: boolean
13511+
- description: 'Comma separated list of product family versions to use in the
13512+
format `product_family:version`. For example,
13513+
13514+
`infra_hosts:1.0.0`. If this parameter is not used, the API will use the
13515+
latest version of each requested
13516+
13517+
product family. Currently all families have one version `1.0.0`.'
13518+
in: query
13519+
name: filter[versions]
13520+
required: false
13521+
schema:
13522+
type: string
13523+
- description: Maximum number of results to return (between 1 and 500) - defaults
13524+
to 500 if limit not specified.
13525+
in: query
13526+
name: page[limit]
13527+
required: false
13528+
schema:
13529+
default: 500
13530+
format: int32
13531+
maximum: 500
13532+
minimum: 1
13533+
type: integer
13534+
- description: List following results with a next_record_id provided in the
13535+
previous query.
13536+
in: query
13537+
name: page[next_record_id]
13538+
required: false
13539+
schema:
13540+
type: string
13541+
responses:
13542+
'200':
13543+
content:
13544+
application/json;datetime-format=rfc3339:
13545+
schema:
13546+
$ref: '#/components/schemas/HourlyUsageResponse'
13547+
description: OK
13548+
'400':
13549+
content:
13550+
application/json;datetime-format=rfc3339:
13551+
schema:
13552+
$ref: '#/components/schemas/APIErrorResponse'
13553+
description: Bad Request
13554+
'403':
13555+
content:
13556+
application/json;datetime-format=rfc3339:
13557+
schema:
13558+
$ref: '#/components/schemas/APIErrorResponse'
13559+
description: Forbidden - User is not authorized
13560+
'429':
13561+
content:
13562+
application/json;datetime-format=rfc3339:
13563+
schema:
13564+
$ref: '#/components/schemas/APIErrorResponse'
13565+
description: Too many requests
13566+
security:
13567+
- apiKeyAuth: []
13568+
appKeyAuth: []
13569+
- AuthZ:
13570+
- usage_read
13571+
summary: Get hourly usage by product family
13572+
tags:
13573+
- Usage Metering
13574+
x-menu-order: 40
13575+
x-undo:
13576+
type: safe
1338513577
/api/v2/usage/lambda_traced_invocations:
1338613578
get:
1338713579
description: Get hourly usage for Lambda Traced Invocations.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
"2022-07-19T14:57:41.335Z"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
{
2+
"log": {
3+
"_recordingName": "Usage Metering/Get hourly usage by product family returns \"Bad Request\" response",
4+
"creator": {
5+
"comment": "persister:fs",
6+
"name": "Polly.JS",
7+
"version": "6.0.5"
8+
},
9+
"entries": [
10+
{
11+
"_id": "cc496d18a216a654906e24e1671e2b27",
12+
"_order": 0,
13+
"cache": {},
14+
"request": {
15+
"bodySize": 0,
16+
"cookies": [],
17+
"headers": [
18+
{
19+
"_fromType": "array",
20+
"name": "accept",
21+
"value": "application/json;datetime-format=rfc3339"
22+
}
23+
],
24+
"headersSize": 700,
25+
"httpVersion": "HTTP/1.1",
26+
"method": "GET",
27+
"queryString": [
28+
{
29+
"name": "filter",
30+
"value": {
31+
"product_families": "infra_hosts",
32+
"timestamp": {
33+
"end": "2022-07-14T14:57:41.335Z",
34+
"start": "2022-07-16T14:57:41.335Z"
35+
}
36+
}
37+
}
38+
],
39+
"url": "https://api.datadoghq.com/api/v2/usage/hourly_usage?filter%5Btimestamp%5D%5Bstart%5D=2022-07-16T14%3A57%3A41.335Z&filter%5Btimestamp%5D%5Bend%5D=2022-07-14T14%3A57%3A41.335Z&filter%5Bproduct_families%5D=infra_hosts"
40+
},
41+
"response": {
42+
"bodySize": 78,
43+
"content": {
44+
"mimeType": "application/json",
45+
"size": 78,
46+
"text": "{\"errors\":[\"start_hr [YYYY-MM-DDThh] must be before end_hr [YYYY-MM-DDThh]\"]}\n"
47+
},
48+
"cookies": [],
49+
"headers": [
50+
{
51+
"name": "content-type",
52+
"value": "application/json"
53+
}
54+
],
55+
"headersSize": 665,
56+
"httpVersion": "HTTP/1.1",
57+
"redirectURL": "",
58+
"status": 400,
59+
"statusText": "Bad Request"
60+
},
61+
"startedDateTime": "2022-07-19T14:57:41.355Z",
62+
"time": 455
63+
}
64+
],
65+
"pages": [],
66+
"version": "1.2"
67+
}
68+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
"2022-07-19T14:57:41.821Z"

cassettes/v2/Usage-Metering_938753175/Get-hourly-usage-by-product-family-returns-OK-response_1090591163/recording.har

Lines changed: 67 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/**
2+
* Get hourly usage by product family returns "OK" response
3+
*/
4+
5+
import { client, v2 } from "@datadog/datadog-api-client";
6+
7+
const configuration = client.createConfiguration();
8+
const apiInstance = new v2.UsageMeteringApi(configuration);
9+
10+
const params: v2.UsageMeteringApiGetHourlyUsageRequest = {
11+
filterTimestampStart: new Date(new Date().getTime() / 1000 + -3 * 86400),
12+
filterProductFamilies: "infra_hosts",
13+
};
14+
15+
apiInstance
16+
.getHourlyUsage(params)
17+
.then((data: v2.HourlyUsageResponse) => {
18+
console.log(
19+
"API called successfully. Returned data: " + JSON.stringify(data)
20+
);
21+
})
22+
.catch((error: any) => console.error(error));

features/support/templating.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ String.prototype.toOperationName = function (): string {
106106

107107
String.prototype.toAttributeName = function (): string {
108108
return String(this)
109-
.replace(/[^A-Za-z0-9](.)/g, function (...matches) {
109+
.replace(/[^A-Za-z0-9]+(.)/g, function (...matches) {
110110
return matches[1].toUpperCase();
111111
})
112112
.replace(/[^A-Za-z0-9]+/g, "");

features/v2/undo.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -867,6 +867,12 @@
867867
"type": "safe"
868868
}
869869
},
870+
"GetHourlyUsage": {
871+
"tag": "Usage Metering",
872+
"undo": {
873+
"type": "safe"
874+
}
875+
},
870876
"GetUsageLambdaTracedInvocations": {
871877
"tag": "Usage Metering",
872878
"undo": {

features/v2/usage_metering.feature

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,23 @@ Feature: Usage Metering
5858
When the request is sent
5959
Then the response status is 200 OK
6060

61+
@team:DataDog/red-zone-revenue-query
62+
Scenario: Get hourly usage by product family returns "Bad Request" response
63+
Given new "GetHourlyUsage" request
64+
And request contains "filter[timestamp][start]" parameter with value "{{ timeISO('now - 3d') }}"
65+
And request contains "filter[product_families]" parameter with value "infra_hosts"
66+
And request contains "filter[timestamp][end]" parameter with value "{{ timeISO('now - 5d') }}"
67+
When the request is sent
68+
Then the response status is 400 Bad Request
69+
70+
@team:DataDog/red-zone-revenue-query
71+
Scenario: Get hourly usage by product family returns "OK" response
72+
Given new "GetHourlyUsage" request
73+
And request contains "filter[timestamp][start]" parameter with value "{{ timeISO('now - 3d') }}"
74+
And request contains "filter[product_families]" parameter with value "infra_hosts"
75+
When the request is sent
76+
Then the response status is 200 OK
77+
6178
@team:DataDog/red-zone-revenue-query
6279
Scenario: Get hourly usage for Application Security returns "Bad Request" response
6380
Given new "GetUsageApplicationSecurityMonitoring" request

0 commit comments

Comments
 (0)