-
Notifications
You must be signed in to change notification settings - Fork 93
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Added cron specific endpoint (#2153)
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: * [x] tests * [x] `latest` for `check_in_id` * [x] requires split up of some monitors code for non `processing` builds Fixes #2101
- Loading branch information
Showing
7 changed files
with
186 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
use axum::extract::{DefaultBodyLimit, FromRequest, Path, Query}; | ||
use axum::response::IntoResponse; | ||
use axum::routing::{post, MethodRouter}; | ||
use relay_common::Uuid; | ||
use relay_config::Config; | ||
use relay_general::protocol::EventId; | ||
use relay_monitors::{CheckIn, CheckInStatus}; | ||
use serde::Deserialize; | ||
|
||
use crate::endpoints::common::{self, BadStoreRequest, TextResponse}; | ||
use crate::envelope::{ContentType, Envelope, Item, ItemType}; | ||
use crate::extractors::RequestMeta; | ||
use crate::service::ServiceState; | ||
|
||
#[derive(Debug, Deserialize)] | ||
struct CronPath { | ||
monitor_slug: String, | ||
} | ||
|
||
#[derive(Debug, Deserialize)] | ||
struct CronQuery { | ||
status: CheckInStatus, | ||
check_in_id: Option<Uuid>, | ||
environment: Option<String>, | ||
duration: Option<f64>, | ||
} | ||
|
||
#[derive(Debug, FromRequest)] | ||
#[from_request(state(ServiceState))] | ||
struct CronParams { | ||
meta: RequestMeta, | ||
#[from_request(via(Path))] | ||
path: CronPath, | ||
#[from_request(via(Query))] | ||
query: CronQuery, | ||
} | ||
|
||
impl CronParams { | ||
fn extract_envelope(self) -> Result<Box<Envelope>, BadStoreRequest> { | ||
let Self { meta, path, query } = self; | ||
|
||
let mut envelope = Envelope::from_request(Some(EventId::new()), meta); | ||
|
||
let mut item = Item::new(ItemType::CheckIn); | ||
item.set_payload( | ||
ContentType::Json, | ||
serde_json::to_vec(&CheckIn { | ||
check_in_id: query.check_in_id.unwrap_or_default(), | ||
monitor_slug: path.monitor_slug, | ||
status: query.status, | ||
environment: query.environment, | ||
duration: query.duration, | ||
monitor_config: None, | ||
}) | ||
.map_err(BadStoreRequest::InvalidJson)?, | ||
); | ||
envelope.add_item(item); | ||
|
||
Ok(envelope) | ||
} | ||
} | ||
|
||
async fn handle( | ||
state: ServiceState, | ||
params: CronParams, | ||
) -> Result<impl IntoResponse, BadStoreRequest> { | ||
let envelope = params.extract_envelope()?; | ||
|
||
// Never respond with a 429 | ||
match common::handle_envelope(&state, envelope).await { | ||
Ok(_) | Err(BadStoreRequest::RateLimited(_)) => (), | ||
Err(error) => return Err(error), | ||
}; | ||
// What do we want to return? | ||
Ok(TextResponse(None)) | ||
} | ||
|
||
pub fn route<B>(config: &Config) -> MethodRouter<ServiceState, B> | ||
where | ||
B: axum::body::HttpBody + Send + 'static, | ||
B::Data: Send, | ||
B::Error: Into<axum::BoxError>, | ||
{ | ||
post(handle).route_layer(DefaultBodyLimit::max(config.max_event_size())) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters