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(http): make endpoint report the upstream status code #5510

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

btasker
Copy link
Contributor

@btasker btasker commented Nov 21, 2024

endpoint() populates the column _sent based on whether upstream returned a 200, however it doesn't report the status code to the caller.

endpoint is used (amongst other things) in 2.x's Notification Rules - not having the status code available can make it quite difficult to troubleshoot why a notification wasn't sent.

With this change, endpoint will include an additional column: status_code

In the context of a notification rule, this will result in entries in _monitoring/notifications carrying the tag status_code, making it possible to graph out notifications by the upstream status code:

from(bucket: "_monitoring")
  |> range(start: v.timeRangeStart, stop: v.timeRangeStop)
  |> filter(fn: (r) => r["_measurement"] == "notifications")
  |> filter(fn: (r) => exists r["status_code"])
  |> group(columns: ["check_id", "status_code"])
  |> aggregateWindow(every: v.windowPeriod, fn: count)

Note: the addition of this column could cause issues where the result is written into a bucket with an explicit schema.

However, explicit schemas are only available on Cloud 2 - the query log has been checked for any queries which could result in issues, with none identified.

Checklist

Dear Author 👋, the following checks should be completed (or explicitly dismissed) before merging.

  • ✏️ Write a PR description, regardless of triviality, to include the value of this PR
  • 🔗 Reference related issues
  • 🏃 Test cases are included to exercise the new code
  • 🧪 If new packages are being introduced to stdlib, link to Working Group discussion notes and ensure it lands under experimental/
  • 📖 If language features are changing, ensure docs/Spec.md has been updated

Dear Reviewer(s) 👋, you are responsible (among others) for ensuring the completeness and quality of the above before approval.

@btasker btasker requested review from a team as code owners November 21, 2024 16:25
@btasker btasker requested review from sanderson and removed request for a team November 21, 2024 16:25
@btasker btasker self-assigned this Nov 21, 2024
Copy link
Contributor

@mhilton mhilton left a comment

Choose a reason for hiding this comment

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

This looks fine to me, but can we just change the standard lib like this?

@sanderson
Copy link
Contributor

To @mhilton's point, we might want to add this to all of the *.endpoint() functions in the stdlib so that they're consistent.

@btasker
Copy link
Contributor Author

btasker commented Nov 21, 2024

Yeah that's a fair point - I did think it'd be worth adding to at least the Slack and PD ones, but hadn't done the same legwork on looking to see whether there are any unusual uses of them.

I don't love changing the return of something quite so core, but this is causing some pain.

The alternatives seem to be

  • Change the notification rule task generator to override endpoint in the tasks it generates - as well as making them all slightly less efficient it'd also be a bit of a pain to do
  • Add a new endpointWithStatus function which duplicates endpoint but includes status (and then update the notification rule generator etc etc).

The latter's doable, but feels a little OTT. On the other hand, it would also be safer.

I'll try have a play around tomorrow

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.

4 participants