- Notifications
You must be signed in to change notification settings - Fork1k
feat: implement observability of notifications subsystem#13799
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Changes from1 commit
7f60c0f
d62d704
96dac65
130de49
e868752
cee93cb
387b557
114797d
5ff29c0
88451a1
09f7305
91e2a23
9f1d6b3
15c4537
53ecad4
bc2a4cb
716e591
d408ed2
2b9eec3
4211c84
24417c5
72bb1be
bfca2c1
6602682
00633a1
f454184
84d07d4
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
Minor refactoring to make testing easierSigned-off-by: Danny Kopping <danny@coder.com>
- Loading branch information
Uh oh!
There was an error while loading.Please reload this page.
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -929,15 +929,20 @@ func (q *FakeQuerier) AcquireNotificationMessages(_ context.Context, arg databas | ||
return nil, err | ||
} | ||
// Shift the first "Count" notifications off the slice (FIFO). | ||
sz := len(q.notificationMessages) | ||
dannykopping marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
if sz > int(arg.Count) { | ||
sz = int(arg.Count) | ||
} | ||
list := q.notificationMessages[:sz] | ||
q.notificationMessages = q.notificationMessages[sz:] | ||
q.mutex.Lock() | ||
defer q.mutex.Unlock() | ||
var out []database.AcquireNotificationMessagesRow | ||
for _, nm := range list { | ||
acquirableStatuses := []database.NotificationMessageStatus{database.NotificationMessageStatusPending, database.NotificationMessageStatusTemporaryFailure} | ||
if !slices.Contains(acquirableStatuses, nm.Status) { | ||
continue | ||
@@ -953,9 +958,9 @@ func (q *FakeQuerier) AcquireNotificationMessages(_ context.Context, arg databas | ||
ID: nm.ID, | ||
Payload: nm.Payload, | ||
Method: nm.Method, | ||
TitleTemplate: "This is a title with {{.Labels.variable}}", | ||
BodyTemplate: "This is a body with {{.Labels.variable}}", | ||
TemplateID: nm.NotificationTemplateID, | ||
}) | ||
} | ||
@@ -1229,15 +1234,15 @@ func (*FakeQuerier) BulkMarkNotificationMessagesFailed(_ context.Context, arg da | ||
if err != nil { | ||
return 0, err | ||
} | ||
returnint64(len(arg.IDs)), nil | ||
} | ||
func (*FakeQuerier) BulkMarkNotificationMessagesSent(_ context.Context, arg database.BulkMarkNotificationMessagesSentParams) (int64, error) { | ||
err := validateDatabaseType(arg) | ||
if err != nil { | ||
return 0, err | ||
} | ||
returnint64(len(arg.IDs)), nil | ||
} | ||
func (*FakeQuerier) CleanTailnetCoordinators(_ context.Context) error { | ||
Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.
Uh oh!
There was an error while loading.Please reload this page.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
ALTER TABLE notification_messages | ||
DROP COLUMN IF EXISTS queued_seconds; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
ALTERTABLE notification_messages | ||
ADD COLUMN queued_seconds FLOATNULL; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. Nit: The name There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. I don't think it necessarily implies integer; Member There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. Fair enough 😄. In the DB, usually it means seconds:
But fine to keep as float if we care about the precision (although I'd prefer to multiply the number to required precision in int). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. I suppose I don't strictlyneed to keep sub-second precision on the length of time messages were queued for. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. This is backing a Prometheus metric, which are always floats, and by convention end in the SI unit, which for time is seconds. It implies no precision. This should be a float: there just isn't any compelling reason to pre-judge the required precision. This is not a banking application, nor do we need to worry about the relative speed of integer vs floating point arithmetic. The name
dannykopping marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. |
Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.
Uh oh!
There was an error while loading.Please reload this page.
Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.
Uh oh!
There was an error while loading.Please reload this page.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package notifications | ||
import ( | ||
"golang.org/x/xerrors" | ||
"github.com/coder/coder/v2/coderd/database" | ||
"github.com/coder/coder/v2/codersdk" | ||
) | ||
func dispatchMethodFromCfg(cfg codersdk.NotificationsConfig) (database.NotificationMethod, error) { | ||
var method database.NotificationMethod | ||
if err := method.Scan(cfg.Method.String()); err != nil { | ||
return "", xerrors.Errorf("given notification method %q is invalid", cfg.Method) | ||
} | ||
return method, nil | ||
} |
Uh oh!
There was an error while loading.Please reload this page.