-
Notifications
You must be signed in to change notification settings - Fork 47
Allow users to configure custom alerts based on data-lake variables #2305
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
base: master
Are you sure you want to change the base?
Allow users to configure custom alerts based on data-lake variables #2305
Conversation
ES-Alexander
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice! :D
Haven't tried it yet. Code mostly seems reasonable, but I feel like it could be cleaned up to reduce some redundancy (although I may be misunderstanding ts/JS limitations), and I've suggested some ideas for improvement (some for now, some maybe for later).
Key new ideas are:
- turning alert triggers into data lake variables (so they can also trigger other things), and
- allowing alerts to compare data lake variables against each other.
| <!-- Conditions Section --> | ||
| <div class="flex flex-col gap-3"> | ||
| <div class="flex items-center justify-between"> | ||
| <label class="text-sm font-medium">Conditions (all must match)</label> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| <label class="text-sm font-medium">Conditions (all must match)</label> | |
| <label class="text-sm font-medium">Trigger when ALL conditions are met:</label> |
| :key="index" | ||
| class="flex flex-col gap-2 p-3 rounded bg-[#FFFFFF11]" | ||
| > | ||
| <!-- Variable Selection for this condition --> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would maybe be good to have an "AND" here, above or before each condition that's not the first one. I didn't see the "all must match" initially, and that could make it clearer.
Even better would be if we could support changing between AND and OR combinations, but then things get complicated from having to determine/specify groupings of them, which is probably overly complex for an initial implementation.
| class="flex-1" | ||
| @update:model-value="onConditionVariableChanged(condition)" | ||
| /> | ||
| <v-tooltip text="Copy variable name for use in custom message" location="top"> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Uhh, aren't data lake references supposed to be made using the ID, not the name?
Variable names aren't guaranteed to be unique...
| variant="outlined" | ||
| density="compact" | ||
| hide-details | ||
| hint="Minimum time between alerts" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| hint="Minimum time between alerts" | |
| hint="Minimum time before this alert can be triggered again" |
| <div class="flex flex-col gap-2"> | ||
| <v-checkbox | ||
| v-model="isDurationEnabled" | ||
| label="Require minimum time meeting conditions" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| label="Require minimum time meeting conditions" | |
| label="Require sustained conditions (ignore brief spikes)" |
| const alert = globalAlerts.find((a) => a.id === id) | ||
| if (!alert) return | ||
|
|
||
| alert.enabled = enabled |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As above, I think this should trigger a cleanup or setup of listeners depending on whether it is becoming disabled or enabled.
| // Set default compare value based on type | ||
| switch (type) { | ||
| case 'boolean': | ||
| condition.compareValue = true | ||
| break | ||
| case 'number': | ||
| condition.compareValue = 0 | ||
| break | ||
| default: | ||
| condition.compareValue = '' | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be using the getDefaultCompareValue function from the typescript file?
| /** | ||
| * Push a success alert | ||
| * @param {string} message - The alert message | ||
| * @param {Date} timeCreated - Optional time created | ||
| */ | ||
| export const pushSuccessAlert = (message: string, timeCreated: Date = new Date()): void => { | ||
| pushAlert(new Alert(AlertLevel.Success, message, timeCreated)) | ||
| } | ||
|
|
||
| /** | ||
| * Push an error alert | ||
| * @param {string} message - The alert message | ||
| * @param {Date} timeCreated - Optional time created | ||
| */ | ||
| export const pushErrorAlert = (message: string, timeCreated: Date = new Date()): void => { | ||
| pushAlert(new Alert(AlertLevel.Error, message, timeCreated)) | ||
| } | ||
|
|
||
| /** | ||
| * Push an info alert | ||
| * @param {string} message - The alert message | ||
| * @param {Date} timeCreated - Optional time created | ||
| */ | ||
| export const pushInfoAlert = (message: string, timeCreated: Date = new Date()): void => { | ||
| pushAlert(new Alert(AlertLevel.Info, message, timeCreated)) | ||
| } | ||
|
|
||
| /** | ||
| * Push a warning alert | ||
| * @param {string} message - The alert message | ||
| * @param {Date} timeCreated - Optional time created | ||
| */ | ||
| export const pushWarningAlert = (message: string, timeCreated: Date = new Date()): void => { | ||
| pushAlert(new Alert(AlertLevel.Warning, message, timeCreated)) | ||
| } | ||
|
|
||
| /** | ||
| * Push a critical alert | ||
| * @param {string} message - The alert message | ||
| * @param {Date} timeCreated - Optional time created | ||
| */ | ||
| export const pushCriticalAlert = (message: string, timeCreated: Date = new Date()): void => { | ||
| pushAlert(new Alert(AlertLevel.Critical, message, timeCreated)) | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a way to define these dynamically? This seems like excessive repetition that then needs to be maintained.
| export const getSortedAlerts = (): Alert[] => { | ||
| return [...alerts].sort((a, b) => a.time_created.getTime() - b.time_created.getTime()) | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's some nearly identical code in alert.ts.
| return [...alerts].sort((a, b) => a.time_created.getTime() - b.time_created.getTime()) | ||
| }) | ||
|
|
||
| // Wrapper functions that delegate to the manager |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need these wrappers, if they have the same signatures as the manager's functions? Could we not just directly use the manager's functions?
|
Relevant to (and possibly closes) #2115 |
Cockpit.0.0.0.2025-12-12.10.29.56.mp4
Helps #1616
Helps #2210
Fix #2304