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

feat: alert template message pt3 #326

Merged
merged 2 commits into from
Feb 28, 2024
Merged

Conversation

wrn14897
Copy link
Contributor

@wrn14897 wrn14897 commented Feb 27, 2024

Use Handlebars to build up alert template and trigger notifyChannel method (with @ prefix)


Ellipsis 🚀 This PR description was created by Ellipsis for commit f59ce35.

Summary:

This PR enhances the alert template building process, supports slack_webhook in the notifyChannel method, introduces new functions, removes the extractChannels function, updates the checkAlerts.test.ts file, all within the checkAlerts.ts file, and modifies the webhook.ts model to include a WebhookService enum and updates the schema.

Key points:

  • Enhances alert template building using Handlebars in checkAlerts.ts
  • Supports slack_webhook in notifyChannel method in checkAlerts.ts
  • Introduces new functions for template rendering and alert message body construction in checkAlerts.ts
  • Removes the extractChannels function in checkAlerts.ts
  • Updates the test file checkAlerts.test.ts
  • Modifies the webhook.ts model to include a WebhookService enum and updates the schema

Generated with ❤️ by ellipsis.dev

Copy link

changeset-bot bot commented Feb 27, 2024

⚠️ No Changeset found

Latest commit: d3e4c00

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copy link

@ellipsis-dev ellipsis-dev bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❌ Changes requested.

  • Reviewed the entire pull request up to b2bc9de
  • Looked at 329 lines of code in 1 files
  • Took 1 minute and 40 seconds to review
More info
  • Skipped 2 files when reviewing.
  • Skipped posting 1 additional comments because they didn't meet confidence threshold of 50%.
1. /packages/api/src/tasks/checkAlerts.ts:323:
  • Assessed confidence : 100%
  • Grade: 0%
  • Comment:
    The function notifyChannel is defined twice in this file. Please remove or rename this function to avoid confusion and unexpected behavior.
  • Reasoning:
    The function notifyChannel is defined twice in the code. The first definition is on line 134 and the second one is on line 323. This is a clear violation of best practices as it can lead to confusion and unexpected behavior. The second definition of the function should be removed or renamed if it serves a different purpose.

Workflow ID: wflow_5qcz5E4t0x195EiO


Want Ellipsis to fix these issues? Tag @ellipsis-dev in a comment. We'll respond in a few minutes. Learn more here.

packages/api/src/tasks/checkAlerts.ts Outdated Show resolved Hide resolved
@wrn14897 wrn14897 force-pushed the warren/alert-template-message-pt3 branch from b2bc9de to 8245c93 Compare February 27, 2024 03:08
Copy link

@ellipsis-dev ellipsis-dev bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 Looks good to me!

  • Performed an incremental review on 8245c93
  • Looked at 24 lines of code in 1 files
  • Took 2 minutes and 46 seconds to review
More info
  • Skipped 0 files when reviewing.
  • Skipped posting 0 additional comments because they didn't meet confidence threshold of 50%.

Workflow ID: wflow_954305eVcfShfnKY


Not what you expected? You can customize the content of the reviews using rules. Learn more here.

Copy link

@ellipsis-dev ellipsis-dev bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 Looks good to me!

  • Performed an incremental review on 7a99b4f
  • Looked at 74 lines of code in 1 files
  • Took 1 minute and 51 seconds to review
More info
  • Skipped 0 files when reviewing.
  • Skipped posting 3 additional comments because they didn't meet confidence threshold of 50%.
1. /packages/api/src/tasks/checkAlerts.ts:269:
  • Assessed confidence : 80%
  • Grade: 20%
  • Comment:
    Consider renaming the function renderAlertTemplate to something like buildAndSendAlertMessage to better reflect its purpose of building the alert message body and sending the alert to the channel.
  • Reasoning:
    The function renderAlertTemplate is being used to build the body of the alert message and send the alert to the channel. However, the function name does not reflect this functionality. It would be more appropriate to name it something like buildAndSendAlertMessage to better reflect its purpose.
2. /packages/api/src/tasks/checkAlerts.ts:170:
  • Assessed confidence : 90%
  • Grade: 0%
  • Comment:
    Consider handling unsupported channel types more gracefully in the notifyChannel function. Instead of throwing an error, you could log a warning and skip the unsupported channel. This would prevent the program flow from being disrupted by an error.
  • Reasoning:
    The function notifyChannel is throwing an error for unsupported channel types. However, it would be better to handle this gracefully, perhaps by logging a warning and skipping the unsupported channel, rather than throwing an error and potentially disrupting the flow of the program.
3. /packages/api/src/tasks/checkAlerts.ts:217:
  • Assessed confidence : 90%
  • Grade: 40%
  • Comment:
    Consider creating a single instance of Handlebars and reusing it, rather than creating a new instance every time the buildAlertMessageTemplateTitle function is called. This could improve performance if the function is called frequently.
  • Reasoning:
    The function buildAlertMessageTemplateTitle is creating a new instance of Handlebars every time it is called. This could be inefficient if the function is called frequently. It would be better to create a single instance of Handlebars and reuse it.

Workflow ID: wflow_hVUSsUWcdAKbFVqB


Not what you expected? You can customize the content of the reviews using rules. Learn more here.

Copy link

@ellipsis-dev ellipsis-dev bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 Looks good to me!

  • Performed an incremental review on 87f97eb
  • Looked at 26 lines of code in 2 files
  • Took 1 minute and 6 seconds to review
More info
  • Skipped 0 files when reviewing.
  • Skipped posting 1 additional comments because they didn't meet confidence threshold of 50%.
1. /packages/api/src/tasks/checkAlerts.ts:295:
  • Assessed confidence : 0%
  • Comment:
    The addition of .trim() here will remove leading and trailing whitespace from the template string. This seems to match the intent suggested by the change in the test file.
  • Reasoning:
    The change in the test file is removing an empty string from the expected output. This suggests that the change in the main file is intended to remove an extra newline from the output. The change in the main file is adding a .trim() call to the end of a template string. This will remove leading and trailing whitespace, including newlines, from the string. This seems to match the intent suggested by the test change.

Workflow ID: wflow_zz2wMxYmhODLQtgu


Not what you expected? You can customize the content of the reviews using rules. Learn more here.

Copy link

@ellipsis-dev ellipsis-dev bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 Looks good to me!

  • Performed an incremental review on d09cb7f
  • Looked at 13 lines of code in 1 files
  • Took 1 minute and 18 seconds to review
More info
  • Skipped 0 files when reviewing.
  • Skipped posting 1 additional comments because they didn't meet confidence threshold of 50%.
1. /packages/api/src/tasks/__tests__/checkAlerts.test.ts:89:
  • Assessed confidence : 0%
  • Comment:
    Good catch on removing the .only from the test suite. This ensures all tests are being run, which is crucial in a shared codebase.
  • Reasoning:
    The change in this PR is a simple removal of the 'only' keyword from a test suite. This is a good change because 'only' restricts the test runner to only run the specified suite or test, which is not ideal in a shared codebase where we want to run all tests.

Workflow ID: wflow_X9vbt6BANySicDaN


Not what you expected? You can customize the content of the reviews using rules. Learn more here.

Copy link

@ellipsis-dev ellipsis-dev bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❌ Changes requested.

  • Performed an incremental review on 2ae9099
  • Looked at 312 lines of code in 2 files
  • Took 2 minutes and 58 seconds to review
More info
  • Skipped 0 files when reviewing.
  • Skipped posting 0 additional comments because they didn't meet confidence threshold of 50%.

Workflow ID: wflow_mtOPENanOCqvW1xm


Want Ellipsis to fix these issues? Tag @ellipsis-dev in a comment. We'll respond in a few minutes. Learn more here.

switch (channel) {
case 'slack_webhook': {
const webhook = await Webhook.findOne({
_id: id,
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function should handle the case where the webhook is not found in the database. Consider adding a check for whether the webhook is null and handle it appropriately.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm...it seems AI is not there yet

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cofounder of Ellipsis here, thanks for this feedback!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hey @hbrooks , what a surprise! Thanks for checking it out

} else if (alert.source === 'chart') {
if (dashboard == null) {
throw new Error('Source is CHART but dashboard is null');
}
return `${group ? `Group: "${group}"` : ''}
rawTemplateBody = `${group ? `Group: "${group}"` : ''}
${value} ${
doesExceedThreshold(
alert.threshold_type === 'above',
alert.threshold,
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider simplifying this complex ternary operation. You could create a separate function to handle this logic or use a more straightforward control flow structure like if-else statements.

Comment on lines +242 to +255
? alert.threshold_type === 'above'
? 'exceeds'
: 'falls below'
: alert.threshold_type === 'above'
? 'falls below'
: 'exceeds'
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

found this existing bug 😅

MikeShi42
MikeShi42 previously approved these changes Feb 28, 2024
Copy link

@ellipsis-dev ellipsis-dev bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❌ Changes requested.

  • Performed an incremental review on 202824d
  • Looked at 82 lines of code in 2 files
  • Took 2 minutes and 8 seconds to review
More info
  • Skipped 0 files when reviewing.
  • Skipped posting 2 additional comments because they didn't meet confidence threshold of 50%.
1. /packages/api/src/tasks/checkAlerts.ts:275:
  • Assessed confidence : 80%
  • Grade: 30%
  • Comment:
    Consider implementing the sanity check for the id in the translateExternalActionsToInternal function. This will ensure the id conforms to the expected format and doesn't contain any malicious or problematic characters.
  • Reasoning:
    The translateExternalActionsToInternal function in checkAlerts.ts has been updated to handle id with special characters and multiple dashes. This is a good improvement as it provides flexibility in the naming of the id. However, there is a comment about a sanity check that is marked as a TODO. It's important to validate the id to ensure it conforms to the expected format and doesn't contain any malicious or problematic characters.
2. /packages/api/src/tasks/checkAlerts.ts:281:
  • Assessed confidence : 80%
  • Grade: 0%
  • Comment:
    Consider including the actual value of alert.source in the error message. This will provide more context when debugging issues related to the renderAlertTemplate function.
  • Reasoning:
    The renderAlertTemplate function in checkAlerts.ts has been updated to support rendering of alert templates. This is a good improvement as it provides flexibility in the creation of alert messages. However, there is a potential issue with the error handling. When the alert.source is not 'search' or 'chart', an error is thrown. However, the error message does not provide enough context about the actual value of alert.source that caused the error. Including the actual value in the error message would make debugging easier.

Workflow ID: wflow_ghdFzB1wpqOszMJz


Want Ellipsis to fix these issues? Tag @ellipsis-dev in a comment. We'll respond in a few minutes. Learn more here.

}) => {
switch (channel) {
case 'slack_webhook': {
const webhook = await Webhook.findOne({
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider adding error handling to manage scenarios where the id provided does not exist in the database. This will improve the robustness of the notifyChannel function.

Copy link

@ellipsis-dev ellipsis-dev bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❌ Changes requested.

  • Performed an incremental review on 67cba25
  • Looked at 76 lines of code in 2 files
  • Took 1 minute and 54 seconds to review
More info
  • Skipped 0 files when reviewing.
  • Skipped posting 0 additional comments because they didn't meet confidence threshold of 50%.

Workflow ID: wflow_GjwDJbSFlz8jOhSK


Want Ellipsis to fix these issues? Tag @ellipsis-dev in a comment. We'll respond in a few minutes. Learn more here.

packages/api/src/tasks/checkAlerts.ts Outdated Show resolved Hide resolved
@wrn14897 wrn14897 force-pushed the warren/alert-template-message-pt3 branch from 4969f09 to bee519a Compare February 28, 2024 07:16
Copy link

@ellipsis-dev ellipsis-dev bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 Looks good to me!

  • Performed an incremental review on 4969f09
  • Looked at 22 lines of code in 1 files
  • Took 1 minute and 27 seconds to review
More info
  • Skipped 0 files when reviewing.
  • Skipped posting 1 additional comments because they didn't meet confidence threshold of 50%.
1. /packages/api/src/tasks/checkAlerts.ts:158:
  • Assessed confidence : 100%
  • Grade: 0%
  • Comment:
    The regular expression used to match the prefix is not anchored to the start of the string. This could lead to unexpected matches. Consider adding ^ at the start of the regular expression to ensure it only matches at the beginning of the string.
$regex: new RegExp(`^${escapeRegExp(id)}`)
  • Reasoning:
    The regular expression used to match the prefix in the notifyChannel function is not anchored to the start of the string. This could lead to unexpected matches.

Workflow ID: wflow_sgpYp1BDs2ErkPlZ


Not what you expected? You can customize the content of the reviews using rules. Learn more here.

Copy link

@ellipsis-dev ellipsis-dev bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❌ Changes requested.

  • Performed an incremental review on bee519a
  • Looked at 670 lines of code in 3 files
  • Took 7 minutes and 30 seconds to review
More info
  • Skipped 2 files when reviewing.
  • Skipped posting 3 additional comments because they didn't meet confidence threshold of 50%.
1. packages/api/src/tasks/checkAlerts.ts:135:
  • Assessed confidence : 50%
  • Comment:
    This function currently only supports Slack webhooks. Consider refactoring it to be more extensible and support other types of webhooks in the future.
  • Reasoning:
    The notifyChannel function in checkAlerts.ts is currently only supporting Slack webhooks. This might limit the functionality of the system if other types of webhooks need to be supported in the future. It would be better to design this function in a more extensible way, so that it can easily support other types of webhooks.
2. packages/api/src/tasks/checkAlerts.ts:274:
  • Assessed confidence : 80%
  • Grade: 20%
  • Comment:
    Consider adding a sanity check or validation for the input to ensure it matches the expected format.
  • Reasoning:
    The translateExternalActionsToInternal function in checkAlerts.ts uses a regular expression to replace certain patterns in the template string. However, there is a comment indicating that a sanity check might be needed. This could potentially lead to unexpected behavior if the input does not match the expected format.
3. packages/api/src/tasks/checkAlerts.ts:286:
  • Assessed confidence : 90%
  • Grade: 0%
  • Comment:
    This function is quite long and contains a large if-else block. Consider breaking it down into smaller, more manageable functions to improve readability and maintainability.
  • Reasoning:
    The renderAlertTemplate function in checkAlerts.ts has a large block of code within an if-else statement. This makes the function quite long and a bit hard to read. It might be beneficial to break this function down into smaller, more manageable functions.

Workflow ID: wflow_Ko0fZnTrvTHYSkCq


Want Ellipsis to fix these issues? Tag @ellipsis-dev in a comment. We'll respond in a few minutes. Learn more here.

@@ -177,40 +225,71 @@ export const buildAlertMessageTemplateTitle = ({
view: AlertMessageTemplateDefaultView;
}) => {
const { alert, dashboard, savedSearch, value } = view;
const handlebars = Handlebars.create();
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider refactoring this complex ternary operation to improve code readability.

@wrn14897 wrn14897 force-pushed the warren/alert-template-message-pt3 branch from bee519a to d3e4c00 Compare February 28, 2024 07:28
Copy link

@ellipsis-dev ellipsis-dev bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 Looks good to me!

  • Performed an incremental review on d3e4c00
  • Looked at 670 lines of code in 3 files
  • Took 2 minutes and 51 seconds to review
More info
  • Skipped 2 files when reviewing.
  • Skipped posting 4 additional comments because they didn't meet confidence threshold of 50%.
1. /packages/api/src/tasks/checkAlerts.ts:135:
  • Assessed confidence : 50%
  • Comment:
    Consider adding a comment to indicate that other types of channels will be supported in the future.
  • Reasoning:
    The notifyChannel function is currently only supporting slack_webhook. It would be better to add a comment to indicate that other types of channels will be supported in the future.
2. /packages/api/src/tasks/checkAlerts.ts:274:
  • Assessed confidence : 60%
  • Grade: 0%
  • Comment:
    Consider adding a comment to explain what this regular expression does for better readability.
  • Reasoning:
    The translateExternalActionsToInternal function is using a regular expression to replace the @ syntax with a template string. This is a good approach, but it would be better to add a comment explaining what the regular expression does for better readability.
3. /packages/api/src/tasks/checkAlerts.ts:285:
  • Assessed confidence : 90%
  • Grade: 0%
  • Comment:
    Consider breaking down this function into smaller, more manageable functions.
  • Reasoning:
    The renderAlertTemplate function is quite large and does a lot of things. It would be better to break it down into smaller, more manageable functions.
4. /packages/api/src/tasks/checkAlerts.ts:477:
  • Assessed confidence : 90%
  • Grade: 20%
  • Comment:
    Consider breaking down the renderAlertTemplate function into smaller, more manageable functions.
  • Reasoning:
    The fireChannelEvent function is calling the renderAlertTemplate function, which is a large function that does a lot of things. It would be better to break down the renderAlertTemplate function into smaller, more manageable functions.

Workflow ID: wflow_GkMyAeEsgySGQhYz


Not what you expected? You can customize the content of the reviews using rules. Learn more here.

@wrn14897 wrn14897 merged commit f59ce35 into main Feb 28, 2024
4 checks passed
@wrn14897 wrn14897 deleted the warren/alert-template-message-pt3 branch February 28, 2024 07:45
Copy link

@ellipsis-dev ellipsis-dev bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 Looks good to me!

  • Performed an incremental review on f59ce35
  • Looked at 670 lines of code in 3 files
  • Took 2 minutes and 32 seconds to review
More info
  • Skipped 2 files when reviewing.
  • Skipped posting 2 additional comments because they didn't meet confidence threshold of 50%.
1. /packages/api/src/tasks/checkAlerts.ts:135:
  • Assessed confidence : 80%
  • Grade: 20%
  • Comment:
    Consider refactoring the notifyChannel function to be more extensible for supporting more types of channels in the future.
  • Reasoning:
    The notifyChannel function is currently only supporting slack_webhook. It would be better to have a more extensible design to support more types of channels in the future.
2. /packages/api/src/tasks/checkAlerts.ts:285:
  • Assessed confidence : 90%
  • Grade: 40%
  • Comment:
    Consider refactoring the renderAlertTemplate function to break it down into smaller, more manageable functions.
  • Reasoning:
    The renderAlertTemplate function is quite large and complex. It might be beneficial to break it down into smaller, more manageable functions.

Workflow ID: wflow_TCu3ZpaBgx6z0OtC


Not what you expected? You can customize the content of the reviews using rules. Learn more here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants