Skip to content

Commit 38c05cb

Browse files
authored
Update dashboard api (#98)
1 parent 8b77e56 commit 38c05cb

File tree

5 files changed

+93
-51
lines changed

5 files changed

+93
-51
lines changed

sentry/dashboards.go

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,25 @@ import (
66
"time"
77
)
88

9+
// Permission represents a dashboard permissions.
10+
type Permission struct {
11+
IsEditableByEveryone *bool `json:"isEditableByEveryone,omitempty"`
12+
TeamsWithEditAccess []*int `json:"teamsWithEditAccess,omitempty"`
13+
}
14+
915
// Dashboard represents a Dashboard.
1016
type Dashboard struct {
11-
ID *string `json:"id,omitempty"`
12-
Title *string `json:"title,omitempty"`
13-
DateCreated *time.Time `json:"dateCreated,omitempty"`
14-
Widgets []*DashboardWidget `json:"widgets,omitempty"`
17+
ID *string `json:"id,omitempty"`
18+
Title *string `json:"title,omitempty"`
19+
DateCreated *time.Time `json:"dateCreated,omitempty"`
20+
Widgets []*DashboardWidget `json:"widgets,omitempty"`
21+
Projects []*int `json:"projects,omitempty"`
22+
Environments []*string `json:"environments,omitempty"`
23+
Period *string `json:"period,omitempty"`
24+
Start *string `json:"start,omitempty"`
25+
End *string `json:"end,omitempty"`
26+
Permissions *Permission `json:"permissions,omitempty"`
27+
IsFavorited *bool `json:"is_favorited,omitempty"`
1528
}
1629

1730
// DashboardsService provides methods for accessing Sentry dashboard API endpoints.

sentry/dashboards_test.go

Lines changed: 41 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package sentry
22

33
import (
44
"context"
5+
"encoding/json"
56
"fmt"
67
"net/http"
78
"testing"
@@ -146,22 +147,39 @@ func TestDashboardsService_Create(t *testing.T) {
146147
mux.HandleFunc("/api/0/organizations/the-interstellar-jurisdiction/dashboards/", func(w http.ResponseWriter, r *http.Request) {
147148
assertMethod(t, "POST", r)
148149
assertPostJSONValue(t, map[string]interface{}{
149-
"title": "General",
150-
"widgets": map[string]interface{}{},
150+
"title": "General",
151+
"permissions": map[string]interface{}{
152+
"isEditableByEveryone": true,
153+
"teamsWithEditAccess": []interface{}{json.Number("3"), json.Number("4")},
154+
},
155+
"projects": []interface{}{json.Number("1"), json.Number("2")},
156+
"period": "14d",
151157
}, r)
152158

153159
w.Header().Set("Content-Type", "application/json")
154160
fmt.Fprint(w, `{
155161
"id": "12072",
156162
"title": "General",
157163
"dateCreated": "2022-06-07T16:48:26.255520Z",
158-
"widgets": []
164+
"widgets": [],
165+
"permissions": {
166+
"isEditableByEveryone": true,
167+
"teamsWithEditAccess": [3, 4]
168+
},
169+
"projects": [1, 2],
170+
"period": "14d"
159171
}`)
160172
})
161173

162174
params := &Dashboard{
163175
Title: String("General"),
164176
Widgets: []*DashboardWidget{},
177+
Permissions: &Permission{
178+
IsEditableByEveryone: Bool(true),
179+
TeamsWithEditAccess: []*int{Int(3), Int(4)},
180+
},
181+
Projects: []*int{Int(1), Int(2)},
182+
Period: String("14d"),
165183
}
166184
ctx := context.Background()
167185
dashboard, _, err := client.Dashboards.Create(ctx, "the-interstellar-jurisdiction", params)
@@ -171,6 +189,12 @@ func TestDashboardsService_Create(t *testing.T) {
171189
Title: String("General"),
172190
DateCreated: Time(mustParseTime("2022-06-07T16:48:26.255520Z")),
173191
Widgets: []*DashboardWidget{},
192+
Projects: []*int{Int(1), Int(2)},
193+
Permissions: &Permission{
194+
IsEditableByEveryone: Bool(true),
195+
TeamsWithEditAccess: []*int{Int(3), Int(4)},
196+
},
197+
Period: String("14d"),
174198
}
175199
assert.Equal(t, expected, dashboard)
176200
assert.NoError(t, err)
@@ -183,24 +207,29 @@ func TestDashboardsService_Update(t *testing.T) {
183207
mux.HandleFunc("/api/0/organizations/the-interstellar-jurisdiction/dashboards/12072/", func(w http.ResponseWriter, r *http.Request) {
184208
assertMethod(t, "PUT", r)
185209
assertPostJSONValue(t, map[string]interface{}{
186-
"id": "12072",
187-
"title": "General",
188-
"widgets": map[string]interface{}{},
210+
"id": "12072",
211+
"title": "General",
212+
"projects": []interface{}{json.Number("1"), json.Number("2")},
213+
"period": "14d",
189214
}, r)
190215

191216
w.Header().Set("Content-Type", "application/json")
192217
fmt.Fprint(w, `{
193218
"id": "12072",
194219
"title": "General",
195220
"dateCreated": "2022-06-07T16:48:26.255520Z",
196-
"widgets": []
221+
"widgets": [],
222+
"projects": [1, 2],
223+
"period": "14d"
197224
}`)
198225
})
199226

200227
params := &Dashboard{
201-
ID: String("12072"),
202-
Title: String("General"),
203-
Widgets: []*DashboardWidget{},
228+
ID: String("12072"),
229+
Title: String("General"),
230+
Widgets: []*DashboardWidget{},
231+
Projects: []*int{Int(1), Int(2)},
232+
Period: String("14d"),
204233
}
205234
ctx := context.Background()
206235
dashboard, _, err := client.Dashboards.Update(ctx, "the-interstellar-jurisdiction", "12072", params)
@@ -210,6 +239,8 @@ func TestDashboardsService_Update(t *testing.T) {
210239
Title: String("General"),
211240
DateCreated: Time(mustParseTime("2022-06-07T16:48:26.255520Z")),
212241
Widgets: []*DashboardWidget{},
242+
Projects: []*int{Int(1), Int(2)},
243+
Period: String("14d"),
213244
}
214245
assert.Equal(t, expected, dashboard)
215246
assert.NoError(t, err)

sentry/issue_alerts_test.go

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -350,18 +350,18 @@ func TestIssueAlertsService_Create(t *testing.T) {
350350
assertPostJSONValue(t, map[string]interface{}{
351351
"actionMatch": "all",
352352
"environment": "production",
353-
"frequency": 30,
353+
"frequency": json.Number("30"),
354354
"name": "Notify errors",
355-
"conditions": []map[string]interface{}{
356-
{
355+
"conditions": []interface{}{
356+
map[string]interface{}{
357357
"interval": "1h",
358358
"name": "The issue is seen more than 10 times in 1h",
359-
"value": 10,
359+
"value": json.Number("10"),
360360
"id": "sentry.rules.conditions.event_frequency.EventFrequencyCondition",
361361
},
362362
},
363-
"actions": []map[string]interface{}{
364-
{
363+
"actions": []interface{}{
364+
map[string]interface{}{
365365
"id": "sentry.integrations.slack.notify_action.SlackNotifyServiceAction",
366366
"name": "Send a notification to the Dummy Slack workspace to #dummy-channel and show tags [environment] in notification",
367367
"tags": "environment",
@@ -501,18 +501,18 @@ func TestIssueAlertsService_CreateWithAsyncTask(t *testing.T) {
501501
assertPostJSONValue(t, map[string]interface{}{
502502
"actionMatch": "all",
503503
"environment": "production",
504-
"frequency": 30,
504+
"frequency": json.Number("30"),
505505
"name": "Notify errors",
506-
"conditions": []map[string]interface{}{
507-
{
506+
"conditions": []interface{}{
507+
map[string]interface{}{
508508
"interval": "1h",
509509
"name": "The issue is seen more than 10 times in 1h",
510-
"value": 10,
510+
"value": json.Number("10"),
511511
"id": "sentry.rules.conditions.event_frequency.EventFrequencyCondition",
512512
},
513513
},
514-
"actions": []map[string]interface{}{
515-
{
514+
"actions": []interface{}{
515+
map[string]interface{}{
516516
"id": "sentry.integrations.slack.notify_action.SlackNotifyServiceAction",
517517
"name": "Send a notification to the Dummy Slack workspace to #dummy-channel and show tags [environment] in notification",
518518
"tags": "environment",
@@ -642,15 +642,15 @@ func TestIssueAlertsService_Update(t *testing.T) {
642642
"frequency": json.Number("30"),
643643
"name": "Notify errors",
644644
"dateCreated": "2019-08-24T18:12:16.321Z",
645-
"conditions": []map[string]interface{}{
646-
{
645+
"conditions": []interface{}{
646+
map[string]interface{}{
647647
"id": "sentry.rules.conditions.event_frequency.EventFrequencyCondition",
648648
"value": json.Number("500"),
649649
"interval": "1h",
650650
},
651651
},
652-
"actions": []map[string]interface{}{
653-
{
652+
"actions": []interface{}{
653+
map[string]interface{}{
654654
"id": "sentry.integrations.slack.notify_action.SlackNotifyServiceAction",
655655
"name": "Send a notification to the Dummy Slack workspace to #dummy-channel and show tags [environment] in notification",
656656
"tags": "environment",
@@ -659,13 +659,13 @@ func TestIssueAlertsService_Update(t *testing.T) {
659659
"workspace": "1234",
660660
},
661661
},
662-
"filters": []map[string]interface{}{
663-
{
662+
"filters": []interface{}{
663+
map[string]interface{}{
664664
"id": "sentry.rules.filters.issue_occurrences.IssueOccurrencesFilter",
665665
"name": "The issue has happened at least 4 times",
666666
"value": json.Number("4"),
667667
},
668-
{
668+
map[string]interface{}{
669669
"attribute": "message",
670670
"id": "sentry.rules.filters.event_attribute.EventAttributeFilter",
671671
"match": "eq",

sentry/metric_alerts_test.go

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -270,44 +270,41 @@ func TestMetricAlertsService_CreateWithAsyncTask(t *testing.T) {
270270
mux.HandleFunc("/api/0/projects/the-interstellar-jurisdiction/pump-station/alert-rules/", func(w http.ResponseWriter, r *http.Request) {
271271
assertMethod(t, "POST", r)
272272
assertPostJSONValue(t, map[string]interface{}{
273-
"id": "12345",
274273
"name": "pump-station-alert",
275274
"environment": "production",
276275
"dataset": "transactions",
277-
"eventTypes": []string{"transaction"},
276+
"eventTypes": []interface{}{"transaction"},
278277
"query": "http.url:http://service/unreadmessages",
279278
"aggregate": "p50(transaction.duration)",
280-
"timeWindow": 10,
281-
"thresholdType": 0,
282-
"resolveThreshold": 0,
283-
"triggers": []map[string]interface{}{
284-
{
285-
"actions": []map[string]interface{}{
286-
{
279+
"timeWindow": json.Number("10"),
280+
"thresholdType": json.Number("0"),
281+
"resolveThreshold": json.Number("0"),
282+
"triggers": []interface{}{
283+
map[string]interface{}{
284+
"actions": []interface{}{
285+
map[string]interface{}{
287286
"alertRuleTriggerId": "56789",
288287
"dateCreated": "2022-04-15T15:06:01.087054Z",
289288
"desc": "Send a Slack notification to #alert-rule-alerts",
290289
"id": "12389",
291290
"inputChannelId": "C0XXXFKLXXX",
292-
"integrationId": 111,
293-
"sentryAppId": nil,
291+
"integrationId": json.Number("123"),
294292
"targetIdentifier": "#alert-rule-alerts",
295293
"targetType": "specific",
296294
"type": "slack",
297295
},
298296
},
299297
"alertRuleId": "12345",
300-
"alertThreshold": 10000,
298+
"alertThreshold": json.Number("55501"),
301299
"dateCreated": "2022-04-15T15:06:01.079598Z",
302300
"id": "56789",
303301
"label": "critical",
304-
"resolveThreshold": 0,
305-
"thresholdType": 0,
302+
"resolveThreshold": json.Number("100"),
303+
"thresholdType": json.Number("0"),
306304
},
307305
},
308-
"projects": []string{"pump-station"},
309-
"owner": "pump-station:12345",
310-
"dateCreated": "2022-04-15T15:06:01.05618Z",
306+
"projects": []interface{}{"pump-station"},
307+
"owner": "pump-station:12345",
311308
}, r)
312309

313310
w.WriteHeader(http.StatusAccepted)
@@ -324,6 +321,7 @@ func TestMetricAlertsService_CreateWithAsyncTask(t *testing.T) {
324321
TimeWindow: Float64(10.0),
325322
ThresholdType: Int(0),
326323
ResolveThreshold: Float64(0),
324+
EventTypes: []string{"transaction"},
327325
Triggers: []*MetricAlertTrigger{
328326
{
329327
ID: String("56789"),

sentry/sentry_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ func assertPostJSONValue(t *testing.T, expected interface{}, req *http.Request)
7575

7676
err := d.Decode(&actual)
7777
assert.NoError(t, err)
78-
assert.ObjectsAreEqualValues(expected, actual)
78+
assert.EqualValues(t, expected, actual)
7979
}
8080

8181
func mustParseTime(value string) time.Time {

0 commit comments

Comments
 (0)