Skip to content

Add sort field to SLOListWidgetQuery #1342

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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": "2023-02-14 22:24:43.220610",
"spec_repo_commit": "7a7cb634"
"regenerated": "2023-02-15 14:54:05.761282",
"spec_repo_commit": "3371aaa2"
},
"v2": {
"apigentools_version": "1.6.4",
"regenerated": "2023-02-14 22:24:43.240902",
"spec_repo_commit": "7a7cb634"
"regenerated": "2023-02-15 14:54:05.774859",
"spec_repo_commit": "3371aaa2"
}
}
}
5 changes: 5 additions & 0 deletions .generator/schemas/v1/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9668,6 +9668,11 @@ components:
description: Widget query.
example: env:prod AND service:my-app
type: string
sort:
description: Options for sorting results.
items:
$ref: '#/components/schemas/WidgetFieldSort'
type: array
required:
- query_string
type: object
Expand Down
64 changes: 64 additions & 0 deletions examples/v1/dashboards/CreateDashboard_109450134.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
"""
Create a new dashboard with slo list widget with sort
"""

from datadog_api_client import ApiClient, Configuration
from datadog_api_client.v1.api.dashboards_api import DashboardsApi
from datadog_api_client.v1.model.dashboard import Dashboard
from datadog_api_client.v1.model.dashboard_layout_type import DashboardLayoutType
from datadog_api_client.v1.model.slo_list_widget_definition import SLOListWidgetDefinition
from datadog_api_client.v1.model.slo_list_widget_definition_type import SLOListWidgetDefinitionType
from datadog_api_client.v1.model.slo_list_widget_query import SLOListWidgetQuery
from datadog_api_client.v1.model.slo_list_widget_request import SLOListWidgetRequest
from datadog_api_client.v1.model.slo_list_widget_request_type import SLOListWidgetRequestType
from datadog_api_client.v1.model.widget import Widget
from datadog_api_client.v1.model.widget_field_sort import WidgetFieldSort
from datadog_api_client.v1.model.widget_layout import WidgetLayout
from datadog_api_client.v1.model.widget_sort import WidgetSort
from datadog_api_client.v1.model.widget_text_align import WidgetTextAlign

body = Dashboard(
title="Example-Create_a_new_dashboard_with_slo_list_widget_with_sort",
description="",
widgets=[
Widget(
layout=WidgetLayout(
x=0,
y=0,
width=60,
height=21,
),
definition=SLOListWidgetDefinition(
title_size="16",
title_align=WidgetTextAlign.LEFT,
type=SLOListWidgetDefinitionType.SLO_LIST,
requests=[
SLOListWidgetRequest(
query=SLOListWidgetQuery(
query_string="env:prod AND service:my-app",
limit=75,
sort=[
WidgetFieldSort(
column="status.sli",
order=WidgetSort.ASCENDING,
),
],
),
request_type=SLOListWidgetRequestType.SLO_LIST,
),
],
),
),
],
template_variables=[],
layout_type=DashboardLayoutType.FREE,
is_read_only=False,
notify_list=[],
)

configuration = Configuration()
with ApiClient(configuration) as api_client:
api_instance = DashboardsApi(api_client)
response = api_instance.create_dashboard(body=body)

print(response)
23 changes: 21 additions & 2 deletions src/datadog_api_client/v1/model/slo_list_widget_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# Copyright 2019-Present Datadog, Inc.
from __future__ import annotations

from typing import Union
from typing import List, Union, TYPE_CHECKING

from datadog_api_client.model_utils import (
ModelNormal,
Expand All @@ -13,6 +13,10 @@
)


if TYPE_CHECKING:
from datadog_api_client.v1.model.widget_field_sort import WidgetFieldSort


class SLOListWidgetQuery(ModelNormal):
validations = {
"limit": {
Expand All @@ -23,17 +27,27 @@ class SLOListWidgetQuery(ModelNormal):

@cached_property
def openapi_types(_):
from datadog_api_client.v1.model.widget_field_sort import WidgetFieldSort

return {
"limit": (int,),
"query_string": (str,),
"sort": ([WidgetFieldSort],),
}

attribute_map = {
"limit": "limit",
"query_string": "query_string",
"sort": "sort",
}

def __init__(self_, query_string: str, limit: Union[int, UnsetType] = unset, **kwargs):
def __init__(
self_,
query_string: str,
limit: Union[int, UnsetType] = unset,
sort: Union[List[WidgetFieldSort], UnsetType] = unset,
**kwargs,
):
"""
Updated SLO List widget.

Expand All @@ -42,9 +56,14 @@ def __init__(self_, query_string: str, limit: Union[int, UnsetType] = unset, **k

:param query_string: Widget query.
:type query_string: str

:param sort: Options for sorting results.
:type sort: [WidgetFieldSort], optional
"""
if limit is not unset:
kwargs["limit"] = limit
if sort is not unset:
kwargs["sort"] = sort
super().__init__(kwargs)

self_.query_string = query_string
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2023-02-14T18:54:56.599Z
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
interactions:
- request:
body: '{"name":"Test-Create_a_new_dashboard_with_slo_list_widget_with_sort-1676400896","query":{"denominator":"sum:httpservice.hits{!code:3xx}.as_count()","numerator":"sum:httpservice.hits{code:2xx}.as_count()"},"thresholds":[{"target":95,"timeframe":"7d","warning":98}],"type":"metric"}'
headers:
accept:
- application/json
content-type:
- application/json
method: POST
uri: https://api.datadoghq.com/api/v1/slo
response:
body:
string: '{"data":[{"id":"80091437d0165587a0831040981e44f9","name":"Test-Create_a_new_dashboard_with_slo_list_widget_with_sort-1676400896","tags":[],"monitor_tags":[],"thresholds":[{"timeframe":"7d","target":95.0,"target_display":"95.","warning":98.0,"warning_display":"98."}],"type":"metric","type_id":1,"description":"","timeframe":"7d","warning_threshold":98,"target_threshold":95,"query":{"denominator":"sum:httpservice.hits{!code:3xx}.as_count()","numerator":"sum:httpservice.hits{code:2xx}.as_count()"},"creator":{"name":null,"handle":"[email protected]","email":"[email protected]"},"created_at":1676400896,"modified_at":1676400896}],"error":null}

'
headers:
content-type:
- application/json
status:
code: 200
message: OK
- request:
body: '{"description":"","is_read_only":false,"layout_type":"free","notify_list":[],"template_variables":[],"title":"Test-Create_a_new_dashboard_with_slo_list_widget_with_sort-1676400896","widgets":[{"definition":{"requests":[{"query":{"limit":75,"query_string":"env:prod
AND service:my-app","sort":[{"column":"status.sli","order":"asc"}]},"request_type":"slo_list"}],"title_align":"left","title_size":"16","type":"slo_list"},"layout":{"height":21,"width":60,"x":0,"y":0}}]}'
headers:
accept:
- application/json
content-type:
- application/json
method: POST
uri: https://api.datadoghq.com/api/v1/dashboard
response:
body:
string: '{"id":"6hq-ih3-tzg","title":"Test-Create_a_new_dashboard_with_slo_list_widget_with_sort-1676400896","description":"","author_handle":"[email protected]","author_name":null,"layout_type":"free","url":"/dashboard/6hq-ih3-tzg/test-createanewdashboardwithslolistwidgetwithsort-1676400896","is_read_only":false,"template_variables":[],"widgets":[{"definition":{"requests":[{"query":{"limit":75,"query_string":"env:prod
AND service:my-app","sort":[{"column":"status.sli","order":"asc"}]},"request_type":"slo_list"}],"title_align":"left","title_size":"16","type":"slo_list"},"layout":{"height":21,"width":60,"x":0,"y":0},"id":1642439378480719}],"notify_list":[],"created_at":"2023-02-14T18:54:57.012649+00:00","modified_at":"2023-02-14T18:54:57.012649+00:00","restricted_roles":[]}

'
headers:
content-type:
- application/json
status:
code: 200
message: OK
- request:
body: null
headers:
accept:
- application/json
method: DELETE
uri: https://api.datadoghq.com/api/v1/dashboard/6hq-ih3-tzg
response:
body:
string: '{"deleted_dashboard_id":"6hq-ih3-tzg"}

'
headers:
content-type:
- application/json
status:
code: 200
message: OK
- request:
body: null
headers:
accept:
- application/json
method: DELETE
uri: https://api.datadoghq.com/api/v1/slo/80091437d0165587a0831040981e44f9
response:
body:
string: '{"data":["80091437d0165587a0831040981e44f9"],"error":null}

'
headers:
content-type:
- application/json
status:
code: 200
message: OK
version: 1
13 changes: 13 additions & 0 deletions tests/v1/features/dashboards.feature
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,19 @@ Feature: Dashboards
And the response "widgets[0].definition.requests[0].query.query_string" is equal to "env:prod AND service:my-app"
And the response "widgets[0].definition.requests[0].query.limit" is equal to 75

@team:DataDog/dashboards
Scenario: Create a new dashboard with slo list widget with sort
Given there is a valid "slo" in the system
And new "CreateDashboard" request
And body from file "dashboards_json_payload/slo_list_widget_with_sort.json"
When the request is sent
Then the response status is 200 OK
And the response "widgets[0].definition.type" is equal to "slo_list"
And the response "widgets[0].definition.requests[0].query.query_string" is equal to "env:prod AND service:my-app"
And the response "widgets[0].definition.requests[0].query.limit" is equal to 75
And the response "widgets[0].definition.requests[0].query.sort[0].column" is equal to "status.sli"
And the response "widgets[0].definition.requests[0].query.sort[0].order" is equal to "asc"

@team:DataDog/dashboards
Scenario: Create a new dashboard with slo widget
Given there is a valid "slo" in the system
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"title": "{{ unique }}",
"description": "",
"widgets": [
{
"layout": {
"x": 0,
"y": 0,
"width": 60,
"height": 21
},
"definition": {
"title_size": "16",
"title_align": "left",
"type": "slo_list",
"requests": [
{
"query": {
"query_string": "env:prod AND service:my-app",
"limit": 75,
"sort": [
{
"column": "status.sli",
"order": "asc"
}
]
},
"request_type": "slo_list"
}
]
}
}
],
"template_variables": [],
"layout_type": "free",
"is_read_only": false,
"notify_list": []
}