Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Various cleanup chores + add a new test #5088

Merged
merged 10 commits into from
Sep 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,6 @@ lcov.info
link/
link.tar.gz
.vscode
# Ignore files used by the "direnv" tool.
.direnv
.envrc
56 changes: 9 additions & 47 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ wasmer-wasix = { path = "./lib/wasix" }

# Wasmer-owned crates
webc = { version = "6.0.0", default-features = false, features = ["package"] }
edge-schema = { version = "=0.1.0" }
shared-buffer = "0.1.4"

# Third-party crates
Expand All @@ -110,6 +109,7 @@ toml = {version = "0.5.9", features = ["preserve_order"]}
indexmap = "2"
serde_yaml = "0.9.34"
libc = { version = "^0.2", default-features = false }
base64 = "0.22.0"

[build-dependencies]
test-generator = { path = "tests/lib/test-generator" }
Expand Down
7 changes: 4 additions & 3 deletions lib/backend-api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@ rust-version.workspace = true
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
# Wasmer dependencies.
edge-schema.workspace = true
wasmer-config = { version = "0.8.0", path = "../config" }
webc.workspace = true


# crates.io dependencies.
reqwest = { workspace = true, default-features = false, features = ["json"] }

anyhow = "1"
serde = { version = "1", features = ["derive"] }
time = { version = "0.3", features = ["formatting", "parsing"] }
Expand All @@ -32,14 +34,13 @@ cynic = { version = "3.7.2", features = ["http-reqwest"] }
pin-project-lite = "0.2.10"
serde_path_to_error = "0.1.14"
harsh = "0.2.2"
reqwest = { workspace = true, default-features = false, features = ["json"] }
merge-streams = "0.1.2"

[target.'cfg(target_family = "wasm")'.dependencies.getrandom]
version = "0.2.14"
features = ["js"]

[dev-dependencies]
base64 = "0.13.1"
base64.workspace = true
tokio = { version = "1.3", features = ["macros", "rt"] }
uuid = { version = "1", features = ["v4"] }
26 changes: 0 additions & 26 deletions lib/backend-api/src/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ use std::{collections::HashSet, time::Duration};

use anyhow::{bail, Context};
use cynic::{MutationBuilder, QueryBuilder};
use edge_schema::schema::NetworkTokenV1;
use futures::StreamExt;
use merge_streams::MergeStreams;
use time::OffsetDateTime;
Expand Down Expand Up @@ -1596,31 +1595,9 @@ pub fn get_package_releases_stream(
)
}

/// Generate a new Edge token.
pub async fn generate_deploy_token_raw(
client: &WasmerClient,
app_version_id: String,
) -> Result<String, anyhow::Error> {
let res = client
.run_graphql(types::GenerateDeployToken::build(
types::GenerateDeployTokenVars { app_version_id },
))
.await?;

res.generate_deploy_token
.map(|x| x.token)
.context("no token returned")
}

#[derive(Debug, PartialEq)]
pub enum GenerateTokenBy {
Id(NetworkTokenV1),
}

#[derive(Debug, PartialEq)]
pub enum TokenKind {
SSH,
Network(GenerateTokenBy),
}

pub async fn generate_deploy_config_token_raw(
Expand All @@ -1632,9 +1609,6 @@ pub async fn generate_deploy_config_token_raw(
types::GenerateDeployConfigTokenVars {
input: match token_kind {
TokenKind::SSH => "{}".to_string(),
TokenKind::Network(by) => match by {
GenerateTokenBy::Id(token) => serde_json::to_string(&token)?,
},
},
},
))
Expand Down
1 change: 0 additions & 1 deletion lib/cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,6 @@ virtual-mio = { version = "0.3.1", path = "../virtual-io" }

webc = { workspace = true }
wasmer-api = { version = "=0.0.34", path = "../backend-api" }
edge-schema.workspace = true
edge-util = { version = "=0.1.0" }
lazy_static = "1.4.0"

Expand Down
6 changes: 3 additions & 3 deletions lib/cli/src/commands/app/logs.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
//! Show logs for an Edge app.

use crate::utils::timestamp::parse_timestamp_or_relative_time_negative_offset;
use colored::Colorize;
use comfy_table::{Cell, Table};
use edge_schema::pretty_duration::parse_timestamp_or_relative_time;
use futures::StreamExt;
use time::{format_description::well_known::Rfc3339, OffsetDateTime};
use wasmer_api::types::{Log, LogStream};
Expand Down Expand Up @@ -37,7 +37,7 @@ pub struct CmdAppLogs {
/// * Unix timestamp (`1136196245`)
/// * Relative time (`10m` / `-1h`, `1d1h30s`)
// TODO: should default to trailing logs once trailing is implemented.
#[clap(long, value_parser = parse_timestamp_or_relative_time, conflicts_with = "request_id")]
#[clap(long, value_parser = parse_timestamp_or_relative_time_negative_offset, conflicts_with = "request_id")]
from: Option<OffsetDateTime>,

/// The date of the latest log entry.
Expand All @@ -48,7 +48,7 @@ pub struct CmdAppLogs {
/// * Simple date (`2022-11-11`)
/// * Unix timestamp (`1136196245`)
/// * Relative time (`10m` / `1h`, `1d1h30s`)
#[clap(long, value_parser = parse_timestamp_or_relative_time, conflicts_with = "request_id")]
#[clap(long, value_parser = parse_timestamp_or_relative_time_negative_offset, conflicts_with = "request_id")]
until: Option<OffsetDateTime>,

/// Maximum log lines to fetch.
Expand Down
2 changes: 2 additions & 0 deletions lib/cli/src/commands/connect.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// NOTE: not currently in use - but kept here to allow easy re-implementation.

use std::net::IpAddr;

use crate::config::WasmerEnv;
Expand Down
3 changes: 0 additions & 3 deletions lib/cli/src/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,9 +198,6 @@ impl WasmerCmd {
Some(Cmd::Container(cmd)) => match cmd {
crate::commands::Container::Unpack(cmd) => cmd.execute(),
},
/*
Some(Cmd::Connect(connect)) => connect.execute(),
*/
#[cfg(feature = "static-artifact-create")]
Some(Cmd::GenCHeader(gen_heder)) => gen_heder.execute(),
#[cfg(feature = "wast")]
Expand Down
1 change: 1 addition & 0 deletions lib/cli/src/utils/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
pub(crate) mod package_wizard;
pub(crate) mod prompts;
pub(crate) mod render;
pub(crate) mod timestamp;

use std::{
path::{Path, PathBuf},
Expand Down
68 changes: 68 additions & 0 deletions lib/cli/src/utils/timestamp.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
use time::{
format_description::well_known::{Rfc2822, Rfc3339},
Date, OffsetDateTime, PrimitiveDateTime, Time,
};

/// Try to parse the string as a timestamp in a number of well-known formats.
///
/// Supported formats,
///
/// - RFC 3339 (`2006-01-02T03:04:05-07:00`)
/// - RFC 2822 (`Mon, 02 Jan 2006 03:04:05 MST`)
/// - Date (`2006-01-02`)
/// - Unix timestamp (`1136196245`)
/// - Relative time (`10m` / `-1h`, `1d`)
pub fn parse_timestamp_or_relative_time(
s: &str,
assume_negative_offset: bool,
) -> Result<OffsetDateTime, anyhow::Error> {
parse_timestamp_or_relative_time_based(s, OffsetDateTime::now_utc(), assume_negative_offset)
}

/// See [`parse_timestamp_or_relative_time`].
///
/// NOTE: assumes a negative offset if time is specified in a format like "1h".
pub fn parse_timestamp_or_relative_time_negative_offset(
s: &str,
) -> Result<OffsetDateTime, anyhow::Error> {
parse_timestamp_or_relative_time(s, true)
}

/// See [`parse_timestamp_or_relative_time`].
pub fn parse_timestamp_or_relative_time_based(
s: &str,
base: OffsetDateTime,
assume_negative_offset: bool,
) -> Result<OffsetDateTime, anyhow::Error> {
if let Ok(t) = OffsetDateTime::parse(s, &Rfc3339) {
return Ok(t);
}
if let Ok(t) = OffsetDateTime::parse(s, &Rfc2822) {
return Ok(t);
}
if let Ok(t) = Date::parse(s, time::macros::format_description!("[year]-[month]-[day]")) {
return Ok(PrimitiveDateTime::new(t, Time::MIDNIGHT).assume_utc());
}
if let Ok(t) = OffsetDateTime::parse(s, time::macros::format_description!("[unix_timestamp]")) {
return Ok(t);
}

// Relative time.
let (is_negative, v) = match s.strip_prefix('-') {
Some(rest) => (true, rest),
// Note: `assume_negative_offset` forces offsets to be negative.
None => (assume_negative_offset, s.trim_start_matches('+')),
};

if let Ok(duration) = humantime::parse_duration(v) {
let time = if is_negative {
base - duration
} else {
base + duration
};

return Ok(time);
}

anyhow::bail!("Unable to parse the timestamp - no known format matched")
}
7 changes: 4 additions & 3 deletions lib/journal/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,22 @@ virtual-net = { path = "../virtual-net", version = "0.8.0", default-features = f
virtual-fs = { path = "../virtual-fs", version = "0.16.0", default-features = false }

shared-buffer = { workspace = true, optional = true }
base64.workspace = true
rkyv = { workspace = true }

thiserror = "1"
bytes = "1.1"
async-trait = { version = "^0.1" }
tracing = "0.1"
derivative = { version = "^2" }
base64 = "0.21"
bincode = { version = "1.3" }
serde = { version = "1.0", default-features = false, features = ["derive"] }
anyhow = "1.0"
rkyv = { workspace = true }
bytecheck = { version = "0.6.8" }
lz4_flex = { version = "0.11" }
num_enum = "0.5.7"
serde_json = { version = "^1" }

[dev-dependencies]
tracing-test = "0.2.4"
tempfile = "3.6.0"
tempfile = "3.6.0"
Loading
Loading