This repository has been archived by the owner on Oct 18, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
361: Server heartbeats r=MarinPostma a=penberg This adds support for server heartbeats. The patch adds three new command line options: `--heartbeat-url URL` is the URL to send a HTTP POST request to periodically to indicate server heatbeat. `--heartbeat-auth AUTH` is the HTTP "Authorization" header to send as part of the HTTP POST request. `--heartbeat-period SECS` is the heartbeat period in seconds. The payload of the HTTP POST request is pretty simple for now: ```json {"rows_read":1234,"rows_written":8765} ``` Fixes #343 Co-authored-by: Pekka Enberg <[email protected]>
- Loading branch information
Showing
7 changed files
with
87 additions
and
5 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,31 @@ | ||
use std::time::Duration; | ||
use tokio::time::sleep; | ||
|
||
use crate::http::stats::StatsResponse; | ||
use crate::stats::Stats; | ||
|
||
pub async fn server_heartbeat( | ||
url: String, | ||
auth: Option<String>, | ||
update_period: Duration, | ||
stats: Stats, | ||
) { | ||
let client = reqwest::Client::new(); | ||
loop { | ||
sleep(update_period).await; | ||
let body = StatsResponse { | ||
rows_read_count: stats.rows_read(), | ||
rows_written_count: stats.rows_written(), | ||
}; | ||
let request = client.post(&url); | ||
let request = if let Some(ref auth) = auth { | ||
request.header("Authorization", auth.clone()) | ||
} else { | ||
request | ||
}; | ||
let request = request.json(&body); | ||
if let Err(err) = request.send().await { | ||
tracing::warn!("Error sending heartbeat: {}", err); | ||
} | ||
} | ||
} |
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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
mod hrana_over_http; | ||
mod stats; | ||
pub mod stats; | ||
mod types; | ||
|
||
use std::net::SocketAddr; | ||
|
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