Skip to content

Commit eae40e0

Browse files
committed
make delivery list and probe APIs not webhook specific
1 parent e06cf1f commit eae40e0

File tree

9 files changed

+212
-217
lines changed

9 files changed

+212
-217
lines changed

nexus/external-api/output/nexus_tags.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,15 +163,15 @@ snapshot_view GET /v1/snapshots/{snapshot}
163163
API operations found with tag "system/alerts"
164164
OPERATION ID METHOD URL PATH
165165
alert_class_list GET /v1/alert-classes
166-
alert_delivery_list GET /v1/alert-deliveries
166+
alert_delivery_list GET /v1/alert-receivers/{receiver}/deliveries
167167
alert_delivery_resend POST /v1/alerts/{alert_id}/resend
168168
alert_receiver_delete DELETE /v1/alert-receivers/{receiver}
169169
alert_receiver_list GET /v1/alert-receivers
170+
alert_receiver_probe POST /v1/alert-receivers/{receiver}/probe
170171
alert_receiver_subscription_add POST /v1/alert-receivers/{receiver}/subscriptions
171172
alert_receiver_subscription_remove DELETE /v1/alert-receivers/{receiver}/subscriptions/{subscription}
172173
alert_receiver_view GET /v1/alert-receivers/{receiver}
173174
webhook_receiver_create POST /v1/webhook-receivers
174-
webhook_receiver_probe POST /v1/webhook-receivers/{receiver}/probe
175175
webhook_receiver_update PUT /v1/webhook-receivers/{receiver}
176176
webhook_secrets_add POST /v1/webhook-secrets
177177
webhook_secrets_delete DELETE /v1/webhook-secrets/{secret_id}

nexus/external-api/src/lib.rs

Lines changed: 36 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -3623,16 +3623,50 @@ pub trait NexusExternalApi {
36233623
/// "true" are included in the response.
36243624
#[endpoint {
36253625
method = GET,
3626-
path = "/v1/alert-deliveries",
3626+
path = "/v1/alert-receivers/{receiver}/deliveries",
36273627
tags = ["system/alerts"],
36283628
}]
36293629
async fn alert_delivery_list(
36303630
rqctx: RequestContext<Self::Context>,
3631-
receiver: Query<params::AlertReceiverSelector>,
3631+
path_params: Path<params::AlertReceiverSelector>,
36323632
state_filter: Query<params::AlertDeliveryStateFilter>,
36333633
pagination: Query<PaginatedByTimeAndId>,
36343634
) -> Result<HttpResponseOk<ResultsPage<views::AlertDelivery>>, HttpError>;
36353635

3636+
/// Send liveness probe to alert receiver
3637+
///
3638+
/// This endpoint synchronously sends a liveness probe to the selected alert
3639+
/// receiver. The response message describes the outcome of the probe:
3640+
/// either the successful response (as appropriate), or indication of why
3641+
/// the probe failed.
3642+
///
3643+
/// The result of the probe is represented as an `AlertDelivery` model.
3644+
/// Details relating to the status of the probe depend on the alert delivery
3645+
/// mechanism, and are included in the `AlertDeliveryAttempts` model. For
3646+
/// example, webhook receiver liveness probes include the HTTP status code
3647+
/// returned by the receiver endpoint.
3648+
///
3649+
/// Note that the response status is `200 OK` as long as a probe request was
3650+
/// able to be sent to the receiver endpoint. If an HTTP-based receiver,
3651+
/// such as a webhook, responds to the another status code, including an
3652+
/// error, this will be indicated by the response body, *not* the status of
3653+
/// the response.
3654+
///
3655+
/// The `resend` query parameter can be used to request re-delivery of
3656+
/// failed events if the liveness probe succeeds. If it is set to true and
3657+
/// the liveness probe succeeds, any alerts for which delivery to this
3658+
/// receiver has failed will be queued for re-delivery.
3659+
#[endpoint {
3660+
method = POST,
3661+
path = "/v1/alert-receivers/{receiver}/probe",
3662+
tags = ["system/alerts"],
3663+
}]
3664+
async fn alert_receiver_probe(
3665+
rqctx: RequestContext<Self::Context>,
3666+
path_params: Path<params::AlertReceiverSelector>,
3667+
query_params: Query<params::AlertReceiverProbe>,
3668+
) -> Result<HttpResponseOk<views::AlertProbeResult>, HttpError>;
3669+
36363670
/// Request re-delivery of alert
36373671
#[endpoint {
36383672
method = POST,
@@ -3674,34 +3708,6 @@ pub trait NexusExternalApi {
36743708
params: TypedBody<params::WebhookReceiverUpdate>,
36753709
) -> Result<HttpResponseUpdatedNoContent, HttpError>;
36763710

3677-
/// Send liveness probe to webhook receiver
3678-
///
3679-
/// This endpoint synchronously sends a liveness probe request to the
3680-
/// selected webhook receiver. The response message describes the outcome of
3681-
/// the probe request: either the response from the receiver endpoint, or an
3682-
/// indication of why the probe failed.
3683-
///
3684-
/// Note that the response status is `200 OK` as long as a probe request was
3685-
/// able to be sent to the receiver endpoint. If the receiver responds with
3686-
/// another status code, including an error, this will be indicated by the
3687-
/// response body, *not* the status of the response.
3688-
///
3689-
/// The `resend` query parameter can be used to request re-delivery of
3690-
/// failed events if the liveness probe succeeds. If it is set to true and
3691-
/// the webhook receiver responds to the probe request with a `2xx` status
3692-
/// code, any events for which delivery to this receiver has failed will be
3693-
/// queued for re-delivery.
3694-
#[endpoint {
3695-
method = POST,
3696-
path = "/v1/webhook-receivers/{receiver}/probe",
3697-
tags = ["system/alerts"],
3698-
}]
3699-
async fn webhook_receiver_probe(
3700-
rqctx: RequestContext<Self::Context>,
3701-
path_params: Path<params::AlertReceiverSelector>,
3702-
query_params: Query<params::WebhookProbe>,
3703-
) -> Result<HttpResponseOk<views::WebhookProbeResult>, HttpError>;
3704-
37053711
/// List webhook receiver secret IDs
37063712
#[endpoint {
37073713
method = GET,

nexus/src/app/webhook.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
3030
use crate::Nexus;
3131
use anyhow::Context;
32-
use chrono::DateTime;
3332
use chrono::TimeDelta;
3433
use chrono::Utc;
3534
use hmac::{Hmac, Mac};
@@ -54,7 +53,6 @@ use nexus_types::external_api::views;
5453
use nexus_types::identity::Asset;
5554
use nexus_types::identity::Resource;
5655
use omicron_common::api::external::CreateResult;
57-
use omicron_common::api::external::DataPageParams;
5856
use omicron_common::api::external::DeleteResult;
5957
use omicron_common::api::external::Error;
6058
use omicron_common::api::external::ListResultVec;
@@ -71,7 +69,6 @@ use sha2::Sha256;
7169
use std::sync::LazyLock;
7270
use std::time::Duration;
7371
use std::time::Instant;
74-
use uuid::Uuid;
7572

7673
impl Nexus {
7774
pub fn webhook_secret_lookup<'a>(
@@ -179,8 +176,8 @@ impl Nexus {
179176
&self,
180177
opctx: &OpContext,
181178
rx: lookup::AlertReceiver<'_>,
182-
params: params::WebhookProbe,
183-
) -> Result<views::WebhookProbeResult, Error> {
179+
params: params::AlertReceiverProbe,
180+
) -> Result<views::AlertProbeResult, Error> {
184181
let (authz_rx, rx) = rx.fetch_for(authz::Action::ListChildren).await?;
185182
let rx_id = authz_rx.id();
186183
let datastore = self.datastore();
@@ -305,7 +302,7 @@ impl Nexus {
305302
None
306303
};
307304

308-
Ok(views::WebhookProbeResult {
305+
Ok(views::AlertProbeResult {
309306
probe: delivery.to_api_delivery(CLASS, &[attempt]),
310307
resends_started,
311308
})

nexus/src/external_api/http_entrypoints.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8032,11 +8032,11 @@ impl NexusExternalApi for NexusExternalApiImpl {
80328032
.await
80338033
}
80348034

8035-
async fn webhook_receiver_probe(
8035+
async fn alert_receiver_probe(
80368036
rqctx: RequestContext<Self::Context>,
80378037
path_params: Path<params::AlertReceiverSelector>,
8038-
query_params: Query<params::WebhookProbe>,
8039-
) -> Result<HttpResponseOk<views::WebhookProbeResult>, HttpError> {
8038+
query_params: Query<params::AlertReceiverProbe>,
8039+
) -> Result<HttpResponseOk<views::AlertProbeResult>, HttpError> {
80408040
let apictx = rqctx.context();
80418041
let handler = async {
80428042
let nexus = &apictx.context.nexus;
@@ -8141,7 +8141,7 @@ impl NexusExternalApi for NexusExternalApiImpl {
81418141

81428142
async fn alert_delivery_list(
81438143
rqctx: RequestContext<Self::Context>,
8144-
receiver: Query<params::AlertReceiverSelector>,
8144+
receiver: Path<params::AlertReceiverSelector>,
81458145
filter: Query<params::AlertDeliveryStateFilter>,
81468146
query: Query<PaginatedByTimeAndId>,
81478147
) -> Result<HttpResponseOk<ResultsPage<views::AlertDelivery>>, HttpError>

nexus/tests/integration_tests/endpoints.rs

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1198,18 +1198,14 @@ pub static DEMO_WEBHOOK_RECEIVER_URL: LazyLock<String> = LazyLock::new(|| {
11981198
format!("{WEBHOOK_RECEIVERS_URL}/{}", *DEMO_WEBHOOK_RECEIVER_NAME)
11991199
});
12001200

1201-
pub static DEMO_WEBHOOK_RECEIVER_PROBE_URL: LazyLock<String> =
1202-
LazyLock::new(|| {
1203-
format!("{WEBHOOK_RECEIVERS_URL}/{}/probe", *DEMO_WEBHOOK_RECEIVER_NAME)
1204-
});
1201+
pub static DEMO_ALERT_RECEIVER_PROBE_URL: LazyLock<String> =
1202+
LazyLock::new(|| format!("{}/probe", *DEMO_ALERT_RECEIVER_URL));
1203+
1204+
pub static DEMO_ALERT_DELIVERIES_URL: LazyLock<String> =
1205+
LazyLock::new(|| format!("{}/deliveries", *DEMO_ALERT_RECEIVER_URL));
12051206

12061207
pub static DEMO_ALERT_SUBSCRIPTIONS_URL: LazyLock<String> =
1207-
LazyLock::new(|| {
1208-
format!(
1209-
"{ALERT_RECEIVERS_URL}/{}/subscriptions",
1210-
*DEMO_WEBHOOK_RECEIVER_NAME
1211-
)
1212-
});
1208+
LazyLock::new(|| format!("{}/subscriptions", *DEMO_ALERT_RECEIVER_URL));
12131209

12141210
pub static DEMO_ALERT_SUBSCRIPTION: LazyLock<shared::AlertSubscription> =
12151211
LazyLock::new(|| "test.foo.**".parse().unwrap());
@@ -1223,15 +1219,11 @@ pub static DEMO_ALERT_SUBSCRIPTION_CREATE: LazyLock<
12231219
pub static DEMO_ALERT_SUBSCRIPTION_DELETE_URL: LazyLock<String> =
12241220
LazyLock::new(|| {
12251221
format!(
1226-
"{ALERT_RECEIVERS_URL}/{}/subscriptions/{}",
1227-
*DEMO_WEBHOOK_RECEIVER_NAME, *DEMO_ALERT_SUBSCRIPTION,
1222+
"{}/subscriptions/{}",
1223+
*DEMO_ALERT_RECEIVER_URL, *DEMO_ALERT_SUBSCRIPTION,
12281224
)
12291225
});
12301226

1231-
pub static DEMO_ALERT_DELIVERY_URL: LazyLock<String> = LazyLock::new(|| {
1232-
format!("/v1/alert-deliveries?receiver={}", *DEMO_WEBHOOK_RECEIVER_NAME)
1233-
});
1234-
12351227
pub static DEMO_WEBHOOK_SECRETS_URL: LazyLock<String> = LazyLock::new(|| {
12361228
format!("/v1/webhook-secrets?receiver={}", *DEMO_WEBHOOK_RECEIVER_NAME)
12371229
});
@@ -2865,7 +2857,7 @@ pub static VERIFY_ENDPOINTS: LazyLock<Vec<VerifyEndpoint>> =
28652857
)],
28662858
},
28672859
VerifyEndpoint {
2868-
url: &DEMO_WEBHOOK_RECEIVER_PROBE_URL,
2860+
url: &DEMO_ALERT_RECEIVER_PROBE_URL,
28692861
visibility: Visibility::Protected,
28702862
unprivileged_access: UnprivilegedAccess::None,
28712863
allowed_methods: vec![AllowedMethod::Post(
@@ -2906,7 +2898,7 @@ pub static VERIFY_ENDPOINTS: LazyLock<Vec<VerifyEndpoint>> =
29062898
allowed_methods: vec![AllowedMethod::Delete],
29072899
},
29082900
VerifyEndpoint {
2909-
url: &DEMO_ALERT_DELIVERY_URL,
2901+
url: &DEMO_ALERT_DELIVERIES_URL,
29102902
visibility: Visibility::Protected,
29112903
unprivileged_access: UnprivilegedAccess::None,
29122904
allowed_methods: vec![AllowedMethod::Get],

nexus/tests/integration_tests/webhooks.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ async fn webhook_send_probe(
244244
webhook_id: &AlertReceiverUuid,
245245
resend: bool,
246246
status: http::StatusCode,
247-
) -> views::WebhookProbeResult {
247+
) -> views::AlertProbeResult {
248248
let pathparams = if resend { "?resend=true" } else { "" };
249249
let path =
250250
format!("{WEBHOOK_RECEIVERS_BASE_PATH}/{webhook_id}/probe{pathparams}");

nexus/types/src/external_api/params.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2536,7 +2536,7 @@ impl AlertDeliveryStateFilter {
25362536
}
25372537

25382538
#[derive(Clone, Debug, Deserialize, Serialize, JsonSchema)]
2539-
pub struct WebhookProbe {
2539+
pub struct AlertReceiverProbe {
25402540
/// If true, resend all events that have not been delivered successfully if
25412541
/// the probe request succeeds.
25422542
#[serde(default)]

nexus/types/src/external_api/views.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1415,10 +1415,10 @@ pub struct AlertDeliveryId {
14151415
pub delivery_id: Uuid,
14161416
}
14171417

1418-
/// Data describing the result of a webhook liveness probe attempt.
1418+
/// Data describing the result of an alert receiver liveness probe attempt.
14191419
#[derive(Clone, Debug, Eq, PartialEq, Deserialize, Serialize, JsonSchema)]
1420-
pub struct WebhookProbeResult {
1421-
/// The outcome of the probe request.
1420+
pub struct AlertProbeResult {
1421+
/// The outcome of the probe delivery.
14221422
pub probe: AlertDelivery,
14231423
/// If the probe request succeeded, and resending failed deliveries on
14241424
/// success was requested, the number of new delivery attempts started.

0 commit comments

Comments
 (0)