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 incident_analytics enum in dashboard widget FormulaAndFunctionEventsDataSource data sources #2594

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.6",
"regenerated": "2024-07-22 20:03:19.855082",
"spec_repo_commit": "cd020fa6"
"regenerated": "2024-07-23 15:33:48.760135",
"spec_repo_commit": "015355f6"
},
"v2": {
"apigentools_version": "1.6.6",
"regenerated": "2024-07-22 20:03:19.873734",
"spec_repo_commit": "cd020fa6"
"regenerated": "2024-07-23 15:33:48.778613",
"spec_repo_commit": "015355f6"
}
}
}
2 changes: 2 additions & 0 deletions .generator/schemas/v1/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2867,6 +2867,7 @@ components:
- events
- ci_tests
- ci_pipelines
- incident_analytics
example: logs
type: string
x-enum-varnames:
Expand All @@ -2880,6 +2881,7 @@ components:
- EVENTS
- CI_TESTS
- CI_PIPELINES
- INCIDENT_ANALYTICS
FormulaAndFunctionMetricAggregation:
description: The aggregation methods available for metrics queries.
enum:
Expand Down
22 changes: 12 additions & 10 deletions api/datadogV1/model_formula_and_function_events_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,17 @@ type FormulaAndFunctionEventsDataSource string

// List of FormulaAndFunctionEventsDataSource.
const (
FORMULAANDFUNCTIONEVENTSDATASOURCE_LOGS FormulaAndFunctionEventsDataSource = "logs"
FORMULAANDFUNCTIONEVENTSDATASOURCE_SPANS FormulaAndFunctionEventsDataSource = "spans"
FORMULAANDFUNCTIONEVENTSDATASOURCE_NETWORK FormulaAndFunctionEventsDataSource = "network"
FORMULAANDFUNCTIONEVENTSDATASOURCE_RUM FormulaAndFunctionEventsDataSource = "rum"
FORMULAANDFUNCTIONEVENTSDATASOURCE_SECURITY_SIGNALS FormulaAndFunctionEventsDataSource = "security_signals"
FORMULAANDFUNCTIONEVENTSDATASOURCE_PROFILES FormulaAndFunctionEventsDataSource = "profiles"
FORMULAANDFUNCTIONEVENTSDATASOURCE_AUDIT FormulaAndFunctionEventsDataSource = "audit"
FORMULAANDFUNCTIONEVENTSDATASOURCE_EVENTS FormulaAndFunctionEventsDataSource = "events"
FORMULAANDFUNCTIONEVENTSDATASOURCE_CI_TESTS FormulaAndFunctionEventsDataSource = "ci_tests"
FORMULAANDFUNCTIONEVENTSDATASOURCE_CI_PIPELINES FormulaAndFunctionEventsDataSource = "ci_pipelines"
FORMULAANDFUNCTIONEVENTSDATASOURCE_LOGS FormulaAndFunctionEventsDataSource = "logs"
FORMULAANDFUNCTIONEVENTSDATASOURCE_SPANS FormulaAndFunctionEventsDataSource = "spans"
FORMULAANDFUNCTIONEVENTSDATASOURCE_NETWORK FormulaAndFunctionEventsDataSource = "network"
FORMULAANDFUNCTIONEVENTSDATASOURCE_RUM FormulaAndFunctionEventsDataSource = "rum"
FORMULAANDFUNCTIONEVENTSDATASOURCE_SECURITY_SIGNALS FormulaAndFunctionEventsDataSource = "security_signals"
FORMULAANDFUNCTIONEVENTSDATASOURCE_PROFILES FormulaAndFunctionEventsDataSource = "profiles"
FORMULAANDFUNCTIONEVENTSDATASOURCE_AUDIT FormulaAndFunctionEventsDataSource = "audit"
FORMULAANDFUNCTIONEVENTSDATASOURCE_EVENTS FormulaAndFunctionEventsDataSource = "events"
FORMULAANDFUNCTIONEVENTSDATASOURCE_CI_TESTS FormulaAndFunctionEventsDataSource = "ci_tests"
FORMULAANDFUNCTIONEVENTSDATASOURCE_CI_PIPELINES FormulaAndFunctionEventsDataSource = "ci_pipelines"
FORMULAANDFUNCTIONEVENTSDATASOURCE_INCIDENT_ANALYTICS FormulaAndFunctionEventsDataSource = "incident_analytics"
)

var allowedFormulaAndFunctionEventsDataSourceEnumValues = []FormulaAndFunctionEventsDataSource{
Expand All @@ -38,6 +39,7 @@ var allowedFormulaAndFunctionEventsDataSourceEnumValues = []FormulaAndFunctionEv
FORMULAANDFUNCTIONEVENTSDATASOURCE_EVENTS,
FORMULAANDFUNCTIONEVENTSDATASOURCE_CI_TESTS,
FORMULAANDFUNCTIONEVENTSDATASOURCE_CI_PIPELINES,
FORMULAANDFUNCTIONEVENTSDATASOURCE_INCIDENT_ANALYTICS,
}

// GetAllowedValues reeturns the list of possible values.
Expand Down
86 changes: 86 additions & 0 deletions examples/v1/dashboards/CreateDashboard_985012506.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
// Create a new timeseries widget with incident_analytics data source

package main

import (
"context"
"encoding/json"
"fmt"
"os"

"github.com/DataDog/datadog-api-client-go/v2/api/datadog"
"github.com/DataDog/datadog-api-client-go/v2/api/datadogV1"
)

func main() {
body := datadogV1.Dashboard{
Title: "Example-Dashboard with incident_analytics datasource",
Widgets: []datadogV1.Widget{
{
Definition: datadogV1.WidgetDefinition{
TimeseriesWidgetDefinition: &datadogV1.TimeseriesWidgetDefinition{
Title: datadog.PtrString(""),
ShowLegend: datadog.PtrBool(true),
LegendLayout: datadogV1.TIMESERIESWIDGETLEGENDLAYOUT_AUTO.Ptr(),
LegendColumns: []datadogV1.TimeseriesWidgetLegendColumn{
datadogV1.TIMESERIESWIDGETLEGENDCOLUMN_AVG,
datadogV1.TIMESERIESWIDGETLEGENDCOLUMN_MIN,
datadogV1.TIMESERIESWIDGETLEGENDCOLUMN_MAX,
datadogV1.TIMESERIESWIDGETLEGENDCOLUMN_VALUE,
datadogV1.TIMESERIESWIDGETLEGENDCOLUMN_SUM,
},
Time: &datadogV1.WidgetTime{},
Type: datadogV1.TIMESERIESWIDGETDEFINITIONTYPE_TIMESERIES,
Requests: []datadogV1.TimeseriesWidgetRequest{
{
Formulas: []datadogV1.WidgetFormula{
{
Formula: "query1",
},
},
Queries: []datadogV1.FormulaAndFunctionQueryDefinition{
datadogV1.FormulaAndFunctionQueryDefinition{
FormulaAndFunctionEventQueryDefinition: &datadogV1.FormulaAndFunctionEventQueryDefinition{
DataSource: datadogV1.FORMULAANDFUNCTIONEVENTSDATASOURCE_INCIDENT_ANALYTICS,
Name: "query1",
Search: &datadogV1.FormulaAndFunctionEventQueryDefinitionSearch{
Query: "test_level:test",
},
Indexes: []string{
"*",
},
Compute: datadogV1.FormulaAndFunctionEventQueryDefinitionCompute{
Aggregation: datadogV1.FORMULAANDFUNCTIONEVENTAGGREGATION_COUNT,
},
GroupBy: []datadogV1.FormulaAndFunctionEventQueryGroupBy{},
}},
},
ResponseFormat: datadogV1.FORMULAANDFUNCTIONRESPONSEFORMAT_TIMESERIES.Ptr(),
Style: &datadogV1.WidgetRequestStyle{
Palette: datadog.PtrString("dog_classic"),
LineType: datadogV1.WIDGETLINETYPE_SOLID.Ptr(),
LineWidth: datadogV1.WIDGETLINEWIDTH_NORMAL.Ptr(),
},
DisplayType: datadogV1.WIDGETDISPLAYTYPE_LINE.Ptr(),
},
},
}},
},
},
LayoutType: datadogV1.DASHBOARDLAYOUTTYPE_ORDERED,
ReflowType: datadogV1.DASHBOARDREFLOWTYPE_AUTO.Ptr(),
}
ctx := datadog.NewDefaultContext(context.Background())
configuration := datadog.NewConfiguration()
apiClient := datadog.NewAPIClient(configuration)
api := datadogV1.NewDashboardsApi(apiClient)
resp, r, err := api.CreateDashboard(ctx, body)

if err != nil {
fmt.Fprintf(os.Stderr, "Error when calling `DashboardsApi.CreateDashboard`: %v\n", err)
fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r)
}

responseContent, _ := json.MarshalIndent(resp, "", " ")
fmt.Fprintf(os.Stdout, "Response from `DashboardsApi.CreateDashboard`:\n%s\n", responseContent)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2024-07-23T14:59:59.215Z
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
interactions:
- request:
body: |
{"layout_type":"ordered","reflow_type":"auto","title":"Test-Create_a_new_timeseries_widget_with_incident_analytics_data_source-1721746799 with incident_analytics datasource","widgets":[{"definition":{"legend_columns":["avg","min","max","value","sum"],"legend_layout":"auto","requests":[{"display_type":"line","formulas":[{"formula":"query1"}],"queries":[{"compute":{"aggregation":"count"},"data_source":"incident_analytics","group_by":[],"indexes":["*"],"name":"query1","search":{"query":"test_level:test"}}],"response_format":"timeseries","style":{"line_type":"solid","line_width":"normal","palette":"dog_classic"}}],"show_legend":true,"time":{},"title":"","type":"timeseries"}}]}
form: {}
headers:
Accept:
- application/json
Content-Type:
- application/json
id: 0
method: POST
url: https://api.datadoghq.com/api/v1/dashboard
response:
body: '{"id":"r29-a2b-nhh","title":"Test-Create_a_new_timeseries_widget_with_incident_analytics_data_source-1721746799
with incident_analytics datasource","description":null,"author_handle":"frog@datadoghq.com","author_name":null,"layout_type":"ordered","url":"/dashboard/r29-a2b-nhh/test-createanewtimeserieswidgetwithincidentanalyticsdatasource-1721746799-with-i","is_read_only":false,"template_variables":null,"widgets":[{"definition":{"legend_columns":["avg","min","max","value","sum"],"legend_layout":"auto","requests":[{"display_type":"line","formulas":[{"formula":"query1"}],"queries":[{"compute":{"aggregation":"count"},"data_source":"incident_analytics","group_by":[],"indexes":["*"],"name":"query1","search":{"query":"test_level:test"}}],"response_format":"timeseries","style":{"line_type":"solid","line_width":"normal","palette":"dog_classic"}}],"show_legend":true,"time":{},"title":"","type":"timeseries"},"id":4216078110414841}],"notify_list":null,"created_at":"2024-07-23T14:59:59.491800+00:00","modified_at":"2024-07-23T14:59:59.491800+00:00","reflow_type":"auto","restricted_roles":[]}

'
code: 200
duration: 0ms
headers:
Content-Type:
- application/json
status: 200 OK
- request:
body: ''
form: {}
headers:
Accept:
- application/json
id: 1
method: DELETE
url: https://api.datadoghq.com/api/v1/dashboard/r29-a2b-nhh
response:
body: '{"deleted_dashboard_id":"r29-a2b-nhh"}

'
code: 200
duration: 0ms
headers:
Content-Type:
- application/json
status: 200 OK
version: 2
9 changes: 9 additions & 0 deletions tests/scenarios/features/v1/dashboards.feature
Original file line number Diff line number Diff line change
Expand Up @@ -830,6 +830,15 @@ Feature: Dashboards
And the response "widgets[0].definition.requests[0].queries[0].data_source" is equal to "ci_tests"
And the response "widgets[0].definition.requests[0].queries[0].search.query" is equal to "test_level:test"

@team:DataDog/dashboards-backend
Scenario: Create a new timeseries widget with incident_analytics data source
Given new "CreateDashboard" request
And body with value {"title":"{{ unique }} with incident_analytics datasource","widgets":[{"definition":{"title":"","show_legend":true,"legend_layout":"auto","legend_columns":["avg","min","max","value","sum"],"time":{},"type":"timeseries","requests":[{"formulas":[{"formula":"query1"}],"queries":[{"data_source":"incident_analytics","name":"query1","search":{"query":"test_level:test"},"indexes":["*"],"compute":{"aggregation":"count"},"group_by":[]}],"response_format":"timeseries","style":{"palette":"dog_classic","line_type":"solid","line_width":"normal"},"display_type":"line"}]}}],"layout_type":"ordered","reflow_type":"auto"}
When the request is sent
Then the response status is 200 OK
And the response "widgets[0].definition.requests[0].queries[0].data_source" is equal to "incident_analytics"
And the response "widgets[0].definition.requests[0].queries[0].search.query" is equal to "test_level:test"

@generated @skip @team:DataDog/dashboards-backend
Scenario: Create a shared dashboard returns "Bad Request" response
Given new "CreatePublicDashboard" request
Expand Down
Loading