Skip to content

Commit 88ab9cf

Browse files
committed
no heartbeats in response when query param is not provided
1 parent 72059fa commit 88ab9cf

File tree

2 files changed

+23
-11
lines changed

2 files changed

+23
-11
lines changed

primitives/src/sentry.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,12 @@ pub struct LastApprovedResponse {
136136
pub heartbeats: Option<Vec<HeartbeatValidatorMessage>>,
137137
}
138138

139+
#[derive(Serialize, Deserialize, Debug, PartialEq, Eq)]
140+
#[serde(rename_all = "camelCase")]
141+
pub struct LastApprovedResponseNoHeartbeats {
142+
pub last_approved: Option<LastApproved>,
143+
}
144+
139145
#[derive(Serialize, Deserialize, Debug)]
140146
pub struct SuccessResponse {
141147
pub success: bool,

sentry/src/routes/channel.rs

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use primitives::{
1010
adapter::Adapter,
1111
sentry::{
1212
channel_list::{ChannelListQuery, LastApprovedQuery},
13-
Event, LastApproved, LastApprovedResponse, SuccessResponse,
13+
Event, LastApproved, LastApprovedResponse, SuccessResponse, LastApprovedResponseNoHeartbeats,
1414
},
1515
validator::MessageTypes,
1616
Channel, ChannelId,
@@ -151,28 +151,34 @@ pub async fn last_approved<A: Adapter>(
151151
let query = serde_urlencoded::from_str::<LastApprovedQuery>(&req.uri().query().unwrap_or(""))?;
152152
let validators = channel.spec.validators;
153153
let channel_id = channel.id;
154-
let heartbeats = if query.with_heartbeat.is_some() {
154+
let response_body = if query.with_heartbeat.is_some() {
155155
let result = try_join_all(
156156
validators
157157
.iter()
158158
.map(|validator| latest_heartbeats(&app.pool, &channel_id, &validator.id)),
159159
)
160160
.await?;
161-
Some(result.into_iter().flatten().collect::<Vec<_>>())
161+
let heartbeats = Some(result.into_iter().flatten().collect::<Vec<_>>());
162+
serde_json::to_string(&LastApprovedResponse {
163+
last_approved: Some(LastApproved {
164+
new_state,
165+
approve_state: Some(approve_state),
166+
}),
167+
heartbeats,
168+
})?
162169
} else {
163-
None
170+
serde_json::to_string(&LastApprovedResponseNoHeartbeats {
171+
last_approved: Some(LastApproved {
172+
new_state,
173+
approve_state: Some(approve_state),
174+
})
175+
})?
164176
};
165177

166178
Ok(Response::builder()
167179
.header("Content-type", "application/json")
168180
.body(
169-
serde_json::to_string(&LastApprovedResponse {
170-
last_approved: Some(LastApproved {
171-
new_state,
172-
approve_state: Some(approve_state),
173-
}),
174-
heartbeats,
175-
})?
181+
response_body
176182
.into(),
177183
)
178184
.unwrap())

0 commit comments

Comments
 (0)