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

cleanup CustomButton backend code + add ngrok/express outgoing webhook e2e test #2544

Merged
merged 30 commits into from
Mar 28, 2024

Conversation

joeyorlando
Copy link
Contributor

@joeyorlando joeyorlando commented Jul 15, 2023

What this PR does

  • removes unused "custom button" backend code now that we've migrated to outgoing webhooks
  • adds new e2e test for webhooks asserting that an ngrok/express webhook handler receives the call as expected + payload is as expected (related to Add suite of e2e tests for new webhook functionality #2691) - skipped for now, the test passes locally but fails on GitHub Actions CI, seems to be networking related

Checklist

  • Unit, integration, and e2e (if applicable) tests updated
  • Documentation added (or pr:no public docs PR label added if not required)

@github-actions
Copy link
Contributor

This pull request has been automatically marked as stale because it has not had activity in the last 30 days. It will be closed in 30 days if no further activity occurs. Please feel free to give a status update now, ping for review, or re-open when it's ready. Thank you for your contributions!

@github-actions github-actions bot added the pr:stale Added to a PR that has been deemed "stale". Managed by the actions/stale GitHub Action label Aug 15, 2023
@github-actions
Copy link
Contributor

This pull request has been automatically closed because it has not had activity in the last 30 days. Please feel free to give a status update now, ping for review, or re-open when it's ready. Thank you for your contributions!

@github-actions github-actions bot closed this Sep 14, 2023
@joeyorlando joeyorlando deleted the jorlando/cleanup-custom-button-stuff branch September 25, 2023 15:50
@joeyorlando joeyorlando restored the jorlando/cleanup-custom-button-stuff branch March 6, 2024 20:05
@joeyorlando joeyorlando reopened this Mar 6, 2024
'passed_last_time': None,
'escalation_counter': 0,
'last_notified_user': None,
'custom_button_trigger': None,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

rather than just remove the custom_button_trigger field here from the docstring, I don't think we should be documenting large types like this in the docstring (this is what type hints are for 🙂)

@joeyorlando joeyorlando added release:ignore PR will not be added to release notes and removed pr:stale Added to a PR that has been deemed "stale". Managed by the actions/stale GitHub Action labels Mar 6, 2024
def test_create_invalid_ical_schedule(schedule_internal_api_setup, make_user_auth_headers):
user, token, _, _, _, _ = schedule_internal_api_setup
client = APIClient()
url = reverse("api-internal:custom_button-list")
Copy link
Contributor Author

Choose a reason for hiding this comment

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

not sure if this was intentional? 🤔

…fana/oncall into jorlando/cleanup-custom-button-stuff
Comment on lines +47 to +59
const app = express();
app.use(express.json());
app.post('/', (req, res) => {
resolveRequest(req.body); // Resolve the promise with the request body
res.send('ok');
});
app.listen(PORT);

/**
* TODO: this might need to be parametrized to be read from an env var
* rather than hardcoding the hostname to be host.docker.internal
*/
const webhookUrl = `http://host.docker.internal:${PORT}`;
Copy link
Contributor Author

@joeyorlando joeyorlando Mar 14, 2024

Choose a reason for hiding this comment

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

tried using ngrok here.. this worked locally, but it seems like there was some issues on CI, with the API being able to communicate with the express server's public internet URL assigned by ngrok (see test failure here).

Refactored in 3f66b87 to use host.docker.internal instead.

See this Slack conversation for more context

@@ -52,34 +50,6 @@ def __repr__(self):
return "%s()" % self.__class__.__name__


class URLValidatorWithoutTLD(URLValidator):
Copy link
Member

Choose a reason for hiding this comment

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

I remember I added this because some OSS users wanted to make requests to docker containers, which default url validator didn't permit. Do we have url validation for webhooks url? if so, should we use something like that there:

 if live_settings.DANGEROUS_WEBHOOKS_ENABLED:
                    URLValidatorWithoutTLD()(webhook)
                else:
                    URLValidator()(webhook)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👋 I believe that's how apps.webhooks.utils.parse_url works.

fwiw the URLValidatorWithoutTLD class was only referenced within the CustomButton model, so to me it made sense to remove it

Copy link
Contributor

Choose a reason for hiding this comment

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

Correct DANGEROUS_WEBHOOKS_ENABLED settings is handled there. Validation happens later in the process now since URLs can be templates

@joeyorlando joeyorlando added this pull request to the merge queue Mar 28, 2024
Merged via the queue into dev with commit c5cd675 Mar 28, 2024
21 checks passed
@joeyorlando joeyorlando deleted the jorlando/cleanup-custom-button-stuff branch March 28, 2024 15:49
github-merge-queue bot pushed a commit that referenced this pull request Apr 2, 2024
# What this PR does

See [this
conversation](https://raintank-corp.slack.com/archives/C025VMT6SPK/p1711991400490289)
for more context.

Also removes the `EscalationPolicy.custom_button_trigger` field which
was previously marked as deprecated in #2544 and migrated
[here](https://github.com/grafana/oncall/blob/dev/engine/apps/webhooks/migrations/0008_auto_20230712_1613.py#L39-L45)

## Checklist

- [ ] Unit, integration, and e2e (if applicable) tests updated (N/A)
- [x] Documentation added (or `pr:no public docs` PR label added if not
required)
- [x] Added the relevant release notes label (see labels prefixed w/
`release:`). These labels dictate how your PR will
    show up in the autogenerated release notes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release:ignore PR will not be added to release notes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants