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 option to set noise reasons for an alert #3133

Merged
merged 36 commits into from
Jul 12, 2023
Merged
Show file tree
Hide file tree
Changes from 32 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
8d686a5
add ability to store alert metadata from ui
Forfold Jun 16, 2023
4642f60
simplify bool
Forfold Jun 20, 2023
be50341
update metadata to feedback
Forfold Jun 20, 2023
4649165
update transition for textfields
Forfold Jun 20, 2023
b1a2c24
fix console warning
Forfold Jun 20, 2023
7ce3c3c
invalidate cache on feedback button press
Forfold Jun 20, 2023
1c23810
add testing and aria labels
Forfold Jun 20, 2023
e8c89f0
metadata -> feedback
Forfold Jun 20, 2023
80b629c
remove comment
Forfold Jun 20, 2023
e369f36
remove sentiment field
Forfold Jun 27, 2023
c952838
use dialog to set alert feedback
Forfold Jun 27, 2023
e63ed43
add notice to show problem alert reason with undo
Forfold Jun 27, 2023
0706219
styling updates
Forfold Jun 27, 2023
046bb20
start using checkboxes to set reasons
Forfold Jun 27, 2023
8f93570
fix checkbox bugs when setting
Forfold Jun 28, 2023
cee16f2
set defaults when editing
Forfold Jun 28, 2023
647cbdd
always show feedback options instead of in dialog
Forfold Jun 28, 2023
129761b
use submit, hide card when banner showing
Forfold Jun 28, 2023
4c2f896
remove unused imports
Forfold Jun 28, 2023
a23f11c
Grammar/wording
Forfold Jun 28, 2023
ac6cd57
add transition and disable submit when empty
Forfold Jun 28, 2023
c611bdd
add testing
Forfold Jun 28, 2023
50ec5ca
remove .only from test
Forfold Jun 28, 2023
8bcd087
revert exporting transitions
Forfold Jun 28, 2023
aae1191
Merge branch 'master' into alert-feedback
Forfold Jun 28, 2023
e41ee27
fix key
Forfold Jun 28, 2023
6876d46
remove fade
Forfold Jun 28, 2023
ed7a16e
remove unused import
Forfold Jun 29, 2023
b2e8390
note -> noiseReason
Forfold Jun 29, 2023
afc4203
use sqlc
Forfold Jun 30, 2023
28aa199
use pgformatter
Forfold Jun 30, 2023
285ab59
PR comments
Forfold Jul 6, 2023
dc7468f
Update alert/store.go
Forfold Jul 6, 2023
a8eeef1
feedback permissions and generated file
Forfold Jul 6, 2023
2f949f3
update test name
Forfold Jul 11, 2023
eadc84a
PR comments
Forfold Jul 11, 2023
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
7 changes: 7 additions & 0 deletions alert/feedback.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package alert

// Feedback represents user provided information about a given alert
type Feedback struct {
AlertID int
NoiseReason string
}
59 changes: 43 additions & 16 deletions alert/queries.sql
Original file line number Diff line number Diff line change
@@ -1,23 +1,50 @@
-- name: LockOneAlertService :one
SELECT maintenance_expires_at notnull::bool AS is_maint_mode,
SELECT
maintenance_expires_at NOTNULL::bool AS is_maint_mode,
alerts.status
FROM services svc
FROM
services svc
JOIN alerts ON alerts.service_id = svc.id
WHERE alerts.id = $1 FOR
UPDATE;
WHERE
alerts.id = $1
FOR UPDATE;

-- name: RequestAlertEscalationByTime :one
UPDATE escalation_policy_state
SET force_escalation = TRUE
WHERE alert_id = $1
AND (
last_escalation <= $2::timestamptz
OR last_escalation IS NULL
) RETURNING TRUE;
UPDATE
escalation_policy_state
SET
force_escalation = TRUE
WHERE
alert_id = $1
AND (last_escalation <= $2::timestamptz
OR last_escalation IS NULL)
RETURNING
TRUE;

-- name: AlertHasEPState :one
SELECT EXISTS (
SELECT 1
FROM escalation_policy_state
WHERE alert_id = $1
) AS has_ep_state;
SELECT
EXISTS (
SELECT
1
FROM
escalation_policy_state
WHERE
alert_id = $1) AS has_ep_state;

-- name: AlertFeedback :one
SELECT
alert_id,
noise_reason
FROM
alert_feedback
WHERE
alert_id = $1;

-- name: SetAlertFeedback :exec
INSERT INTO alert_feedback(alert_id, noise_reason)
VALUES ($1, $2)
ON CONFLICT (alert_id)
DO UPDATE SET
noise_reason = $2
WHERE
alert_feedback.alert_id = $1;
36 changes: 36 additions & 0 deletions alert/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -791,3 +791,39 @@ func (s *Store) State(ctx context.Context, alertIDs []int) ([]State, error) {

return list, nil
}

func (s *Store) Feedback(ctx context.Context, alertID int) (f Feedback, err error) {
Forfold marked this conversation as resolved.
Show resolved Hide resolved
row, err := gadb.New(s.db).AlertFeedback(ctx, int64(alertID))
if errors.Is(err, sql.ErrNoRows) {
Forfold marked this conversation as resolved.
Show resolved Hide resolved
return Feedback{
AlertID: alertID,
}, nil
}

return Feedback{
AlertID: int(row.AlertID),
NoiseReason: row.NoiseReason.String,
}, err
}

func (s Store) UpdateFeedback(ctx context.Context, feedback *Feedback) error {
err := permission.LimitCheckAny(ctx, permission.System, permission.User)
if err != nil {
return err
}

err = validate.Text("Noise Reason", feedback.NoiseReason, 1, 255)
Forfold marked this conversation as resolved.
Show resolved Hide resolved
if err != nil {
return err
}

err = gadb.New(s.db).SetAlertFeedback(ctx, gadb.SetAlertFeedbackParams{
Forfold marked this conversation as resolved.
Show resolved Hide resolved
AlertID: int64(feedback.AlertID),
NoiseReason: sql.NullString{String: feedback.NoiseReason, Valid: true},
})
if err != nil {
return err
}

return nil
}
5 changes: 5 additions & 0 deletions gadb/models.go

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

52 changes: 46 additions & 6 deletions gadb/queries.sql.go

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

Loading