Skip to content

Commit

Permalink
fix: webhook payload (#302)
Browse files Browse the repository at this point in the history
  • Loading branch information
mahatoankitkumar authored Dec 11, 2024
1 parent 95b87c5 commit 90beb70
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions crates/experimentation_platform/src/api/experiments/handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ async fn create(
{
execute_webhook_call(
&experiments_webhook_config,
&inserted_experiment,
&ExperimentResponse::from(inserted_experiment),
&config_version_id,
&tenant,
WebhookEvent::ExperimentCreated,
Expand Down Expand Up @@ -327,12 +327,14 @@ async fn conclude_handler(
)
.await?;

let experiment_response = ExperimentResponse::from(response);

if let WebhookConfig::Enabled(experiments_webhook_config) =
tenant_config.experiments_webhook_config
{
execute_webhook_call(
&experiments_webhook_config,
&response,
&experiment_response,
&config_version_id,
&tenant,
WebhookEvent::ExperimentConcluded,
Expand All @@ -343,7 +345,7 @@ async fn conclude_handler(

let mut http_resp = HttpResponse::Ok();
add_config_version_to_header(&config_version_id, &mut http_resp);
Ok(http_resp.json(ExperimentResponse::from(response)))
Ok(http_resp.json(experiment_response))
}

pub async fn conclude(
Expand Down Expand Up @@ -691,6 +693,7 @@ async fn ramp(
.get_result(&mut conn)?;

let (_, config_version_id) = fetch_cac_config(&tenant, &data).await?;
let experiment_response = ExperimentResponse::from(updated_experiment);

let webhook_event = if new_traffic_percentage == 0
&& matches!(experiment.status, ExperimentStatusType::CREATED)
Expand All @@ -704,7 +707,7 @@ async fn ramp(
{
execute_webhook_call(
&experiments_webhook_config,
&updated_experiment,
&experiment_response,
&config_version_id,
&tenant,
webhook_event,
Expand All @@ -713,7 +716,7 @@ async fn ramp(
.await?;
}

Ok(Json(ExperimentResponse::from(updated_experiment)))
Ok(Json(experiment_response))
}

#[put("/{id}/overrides")]
Expand Down Expand Up @@ -934,12 +937,14 @@ async fn update_overrides(
))
.get_result::<Experiment>(&mut conn)?;

let experiment_response = ExperimentResponse::from(updated_experiment);

if let WebhookConfig::Enabled(experiments_webhook_config) =
tenant_config.experiments_webhook_config
{
execute_webhook_call(
&experiments_webhook_config,
&updated_experiment,
&experiment_response,
&config_version_id,
&tenant,
WebhookEvent::ExperimentUpdated,
Expand All @@ -950,7 +955,7 @@ async fn update_overrides(

let mut http_resp = HttpResponse::Ok();
add_config_version_to_header(&config_version_id, &mut http_resp);
Ok(http_resp.json(ExperimentResponse::from(updated_experiment)))
Ok(http_resp.json(experiment_response))
}

#[get("/audit")]
Expand Down

0 comments on commit 90beb70

Please sign in to comment.