-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor parts of Plane into a
plane-common
crate (DIS-2967) (#849)
The main `plane` crate contains a client, but depending on it in another project requires bringing in _all_ of Plane, including the openssl dependency. This breaks the client (and other pieces) out into a `plane-common` crate with the parts needed to "consume" Plane as a client, and a crate for Plane itself (in particular, without the database and ACME stuff, which bring in other dependencies that can be hard to wrangle). This looks like a huge PR but there is essentially no net new code here; files are just moved around. A few notes: - I got rid of `plane-dynamic`; it was a hack to make tests compile faster but it should be less necessary now that we have broken up Plane into several crates. - Roughly, the criteria for "what goes in common" is "the client and everything it depends on". `plane` depends on `plane-common`, but `plane-common` does NOT depend on `plane`, so things like `ExponentialBackoff` (used by the client to manage reconnects) go in `plane-common`. Todo: - [x] get `test_get_metrics` and `backend_lifecycle` tests to pass. - [x] rename to `plane-common`? - [x] p2 PR for refactor and ensure p2 integration tests pass
- Loading branch information
Showing
102 changed files
with
893 additions
and
586 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
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,29 @@ | ||
[package] | ||
name = "plane-common" | ||
version = "0.5.1" | ||
edition = "2021" | ||
|
||
[dependencies] | ||
axum = { version = "0.7.7", features = ["ws"] } | ||
bollard = "0.17.0" | ||
chrono = { version = "0.4.31", features = ["serde"] } | ||
clap = "4.4.10" | ||
data-encoding = "2.4.0" | ||
futures-util = "0.3.29" | ||
rand = "0.8.5" | ||
reqwest = { version = "0.12.8", features = ["json"] } | ||
serde = "1.0.109" | ||
serde_json = "1.0.107" | ||
serde_with = "3.4.0" | ||
thiserror = "1.0.50" | ||
tokio = { version = "1.33.0", features = ["sync"] } | ||
tokio-tungstenite = "0.24.0" | ||
tracing = "0.1.40" | ||
tungstenite = "0.24.0" | ||
url = "2.4.1" | ||
valuable = { version = "0.1.0", features = ["derive"] } | ||
|
||
[dev-dependencies] | ||
anyhow = "1.0.93" | ||
async-stream = "0.3.6" | ||
axum = "0.7.9" |
File renamed without changes.
File renamed without changes.
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,68 @@ | ||
use std::time::{Duration, SystemTime}; | ||
|
||
pub struct ExponentialBackoff { | ||
initial_duration_millis: u128, | ||
max_duration: Duration, | ||
defer_duration: Duration, | ||
multiplier: f64, | ||
step: i32, | ||
deferred_reset: Option<SystemTime>, | ||
} | ||
|
||
impl ExponentialBackoff { | ||
pub fn new( | ||
initial_duration: Duration, | ||
max_duration: Duration, | ||
multiplier: f64, | ||
defer_duration: Duration, | ||
) -> Self { | ||
let initial_duration_millis = initial_duration.as_millis(); | ||
|
||
Self { | ||
initial_duration_millis, | ||
max_duration, | ||
multiplier, | ||
step: 0, | ||
defer_duration, | ||
deferred_reset: None, | ||
} | ||
} | ||
|
||
/// Reset the backoff, but only if `wait` is not called again for at least `defer_duration`. | ||
pub fn defer_reset(&mut self) { | ||
self.deferred_reset = Some(SystemTime::now() + self.defer_duration); | ||
} | ||
|
||
pub async fn wait(&mut self) { | ||
if let Some(deferred_reset) = self.deferred_reset { | ||
self.deferred_reset = None; | ||
if SystemTime::now() > deferred_reset { | ||
self.reset(); | ||
return; | ||
} | ||
} | ||
|
||
let duration = self.initial_duration_millis as f64 * self.multiplier.powi(self.step); | ||
let duration = Duration::from_millis(duration as u64); | ||
let duration = duration.min(self.max_duration); | ||
tokio::time::sleep(duration).await; | ||
|
||
self.step += 1; | ||
} | ||
|
||
pub fn reset(&mut self) { | ||
self.deferred_reset = None; | ||
self.step = 0; | ||
} | ||
} | ||
|
||
impl Default for ExponentialBackoff { | ||
fn default() -> Self { | ||
Self::new( | ||
Duration::from_secs(1), | ||
Duration::from_secs(60), | ||
1.1, | ||
Duration::from_secs(60), | ||
) | ||
} | ||
} |
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
File renamed without changes.
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
4 changes: 2 additions & 2 deletions
4
plane/src/typed_socket/mod.rs → common/src/typed_socket/mod.rs
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
Oops, something went wrong.