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: Added cron specific endpoint #2153

Merged
merged 8 commits into from
Jun 6, 2023
Merged

Conversation

mitsuhiko
Copy link
Member

@mitsuhiko mitsuhiko commented May 24, 2023

Implements a cron specific API endpoint. The check_in_id is changed to nullable in this. If a check_in_id is not supplied, the consumer will get the nil check_in_id which is an alias for "latest". I decided not to tackle the base62 implementation, mostly because now that this reuses the generic infrastructure it might be quite confusing if we end up with different key formats.

The URL format is also slightly different than in the original ticket. The following options are supported:

curl -u sentry_key: https://oXXX.ingest.sentry.io/api/cron/{monitor_slug}/?status={status}
curl https://oXXX.ingest.sentry.io/api/cron/{monitor_slug}/?status={status}&sentry_key={sentry_key}
curl https://oXXX.ingest.sentry.io/api/cron/{monitor_slug}/{sentry_key}/?status={status}

Work remaining:

  • tests
  • latest for check_in_id
  • requires split up of some monitors code for non processing builds

Fixes #2101
Fixes getsentry/sentry#49203

@mitsuhiko mitsuhiko requested a review from a team May 24, 2023 11:05
@mitsuhiko mitsuhiko marked this pull request as draft May 24, 2023 11:05
@mitsuhiko mitsuhiko marked this pull request as ready for review May 24, 2023 15:06
@evanpurkhiser
Copy link
Member

Looking over this I think we're good to merge this.

I'll create some follow up tickets since not long after we'll likely also want to support POSTing to this endpoint to support all the features we have in the existing endpoints (passing monitor configurations for upserts)

@mitsuhiko
Copy link
Member Author

@evanpurkhiser fwiw I did implement some parameters as query strings. Eg as implemented you can pass ?check_in_id=.... for instance. (See all in CronQuery). But I do agree that a post endpoint would be nice.

Copy link
Contributor

@olksdr olksdr left a comment

Choose a reason for hiding this comment

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

Requesting changes, since I have still few questions I would like to clarify before merging this into the Relay.

@@ -6,6 +6,8 @@

- Use different error message for empty strings in schema processing. ([#2151](https://github.com/getsentry/relay/pull/2151))

- Relay now supports a simplified cron check-in API. ([#2153](https://github.com/getsentry/relay/pull/2153))
Copy link
Contributor

Choose a reason for hiding this comment

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

There is the unnecessary new line before this record

Comment on lines +59 to +62
.route("/api/cron/:monitor_slug/:sentry_key", cron::route(config))
.route("/api/cron/:monitor_slug/:sentry_key/", cron::route(config))
.route("/api/cron/:monitor_slug", cron::route(config))
.route("/api/cron/:monitor_slug/", cron::route(config))
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do we have to support trailing / and no trailing / URLs? Have the routes without trailing slashes been already exposed to customers and customer got used to using them by now?

If not, IMO we have to keep our endpoints consistent, and steer the customers to use only one defined route. And currently we have / at the end, which I would also lean to.

Choose a reason for hiding this comment

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

I generally think, from a devex perspective, it's confusing to get errors for missing (or extra) slashes at the end of an URL. Although, I would have imagined we handle this in a cleaner way that adding both URL variants.

Copy link
Member

Choose a reason for hiding this comment

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

Agree would be nice to handle this in a more general way

@@ -479,6 +480,30 @@ fn auth_from_parts(req: &Parts, path_key: Option<String>) -> Result<Auth, BadEve
auth = Some(header.parse::<Auth>()?);
}

// try to get authentication info from basic auth
if let Some(basic_auth) = req
Copy link
Contributor

Choose a reason for hiding this comment

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

What the reason even to add basic auth?

Using basic auth is super confusion to me to be honest.

Especially when you look at the format users should use to make it work. And I talk about the part when you have yo prove the key (curl -u sentry_key: ) this colon after sentry_key is super easy to miss and mess up your curl command. IMO it makes this very error-prone to the customer.

Much easier and more explicit way would be to use the header which we support or path param, which is also supported.

Copy link
Member

Choose a reason for hiding this comment

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

We're adding this as a bit of an experiment for crons to feel out the ergonomics and DX doing it this way.

I don't think we're planning to immediately tell customers to use this. I agree with the points you make though @olksdr, I think it's not unlikely this will get removed.

Copy link
Contributor

Choose a reason for hiding this comment

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

Please, add the note here, which explains why this added and that this is just an experiment and will be removed in the follow-up.

Copy link
Member Author

Choose a reason for hiding this comment

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

@olksdr fwiw I think basic auth should be generally supported, beyond this experiment, entirely independent of this. From the original x-sentry-auth header basically nothing remains and we already support auth purely by ?sentry_key in the URL. At this point I would honestly love to see us supporting just Bearer and basic auth with just the public key.

cc @jan-auer

Ok(_) | Err(BadStoreRequest::RateLimited(_)) => (),
Err(error) => return Err(error),
};
// What do we want to return?
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we want to have this comment here?

Copy link
Contributor

Choose a reason for hiding this comment

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

@evanpurkhiser can we remove this comment? And return what you want to return? Or add a note here to followup and why the return value cannot be decided right now.

@evanpurkhiser
Copy link
Member

@olksdr Anything else you wanted to follow up with on this? @mitsuhiko I think we're good to go ahead and merge this in and start playing with it yeah?

evanpurkhiser added a commit to getsentry/sentry that referenced this pull request Jun 2, 2023
This is to support getsentry/relay#2153

Provdes a means to creating check-ins without giving a check_in_id in
the consumer payload.

Documentation for this is here getsentry/develop#950

Fixes: #49664
evanpurkhiser added a commit to getsentry/sentry that referenced this pull request Jun 2, 2023
This is to support getsentry/relay#2153

Provdes a means to creating check-ins without giving a check_in_id in
the consumer payload.

Documentation for this is here
getsentry/develop#950

Fixes: #49664
Copy link
Contributor

@olksdr olksdr left a comment

Choose a reason for hiding this comment

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

Left few comments.
Will approve to unblock you, if the open questions will be followed up on.

And also maybe @jan-auer wants also have a quick review

@@ -479,6 +480,30 @@ fn auth_from_parts(req: &Parts, path_key: Option<String>) -> Result<Auth, BadEve
auth = Some(header.parse::<Auth>()?);
}

// try to get authentication info from basic auth
if let Some(basic_auth) = req
Copy link
Contributor

Choose a reason for hiding this comment

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

Please, add the note here, which explains why this added and that this is just an experiment and will be removed in the follow-up.

Ok(_) | Err(BadStoreRequest::RateLimited(_)) => (),
Err(error) => return Err(error),
};
// What do we want to return?
Copy link
Contributor

Choose a reason for hiding this comment

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

@evanpurkhiser can we remove this comment? And return what you want to return? Or add a note here to followup and why the return value cannot be decided right now.

Copy link
Contributor

@olksdr olksdr left a comment

Choose a reason for hiding this comment

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

Left few comments.
Will approve to unblock you, if the open questions will be followed up on.

And also maybe @jan-auer wants also have a quick review

monitor_slug = "my-monitor"
public_key = relay.get_dsn_public_key(project_id)
basic_auth = base64.b64encode((public_key + ":").encode("utf-8")).decode("utf-8")
relay.post(
Copy link
Member

Choose a reason for hiding this comment

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

Just noticed, this should be get right @mitsuhiko ?

Copy link
Member Author

Choose a reason for hiding this comment

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

The endpoint supports either.

Copy link
Member

Choose a reason for hiding this comment

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

Ah cool. I'll expand on POST in a future PR.

@evanpurkhiser
Copy link
Member

Will follow up on your comments @olksdr Thanks!

@evanpurkhiser evanpurkhiser merged commit 9c7f7e8 into master Jun 6, 2023
@evanpurkhiser evanpurkhiser deleted the feature/cron-endpoint branch June 6, 2023 17:11
jan-auer added a commit that referenced this pull request Jun 14, 2023
* master: (32 commits)
  feat(txname): Mark all URL transactions as sanitized (#2210)
  fix(profiles): Enforce profile quotas on metrics buckets (#2212)
  revert(spans): Move span metrics back to transactions namespace (#2206)
  instr(metrics): Add values to invalid metric errors (#2201)
  ref(spans): Move span metrics to spans namespace (#2205)
  chore(protocol): Add missing py/changelog entry for lock property (#2203)
  build(py): Move pytest.ini to tests directory (#2204)
  ref: Use serde collect_str to avoid allocations (#2149)
  chore(gocd): Auto approve deploy relay-pop on check success (#2200)
  test(document-pii): Fix flaky test (#2198)
  feat(spans): Extract transaction `user` into span's databag (#2197)
  feat(spans): Extract `release` tag from the transaction to the span (#2189)
  ref(metrics-extraction): Split span and transaction metric extraction (#2191)
  ref(crons): Support GET in the check-in endpoint (#2192)
  ref(spans): Introduce opinionated casing in span metrics (#2193)
  chore(py): Bump `requests` lib version (#2194)
  doc: document pii fields (#1972)
  feat: Added cron specific endpoint (#2153)
  feat(profiling): Extract app identifier from app context (#2172)
  feat(ci): Add CI-check for pop-deploys  (#2184)
  ...
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.

Crons: Relay Updates Phase 2 - New Ingest Endpoint [Crons] Implement a monitor checkin API endpoint
4 participants