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

Add formula and function slo query to dash widgets #1373

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-05-17 14:44:35.705822",
"spec_repo_commit": "f8bfb8c1"
"regenerated": "2023-05-17 20:58:05.065018",
"spec_repo_commit": "d8186149"
},
"v2": {
"apigentools_version": "1.6.4",
"regenerated": "2023-05-17 14:44:35.718657",
"spec_repo_commit": "f8bfb8c1"
"regenerated": "2023-05-17 20:58:05.077115",
"spec_repo_commit": "d8186149"
}
}
}
76 changes: 76 additions & 0 deletions .generator/schemas/v1/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2728,6 +2728,7 @@ components:
- $ref: '#/components/schemas/FormulaAndFunctionProcessQueryDefinition'
- $ref: '#/components/schemas/FormulaAndFunctionApmDependencyStatsQueryDefinition'
- $ref: '#/components/schemas/FormulaAndFunctionApmResourceStatsQueryDefinition'
- $ref: '#/components/schemas/FormulaAndFunctionSLOQueryDefinition'
type: object
FormulaAndFunctionResponseFormat:
description: Timeseries or Scalar response.
Expand All @@ -2739,6 +2740,81 @@ components:
x-enum-varnames:
- TIMESERIES
- SCALAR
FormulaAndFunctionSLODataSource:
description: Data source for SLO measures queries.
enum:
- slo
example: slo
type: string
x-enum-varnames:
- SLO
FormulaAndFunctionSLOGroupMode:
description: Group mode to query measures.
enum:
- overall
- components
example: overall
type: string
x-enum-varnames:
- OVERALL
- COMPONENTS
FormulaAndFunctionSLOMeasure:
description: SLO measures queries.
enum:
- good_events
- bad_events
- slo_status
- error_budget_remaining
- burn_rate
- error_budget_burndown
example: slo_status
type: string
x-enum-varnames:
- GOOD_EVENTS
- BAD_EVENTS
- SLO_STATUS
- ERROR_BUDGET_REMAINING
- BURN_RATE
- ERROR_BUDGET_BURNDOWN
FormulaAndFunctionSLOQueryDefinition:
description: A formula and functions metrics query.
example:
data_source: slo
group_mode: overall
measure: good_events
name: my_slo
slo_id: '12345678910'
slo_query_type: metric
properties:
data_source:
$ref: '#/components/schemas/FormulaAndFunctionSLODataSource'
group_mode:
$ref: '#/components/schemas/FormulaAndFunctionSLOGroupMode'
measure:
$ref: '#/components/schemas/FormulaAndFunctionSLOMeasure'
name:
description: Name of the query for use in formulas.
example: my_slo
type: string
slo_id:
description: ID of an SLO to query measures.
example: '12345678910'
type: string
slo_query_type:
$ref: '#/components/schemas/FormulaAndFunctionSLOQueryType'
required:
- data_source
- slo_id
- measure
type: object
FormulaAndFunctionSLOQueryType:
description: Name of the query for use in formulas.
enum:
- metric
example: metric
type: string
x-enum-varnames:
- METRIC
FreeTextWidgetDefinition:
description: Free text is a widget that allows you to add headings to your screenboard.
Commonly used to state the overall purpose of the dashboard. Only available
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2023-05-16T22:06:53.853Z

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

57 changes: 57 additions & 0 deletions examples/v1/dashboards/CreateDashboard_3562282606.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# Create a new dashboard with a change widget using formulas and functions slo query

require "datadog_api_client"
api_instance = DatadogAPIClient::V1::DashboardsAPI.new

# there is a valid "slo" in the system
SLO_DATA_0_ID = ENV["SLO_DATA_0_ID"]

body = DatadogAPIClient::V1::Dashboard.new({
title: "Example-Dashboard",
widgets: [
DatadogAPIClient::V1::Widget.new({
definition: DatadogAPIClient::V1::ChangeWidgetDefinition.new({
title: "",
title_size: "16",
title_align: DatadogAPIClient::V1::WidgetTextAlign::LEFT,
time: DatadogAPIClient::V1::WidgetTime.new({}),
type: DatadogAPIClient::V1::ChangeWidgetDefinitionType::CHANGE,
requests: [
DatadogAPIClient::V1::ChangeWidgetRequest.new({
formulas: [
DatadogAPIClient::V1::WidgetFormula.new({
formula: "hour_before(query1)",
}),
DatadogAPIClient::V1::WidgetFormula.new({
formula: "query1",
}),
],
queries: [
DatadogAPIClient::V1::FormulaAndFunctionSLOQueryDefinition.new({
name: "query1",
data_source: DatadogAPIClient::V1::FormulaAndFunctionSLODataSource::SLO,
slo_id: SLO_DATA_0_ID,
measure: DatadogAPIClient::V1::FormulaAndFunctionSLOMeasure::SLO_STATUS,
group_mode: DatadogAPIClient::V1::FormulaAndFunctionSLOGroupMode::OVERALL,
slo_query_type: DatadogAPIClient::V1::FormulaAndFunctionSLOQueryType::METRIC,
}),
],
response_format: DatadogAPIClient::V1::FormulaAndFunctionResponseFormat::SCALAR,
order_by: DatadogAPIClient::V1::WidgetOrderBy::CHANGE,
change_type: DatadogAPIClient::V1::WidgetChangeType::ABSOLUTE,
increase_good: true,
order_dir: DatadogAPIClient::V1::WidgetSort::ASCENDING,
}),
],
}),
layout: DatadogAPIClient::V1::WidgetLayout.new({
x: 0,
y: 0,
width: 4,
height: 2,
}),
}),
],
layout_type: DatadogAPIClient::V1::DashboardLayoutType::ORDERED,
})
p api_instance.create_dashboard(body)
21 changes: 21 additions & 0 deletions features/v1/dashboards.feature
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,27 @@ Feature: Dashboards
And the response "widgets[0].definition.requests[0].profile_metrics_query.compute.facet" is equal to "@prof_core_cpu_cores"
And the response "widgets[0].definition.requests[0].profile_metrics_query.compute.aggregation" is equal to "sum"

@team:DataDog/dashboards-backend
Scenario: Create a new dashboard with a change widget using formulas and functions slo query
Given there is a valid "slo" in the system
And new "CreateDashboard" request
And body with value { "title": "{{ unique }}", "widgets": [ { "definition": {"title": "", "title_size": "16", "title_align": "left", "time": {}, "type": "change", "requests": [ {"formulas": [ { "formula": "hour_before(query1)" }, { "formula": "query1" } ], "queries": [ {"name": "query1", "data_source": "slo", "slo_id": "{{ slo.data[0].id }}", "measure": "slo_status", "group_mode": "overall", "slo_query_type": "metric" } ], "response_format": "scalar", "order_by": "change", "change_type": "absolute", "increase_good": true, "order_dir": "asc" } ] }, "layout": { "x":0, "y": 0, "width": 4, "height": 2 } } ], "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].increase_good" is equal to true
And the response "widgets[0].definition.requests[0].order_by" is equal to "change"
And the response "widgets[0].definition.requests[0].change_type" is equal to "absolute"
And the response "widgets[0].definition.requests[0].order_dir" is equal to "asc"
And the response "widgets[0].definition.requests[0].queries[0].data_source" is equal to "slo"
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].group_mode" is equal to "overall"
And the response "widgets[0].definition.requests[0].queries[0].measure" is equal to "slo_status"
And the response "widgets[0].definition.requests[0].queries[0].slo_query_type" is equal to "metric"
And the response "widgets[0].definition.requests[0].queries[0].slo_id" has the same value as "slo.data[0].id"
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-backend
Scenario: Create a new dashboard with a formulas and functions change widget
Given new "CreateDashboard" request
Expand Down
5 changes: 5 additions & 0 deletions lib/datadog_api_client/inflector.rb
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,11 @@ def overrides
"v1.formula_and_function_process_query_definition" => "FormulaAndFunctionProcessQueryDefinition",
"v1.formula_and_function_query_definition" => "FormulaAndFunctionQueryDefinition",
"v1.formula_and_function_response_format" => "FormulaAndFunctionResponseFormat",
"v1.formula_and_function_slo_data_source" => "FormulaAndFunctionSLODataSource",
"v1.formula_and_function_slo_group_mode" => "FormulaAndFunctionSLOGroupMode",
"v1.formula_and_function_slo_measure" => "FormulaAndFunctionSLOMeasure",
"v1.formula_and_function_slo_query_definition" => "FormulaAndFunctionSLOQueryDefinition",
"v1.formula_and_function_slo_query_type" => "FormulaAndFunctionSLOQueryType",
"v1.free_text_widget_definition" => "FreeTextWidgetDefinition",
"v1.free_text_widget_definition_type" => "FreeTextWidgetDefinitionType",
"v1.funnel_query" => "FunnelQuery",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ def openapi_one_of
:'FormulaAndFunctionEventQueryDefinition',
:'FormulaAndFunctionProcessQueryDefinition',
:'FormulaAndFunctionApmDependencyStatsQueryDefinition',
:'FormulaAndFunctionApmResourceStatsQueryDefinition'
:'FormulaAndFunctionApmResourceStatsQueryDefinition',
:'FormulaAndFunctionSLOQueryDefinition'
]
end
# Builds the object
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
=begin
#Datadog API V1 Collection

#Collection of all Datadog Public endpoints.

The version of the OpenAPI document: 1.0
Contact: support@datadoghq.com
Generated by: https://github.com/DataDog/datadog-api-client-ruby/tree/master/.generator

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 2020-Present Datadog, Inc.

=end

require 'date'
require 'time'

module DatadogAPIClient::V1
# Data source for SLO measures queries.
class FormulaAndFunctionSLODataSource
include BaseEnumModel

SLO = "slo".freeze
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
=begin
#Datadog API V1 Collection

#Collection of all Datadog Public endpoints.

The version of the OpenAPI document: 1.0
Contact: support@datadoghq.com
Generated by: https://github.com/DataDog/datadog-api-client-ruby/tree/master/.generator

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 2020-Present Datadog, Inc.

=end

require 'date'
require 'time'

module DatadogAPIClient::V1
# Group mode to query measures.
class FormulaAndFunctionSLOGroupMode
include BaseEnumModel

OVERALL = "overall".freeze
COMPONENTS = "components".freeze
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
=begin
#Datadog API V1 Collection

#Collection of all Datadog Public endpoints.

The version of the OpenAPI document: 1.0
Contact: support@datadoghq.com
Generated by: https://github.com/DataDog/datadog-api-client-ruby/tree/master/.generator

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 2020-Present Datadog, Inc.

=end

require 'date'
require 'time'

module DatadogAPIClient::V1
# SLO measures queries.
class FormulaAndFunctionSLOMeasure
include BaseEnumModel

GOOD_EVENTS = "good_events".freeze
BAD_EVENTS = "bad_events".freeze
SLO_STATUS = "slo_status".freeze
ERROR_BUDGET_REMAINING = "error_budget_remaining".freeze
BURN_RATE = "burn_rate".freeze
ERROR_BUDGET_BURNDOWN = "error_budget_burndown".freeze
end
end
Loading