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 support for Error Tracking monitors #1395

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.2",
"regenerated": "2022-03-17 17:21:23.574759",
"spec_repo_commit": "31d44cb6"
"regenerated": "2022-03-17 20:07:28.088200",
"spec_repo_commit": "717103c5"
},
"v2": {
"apigentools_version": "1.6.2",
"regenerated": "2022-03-17 17:21:23.590260",
"spec_repo_commit": "31d44cb6"
"regenerated": "2022-03-17 20:07:28.103072",
"spec_repo_commit": "717103c5"
}
}
}
31 changes: 30 additions & 1 deletion .generator/schemas/v1/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6491,6 +6491,7 @@ components:
- event-v2 alert
- audit alert
- ci-pipelines alert
- error-tracking alert
example: query alert
type: string
x-enum-varnames:
Expand All @@ -6508,6 +6509,7 @@ components:
- EVENT_V2_ALERT
- AUDIT_ALERT
- CI_PIPELINES_ALERT
- ERROR_TRACKING_ALERT
MonitorUpdateRequest:
description: Object describing a monitor update request.
properties:
Expand Down Expand Up @@ -21258,6 +21260,8 @@ paths:

- audit: `audit alert`

- error-tracking: `error-tracking alert`


#### Query Types

Expand Down Expand Up @@ -21534,7 +21538,32 @@ paths:
- **`#`** an integer or decimal number used to set the threshold.


**NOTE** Only available in closed beta on US1, EU, US3 and US5.'
**NOTE** Only available in closed beta on US1, EU, US3 and US5.


**Error Tracking Alert Query**


Example(RUM): `error-tracking-rum(query).rollup(rollup_method[, measure]).last(time_window)
operator #`

Example(APM Traces): `error-tracking-traces(query).rollup(rollup_method[,
measure]).last(time_window) operator #`


- **`query`** The search query - following the [Log search syntax](https://docs.datadoghq.com/logs/search_syntax/).

- **`rollup_method`** The stats roll-up method - supports `count`, `avg`,
and `cardinality`.

- **`measure`** For `avg` and cardinality `rollup_method` - specify the measure
or the facet name you want to use.

- **`time_window`** #m (between 1 and 2880), #h (between 1 and 48).

- **`operator`** `<`, `<=`, `>`, `>=`, `==`, or `!=`.

- **`#`** an integer or decimal number used to set the threshold.'
operationId: CreateMonitor
requestBody:
content:
Expand Down
13 changes: 13 additions & 0 deletions api/v1/datadog/api_monitors.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ type apiCreateMonitorRequest struct {
* - watchdog: `event alert`
* - event-v2: `event-v2 alert`
* - audit: `audit alert`
* - error-tracking: `error-tracking alert`
*
* #### Query Types
*
Expand Down Expand Up @@ -351,6 +352,18 @@ type apiCreateMonitorRequest struct {
* - **`#`** an integer or decimal number used to set the threshold.
*
* **NOTE** Only available in closed beta on US1, EU, US3 and US5.
*
* **Error Tracking Alert Query**
*
* Example(RUM): `error-tracking-rum(query).rollup(rollup_method[, measure]).last(time_window) operator #`
* Example(APM Traces): `error-tracking-traces(query).rollup(rollup_method[, measure]).last(time_window) operator #`
*
* - **`query`** The search query - following the [Log search syntax](https://docs.datadoghq.com/logs/search_syntax/).
* - **`rollup_method`** The stats roll-up method - supports `count`, `avg`, and `cardinality`.
* - **`measure`** For `avg` and cardinality `rollup_method` - specify the measure or the facet name you want to use.
* - **`time_window`** #m (between 1 and 2880), #h (between 1 and 48).
* - **`operator`** `<`, `<=`, `>`, `>=`, `==`, or `!=`.
* - **`#`** an integer or decimal number used to set the threshold.
*/
func (a *MonitorsApiService) CreateMonitor(ctx _context.Context, body Monitor) (Monitor, *_nethttp.Response, error) {
req := apiCreateMonitorRequest{
Expand Down
2 changes: 2 additions & 0 deletions api/v1/datadog/model_monitor_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ const (
MONITORTYPE_EVENT_V2_ALERT MonitorType = "event-v2 alert"
MONITORTYPE_AUDIT_ALERT MonitorType = "audit alert"
MONITORTYPE_CI_PIPELINES_ALERT MonitorType = "ci-pipelines alert"
MONITORTYPE_ERROR_TRACKING_ALERT MonitorType = "error-tracking alert"
)

var allowedMonitorTypeEnumValues = []MonitorType{
Expand All @@ -47,6 +48,7 @@ var allowedMonitorTypeEnumValues = []MonitorType{
MONITORTYPE_EVENT_V2_ALERT,
MONITORTYPE_AUDIT_ALERT,
MONITORTYPE_CI_PIPELINES_ALERT,
MONITORTYPE_ERROR_TRACKING_ALERT,
}

func (w *MonitorType) GetAllowedValues() []MonitorType {
Expand Down
43 changes: 43 additions & 0 deletions examples/v1/monitors/CreateMonitor_440013737.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// Create an Error Tracking monitor returns "OK" response

package main

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

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

func main() {
body := datadog.Monitor{
Name: datadog.PtrString("Example-Create_an_Error_Tracking_monitor_returns_OK_response"),
Type: datadog.MONITORTYPE_ERROR_TRACKING_ALERT,
Query: `error-tracking-rum("service:foo AND @error.source:source").rollup("count").by("@issue.id").last("1h") >= 1`,
Message: datadog.PtrString("some message"),
Tags: &[]string{
"test:examplecreateanerrortrackingmonitorreturnsokresponse",
"env:ci",
},
Priority: *datadog.NewNullableInt64(datadog.PtrInt64(3)),
Options: &datadog.MonitorOptions{
Thresholds: &datadog.MonitorThresholds{
Critical: datadog.PtrFloat64(1),
},
},
}
ctx := datadog.NewDefaultContext(context.Background())
configuration := datadog.NewConfiguration()
apiClient := datadog.NewAPIClient(configuration)
resp, r, err := apiClient.MonitorsApi.CreateMonitor(ctx, body)

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

responseContent, _ := json.MarshalIndent(resp, "", " ")
fmt.Fprintf(os.Stdout, "Response from `MonitorsApi.CreateMonitor`:\n%s\n", responseContent)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2022-03-17T20:05:01.132Z
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
interactions:
- request:
body: |
{"message":"some message","name":"Test-Create_an_Error_Tracking_monitor_returns_OK_response-1647547501","options":{"thresholds":{"critical":1}},"priority":3,"query":"error-tracking-rum(\"service:foo AND @error.source:source\").rollup(\"count\").by(\"@issue.id\").last(\"1h\") \u003e= 1","tags":["test:testcreateanerrortrackingmonitorreturnsokresponse1647547501","env:ci"],"type":"error-tracking alert"}
form: {}
headers:
Accept:
- application/json
Content-Type:
- application/json
method: POST
url: https://api.datadoghq.com/api/v1/monitor
response:
body: '{"restricted_roles":null,"tags":["test:testcreateanerrortrackingmonitorreturnsokresponse1647547501","env:ci"],"deleted":null,"query":"error-tracking-rum(\"service:foo
AND @error.source:source\").rollup(\"count\").by(\"@issue.id\").last(\"1h\")
>= 1","message":"some message","id":66239295,"multi":true,"name":"Test-Create_an_Error_Tracking_monitor_returns_OK_response-1647547501","created":"2022-03-17T20:05:01.603951+00:00","created_at":1647547501000,"creator":{"id":1445416,"handle":"[email protected]","name":null,"email":"[email protected]"},"org_id":321813,"modified":"2022-03-17T20:05:01.603951+00:00","priority":3,"overall_state_modified":null,"overall_state":"No
Data","type":"error-tracking alert","options":{"notify_audit":false,"silenced":{},"include_tags":true,"thresholds":{"critical":1.0},"new_host_delay":300,"notify_no_data":false,"groupby_simple_monitor":false}}'
code: 200
duration: ''
headers:
Content-Type:
- application/json
status: 200 OK
- request:
body: ''
form: {}
headers:
Accept:
- application/json
method: DELETE
url: https://api.datadoghq.com/api/v1/monitor/66239295
response:
body: '{"deleted_monitor_id":66239295}'
code: 200
duration: ''
headers:
Content-Type:
- application/json
status: 200 OK
version: 1
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"name": "{{ unique}}",
"type": "error-tracking alert",
"query": "error-tracking-rum(\"service:foo AND @error.source:source\").rollup(\"count\").by(\"@issue.id\").last(\"1h\") >= 1",
"message": "some message",
"tags": ["test:{{ unique_lower_alnum }}", "env:ci"],
"priority": 3,
"options": { "thresholds": { "critical": 1 } }
}
7 changes: 7 additions & 0 deletions tests/scenarios/features/v1/monitors.feature
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,13 @@ Feature: Monitors
When the request is sent
Then the response status is 200 OK

@team:DataDog/monitor-app
Scenario: Create an Error Tracking monitor returns "OK" response
Given new "CreateMonitor" request
And body from file "monitor_error_tracking_alert_payload.json"
When the request is sent
Then the response status is 200 OK

@generated @skip @team:DataDog/monitor-app
Scenario: Delete a monitor returns "Bad Request" response
Given new "DeleteMonitor" request
Expand Down