Skip to content

Commit 78014e9

Browse files
api-clients-generation-pipeline[bot]skarimoci.datadog-api-spec
authored
Add distribution points intake endpoint (#1019)
* fix model and example generation * attempt to fix python examples * remove item created by merge * Regenerate client from commit 4569968f of spec repo Co-authored-by: Sherzod K <[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 d40d2d6 commit 78014e9

17 files changed

+702
-24
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-06-09 11:12:56.877550",
8-
"spec_repo_commit": "b9e36dc8"
7+
"regenerated": "2022-06-10 18:23:54.710325",
8+
"spec_repo_commit": "4569968f"
99
},
1010
"v2": {
1111
"apigentools_version": "1.6.2",
12-
"regenerated": "2022-06-09 11:12:56.889464",
13-
"spec_repo_commit": "b9e36dc8"
12+
"regenerated": "2022-06-10 18:23:54.722867",
13+
"spec_repo_commit": "4569968f"
1414
}
1515
}
1616
}

.generator/schemas/v1/openapi.yaml

Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1299,6 +1299,96 @@ components:
12991299
type: integer
13001300
readOnly: true
13011301
type: object
1302+
DistributionPoint:
1303+
description: Array of distribution points.
1304+
example:
1305+
- 1575317847.0
1306+
- - 0.5
1307+
- 1.0
1308+
items:
1309+
description: List of distribution point.
1310+
oneOf:
1311+
- $ref: '#/components/schemas/DistributionPointTimestamp'
1312+
- $ref: '#/components/schemas/DistributionPointData'
1313+
maxItems: 2
1314+
minItems: 2
1315+
type: array
1316+
DistributionPointData:
1317+
description: Distribution point data.
1318+
items:
1319+
description: List of distribution point data.
1320+
format: double
1321+
type: number
1322+
type: array
1323+
DistributionPointTimestamp:
1324+
description: Distribution point timestamp. It should be in seconds and current.
1325+
format: double
1326+
type: number
1327+
DistributionPointsContentEncoding:
1328+
description: HTTP header used to compress the media-type.
1329+
enum:
1330+
- deflate
1331+
type: string
1332+
x-enum-varnames:
1333+
- DEFLATE
1334+
DistributionPointsPayload:
1335+
description: The distribution points payload.
1336+
properties:
1337+
series:
1338+
description: A list of distribution points series to submit to Datadog.
1339+
example:
1340+
- metric: system.load.1
1341+
points:
1342+
- - 1475317847.0
1343+
- - 1.0
1344+
- 2.0
1345+
items:
1346+
$ref: '#/components/schemas/DistributionPointsSeries'
1347+
type: array
1348+
required:
1349+
- series
1350+
type: object
1351+
DistributionPointsSeries:
1352+
description: A distribution points metric to submit to Datadog.
1353+
properties:
1354+
host:
1355+
description: The name of the host that produced the distribution point metric.
1356+
example: test.example.com
1357+
type: string
1358+
metric:
1359+
description: The name of the distribution points metric.
1360+
example: system.load.1
1361+
type: string
1362+
points:
1363+
description: Points relating to the distribution point metric. All points
1364+
must be tuples with timestamp and a list of values (cannot be a string).
1365+
Timestamps should be in POSIX time in seconds.
1366+
items:
1367+
$ref: '#/components/schemas/DistributionPoint'
1368+
type: array
1369+
tags:
1370+
description: A list of tags associated with the distribution point metric.
1371+
example:
1372+
- environment:test
1373+
items:
1374+
description: Individual tags.
1375+
type: string
1376+
type: array
1377+
type:
1378+
$ref: '#/components/schemas/DistributionPointsType'
1379+
required:
1380+
- metric
1381+
- points
1382+
type: object
1383+
DistributionPointsType:
1384+
default: distribution
1385+
description: The type of the distribution point.
1386+
enum:
1387+
- distribution
1388+
example: distribution
1389+
type: string
1390+
x-enum-varnames:
1391+
- DISTRIBUTION
13021392
DistributionWidgetDefinition:
13031393
description: "The Distribution visualization is another way of showing metrics\naggregated
13041394
across one or several tags, such as hosts.\nUnlike the heat map, a distribution
@@ -18016,6 +18106,74 @@ paths:
1801618106
x-menu-order: 6
1801718107
x-undo:
1801818108
type: idempotent
18109+
/api/v1/distribution_points:
18110+
post:
18111+
description: "The distribution points end-point allows you to post distribution
18112+
data that can be graphed on Datadog\u2019s dashboards."
18113+
operationId: SubmitDistributionPoints
18114+
parameters:
18115+
- description: HTTP header used to compress the media-type.
18116+
in: header
18117+
name: Content-Encoding
18118+
required: false
18119+
schema:
18120+
$ref: '#/components/schemas/DistributionPointsContentEncoding'
18121+
requestBody:
18122+
content:
18123+
text/json:
18124+
examples:
18125+
dynamic-points:
18126+
description: "Post time-series data that can be graphed on Datadog\u2019s
18127+
dashboards."
18128+
externalValue: examples/metrics/distribution-points.json.sh
18129+
summary: Dynamic Points
18130+
x-variables:
18131+
NOW: $(date +%s)
18132+
schema:
18133+
$ref: '#/components/schemas/DistributionPointsPayload'
18134+
required: true
18135+
responses:
18136+
'202':
18137+
content:
18138+
text/json:
18139+
schema:
18140+
$ref: '#/components/schemas/IntakePayloadAccepted'
18141+
description: Payload accepted
18142+
'400':
18143+
content:
18144+
text/json:
18145+
schema:
18146+
$ref: '#/components/schemas/APIErrorResponse'
18147+
description: Bad Request
18148+
'403':
18149+
content:
18150+
text/json:
18151+
schema:
18152+
$ref: '#/components/schemas/APIErrorResponse'
18153+
description: Authentication error
18154+
'408':
18155+
content:
18156+
text/json:
18157+
schema:
18158+
$ref: '#/components/schemas/APIErrorResponse'
18159+
description: Request timeout
18160+
'413':
18161+
content:
18162+
text/json:
18163+
schema:
18164+
$ref: '#/components/schemas/APIErrorResponse'
18165+
description: Payload too large
18166+
'429':
18167+
$ref: '#/components/responses/TooManyRequestsResponse'
18168+
security:
18169+
- apiKeyAuth: []
18170+
summary: Submit distribution points
18171+
tags:
18172+
- Metrics
18173+
x-codegen-request-body-name: body
18174+
x-menu-order: 1
18175+
x-undo:
18176+
type: safe
1801918177
/api/v1/downtime:
1802018178
get:
1802118179
description: Get all scheduled downtimes.

.generator/src/generator/formatter.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313

1414
MODEL_IMPORT_TPL = "datadog_api_client.{version}.model.{name}"
15+
PRIMITIVE_TYPES = ["string", "number", "boolean", "integer"]
1516

1617
EDGE_CASES = {}
1718
replacement_file = (
@@ -237,6 +238,24 @@ def format_data_with_schema_list(
237238
assert version is not None
238239
name, imports = get_name_and_imports(schema, version, imports)
239240

241+
if "oneOf" in schema:
242+
for sub_schema in schema["oneOf"]:
243+
try:
244+
value, one_of_imports = format_data_with_schema(
245+
data,
246+
sub_schema,
247+
replace_values=replace_values,
248+
version=version,
249+
)
250+
except (KeyError, ValueError) as e:
251+
continue
252+
# Workaround to not generate schema for primitive nested oneOfs
253+
if sub_schema.get("items", {}).get("type") in PRIMITIVE_TYPES:
254+
return data, imports
255+
256+
return value, one_of_imports
257+
raise ValueError(f"{data} is not valid oneOf {schema}")
258+
240259
parameters = ""
241260
for d in data:
242261
value, extra_imports = format_data_with_schema(

.generator/src/generator/openapi.py

Lines changed: 36 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010

1111
from . import formatter
1212

13+
PRIMITIVE_TYPES = ["string", "number", "boolean", "integer"]
14+
1315
with (pathlib.Path(__file__).parent / "replacement.json").open() as f:
1416
EDGE_CASES = json.load(f)
1517

@@ -20,20 +22,7 @@ def load(filename):
2022
return JsonRef.replace_refs(yaml.load(fp, Loader=CSafeLoader))
2123

2224

23-
def type_to_python(schema, alternative_name=None):
24-
"""Return Python type name for the type."""
25-
name = formatter.get_name(schema)
26-
if name:
27-
if "enum" in schema:
28-
return name
29-
if schema.get("type", "object") in ("object", "array"):
30-
return name
31-
32-
type_ = schema.get("type")
33-
if type_ is None:
34-
if "items" in schema:
35-
type_ = "array"
36-
25+
def type_ty_python_helper(type_, schema, alternative_name=None, in_list=False):
3726
if type_ is None:
3827
return "bool, date, datetime, dict, float, int, list, str, none_type"
3928

@@ -51,7 +40,7 @@ def type_to_python(schema, alternative_name=None):
5140
elif type_ == "boolean":
5241
return "bool"
5342
elif type_ == "array":
54-
return "[{}]".format(type_to_python(schema["items"]))
43+
return "[{}]".format(type_to_python(schema["items"], in_list=True))
5544
elif type_ == "object":
5645
if "additionalProperties" in schema:
5746
nested_schema = schema["additionalProperties"]
@@ -76,6 +65,32 @@ def type_to_python(schema, alternative_name=None):
7665
raise ValueError(f"Unknown type {type_}")
7766

7867

68+
def type_to_python(schema, alternative_name=None, in_list=False):
69+
"""Return Python type name for the type."""
70+
name = formatter.get_name(schema)
71+
if name:
72+
if "enum" in schema:
73+
return name
74+
if schema.get("type", "object") in ("object", "array"):
75+
return name
76+
77+
type_ = schema.get("type")
78+
if type_ is None:
79+
if "oneOf" in schema and in_list:
80+
type_ = ""
81+
for child in schema["oneOf"]:
82+
# We do not generate model for nested primitive oneOfs
83+
if in_list and "items" in child and child["items"].get("type") in PRIMITIVE_TYPES:
84+
type_ += f"{type_ty_python_helper(child.get('type'), child, in_list=in_list)},"
85+
else:
86+
type_ += f"{type_to_python(child, in_list=in_list)},"
87+
return type_
88+
if "items" in schema:
89+
type_ = "array"
90+
91+
return type_ty_python_helper(type_, schema, alternative_name=alternative_name, in_list=in_list)
92+
93+
7994
def get_type_for_attribute(schema, attribute, current_name=None):
8095
"""Return Python type name for the attribute."""
8196
child_schema = schema.get("properties", {}).get(attribute)
@@ -120,7 +135,7 @@ def get_enum_default(model):
120135
return model["enum"][0] if len(model["enum"]) == 1 else model.get("default")
121136

122137

123-
def child_models(schema, alternative_name=None, seen=None):
138+
def child_models(schema, alternative_name=None, seen=None, in_list=False):
124139
seen = seen or set()
125140
current_name = formatter.get_name(schema)
126141
name = current_name or alternative_name
@@ -133,6 +148,9 @@ def child_models(schema, alternative_name=None, seen=None):
133148
if "oneOf" in schema:
134149
has_sub_models = True
135150
for child in schema["oneOf"]:
151+
# Don't generate models for nested primitive types
152+
if in_list and child.get("type") in PRIMITIVE_TYPES:
153+
return
136154
yield from child_models(child, seen=seen)
137155
if "anyOf" in schema:
138156
has_sub_models = True
@@ -144,6 +162,7 @@ def child_models(schema, alternative_name=None, seen=None):
144162
schema["items"],
145163
None,
146164
seen=seen,
165+
in_list=True
147166
)
148167

149168
if schema.get("type") == "object" or "properties" in schema or has_sub_models:
@@ -152,7 +171,7 @@ def child_models(schema, alternative_name=None, seen=None):
152171
return
153172

154173
if name is None:
155-
raise ValueError(f"Schema {schema} has no name")
174+
return
156175

157176
if name in seen:
158177
return

.generator/src/generator/templates/model_simple.j2

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ class {{ name }}(ModelSimple):
5252
}
5353
{%- else %}
5454
return {
55-
"value": ([{{ type_to_python(model.get("items")) }}{%- if model["items"].get("nullable") %}, none_type{%- endif %}],),
55+
"value": ([{{ type_to_python(model.get("items"), in_list=True) }}{%- if model["items"].get("nullable") %}, none_type{%- endif %}],),
5656
}
5757
{%- endif %}
5858

@@ -68,7 +68,7 @@ class {{ name }}(ModelSimple):
6868
{%- if ref %}
6969
:type value: [{{ ref }}]
7070
{%- else %}
71-
:type value: [{{ type_to_python(model.get("items")) }}{%- if model["items"].get("nullable") %}, none_type{%- endif %}]
71+
:type value: [{{ type_to_python(model.get("items"), in_list=True) }}{%- if model["items"].get("nullable") %}, none_type{%- endif %}]
7272
{%- endif %}
7373
"""
7474
super().__init__(kwargs)

docs/datadog_api_client.v1.model.rst

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -470,6 +470,41 @@ deleted\_monitor
470470
:members:
471471
:show-inheritance:
472472

473+
distribution\_point
474+
-------------------
475+
476+
.. automodule:: datadog_api_client.v1.model.distribution_point
477+
:members:
478+
:show-inheritance:
479+
480+
distribution\_points\_content\_encoding
481+
---------------------------------------
482+
483+
.. automodule:: datadog_api_client.v1.model.distribution_points_content_encoding
484+
:members:
485+
:show-inheritance:
486+
487+
distribution\_points\_payload
488+
-----------------------------
489+
490+
.. automodule:: datadog_api_client.v1.model.distribution_points_payload
491+
:members:
492+
:show-inheritance:
493+
494+
distribution\_points\_series
495+
----------------------------
496+
497+
.. automodule:: datadog_api_client.v1.model.distribution_points_series
498+
:members:
499+
:show-inheritance:
500+
501+
distribution\_points\_type
502+
--------------------------
503+
504+
.. automodule:: datadog_api_client.v1.model.distribution_points_type
505+
:members:
506+
:show-inheritance:
507+
473508
distribution\_widget\_definition
474509
--------------------------------
475510

0 commit comments

Comments
 (0)