-
Notifications
You must be signed in to change notification settings - Fork 1
Notification delays and timeouts are not clear #85
Comments
Still need to post the paper notes, but coming at this from the README in, here is what I see. configure doc entry for
The config file doesn't have any doc comments (boo, I should have caught that). // MSTeams represents the various configuration settings used to send
// notifications to a Microsoft Teams channel.
type MSTeams struct {
// ...
// Delay is the number of seconds to wait between Microsoft Teams message
// delivery attempts.
Delay *int `toml:"delay" arg:"--teams-notify-delay,env:BRICK_MSTEAMS_WEBHOOK_DELAY" help:"The number of seconds to wait between Microsoft Teams message delivery attempts."`
// Retries is the number of attempts that this application will make to
// deliver Microsoft Teams messages before giving up.
Retries *int `toml:"retries" arg:"--teams-notify-retries,env:BRICK_MSTEAMS_WEBHOOK_RETRIES" help:"The number of attempts that this application will make to deliver Microsoft Teams messages before giving up."`
} The struct tag content scrolls off the page a bit, but the doc comments mirror the help text. From this point we have a getter method defined to retrieve the "winning" value between CLI flag, env var and config file: // TeamsNotificationDelay returns the user-provided delay for Microsoft Teams
// notifications or the default value if not provided. CLI flag values take
// precedence if provided. This delay is added regardless of whether a
// previous notification delivery attempt has been made.
func (c Config) TeamsNotificationDelay() int {
switch {
case c.cliConfig.MSTeams.Delay != nil:
return *c.cliConfig.MSTeams.Delay
case c.fileConfig.MSTeams.Delay != nil:
return *c.fileConfig.MSTeams.Delay
default:
return defaultMSTeamsDelay
}
} The doc comments and setting name mostly match what was said before, but this stands out:
This is our first time seeing that. If no specific options are provided, what default is applied via the // the number of seconds to wait between retry attempts; applies to
// Microsoft Teams notifications only
defaultMSTeamsDelay int = 5 This is key:
This is the first time we see that the value is intended to be applied to retry attempts, not all attempts. How is this value used in the code? I vaguely recall applying it literally at one point in the development cycle before I worked out a scheduling mechanism to allow for spacing the notifications in such a way that we still respected the remote API limit. Anyway, to parallel what the OP shows, this is how the getter method is called: Lines 627 to 638 in 30fdb08
and this is how the value is referenced inside of the Lines 340 to 350 in ddc57ab
Here we can clearly see it described as The Lines 399 to 404 in ddc57ab
The function description is a bit lacking (working on that), but this bit has thus far survived the (as of yet unmerged) doc comments update mostly intact:
The intent here is clear:
This matches what is implied with the What is actually done at the code level? Not long after receiving a value back, the Lines 435 to 448 in ddc57ab
The Lines 421 to 423 in ddc57ab
where brick/vendor/github.com/atc0005/send2teams/teams/teams.go Lines 332 to 335 in ddc57ab
Unless I missed something, the retry delay value (thankfully, it is consistently referred to as |
The questions now:
Since this project hasn't been released yet and nobody is actually using it, we (I) have all options on the table. |
I'm thinking that this would be the first step. Since the provided value is used primarily to space out retry delays, that seems to be the best approach here. As I mentioned earlier, I believe in an earlier version of the code that I wasn't using scheduling so much as artificial delays at the start of notification to enforce respect for the remote API limit. This was true even if earlier send attempts resulted in a number of retries (with delays between them) which would have ensured that the application's message attempts already were respecting the limit. This could result in a minimum of 5 seconds delay (the intent), but could just as easily lead to 10-15 seconds delay. For a potentially (however unlikely) busy system, this would result in messages that were queued longer than strictly necessary. Not a deal breaker, but it was the reason that I wrote in scheduling support. |
I barely touched on this except to make loose references to it, but here are the API-limit specific settings: // NotifyMgrTeamsNotificationDelay is the delay between Microsoft Teams
// notification attempts. This delay is intended to help prevent
// unintentional abuse of remote services.
NotifyMgrTeamsNotificationDelay time.Duration = 5 * time.Second
// NotifyMgrEmailNotificationDelay is the delay between email notification
// attempts. This delay is intended to help prevent unintentional abuse of
// remote services.
NotifyMgrEmailNotificationDelay time.Duration = 5 * time.Second As already indicated, I believe that an earlier version of the code did not make a clear distinction between the retry delay value and the overall API-limit value, but ironically I've since squashed the commits and have pruned the older branches; I don't have (easy) access to the older branches where I believe this design was applicable. Either way, the Lines 357 to 360 in ddc57ab
This "scheduler" is used to return the next available notification schedule based on the notification "spacing" or delay configured via the The Lines 390 to 392 in ddc57ab
This new value ( Lines 399 to 404 in ddc57ab
To put it another way, the |
Ignoring the fact that there is likely a much better way to handle this (e.g., use a type+method instead of a standalone function), this is the proposed "fix" for the confusion I ran into earlier: go teamsNotifier(
ctx,
cfg.TeamsWebhookURL(),
config.NotifyMgrTeamsNotificationTimeout,
config.NotifyMgrTeamsNotificationRateLimit,
cfg.TeamsNotificationRetries(),
cfg.TeamsNotificationRetryDelay(),
teamsNotifyWorkQueue,
teamsNotifyResultQueue,
teamsNotifyDone,
)
} I can then tweak the parameter names for That too far too long to work out. |
BACKSTORY As I went to start work towards implementing email notification support per GH-3, I was struck by how unclear the arguments to the `emailNotifier` function (and similarly, the `teamsNotifier` function) were. The difference between `config.NotifyMgrEmailNotificationDelay` and `cfg.EmailNotificationDelay()` were not immediately clear and it took longer than I'd like to admit to fully backtrack and confirm not only the original intent, but the current behavior surrounding those settings. This commit attempts to clarify not only the original intent, but the purpose behind each related portion of code surrounding what I know understand to be handling the rate limit (formerly named `config.NotifyMgrEmailNotificationDelay`) and notification retry delay. CHANGES - documentation - README.md - update "feature" entry to emphasize configurable retries, but hard-coded notifications rate-limit (hopefully soon to change) - configure.md - updated description - updated command-line flag name - updated environment variable name - updated help text/description for flag - doc.go - explicitly note that it is the retry delay that is configurable - configuration file - rename `delay` to `retry_delay` - add missing doc comments for each msteams section setting - code - search/replace across codebase to replace `Delay` with `RetryDelay` - this includes renaming the `Delay` field for the `MSTeams` type, and its associated flag, environment variable and TOML config file setting - replace `sendDelay` parameter with `sendRateLimit` to better communicate what the incoming value to `teamsNotifier` and `emailNotifier` is intended for - doc comments - fixes to correct wrong information - fixes to better communicate the intent and real behavior REFERENCES - refs GH-85
FWIW, I found an old backup of the go emailNotifier(
ctx,
config.NotifyMgrEmailTimeout,
config.NotifyMgrEmailNotificationDelay,
cfg.Retries,
cfg.RetriesDelay,
emailNotifyWorkQueue,
emailNotifyResultQueue,
emailNotifyDone,
) As I alluded to, the intent was previously clearer (particularly with the |
BACKSTORY As I went to start work towards implementing email notification support per GH-3, I was struck by how unclear the arguments to the `emailNotifier` function (and similarly, the `teamsNotifier` function) were. The difference between `config.NotifyMgrEmailNotificationDelay` and `cfg.EmailNotificationDelay()` were not immediately clear and it took longer than I'd like to admit to fully backtrack and confirm not only the original intent, but the current behavior surrounding those settings. This commit attempts to clarify not only the original intent, but the purpose behind each related portion of code surrounding what I know understand to be handling the rate limit (formerly named `config.NotifyMgrEmailNotificationDelay`) and notification retry delay. CHANGES - documentation - README.md - update "feature" entry to emphasize configurable retries, but hard-coded notifications rate limit (hopefully soon to change) - configure.md - updated description - updated command-line flag name - updated environment variable name - updated help text/description for flag - doc.go - explicitly note that it is the retry delay that is configurable - configuration file - rename `delay` to `retry_delay` - add missing doc comments for each msteams section setting - code - search/replace across codebase to replace `Delay` with `RetryDelay` - this includes renaming the `Delay` field for the `MSTeams` type, and its associated flag, environment variable and TOML config file setting - replace `sendDelay` parameter with `sendRateLimit` to better communicate what the incoming value to `teamsNotifier` and `emailNotifier` is intended for - doc comments - fixes to correct wrong information - fixes to better communicate the intent and real behavior REFERENCES - refs GH-85
BACKSTORY As I went to start work towards implementing email notification support per GH-3, I was struck by how unclear the arguments to the `emailNotifier` function (and similarly, the `teamsNotifier` function) were. The difference between `config.NotifyMgrEmailNotificationDelay` and `cfg.EmailNotificationDelay()` were not immediately clear and it took longer than I'd like to admit to fully backtrack and confirm not only the original intent, but the current behavior surrounding those settings. This commit attempts to clarify not only the original intent, but the purpose behind each related portion of code surrounding what I know understand to be handling the rate limit (formerly named `config.NotifyMgrEmailNotificationDelay`) and notification retry delay. CHANGES - documentation - README.md - update "feature" entry to emphasize configurable retries, but hard-coded notifications rate limit (hopefully soon to change) - configure.md - updated description - updated command-line flag name - updated environment variable name - updated help text/description for flag - doc.go - explicitly note that it is the retry delay that is configurable - configuration file - rename `delay` to `retry_delay` - add missing doc comments for each msteams section setting - code - search/replace across codebase to replace `Delay` with `RetryDelay` - this includes renaming the `Delay` field for the `MSTeams` type, and its associated flag, environment variable and TOML config file setting - replace `sendDelay` parameter with `sendRateLimit` to better communicate what the incoming value to `teamsNotifier` and `emailNotifier` is intended for - doc comments - fixes to correct wrong information - fixes to better communicate the intent and real behavior REFERENCES - refs GH-85
BACKSTORY As I went to start work towards implementing email notification support per GH-3, I was struck by how unclear the arguments to the `emailNotifier` function (and similarly, the `teamsNotifier` function) were. The difference between `config.NotifyMgrEmailNotificationDelay` and `cfg.EmailNotificationDelay()` were not immediately clear and it took longer than I'd like to admit to fully backtrack and confirm not only the original intent, but the current behavior surrounding those settings. This commit attempts to clarify not only the original intent, but the purpose behind each related portion of code surrounding what I know understand to be handling the rate limit (formerly named `config.NotifyMgrEmailNotificationDelay`) and notification retry delay. CHANGES - documentation - README.md - update "feature" entry to emphasize configurable retries, but hard-coded notifications rate limit (hopefully soon to change) - configure.md - updated description - updated command-line flag name - updated environment variable name - updated help text/description for flag - doc.go - explicitly note that it is the retry delay that is configurable - configuration file - rename `delay` to `retry_delay` - add missing doc comments for each msteams section setting - code - search/replace across codebase to replace `Delay` with `RetryDelay` - this includes renaming the `Delay` field for the `MSTeams` type, and its associated flag, environment variable and TOML config file setting - replace `sendDelay` parameter with `sendRateLimit` to better communicate what the incoming value to `teamsNotifier` and `emailNotifier` is intended for - doc comments - fixes to correct wrong information - fixes to better communicate the intent and real behavior REFERENCES - refs GH-85
BACKSTORY As I went to start work towards implementing email notification support per GH-3, I was struck by how unclear the arguments to the `emailNotifier` function (and similarly, the `teamsNotifier` function) were. The difference between `config.NotifyMgrEmailNotificationDelay` and `cfg.EmailNotificationDelay()` were not immediately clear and it took longer than I'd like to admit to fully backtrack and confirm not only the original intent, but the current behavior surrounding those settings. This commit attempts to clarify not only the original intent, but the purpose behind each related portion of code surrounding what I now understand to be handling the rate limit (formerly named `config.NotifyMgrEmailNotificationDelay`) and notification retry delay. CHANGES - documentation - README.md - update "feature" entry to emphasize configurable retries, but hard-coded notifications rate limit (hopefully soon to change) - configure.md - updated description - updated command-line flag name - updated environment variable name - updated help text/description for flag - doc.go - explicitly note that it is the retry delay that is configurable - configuration file - rename `delay` to `retry_delay` - add missing doc comments for each msteams section setting - code - search/replace across codebase to replace `Delay` with `RetryDelay` - this includes renaming the `Delay` field for the `MSTeams` type, and its associated flag, environment variable and TOML config file setting - replace `sendDelay` parameter with `sendRateLimit` to better communicate what the incoming value to `teamsNotifier` and `emailNotifier` is intended for - doc comments - fixes to correct wrong information - fixes to better communicate the intent and real behavior REFERENCES - refs GH-85
BACKSTORY As I went to start work towards implementing email notification support per GH-3, I was struck by how unclear the arguments to the `emailNotifier` function (and similarly, the `teamsNotifier` function) were. The difference between `config.NotifyMgrEmailNotificationDelay` and `cfg.EmailNotificationDelay()` were not immediately clear and it took longer than I'd like to admit to fully backtrack and confirm not only the original intent, but the current behavior surrounding those settings. This commit attempts to clarify not only the original intent, but the purpose behind each related portion of code surrounding what I now understand to be handling the rate limit and notification retry delay. CHANGES - documentation - README.md - update "feature" entry to emphasize configurable retries, but hard-coded notifications rate limit (hopefully soon to change) - configure.md - updated description - updated command-line flag name - updated environment variable name - updated help text/description for flag - doc.go - explicitly note that it is the retry delay that is configurable - configuration file - rename `delay` to `retry_delay` - add missing doc comments for each msteams section setting - code - search/replace across codebase to replace `Delay` with `RetryDelay` - this includes renaming the `Delay` field for the `MSTeams` type, and its associated flag, environment variable and TOML config file setting - replace `sendDelay` parameter with `sendRateLimit` to better communicate what the incoming value to `teamsNotifier` and `emailNotifier` is intended for - doc comments - fixes to correct wrong information - fixes to better communicate the intent and real behavior REFERENCES - refs GH-85
SUMMARY As a follow-up to GH-87, this commit exposes a new setting that allows directly configuring the rate limit used for Teams notifications. GH-3 will be responsible for exposing the same setting for email notifications. CHANGES - update documentation to note new setting - README - GoDoc - configure - configuration file - new `rate_limit` setting - code - remove rate limit constants in favor of external settings (email rate limit setting scheduled for GH-3) and default const value if not specified externally - new `TeamsNotificationRateLimit` getter func - new `EmailNotificationRateLimit` getter func - stub only; further work scheduled for GH-3 REFERENCES refs GH-87, GH-85, GH-19, GH-3
While I was actively developing the functionality the intent of each setting, constant and parameter (for the most part) was clear to me, but while working to implement GH-3 I ran across the function call and had to dig deeper than I would have liked to figure out what the difference was between
config.NotifyMgrEmailNotificationDelay
andcfg.EmailNotificationDelay()
.There is a difference, but in hindsight the names are too close together to easily tell what the purpose of each is.
Ultimately I think the
cfg.EmailNotificationDelay()
func used to be namedcfg.EmailNotificationRetriesDelay()
orcfg.EmailNotificationRetryDelay()
(or the value referenced within was) and at that point it was probably clearer what was going on.brick/cmd/brick/notify.go
Lines 645 to 655 in 30fdb08
TODO:
Add scratch notes detailing my findings so that I can work that explanation into the code via doc comment updates and also via variable/function/whatever name changes to better communicate the intent.
The text was updated successfully, but these errors were encountered: