datadog_api_client 2.13.0 → 2.15.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (148) hide show
  1. checksums.yaml +4 -4
  2. data/.apigentools-info +4 -4
  3. data/.generator/schemas/v1/openapi.yaml +346 -36
  4. data/.generator/schemas/v2/openapi.yaml +436 -174
  5. data/.generator/src/generator/formatter.py +34 -29
  6. data/.generator/src/generator/openapi.py +3 -1
  7. data/.generator/src/generator/templates/api.j2 +8 -2
  8. data/.generator/src/generator/templates/api_client.j2 +81 -53
  9. data/.generator/src/generator/templates/configuration.j2 +21 -0
  10. data/.pre-commit-config.yaml +2 -2
  11. data/CHANGELOG.md +57 -0
  12. data/README.md +23 -0
  13. data/examples/v1/azure-integration/CreateAzureIntegration.rb +3 -0
  14. data/examples/v1/azure-integration/DeleteAzureIntegration.rb +3 -0
  15. data/examples/v1/azure-integration/UpdateAzureHostFilters.rb +3 -0
  16. data/examples/v1/azure-integration/UpdateAzureIntegration.rb +3 -0
  17. data/examples/v1/dashboards/CreateDashboard_252716965.rb +6 -0
  18. data/examples/v1/dashboards/CreateDashboard_2618036642.rb +36 -0
  19. data/examples/v1/dashboards/CreateDashboard_2705593938.rb +3 -0
  20. data/examples/v1/dashboards/CreateDashboard_3777304439.rb +50 -0
  21. data/examples/v1/dashboards/DeletePublicDashboardInvitation.rb +3 -3
  22. data/examples/v1/dashboards/ListDashboards_1062671515.rb +8 -0
  23. data/examples/v1/monitors/ListMonitors_2966492814.rb +8 -0
  24. data/examples/v1/notebooks/ListNotebooks_788665428.rb +8 -0
  25. data/examples/v1/service-level-objective-corrections/ListSLOCorrection_2647266873.rb +8 -0
  26. data/examples/v1/service-level-objectives/ListSLOs_3036942817.rb +8 -0
  27. data/examples/v1/synthetics/CreateSyntheticsAPITest_1487281163.rb +2 -0
  28. data/examples/v1/synthetics/ListTests_1938827783.rb +8 -0
  29. data/examples/v2/ci-visibility-pipelines/CreateCIAppPipelineEvent.rb +3 -0
  30. data/examples/v2/ci-visibility-pipelines/CreateCIAppPipelineEvent_129899466.rb +3 -0
  31. data/examples/v2/downtimes/CancelDowntime.rb +0 -3
  32. data/examples/v2/downtimes/CreateDowntime.rb +0 -3
  33. data/examples/v2/downtimes/GetDowntime.rb +0 -3
  34. data/examples/v2/downtimes/ListDowntimes.rb +0 -3
  35. data/examples/v2/downtimes/ListDowntimes_805770330.rb +8 -0
  36. data/examples/v2/downtimes/ListMonitorDowntimes.rb +0 -3
  37. data/examples/v2/downtimes/ListMonitorDowntimes_128979780.rb +0 -3
  38. data/examples/v2/downtimes/UpdateDowntime.rb +0 -3
  39. data/examples/v2/logs/AggregateLogs_2955613758.rb +1 -1
  40. data/examples/v2/security-monitoring/CreateSecurityMonitoringRule_1092490364.rb +1 -1
  41. data/examples/v2/security-monitoring/UpdateSecurityMonitoringRule_428087276.rb +1 -1
  42. data/examples/v2/teams/CreateTeam.rb +2 -2
  43. data/examples/v2/teams/CreateTeam_252121814.rb +24 -0
  44. data/examples/v2/teams/GetUserMemberships.rb +8 -0
  45. data/examples/v2/teams/ListTeams_3592098458.rb +8 -0
  46. data/examples/v2/teams/UpdateTeam.rb +9 -0
  47. data/examples/v2/users/ListUsers_4075885358.rb +8 -0
  48. data/lib/datadog_api_client/api_client.rb +81 -53
  49. data/lib/datadog_api_client/configuration.rb +22 -6
  50. data/lib/datadog_api_client/inflector.rb +11 -1
  51. data/lib/datadog_api_client/v1/api/dashboards_api.rb +25 -0
  52. data/lib/datadog_api_client/v1/api/monitors_api.rb +22 -0
  53. data/lib/datadog_api_client/v1/api/notebooks_api.rb +21 -0
  54. data/lib/datadog_api_client/v1/api/service_level_objective_corrections_api.rb +23 -2
  55. data/lib/datadog_api_client/v1/api/service_level_objectives_api.rb +31 -10
  56. data/lib/datadog_api_client/v1/api/synthetics_api.rb +25 -3
  57. data/lib/datadog_api_client/v1/api/usage_metering_api.rb +3 -3
  58. data/lib/datadog_api_client/v1/models/azure_account.rb +32 -1
  59. data/lib/datadog_api_client/v1/models/distribution_widget_definition.rb +13 -1
  60. data/lib/datadog_api_client/v1/models/heat_map_widget_request.rb +35 -1
  61. data/lib/datadog_api_client/v1/models/hourly_usage_attribution_usage_type.rb +4 -0
  62. data/lib/datadog_api_client/v1/models/list_stream_source.rb +1 -0
  63. data/lib/datadog_api_client/v1/models/monitor.rb +1 -1
  64. data/lib/datadog_api_client/v1/models/monitor_options.rb +1 -1
  65. data/lib/datadog_api_client/v1/models/monthly_usage_attribution_supported_metrics.rb +8 -0
  66. data/lib/datadog_api_client/v1/models/monthly_usage_attribution_values.rb +81 -1
  67. data/lib/datadog_api_client/v1/models/sunburst_widget_request.rb +14 -4
  68. data/lib/datadog_api_client/v1/models/synthetics_assertion_target.rb +11 -1
  69. data/lib/datadog_api_client/v1/models/synthetics_assertion_timings_scope.rb +27 -0
  70. data/lib/datadog_api_client/v1/models/synthetics_test_request.rb +11 -1
  71. data/lib/datadog_api_client/v1/models/usage_ci_visibility_hour.rb +12 -1
  72. data/lib/datadog_api_client/v1/models/usage_profiling_hour.rb +12 -1
  73. data/lib/datadog_api_client/v1/models/usage_summary_date.rb +44 -4
  74. data/lib/datadog_api_client/v1/models/usage_summary_date_org.rb +44 -4
  75. data/lib/datadog_api_client/v1/models/usage_summary_response.rb +44 -4
  76. data/lib/datadog_api_client/v1/models/widget_comparator.rb +1 -0
  77. data/lib/datadog_api_client/v2/api/audit_api.rb +1 -1
  78. data/lib/datadog_api_client/v2/api/ci_visibility_pipelines_api.rb +11 -7
  79. data/lib/datadog_api_client/v2/api/ci_visibility_tests_api.rb +1 -1
  80. data/lib/datadog_api_client/v2/api/downtimes_api.rb +25 -36
  81. data/lib/datadog_api_client/v2/api/events_api.rb +1 -1
  82. data/lib/datadog_api_client/v2/api/ip_allowlist_api.rb +2 -2
  83. data/lib/datadog_api_client/v2/api/logs_api.rb +1 -1
  84. data/lib/datadog_api_client/v2/api/metrics_api.rb +1 -1
  85. data/lib/datadog_api_client/v2/api/processes_api.rb +1 -1
  86. data/lib/datadog_api_client/v2/api/rum_api.rb +1 -1
  87. data/lib/datadog_api_client/v2/api/security_monitoring_api.rb +6 -6
  88. data/lib/datadog_api_client/v2/api/service_definition_api.rb +2 -2
  89. data/lib/datadog_api_client/v2/api/spans_api.rb +1 -1
  90. data/lib/datadog_api_client/v2/api/spans_metrics_api.rb +2 -2
  91. data/lib/datadog_api_client/v2/api/teams_api.rb +87 -0
  92. data/lib/datadog_api_client/v2/api/usage_metering_api.rb +1 -1
  93. data/lib/datadog_api_client/v2/api/users_api.rb +22 -0
  94. data/lib/datadog_api_client/v2/models/application_key_create_attributes.rb +1 -1
  95. data/lib/datadog_api_client/v2/models/application_key_update_attributes.rb +1 -1
  96. data/lib/datadog_api_client/v2/models/audit_logs_event_attributes.rb +11 -1
  97. data/lib/datadog_api_client/v2/models/ci_app_event_attributes.rb +9 -21
  98. data/lib/datadog_api_client/v2/models/ci_app_pipeline_event.rb +1 -1
  99. data/lib/datadog_api_client/v2/models/{team_data.rb → ci_app_pipeline_event_attributes.rb} +24 -62
  100. data/lib/datadog_api_client/v2/models/ci_app_pipeline_level.rb +30 -0
  101. data/lib/datadog_api_client/v2/models/ci_app_pipelines_query_filter.rb +1 -1
  102. data/lib/datadog_api_client/v2/models/ci_app_test_level.rb +29 -0
  103. data/lib/datadog_api_client/v2/models/ci_app_tests_analytics_aggregate_response.rb +1 -1
  104. data/lib/datadog_api_client/v2/models/ci_app_tests_query_filter.rb +1 -1
  105. data/lib/datadog_api_client/v2/models/cloud_configuration_rule_compliance_signal_options.rb +25 -1
  106. data/lib/datadog_api_client/v2/models/dashboard_list_item.rb +25 -1
  107. data/lib/datadog_api_client/v2/models/downtime_relationships_monitor_data.rb +1 -1
  108. data/lib/datadog_api_client/v2/models/downtime_schedule_one_time_response.rb +19 -1
  109. data/lib/datadog_api_client/v2/models/formula_limit.rb +1 -0
  110. data/lib/datadog_api_client/v2/models/full_application_key_attributes.rb +1 -1
  111. data/lib/datadog_api_client/v2/models/logs_aggregate_request.rb +1 -1
  112. data/lib/datadog_api_client/v2/models/logs_aggregate_request_page.rb +1 -1
  113. data/lib/datadog_api_client/v2/models/logs_group_by.rb +3 -2
  114. data/lib/datadog_api_client/v2/models/logs_group_by_histogram.rb +1 -1
  115. data/lib/datadog_api_client/v2/models/logs_list_request.rb +1 -1
  116. data/lib/datadog_api_client/v2/models/logs_query_options.rb +1 -1
  117. data/lib/datadog_api_client/v2/models/logs_response_metadata_page.rb +1 -1
  118. data/lib/datadog_api_client/v2/models/on_demand_concurrency_cap.rb +14 -4
  119. data/lib/datadog_api_client/v2/models/on_demand_concurrency_cap_type.rb +26 -0
  120. data/lib/datadog_api_client/v2/models/partial_application_key_attributes.rb +1 -1
  121. data/lib/datadog_api_client/v2/models/query_formula.rb +1 -0
  122. data/lib/datadog_api_client/v2/models/relationship_to_team_links.rb +14 -4
  123. data/lib/datadog_api_client/v2/models/relationship_to_user_team_permission.rb +14 -4
  124. data/lib/datadog_api_client/v2/models/security_monitoring_signal_metadata_type.rb +26 -0
  125. data/lib/datadog_api_client/v2/models/security_monitoring_signal_response.rb +80 -0
  126. data/lib/datadog_api_client/v2/models/security_monitoring_signal_rule_response_query.rb +26 -2
  127. data/lib/datadog_api_client/v2/models/security_monitoring_signal_state_update_data.rb +24 -4
  128. data/lib/datadog_api_client/v2/models/security_monitoring_signal_triage_update_data.rb +24 -4
  129. data/lib/datadog_api_client/v2/models/security_monitoring_standard_rule_query.rb +1 -19
  130. data/lib/datadog_api_client/v2/models/security_monitoring_triage_user.rb +11 -1
  131. data/lib/datadog_api_client/v2/models/sensitive_data_scanner_get_config_response_data.rb +11 -1
  132. data/lib/datadog_api_client/v2/models/sensitive_data_scanner_meta.rb +11 -1
  133. data/lib/datadog_api_client/v2/models/sensitive_data_scanner_standard_pattern_attributes.rb +11 -1
  134. data/lib/datadog_api_client/v2/models/team_attributes.rb +50 -4
  135. data/lib/datadog_api_client/v2/models/team_create_attributes.rb +57 -4
  136. data/lib/datadog_api_client/v2/models/team_relationships_links.rb +80 -0
  137. data/lib/datadog_api_client/v2/models/team_response.rb +1 -1
  138. data/lib/datadog_api_client/v2/models/team_update_attributes.rb +57 -4
  139. data/lib/datadog_api_client/v2/models/teams_response.rb +24 -4
  140. data/lib/datadog_api_client/v2/models/teams_response_links.rb +129 -0
  141. data/lib/datadog_api_client/v2/models/teams_response_meta.rb +80 -0
  142. data/lib/datadog_api_client/v2/models/teams_response_meta_pagination.rb +150 -0
  143. data/lib/datadog_api_client/v2/models/usage_attributes_object.rb +11 -1
  144. data/lib/datadog_api_client/v2/models/user_teams_response.rb +24 -4
  145. data/lib/datadog_api_client/version.rb +1 -1
  146. data/spec/configuration_spec.rb +17 -0
  147. data/spec/retry_spec.rb +44 -0
  148. metadata +28 -3
@@ -2,7 +2,6 @@
2
2
  import pathlib
3
3
  import json
4
4
  import re
5
- import warnings
6
5
  from functools import singledispatch
7
6
 
8
7
 
@@ -185,6 +184,8 @@ def _format_oneof(data, schema, name_prefix=None, replace_values=None):
185
184
  matched = 0
186
185
  for sub_schema in schema["oneOf"]:
187
186
  try:
187
+ if "items" in sub_schema and not isinstance(data, list):
188
+ continue
188
189
  formatted = format_data_with_schema(
189
190
  data,
190
191
  sub_schema,
@@ -196,13 +197,11 @@ def _format_oneof(data, schema, name_prefix=None, replace_values=None):
196
197
  # parameters += formatted
197
198
  parameters = formatted
198
199
  matched += 1
199
- except (KeyError, ValueError):
200
+ except (KeyError, ValueError, TypeError):
200
201
  pass
201
202
 
202
- if matched == 0:
203
+ if matched != 1:
203
204
  raise ValueError(f"[{matched}] {data} is not valid for schema")
204
- elif matched > 1:
205
- warnings.warn(f"[{matched}] {data} is not valid for schema")
206
205
 
207
206
  return parameters
208
207
 
@@ -246,11 +245,28 @@ def format_data_with_schema(
246
245
  def open_file(x):
247
246
  return f"File.open({repr(x)}, 'r')"
248
247
 
248
+ def format_number(x):
249
+ if isinstance(x, (bool, str)):
250
+ raise TypeError(f"{x} is not supported type {schema}")
251
+ return str(x)
252
+
253
+ def format_string(x):
254
+ if isinstance(x, bool):
255
+ raise TypeError(f"{x} is not supported type {schema}")
256
+ if schema.get("format") == "binary":
257
+ return open_file(x)
258
+ return repr(x)
259
+
260
+ def format_boolean(x):
261
+ if not isinstance(x, bool):
262
+ raise TypeError(f"{x} is not supported type {schema}")
263
+ return "true" if x else "false"
264
+
249
265
  formatter = {
250
- "number": str,
251
- "integer": str,
252
- "boolean": lambda x: "true" if x else "false",
253
- "string": open_file if schema.get("format") == "binary" else repr,
266
+ "number": format_number,
267
+ "integer": format_number,
268
+ "boolean": format_boolean,
269
+ "string": format_string,
254
270
  None: repr,
255
271
  }[schema.get("type")]
256
272
 
@@ -281,18 +297,7 @@ def format_data_with_schema_list(
281
297
  name = get_name(schema)
282
298
 
283
299
  if "oneOf" in schema:
284
- for sub_schema in schema["oneOf"]:
285
- try:
286
- value = format_data_with_schema(
287
- data,
288
- sub_schema,
289
- replace_values=replace_values,
290
- default_name=name,
291
- )
292
- except (KeyError, ValueError):
293
- continue
294
- return value
295
- raise ValueError(f"{data} is not valid oneOf {schema}")
300
+ return _format_oneof(data, schema, name_prefix=name_prefix, replace_values=replace_values)
296
301
 
297
302
  parameters = ""
298
303
  for d in data:
@@ -324,7 +329,7 @@ def format_data_with_schema_dict(
324
329
  missing = required_properties - set(data.keys())
325
330
  if missing:
326
331
  raise ValueError(f"missing required properties: {missing}")
327
-
332
+
328
333
  for k, v in data.items():
329
334
  if k not in schema["properties"]:
330
335
  continue
@@ -355,18 +360,18 @@ def format_data_with_schema_dict(
355
360
  if default_name and not schema.get("additionalProperties") and schema.get("properties"):
356
361
  name = default_name
357
362
  else:
358
- name = "dict"
359
- warnings.warn(f"Unnamed schema {schema} for {data}")
363
+ if not parameters and data:
364
+ parameters = ", ".join(f"\"{k}\": \"{v}\"" for k, v in data.items())
365
+ return f"{{\n{parameters}}}"
360
366
 
361
367
  if "oneOf" in schema:
362
368
  name = None
363
369
  parameters = _format_oneof(data, schema, name_prefix=name_prefix, replace_values=replace_values)
364
370
 
365
- if name == "dict":
366
- if not parameters and data:
367
- parameters = ", ".join(f"\"{k}\": \"{v}\"" for k, v in data.items())
368
- return f"{{\n{parameters}}}"
369
- elif name:
371
+ if parameters == "" and schema.get("type") == "string":
372
+ raise ValueError(f"No schema matched for {data}")
373
+
374
+ if name:
370
375
  return f"{name_prefix}{name}.new({{\n{parameters}}})"
371
376
 
372
377
  return parameters
@@ -477,7 +477,7 @@ def get_container(operation, attribute_path, with_type=False):
477
477
  ".".join(formatter.attribute_name(a) for a in attribute_path.split(".")[1:]),
478
478
  get_type(parameter, attribute_path.split(".")[1]),
479
479
  )
480
- return f'opts, "{formatter.attribute_path(attribute_path)}"{get_type(parameter)}'
480
+ return f'opts, "{formatter.attribute_path(attribute_path)}"{get_type(parameter)}'
481
481
 
482
482
 
483
483
  def get_type_at_path(operation, attribute_path):
@@ -491,6 +491,8 @@ def get_type_at_path(operation, attribute_path):
491
491
  if content is None:
492
492
  raise RuntimeError("Default response not found")
493
493
  content = content["schema"]
494
+ if not attribute_path:
495
+ return get_name(content.get("items"))
494
496
  for attr in attribute_path.split("."):
495
497
  content = content["properties"][attr]
496
498
  return get_name(content.get("items"))
@@ -228,10 +228,13 @@ module {{ module_name }}::{{ version|upper }}
228
228
  api_version = "{{ version|upper }}"
229
229
  page_size = @api_client.get_attribute_from_path({{ get_container(operation, pagination.limitParam) }}, {{ get_default(operation, pagination.limitParam) }})
230
230
  @api_client.set_attribute_from_path(api_version, {{ get_container(operation, pagination.limitParam, True) }}, page_size)
231
+ {%- if pagination.pageParam %}
232
+ @api_client.set_attribute_from_path(api_version, {{ get_container(operation, pagination.pageParam, True) }}, 0)
233
+ {%- endif %}
231
234
  while true do
232
235
  response = {{ operation.operationId|snake_case }}({% for name, parameter in operation|parameters if parameter.required %}{{ name|attribute_name }}, {% endfor %}opts)
233
- @api_client.get_attribute_from_path(response, "{{ pagination.resultsPath|attribute_path }}").each { |item| yield(item) }
234
- if @api_client.get_attribute_from_path(response, "{{ pagination.resultsPath|attribute_path }}").length < page_size
236
+ @api_client.get_attribute_from_path(response, "{{ pagination.resultsPath|default('')|attribute_path }}").each { |item| yield(item) }
237
+ if @api_client.get_attribute_from_path(response, "{{ pagination.resultsPath|default('')|attribute_path }}").length < page_size
235
238
  break
236
239
  end
237
240
  {%- if pagination.pageOffsetParam %}
@@ -240,6 +243,9 @@ module {{ module_name }}::{{ version|upper }}
240
243
  {%- if pagination.cursorParam %}
241
244
  @api_client.set_attribute_from_path(api_version, {{ get_container(operation, pagination.cursorParam, True) }}, @api_client.get_attribute_from_path(response, "{{ pagination.cursorPath }}"))
242
245
  {%- endif %}
246
+ {%- if pagination.pageParam %}
247
+ @api_client.set_attribute_from_path(api_version, {{ get_container(operation, pagination.pageParam, True) }}, @api_client.get_attribute_from_path({{ get_container(operation, pagination.pageParam) }}, 0) + 1)
248
+ {%- endif %}
243
249
  end
244
250
  end
245
251
  {%- endif %}
@@ -44,71 +44,99 @@ module {{ module_name }}
44
44
  # the data deserialized from response body (could be nil), response status code and response headers.
45
45
  def call_api(http_method, path, opts = {})
46
46
  request = build_request(http_method, path, opts)
47
- if opts[:stream_body]
48
- tempfile = nil
49
- encoding = nil
50
-
51
- response = request.perform do | chunk |
52
- unless tempfile
53
- content_disposition = chunk.http_response.header['Content-Disposition']
54
- if content_disposition && content_disposition =~ /filename=/i
55
- filename = content_disposition[/filename=['"]?([^'"\s]+)['"]?/, 1]
56
- prefix = sanitize_filename(filename)
57
- else
58
- prefix = 'download-'
59
- end
60
- prefix = prefix + '-' unless prefix.end_with?('-')
61
- unless encoding
62
- encoding = chunk.encoding
47
+ attempt = 0
48
+ loop do
49
+ if opts[:stream_body]
50
+ tempfile = nil
51
+ encoding = nil
52
+
53
+ response = request.perform do | chunk |
54
+ unless tempfile
55
+ content_disposition = chunk.http_response.header['Content-Disposition']
56
+ if content_disposition && content_disposition =~ /filename=/i
57
+ filename = content_disposition[/filename=['"]?([^'"\s]+)['"]?/, 1]
58
+ prefix = sanitize_filename(filename)
59
+ else
60
+ prefix = 'download-'
61
+ end
62
+ prefix = prefix + '-' unless prefix.end_with?('-')
63
+ unless encoding
64
+ encoding = chunk.encoding
65
+ end
66
+ tempfile = Tempfile.open(prefix, @config.temp_folder_path, encoding: encoding)
67
+ @tempfile = tempfile
63
68
  end
64
- tempfile = Tempfile.open(prefix, @config.temp_folder_path, encoding: encoding)
65
- @tempfile = tempfile
69
+ chunk.force_encoding(encoding)
70
+ tempfile.write(chunk)
71
+ end
72
+ if tempfile
73
+ tempfile.close
74
+ @config.logger.info "Temp file written to #{tempfile.path}, please copy the file to a proper folder "\
75
+ "with e.g. `FileUtils.cp(tempfile.path, '/new/file/path')` otherwise the temp file "\
76
+ "will be deleted automatically with GC. It's also recommended to delete the temp file "\
77
+ "explicitly with `tempfile.delete`"
66
78
  end
67
- chunk.force_encoding(encoding)
68
- tempfile.write(chunk)
79
+ else
80
+ response = request.perform
69
81
  end
70
- if tempfile
71
- tempfile.close
72
- @config.logger.info "Temp file written to #{tempfile.path}, please copy the file to a proper folder "\
73
- "with e.g. `FileUtils.cp(tempfile.path, '/new/file/path')` otherwise the temp file "\
74
- "will be deleted automatically with GC. It's also recommended to delete the temp file "\
75
- "explicitly with `tempfile.delete`"
82
+
83
+ if @config.debugging
84
+ @config.logger.debug "HTTP response body ~BEGIN~\n#{response.body}\n~END~\n"
76
85
  end
77
- else
78
- response = request.perform
79
- end
80
86
 
81
- if @config.debugging
82
- @config.logger.debug "HTTP response body ~BEGIN~\n#{response.body}\n~END~\n"
83
- end
87
+ unless response.success?
88
+ if response.request_timeout?
89
+ fail APIError.new('Connection timed out')
90
+ elsif response.code == 0
91
+ # Errors from libcurl will be made visible here
92
+ fail APIError.new(:code => 0,
93
+ :message => response.return_message)
94
+ else
95
+ body = response.body
96
+ if response.headers['Content-Encoding'].eql?('gzip') && !(body.nil? || body.empty?) then
97
+ gzip = Zlib::Inflate.new(Zlib::MAX_WBITS + 16)
98
+ body = gzip.inflate(body)
99
+ gzip.close
100
+ end
101
+ if should_retry(attempt, @config.max_retries, response.code, @config.enable_retry)
102
+ sleep calculate_retry_interval(response, @config.backoff_base, @config.backoff_multiplier, attempt, @config.timeout)
103
+ attempt = attempt + 1
104
+ next
105
+ else
106
+ fail APIError.new(:code => response.code,
107
+ :response_headers => response.headers,
108
+ :response_body => body),
109
+ response.message
110
+ end
111
+ end
112
+ end
84
113
 
85
- unless response.success?
86
- if response.request_timeout?
87
- fail APIError.new('Connection timed out')
88
- elsif response.code == 0
89
- # Errors from libcurl will be made visible here
90
- fail APIError.new(:code => 0,
91
- :message => response.return_message)
114
+ if opts[:return_type]
115
+ data = deserialize(opts[:api_version], response, opts[:return_type])
92
116
  else
93
- body = response.body
94
- if response.headers['Content-Encoding'].eql?('gzip') && !(body.nil? || body.empty?) then
95
- gzip = Zlib::Inflate.new(Zlib::MAX_WBITS + 16)
96
- body = gzip.inflate(body)
97
- gzip.close
98
- end
99
- fail APIError.new(:code => response.code,
100
- :response_headers => response.headers,
101
- :response_body => body),
102
- response.message
117
+ data = nil
103
118
  end
119
+ return data, response.code, response.headers
104
120
  end
121
+ end
122
+
123
+ # Check if an http request should be retried
124
+ def should_retry(attempt, max_retries, http_code, enable_retry)
125
+ (http_code == 429 || http_code >= 500) && max_retries > attempt && enable_retry
126
+ end
105
127
 
106
- if opts[:return_type]
107
- data = deserialize(opts[:api_version], response, opts[:return_type])
128
+ # Calculate the sleep interval between 2 retry attempts
129
+ def calculate_retry_interval(response, backoff_base, backoff_multiplier, attempt, timeout)
130
+ reset_header = response.headers['X-Ratelimit-Reset']
131
+ if !reset_header.nil? && !reset_header.empty?
132
+ sleep_time = reset_header.to_i
108
133
  else
109
- data = nil
134
+ sleep_time = (backoff_multiplier**attempt) * backoff_base
135
+ if timeout && timeout > 0
136
+ sleep_time = [timeout, sleep_time].min
137
+ end
110
138
  end
111
- return data, response.code, response.headers
139
+ sleep_time
112
140
  end
113
141
 
114
142
  # Build the HTTP request
@@ -138,6 +138,16 @@ module {{ module_name }}
138
138
  # Password for proxy server authentication
139
139
  attr_accessor :http_proxypass
140
140
 
141
+ # Enable retry when rate limited
142
+ attr_accessor :enable_retry
143
+
144
+ # Retry backoff calculation parameters
145
+ attr_accessor :backoff_base
146
+ attr_accessor :backoff_multiplier
147
+
148
+ # Maximum number of retry attempts allowed
149
+ attr_accessor :max_retries
150
+
141
151
  def initialize
142
152
  {%- set default_server = openapi.servers[0]|format_server %}
143
153
  @scheme = '{{ default_server.scheme }}'
@@ -149,6 +159,10 @@ module {{ module_name }}
149
159
  @server_operation_variables = {}
150
160
  @api_key = {}
151
161
  @api_key_prefix = {}
162
+ @enable_retry = false
163
+ @backoff_base = 2
164
+ @backoff_multiplier = 2
165
+ @max_retries = 3
152
166
  @timeout = nil
153
167
  @client_side_validation = true
154
168
  @verify_ssl = true
@@ -188,6 +202,13 @@ module {{ module_name }}
188
202
  @@default ||= Configuration.new
189
203
  end
190
204
 
205
+ def backoff_base=(value)
206
+ if value < 2
207
+ raise ArgumentError, 'backoff_base cannot be smaller than 2'
208
+ end
209
+ @backoff_base = value
210
+ end
211
+
191
212
  def configure
192
213
  yield(self) if block_given?
193
214
  end
@@ -19,7 +19,7 @@ repos:
19
19
  name: Format documentation
20
20
  stages: [manual]
21
21
  language: node
22
- language_version: 14.12.0
22
+ language_version: 20.5.0
23
23
  entry: prettier --write --list-different --ignore-unknown README.md
24
24
  "types": [text]
25
25
  files: 'README.md'
@@ -27,7 +27,7 @@ repos:
27
27
  additional_dependencies:
28
28
  # When updating the version of prettier, make sure to check the pre-commit file
29
29
  # And keep the `entry` here up to date https://github.com/pre-commit/mirrors-prettier/blob/master/.pre-commit-hooks.yaml
30
- - prettier@2.5.1
30
+ - prettier@3.0.0
31
31
  - id: generator
32
32
  name: generator
33
33
  language: python
data/CHANGELOG.md CHANGED
@@ -1,5 +1,62 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## 2.15.0 / 2023-09-14
4
+
5
+ ### Fixed
6
+ * Fix downtimes monitor relationship id schema type by @api-clients-generation-pipeline in https://github.com/DataDog/datadog-api-client-ruby/pull/1524
7
+ ### Added
8
+ * Add trace_stream to dashboard ListStreamSource by @api-clients-generation-pipeline in https://github.com/DataDog/datadog-api-client-ruby/pull/1499
9
+ * Add pagination extension to SLO corrections by @api-clients-generation-pipeline in https://github.com/DataDog/datadog-api-client-ruby/pull/1509
10
+ * Adding aas count to the documentation for summary and hourly usage endpoints by @api-clients-generation-pipeline in https://github.com/DataDog/datadog-api-client-ruby/pull/1511
11
+ * Add pagination extension to SLOs by @api-clients-generation-pipeline in https://github.com/DataDog/datadog-api-client-ruby/pull/1510
12
+ * Add pagination extension to monitors by @api-clients-generation-pipeline in https://github.com/DataDog/datadog-api-client-ruby/pull/1512
13
+ * Add pagination extension to synthetics tests by @api-clients-generation-pipeline in https://github.com/DataDog/datadog-api-client-ruby/pull/1516
14
+ * Add 'style' to sunburst requests by @api-clients-generation-pipeline in https://github.com/DataDog/datadog-api-client-ruby/pull/1515
15
+ * Add pagination extension to notebook by @api-clients-generation-pipeline in https://github.com/DataDog/datadog-api-client-ruby/pull/1517
16
+ * Add support for dashboard listing pagination parameters by @api-clients-generation-pipeline in https://github.com/DataDog/datadog-api-client-ruby/pull/1521
17
+ * Add pagination parameters to downtimes listing by @api-clients-generation-pipeline in https://github.com/DataDog/datadog-api-client-ruby/pull/1523
18
+ * Add pagination extension to user list by @api-clients-generation-pipeline in https://github.com/DataDog/datadog-api-client-ruby/pull/1522
19
+ * Add pagination extension to team listing by @api-clients-generation-pipeline in https://github.com/DataDog/datadog-api-client-ruby/pull/1525
20
+ * Remove private beta for Downtimes v2 by @api-clients-generation-pipeline in https://github.com/DataDog/datadog-api-client-ruby/pull/1519
21
+ * Update v1 monitor api docs to exclude downtimes v2 by @api-clients-generation-pipeline in https://github.com/DataDog/datadog-api-client-ruby/pull/1534
22
+ * Add timing scope for response time assertions by @api-clients-generation-pipeline in https://github.com/DataDog/datadog-api-client-ruby/pull/1526
23
+ * Add Formula and Function query support to heatmap widgets by @api-clients-generation-pipeline in https://github.com/DataDog/datadog-api-client-ruby/pull/1535
24
+ * Add synthetics mobile application testing to usage metering API by @api-clients-generation-pipeline in https://github.com/DataDog/datadog-api-client-ruby/pull/1531
25
+
26
+
27
+ **Full Changelog**: https://github.com/DataDog/datadog-api-client-ruby/compare/v2.14.0...v2.15.0
28
+
29
+ ## 2.14.0 / 2023-08-23
30
+
31
+ ### Fixed
32
+ * Update team schemas by @api-clients-generation-pipeline in https://github.com/DataDog/datadog-api-client-ruby/pull/1470
33
+ * Mark downtime v2 start response as required by @api-clients-generation-pipeline in https://github.com/DataDog/datadog-api-client-ruby/pull/1482
34
+ * Document new properties and fix security monitoring schemas by @api-clients-generation-pipeline in https://github.com/DataDog/datadog-api-client-ruby/pull/1469
35
+ * Add missing CI App fields `page` and `test_level` by @api-clients-generation-pipeline in https://github.com/DataDog/datadog-api-client-ruby/pull/1448
36
+ ### Added
37
+ * Update stated limit for api/v2/metrics from 14 days to 30 days by @api-clients-generation-pipeline in https://github.com/DataDog/datadog-api-client-ruby/pull/1476
38
+ * Add missing sensitive data scanner fields by @api-clients-generation-pipeline in https://github.com/DataDog/datadog-api-client-ruby/pull/1466
39
+ * Add Workflow Executions to usage metering API by @api-clients-generation-pipeline in https://github.com/DataDog/datadog-api-client-ruby/pull/1478
40
+ * Add missing `type` field for OnDemandConcurrencyCap response by @api-clients-generation-pipeline in https://github.com/DataDog/datadog-api-client-ruby/pull/1468
41
+ * Add CI Visibility Intelligent Test Runner to usage metering API by @api-clients-generation-pipeline in https://github.com/DataDog/datadog-api-client-ruby/pull/1477
42
+ * Add custom_links to distribution widget schema by @api-clients-generation-pipeline in https://github.com/DataDog/datadog-api-client-ruby/pull/1485
43
+ * Add usage field `region` by @api-clients-generation-pipeline in https://github.com/DataDog/datadog-api-client-ruby/pull/1486
44
+ * Add `message` field to audit logs response by @api-clients-generation-pipeline in https://github.com/DataDog/datadog-api-client-ruby/pull/1488
45
+ * Add `tags` field to dashboard list response by @api-clients-generation-pipeline in https://github.com/DataDog/datadog-api-client-ruby/pull/1487
46
+ * API specs for user team memberships by @api-clients-generation-pipeline in https://github.com/DataDog/datadog-api-client-ruby/pull/1495
47
+ * Document `EQUAL` comparator by @api-clients-generation-pipeline in https://github.com/DataDog/datadog-api-client-ruby/pull/1498
48
+ * Add persistCookies option synthetics test request by @api-clients-generation-pipeline in https://github.com/DataDog/datadog-api-client-ruby/pull/1497
49
+ * Expose sds_scanned_bytes_usage in usage attribution API by @api-clients-generation-pipeline in https://github.com/DataDog/datadog-api-client-ruby/pull/1501
50
+ * Add support in azure integration endpoint for app service plan filters/cspm/custom metrics by @api-clients-generation-pipeline in https://github.com/DataDog/datadog-api-client-ruby/pull/1496
51
+ * Add APM and USM usage attribution type by @api-clients-generation-pipeline in https://github.com/DataDog/datadog-api-client-ruby/pull/1494
52
+ * Document new attributes for team models by @api-clients-generation-pipeline in https://github.com/DataDog/datadog-api-client-ruby/pull/1492
53
+ * Add retry support by @HantingZhang2 in https://github.com/DataDog/datadog-api-client-ruby/pull/1502
54
+
55
+ ## New Contributors
56
+ * @HantingZhang2 made their first contribution in https://github.com/DataDog/datadog-api-client-ruby/pull/1502
57
+
58
+ **Full Changelog**: https://github.com/DataDog/datadog-api-client-ruby/compare/v2.13.0...v2.14.0
59
+
3
60
  ## 2.13.0 / 2023-07-20
4
61
 
5
62
  ### Fixed
data/README.md CHANGED
@@ -165,6 +165,29 @@ api_instance.list_incidents_with_pagination() do |incident|
165
165
  end
166
166
  ```
167
167
 
168
+ ### Retry
169
+
170
+ To enable the client to retry when rate limited (status 429) or status 500 and above:
171
+
172
+ ```ruby
173
+ config = DatadogAPIClient::Configuration.new
174
+ config.enable_retry = true
175
+ client = DatadogAPIClient::APIClient.new(config)
176
+ ```
177
+
178
+ The interval between 2 retry attempts will be the value of the `x-ratelimit-reset` response header when available.
179
+ If not, it will be :
180
+
181
+ ```ruby
182
+ (config.backoffMultiplier ** current_retry_count) * config.backoffBase
183
+ ```
184
+
185
+ The maximum number of retry attempts is `3` by default and can be modified with
186
+
187
+ ```ruby
188
+ config.maxRetries
189
+ ```
190
+
168
191
  ## Documentation
169
192
 
170
193
  If you are interested in general documentation for all public Datadog API endpoints, checkout the [general documentation site][api docs].
@@ -4,9 +4,12 @@ require "datadog_api_client"
4
4
  api_instance = DatadogAPIClient::V1::AzureIntegrationAPI.new
5
5
 
6
6
  body = DatadogAPIClient::V1::AzureAccount.new({
7
+ app_service_plan_filters: "key:value,filter:example",
7
8
  automute: true,
8
9
  client_id: "testc7f6-1234-5678-9101-3fcbf464test",
9
10
  client_secret: "testingx./Sw*g/Y33t..R1cH+hScMDt",
11
+ cspm_enabled: true,
12
+ custom_metrics_enabled: true,
10
13
  errors: [
11
14
  "*",
12
15
  ],
@@ -4,9 +4,12 @@ require "datadog_api_client"
4
4
  api_instance = DatadogAPIClient::V1::AzureIntegrationAPI.new
5
5
 
6
6
  body = DatadogAPIClient::V1::AzureAccount.new({
7
+ app_service_plan_filters: "key:value,filter:example",
7
8
  automute: true,
8
9
  client_id: "testc7f6-1234-5678-9101-3fcbf464test",
9
10
  client_secret: "testingx./Sw*g/Y33t..R1cH+hScMDt",
11
+ cspm_enabled: true,
12
+ custom_metrics_enabled: true,
10
13
  errors: [
11
14
  "*",
12
15
  ],
@@ -4,9 +4,12 @@ require "datadog_api_client"
4
4
  api_instance = DatadogAPIClient::V1::AzureIntegrationAPI.new
5
5
 
6
6
  body = DatadogAPIClient::V1::AzureAccount.new({
7
+ app_service_plan_filters: "key:value,filter:example",
7
8
  automute: true,
8
9
  client_id: "testc7f6-1234-5678-9101-3fcbf464test",
9
10
  client_secret: "testingx./Sw*g/Y33t..R1cH+hScMDt",
11
+ cspm_enabled: true,
12
+ custom_metrics_enabled: true,
10
13
  errors: [
11
14
  "*",
12
15
  ],
@@ -4,9 +4,12 @@ require "datadog_api_client"
4
4
  api_instance = DatadogAPIClient::V1::AzureIntegrationAPI.new
5
5
 
6
6
  body = DatadogAPIClient::V1::AzureAccount.new({
7
+ app_service_plan_filters: "key:value,filter:example",
7
8
  automute: true,
8
9
  client_id: "testc7f6-1234-5678-9101-3fcbf464test",
9
10
  client_secret: "testingx./Sw*g/Y33t..R1cH+hScMDt",
11
+ cspm_enabled: true,
12
+ custom_metrics_enabled: true,
10
13
  errors: [
11
14
  "*",
12
15
  ],
@@ -13,6 +13,12 @@ body = DatadogAPIClient::V1::Dashboard.new({
13
13
  title_align: DatadogAPIClient::V1::WidgetTextAlign::LEFT,
14
14
  show_legend: false,
15
15
  type: DatadogAPIClient::V1::DistributionWidgetDefinitionType::DISTRIBUTION,
16
+ custom_links: [
17
+ DatadogAPIClient::V1::WidgetCustomLink.new({
18
+ label: "Example",
19
+ link: "https://example.org/",
20
+ }),
21
+ ],
16
22
  xaxis: DatadogAPIClient::V1::DistributionWidgetXAxis.new({
17
23
  max: "auto",
18
24
  include_zero: true,
@@ -0,0 +1,36 @@
1
+ # Create a new dashboard with trace_stream widget
2
+
3
+ require "datadog_api_client"
4
+ api_instance = DatadogAPIClient::V1::DashboardsAPI.new
5
+
6
+ body = DatadogAPIClient::V1::Dashboard.new({
7
+ layout_type: DatadogAPIClient::V1::DashboardLayoutType::ORDERED,
8
+ title: "Example-Dashboard with list_stream widget",
9
+ widgets: [
10
+ DatadogAPIClient::V1::Widget.new({
11
+ definition: DatadogAPIClient::V1::ListStreamWidgetDefinition.new({
12
+ type: DatadogAPIClient::V1::ListStreamWidgetDefinitionType::LIST_STREAM,
13
+ requests: [
14
+ DatadogAPIClient::V1::ListStreamWidgetRequest.new({
15
+ columns: [
16
+ DatadogAPIClient::V1::ListStreamColumn.new({
17
+ width: DatadogAPIClient::V1::ListStreamColumnWidth::AUTO,
18
+ field: "timestamp",
19
+ }),
20
+ DatadogAPIClient::V1::ListStreamColumn.new({
21
+ width: DatadogAPIClient::V1::ListStreamColumnWidth::AUTO,
22
+ field: "service",
23
+ }),
24
+ ],
25
+ query: DatadogAPIClient::V1::ListStreamQuery.new({
26
+ data_source: DatadogAPIClient::V1::ListStreamSource::TRACE_STREAM,
27
+ query_string: "",
28
+ }),
29
+ response_format: DatadogAPIClient::V1::ListStreamResponseFormat::EVENT_LIST,
30
+ }),
31
+ ],
32
+ }),
33
+ }),
34
+ ],
35
+ })
36
+ p api_instance.create_dashboard(body)
@@ -28,6 +28,9 @@ body = DatadogAPIClient::V1::Dashboard.new({
28
28
  aggregator: DatadogAPIClient::V1::FormulaAndFunctionMetricAggregation::SUM,
29
29
  }),
30
30
  ],
31
+ style: DatadogAPIClient::V1::WidgetStyle.new({
32
+ palette: "dog_classic",
33
+ }),
31
34
  }),
32
35
  ],
33
36
  }),
@@ -0,0 +1,50 @@
1
+ # Create a new dashboard with formula and function heatmap widget
2
+
3
+ require "datadog_api_client"
4
+ api_instance = DatadogAPIClient::V1::DashboardsAPI.new
5
+
6
+ body = DatadogAPIClient::V1::Dashboard.new({
7
+ title: "Example-Dashboard",
8
+ widgets: [
9
+ DatadogAPIClient::V1::Widget.new({
10
+ layout: DatadogAPIClient::V1::WidgetLayout.new({
11
+ x: 0,
12
+ y: 0,
13
+ width: 47,
14
+ height: 15,
15
+ }),
16
+ definition: DatadogAPIClient::V1::HeatMapWidgetDefinition.new({
17
+ title: "",
18
+ title_size: "16",
19
+ title_align: DatadogAPIClient::V1::WidgetTextAlign::LEFT,
20
+ time: DatadogAPIClient::V1::WidgetTime.new({}),
21
+ type: DatadogAPIClient::V1::HeatMapWidgetDefinitionType::HEATMAP,
22
+ requests: [
23
+ DatadogAPIClient::V1::HeatMapWidgetRequest.new({
24
+ response_format: DatadogAPIClient::V1::FormulaAndFunctionResponseFormat::TIMESERIES,
25
+ queries: [
26
+ DatadogAPIClient::V1::FormulaAndFunctionMetricQueryDefinition.new({
27
+ data_source: DatadogAPIClient::V1::FormulaAndFunctionMetricDataSource::METRICS,
28
+ name: "query1",
29
+ query: "avg:system.cpu.user{*}",
30
+ }),
31
+ ],
32
+ formulas: [
33
+ DatadogAPIClient::V1::WidgetFormula.new({
34
+ formula: "query1",
35
+ }),
36
+ ],
37
+ style: DatadogAPIClient::V1::WidgetStyle.new({
38
+ palette: "dog_classic",
39
+ }),
40
+ }),
41
+ ],
42
+ }),
43
+ }),
44
+ ],
45
+ template_variables: [],
46
+ layout_type: DatadogAPIClient::V1::DashboardLayoutType::FREE,
47
+ is_read_only: false,
48
+ notify_list: [],
49
+ })
50
+ p api_instance.create_dashboard(body)