Skip to content
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

Support formulas and functions in Treemap Widget #782

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.5.1.dev2",
"regenerated": "2022-01-12 15:42:27.276817",
"spec_repo_commit": "9a4c69f"
"regenerated": "2022-01-12 16:36:57.460339",
"spec_repo_commit": "9f3c740"
},
"v2": {
"apigentools_version": "1.5.1.dev2",
"regenerated": "2022-01-12 15:42:27.797360",
"spec_repo_commit": "9a4c69f"
"regenerated": "2022-01-12 16:36:57.916544",
"spec_repo_commit": "9f3c740"
}
}
}
17 changes: 14 additions & 3 deletions .generator/schemas/v1/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12260,9 +12260,6 @@ components:
required:
- type
- requests
- size_by
- color_by
- group_by
type: object
TreeMapWidgetDefinitionType:
default: treemap
Expand All @@ -12276,9 +12273,23 @@ components:
TreeMapWidgetRequest:
description: An updated treemap widget.
properties:
formulas:
description: List of formulas that operate on queries. **This feature is
currently in beta.**
items:
$ref: '#/components/schemas/WidgetFormula'
type: array
q:
description: The widget metrics query.
type: string
queries:
description: List of queries that can be returned directly or used in formulas.
**This feature is currently in beta.**
items:
$ref: '#/components/schemas/FormulaAndFunctionQueryDefinition'
type: array
response_format:
$ref: '#/components/schemas/FormulaAndFunctionResponseFormat'
type: object
UsageAnalyzedLogsHour:
description: The number of analyzed logs for each hour for a given organization.
Expand Down
6 changes: 3 additions & 3 deletions docs/v1/TreeMapWidgetDefinition.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 6 additions & 3 deletions docs/v1/TreeMapWidgetRequest.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

65 changes: 65 additions & 0 deletions examples/v1/dashboards/CreateDashboard_1024858348.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
"""
Create a new dashboard with a formulas and functions treemap widget
"""

from datadog_api_client.v1 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.formula_and_function_event_aggregation import FormulaAndFunctionEventAggregation
from datadog_api_client.v1.model.formula_and_function_event_query_definition import (
FormulaAndFunctionEventQueryDefinition,
)
from datadog_api_client.v1.model.formula_and_function_event_query_definition_compute import (
FormulaAndFunctionEventQueryDefinitionCompute,
)
from datadog_api_client.v1.model.formula_and_function_event_query_definition_search import (
FormulaAndFunctionEventQueryDefinitionSearch,
)
from datadog_api_client.v1.model.formula_and_function_events_data_source import FormulaAndFunctionEventsDataSource
from datadog_api_client.v1.model.formula_and_function_response_format import FormulaAndFunctionResponseFormat
from datadog_api_client.v1.model.tree_map_widget_definition import TreeMapWidgetDefinition
from datadog_api_client.v1.model.tree_map_widget_definition_type import TreeMapWidgetDefinitionType
from datadog_api_client.v1.model.tree_map_widget_request import TreeMapWidgetRequest
from datadog_api_client.v1.model.widget import Widget
from datadog_api_client.v1.model.widget_formula import WidgetFormula
from datadog_api_client.v1.model.widget_layout import WidgetLayout

body = Dashboard(
title="Example-Create_a_new_dashboard_with_a_formulas_and_functions_treemap_widget",
widgets=[
Widget(
definition=TreeMapWidgetDefinition(
title="",
type=TreeMapWidgetDefinitionType("treemap"),
requests=[
TreeMapWidgetRequest(
formulas=[WidgetFormula(formula="hour_before(query1)"), WidgetFormula(formula="query1")],
queries=[
FormulaAndFunctionEventQueryDefinition(
data_source=FormulaAndFunctionEventsDataSource("logs"),
name="query1",
search=FormulaAndFunctionEventQueryDefinitionSearch(query=""),
indexes=["*"],
compute=FormulaAndFunctionEventQueryDefinitionCompute(
aggregation=FormulaAndFunctionEventAggregation("count")
),
group_by=[],
)
],
response_format=FormulaAndFunctionResponseFormat("scalar"),
)
],
),
layout=WidgetLayout(x=0, y=0, width=4, height=4),
)
],
layout_type=DashboardLayoutType("ordered"),
)

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

print(response)
20 changes: 7 additions & 13 deletions src/datadog_api_client/v1/model/tree_map_widget_definition.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions src/datadog_api_client/v1/model/tree_map_widget_request.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions src/datadog_api_client/v1/model/widget_definition.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2022-01-12T10:11:31.394Z
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
interactions:
- request:
body: '{"layout_type":"ordered","title":"Test-Create_a_new_dashboard_with_a_formulas_and_functions_treemap_widget-1641982291","widgets":[{"definition":{"requests":[{"formulas":[{"formula":"hour_before(query1)"},{"formula":"query1"}],"queries":[{"compute":{"aggregation":"count"},"data_source":"logs","group_by":[],"indexes":["*"],"name":"query1","search":{"query":""}}],"response_format":"scalar"}],"title":"","type":"treemap"},"layout":{"height":4,"width":4,"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: '{"notify_list":null,"description":null,"restricted_roles":[],"author_name":null,"template_variables":null,"is_read_only":false,"id":"2ar-acj-hxc","title":"Test-Create_a_new_dashboard_with_a_formulas_and_functions_treemap_widget-1641982291","url":"/dashboard/2ar-acj-hxc/test-createanewdashboardwithaformulasandfunctionstreemapwidget-1641982291","created_at":"2022-01-12T10:11:31.601485+00:00","modified_at":"2022-01-12T10:11:31.601485+00:00","author_handle":"frog@datadoghq.com","widgets":[{"definition":{"requests":[{"formulas":[{"formula":"hour_before(query1)"},{"formula":"query1"}],"response_format":"scalar","queries":[{"search":{"query":""},"data_source":"logs","compute":{"aggregation":"count"},"name":"query1","indexes":["*"],"group_by":[]}]}],"type":"treemap","title":""},"layout":{"y":0,"width":4,"x":0,"height":4},"id":2836171994664464}],"layout_type":"ordered"}'
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/2ar-acj-hxc
response:
body:
string: '{"deleted_dashboard_id":"2ar-acj-hxc"}'
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 @@ -41,6 +41,19 @@ Feature: Dashboards
And the response "widgets[0].definition.requests[0].formulas[0].formula" is equal to "hour_before(query1)"
And the response "widgets[0].definition.requests[0].formulas[1].formula" is equal to "query1"

@team:DataDog/dashboards
Scenario: Create a new dashboard with a formulas and functions treemap widget
Given new "CreateDashboard" request
And body with value { "title": "{{ unique }}", "widgets": [ { "definition": { "title": "", "type": "treemap", "requests": [ { "formulas": [ { "formula": "hour_before(query1)" }, { "formula": "query1" } ], "queries": [ { "data_source": "logs", "name": "query1", "search": { "query": "" }, "indexes": [ "*" ], "compute": { "aggregation": "count" }, "group_by": [] } ], "response_format": "scalar" } ] }, "layout": { "x": 0, "y": 0, "width": 4, "height": 4 } } ], "layout_type": "ordered" }
When the request is sent
Then the response status is 200 OK
And the response "widgets[0].definition.requests[0].response_format" is equal to "scalar"
And the response "widgets[0].definition.requests[0].queries[0].data_source" is equal to "logs"
And the response "widgets[0].definition.requests[0].queries[0].name" is equal to "query1"
And the response "widgets[0].definition.requests[0].queries[0].compute.aggregation" is equal to "count"
And the response "widgets[0].definition.requests[0].formulas[0].formula" is equal to "hour_before(query1)"
And the response "widgets[0].definition.requests[0].formulas[1].formula" is equal to "query1"

@team:DataDog/dashboards
Scenario: Create a new dashboard with a query value widget using the percentile aggregator
Given new "CreateDashboard" request
Expand Down