Skip to content

Commit

Permalink
Add include_percentiles field in Logs Custom Metrics (#1224)
Browse files Browse the repository at this point in the history
Co-authored-by: ci.datadog-api-spec <[email protected]>
  • Loading branch information
api-clients-generation-pipeline[bot] and ci.datadog-api-spec authored Nov 21, 2022
1 parent 7d7b1e1 commit 607a713
Show file tree
Hide file tree
Showing 17 changed files with 235 additions and 18 deletions.
8 changes: 4 additions & 4 deletions .apigentools-info
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
"spec_versions": {
"v1": {
"apigentools_version": "1.6.4",
"regenerated": "2022-11-21 18:48:28.015320",
"spec_repo_commit": "9015efdd"
"regenerated": "2022-11-21 20:01:47.849955",
"spec_repo_commit": "4ca2c235"
},
"v2": {
"apigentools_version": "1.6.4",
"regenerated": "2022-11-21 18:48:28.030582",
"spec_repo_commit": "9015efdd"
"regenerated": "2022-11-21 20:01:47.861729",
"spec_repo_commit": "4ca2c235"
}
}
}
21 changes: 20 additions & 1 deletion .generator/schemas/v2/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5012,6 +5012,8 @@ components:
properties:
aggregation_type:
$ref: '#/components/schemas/LogsMetricComputeAggregationType'
include_percentiles:
$ref: '#/components/schemas/LogsMetricComputeIncludePercentiles'
path:
description: The path to the value the log-based metric will aggregate on
(only used if the aggregation type is a "distribution").
Expand All @@ -5030,6 +5032,13 @@ components:
x-enum-varnames:
- COUNT
- DISTRIBUTION
LogsMetricComputeIncludePercentiles:
description: 'Toggle to include or exclude percentile aggregations for distribution
metrics.

Only present when the `aggregation_type` is `distribution`.'
example: true
type: boolean
LogsMetricCreateAttributes:
description: The object describing the Datadog log-based metric to create.
properties:
Expand Down Expand Up @@ -5121,6 +5130,8 @@ components:
properties:
aggregation_type:
$ref: '#/components/schemas/LogsMetricResponseComputeAggregationType'
include_percentiles:
$ref: '#/components/schemas/LogsMetricComputeIncludePercentiles'
path:
description: The path to the value the log-based metric will aggregate on
(only used if the aggregation type is a "distribution").
Expand Down Expand Up @@ -5182,6 +5193,8 @@ components:
LogsMetricUpdateAttributes:
description: The log-based metric properties that will be updated.
properties:
compute:
$ref: '#/components/schemas/LogsMetricUpdateCompute'
filter:
$ref: '#/components/schemas/LogsMetricFilter'
group_by:
Expand All @@ -5190,6 +5203,12 @@ components:
$ref: '#/components/schemas/LogsMetricGroupBy'
type: array
type: object
LogsMetricUpdateCompute:
description: The compute rule to compute the log-based metric.
properties:
include_percentiles:
$ref: '#/components/schemas/LogsMetricComputeIncludePercentiles'
type: object
LogsMetricUpdateData:
description: The new log-based metric properties.
properties:
Expand Down Expand Up @@ -5978,7 +5997,7 @@ components:
format: date-time
type: string
include_percentiles:
description: 'Toggle to turn on/off percentile aggregations for distribution
description: 'Toggle to include or exclude percentile aggregations for distribution
metrics.

Only present when the `metric_type` is `distribution`.'
Expand Down
7 changes: 7 additions & 0 deletions docs/datadog_api_client.v2.model.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2241,6 +2241,13 @@ logs\_metric\_update\_attributes
:members:
:show-inheritance:

logs\_metric\_update\_compute
-----------------------------

.. automodule:: datadog_api_client.v2.model.logs_metric_update_compute
:members:
:show-inheritance:

logs\_metric\_update\_data
--------------------------

Expand Down
4 changes: 3 additions & 1 deletion examples/v2/logs-metrics/CreateLogsMetric.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
type=LogsMetricType.LOGS_METRICS,
attributes=LogsMetricCreateAttributes(
compute=LogsMetricCompute(
aggregation_type=LogsMetricComputeAggregationType.COUNT,
aggregation_type=LogsMetricComputeAggregationType.DISTRIBUTION,
include_percentiles=True,
path="@duration",
),
),
),
Expand Down
33 changes: 33 additions & 0 deletions examples/v2/logs-metrics/UpdateLogsMetric_1901534424.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
"""
Update a log-based metric with include_percentiles field returns "OK" response
"""

from os import environ
from datadog_api_client import ApiClient, Configuration
from datadog_api_client.v2.api.logs_metrics_api import LogsMetricsApi
from datadog_api_client.v2.model.logs_metric_type import LogsMetricType
from datadog_api_client.v2.model.logs_metric_update_attributes import LogsMetricUpdateAttributes
from datadog_api_client.v2.model.logs_metric_update_compute import LogsMetricUpdateCompute
from datadog_api_client.v2.model.logs_metric_update_data import LogsMetricUpdateData
from datadog_api_client.v2.model.logs_metric_update_request import LogsMetricUpdateRequest

# there is a valid "logs_metric_percentile" in the system
LOGS_METRIC_PERCENTILE_DATA_ID = environ["LOGS_METRIC_PERCENTILE_DATA_ID"]

body = LogsMetricUpdateRequest(
data=LogsMetricUpdateData(
type=LogsMetricType.LOGS_METRICS,
attributes=LogsMetricUpdateAttributes(
compute=LogsMetricUpdateCompute(
include_percentiles=False,
),
),
),
)

configuration = Configuration()
with ApiClient(configuration) as api_client:
api_instance = LogsMetricsApi(api_client)
response = api_instance.update_logs_metric(metric_id=LOGS_METRIC_PERCENTILE_DATA_ID, body=body)

print(response)
14 changes: 13 additions & 1 deletion src/datadog_api_client/v2/model/logs_metric_compute.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,26 +24,38 @@ def openapi_types(_):

return {
"aggregation_type": (LogsMetricComputeAggregationType,),
"include_percentiles": (bool,),
"path": (str,),
}

attribute_map = {
"aggregation_type": "aggregation_type",
"include_percentiles": "include_percentiles",
"path": "path",
}

def __init__(
self_, aggregation_type: LogsMetricComputeAggregationType, path: Union[str, UnsetType] = unset, **kwargs
self_,
aggregation_type: LogsMetricComputeAggregationType,
include_percentiles: Union[bool, UnsetType] = unset,
path: Union[str, UnsetType] = unset,
**kwargs,
):
"""
The compute rule to compute the log-based metric.
:param aggregation_type: The type of aggregation to use.
:type aggregation_type: LogsMetricComputeAggregationType
:param include_percentiles: Toggle to include or exclude percentile aggregations for distribution metrics.
Only present when the ``aggregation_type`` is ``distribution``.
:type include_percentiles: bool, optional
:param path: The path to the value the log-based metric will aggregate on (only used if the aggregation type is a "distribution").
:type path: str, optional
"""
if include_percentiles is not unset:
kwargs["include_percentiles"] = include_percentiles
if path is not unset:
kwargs["path"] = path
super().__init__(kwargs)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,20 @@ def openapi_types(_):

return {
"aggregation_type": (LogsMetricResponseComputeAggregationType,),
"include_percentiles": (bool,),
"path": (str,),
}

attribute_map = {
"aggregation_type": "aggregation_type",
"include_percentiles": "include_percentiles",
"path": "path",
}

def __init__(
self_,
aggregation_type: Union[LogsMetricResponseComputeAggregationType, UnsetType] = unset,
include_percentiles: Union[bool, UnsetType] = unset,
path: Union[str, UnsetType] = unset,
**kwargs,
):
Expand All @@ -48,11 +51,17 @@ def __init__(
:param aggregation_type: The type of aggregation to use.
:type aggregation_type: LogsMetricResponseComputeAggregationType, optional
:param include_percentiles: Toggle to include or exclude percentile aggregations for distribution metrics.
Only present when the ``aggregation_type`` is ``distribution``.
:type include_percentiles: bool, optional
:param path: The path to the value the log-based metric will aggregate on (only used if the aggregation type is a "distribution").
:type path: str, optional
"""
if aggregation_type is not unset:
kwargs["aggregation_type"] = aggregation_type
if include_percentiles is not unset:
kwargs["include_percentiles"] = include_percentiles
if path is not unset:
kwargs["path"] = path
super().__init__(kwargs)
10 changes: 10 additions & 0 deletions src/datadog_api_client/v2/model/logs_metric_update_attributes.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,41 +14,51 @@


if TYPE_CHECKING:
from datadog_api_client.v2.model.logs_metric_update_compute import LogsMetricUpdateCompute
from datadog_api_client.v2.model.logs_metric_filter import LogsMetricFilter
from datadog_api_client.v2.model.logs_metric_group_by import LogsMetricGroupBy


class LogsMetricUpdateAttributes(ModelNormal):
@cached_property
def openapi_types(_):
from datadog_api_client.v2.model.logs_metric_update_compute import LogsMetricUpdateCompute
from datadog_api_client.v2.model.logs_metric_filter import LogsMetricFilter
from datadog_api_client.v2.model.logs_metric_group_by import LogsMetricGroupBy

return {
"compute": (LogsMetricUpdateCompute,),
"filter": (LogsMetricFilter,),
"group_by": ([LogsMetricGroupBy],),
}

attribute_map = {
"compute": "compute",
"filter": "filter",
"group_by": "group_by",
}

def __init__(
self_,
compute: Union[LogsMetricUpdateCompute, UnsetType] = unset,
filter: Union[LogsMetricFilter, UnsetType] = unset,
group_by: Union[List[LogsMetricGroupBy], UnsetType] = unset,
**kwargs,
):
"""
The log-based metric properties that will be updated.
:param compute: The compute rule to compute the log-based metric.
:type compute: LogsMetricUpdateCompute, optional
:param filter: The log-based metric filter. Logs matching this filter will be aggregated in this metric.
:type filter: LogsMetricFilter, optional
:param group_by: The rules for the group by.
:type group_by: [LogsMetricGroupBy], optional
"""
if compute is not unset:
kwargs["compute"] = compute
if filter is not unset:
kwargs["filter"] = filter
if group_by is not unset:
Expand Down
37 changes: 37 additions & 0 deletions src/datadog_api_client/v2/model/logs_metric_update_compute.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Unless explicitly stated otherwise all files in this repository are licensed under the Apache-2.0 License.
# This product includes software developed at Datadog (https://www.datadoghq.com/).
# Copyright 2019-Present Datadog, Inc.
from __future__ import annotations

from typing import Union

from datadog_api_client.model_utils import (
ModelNormal,
cached_property,
unset,
UnsetType,
)


class LogsMetricUpdateCompute(ModelNormal):
@cached_property
def openapi_types(_):
return {
"include_percentiles": (bool,),
}

attribute_map = {
"include_percentiles": "include_percentiles",
}

def __init__(self_, include_percentiles: Union[bool, UnsetType] = unset, **kwargs):
"""
The compute rule to compute the log-based metric.
:param include_percentiles: Toggle to include or exclude percentile aggregations for distribution metrics.
Only present when the ``aggregation_type`` is ``distribution``.
:type include_percentiles: bool, optional
"""
if include_percentiles is not unset:
kwargs["include_percentiles"] = include_percentiles
super().__init__(kwargs)
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def __init__(
:param created_at: Timestamp when the tag configuration was created.
:type created_at: datetime, optional
:param include_percentiles: Toggle to turn on/off percentile aggregations for distribution metrics.
:param include_percentiles: Toggle to include or exclude percentile aggregations for distribution metrics.
Only present when the ``metric_type`` is ``distribution``.
:type include_percentiles: bool, optional
Expand Down
1 change: 1 addition & 0 deletions src/datadog_api_client/v2/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,7 @@
from datadog_api_client.v2.model.logs_metric_response_group_by import LogsMetricResponseGroupBy
from datadog_api_client.v2.model.logs_metric_type import LogsMetricType
from datadog_api_client.v2.model.logs_metric_update_attributes import LogsMetricUpdateAttributes
from datadog_api_client.v2.model.logs_metric_update_compute import LogsMetricUpdateCompute
from datadog_api_client.v2.model.logs_metric_update_data import LogsMetricUpdateData
from datadog_api_client.v2.model.logs_metric_update_request import LogsMetricUpdateRequest
from datadog_api_client.v2.model.logs_metrics_response import LogsMetricsResponse
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2022-05-12T09:52:22.599Z
2022-11-21T15:36:05.545Z
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
interactions:
- request:
body: '{"data":{"attributes":{"compute":{"aggregation_type":"count"}},"id":"Test-Create_a_log_based_metric_returns_OK_response-1652349142","type":"logs_metrics"}}'
body: '{"data":{"attributes":{"compute":{"aggregation_type":"distribution","include_percentiles":true,"path":"@duration"}},"id":"Test-Create_a_log_based_metric_returns_OK_response-1669044965","type":"logs_metrics"}}'
headers:
accept:
- application/json
Expand All @@ -10,7 +10,9 @@ interactions:
uri: https://api.datadoghq.com/api/v2/logs/config/metrics
response:
body:
string: '{"data":{"attributes":{"filter":{"query":"*"},"group_by":[],"compute":{"aggregation_type":"count"}},"type":"logs_metrics","id":"Test_Create_a_log_based_metric_returns_OK_response_1652349142"}}'
string: '{"data":{"attributes":{"filter":{"query":"*"},"group_by":[],"compute":{"path":"@duration","include_percentiles":true,"aggregation_type":"distribution"}},"type":"logs_metrics","id":"Test_Create_a_log_based_metric_returns_OK_response_1669044965"}}
'
headers:
content-type:
- application/json
Expand All @@ -23,10 +25,12 @@ interactions:
accept:
- '*/*'
method: DELETE
uri: https://api.datadoghq.com/api/v2/logs/config/metrics/Test_Create_a_log_based_metric_returns_OK_response_1652349142
uri: https://api.datadoghq.com/api/v2/logs/config/metrics/Test_Create_a_log_based_metric_returns_OK_response_1669044965
response:
body:
string: '{}'
string: '{}
'
headers:
content-type:
- application/json
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2022-11-21T19:49:25.214Z
Loading

0 comments on commit 607a713

Please sign in to comment.