mirror of
https://github.com/mii443/wasmer.git
synced 2025-12-08 13:48:26 +00:00
add log streams
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -12,7 +12,7 @@ use crate::{
|
||||
types::{
|
||||
self, CreateNamespaceVars, DeployApp, DeployAppConnection, DeployAppVersion,
|
||||
DeployAppVersionConnection, GetDeployAppAndVersion, GetDeployAppVersionsVars,
|
||||
GetNamespaceAppsVars, Log, PackageVersionConnection, PublishDeployAppVars,
|
||||
GetNamespaceAppsVars, Log, LogStream, PackageVersionConnection, PublishDeployAppVars,
|
||||
},
|
||||
GraphQLApiFailure, WasmerClient,
|
||||
};
|
||||
@@ -679,6 +679,7 @@ fn get_app_logs(
|
||||
start: OffsetDateTime,
|
||||
end: Option<OffsetDateTime>,
|
||||
watch: bool,
|
||||
streams: Option<Vec<LogStream>>,
|
||||
) -> impl futures::Stream<Item = Result<Vec<Log>, anyhow::Error>> + '_ {
|
||||
// Note: the backend will limit responses to a certain number of log
|
||||
// messages, so we use try_unfold() to keep calling it until we stop getting
|
||||
@@ -696,6 +697,7 @@ fn get_app_logs(
|
||||
first: Some(10),
|
||||
starting_from: unix_timestamp(start),
|
||||
until: end.map(unix_timestamp),
|
||||
streams: streams.clone(),
|
||||
};
|
||||
|
||||
let fut = async move {
|
||||
@@ -766,8 +768,9 @@ pub async fn get_app_logs_paginated(
|
||||
start: OffsetDateTime,
|
||||
end: Option<OffsetDateTime>,
|
||||
watch: bool,
|
||||
streams: Option<Vec<LogStream>>,
|
||||
) -> impl futures::Stream<Item = Result<Vec<Log>, anyhow::Error>> + '_ {
|
||||
let stream = get_app_logs(client, name, owner, tag, start, end, watch);
|
||||
let stream = get_app_logs(client, name, owner, tag, start, end, watch, streams);
|
||||
|
||||
stream.map(|res| {
|
||||
let mut logs = Vec::new();
|
||||
|
||||
@@ -591,6 +591,12 @@ mod queries {
|
||||
pub token: String,
|
||||
}
|
||||
|
||||
#[derive(cynic::Enum, Clone, Copy, Debug)]
|
||||
pub enum LogStream {
|
||||
Stdout,
|
||||
Stderr,
|
||||
}
|
||||
|
||||
#[derive(cynic::QueryVariables, Debug, Clone)]
|
||||
pub struct GetDeployAppLogsVars {
|
||||
pub name: String,
|
||||
@@ -605,6 +611,8 @@ mod queries {
|
||||
/// epoch.
|
||||
pub until: Option<f64>,
|
||||
pub first: Option<i32>,
|
||||
|
||||
pub streams: Option<Vec<LogStream>>,
|
||||
}
|
||||
|
||||
#[derive(cynic::QueryFragment, Debug)]
|
||||
|
||||
@@ -4,7 +4,7 @@ use comfy_table::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;
|
||||
use wasmer_api::types::{Log, LogStream};
|
||||
|
||||
use crate::{
|
||||
opts::{ApiOpts, ListFormatOpts},
|
||||
@@ -59,6 +59,14 @@ pub struct CmdAppLogs {
|
||||
/// - namespace/name
|
||||
/// - namespace/name@version
|
||||
ident: Identifier,
|
||||
|
||||
/// Enables STDOUT log stream
|
||||
#[clap(long)]
|
||||
stdout: bool,
|
||||
|
||||
/// Enables STDERR log stream
|
||||
#[clap(long)]
|
||||
stderr: bool,
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
@@ -95,6 +103,12 @@ impl crate::commands::AsyncCliCommand for CmdAppLogs {
|
||||
"Fetching logs",
|
||||
);
|
||||
|
||||
let streams = Vec::from(match (self.stdout, self.stderr) {
|
||||
(true, true) | (false, false) => &[LogStream::Stdout, LogStream::Stderr][..],
|
||||
(true, false) => &[LogStream::Stdout][..],
|
||||
(false, true) => &[LogStream::Stderr][..],
|
||||
});
|
||||
|
||||
let logs_stream = wasmer_api::query::get_app_logs_paginated(
|
||||
&client,
|
||||
name.clone(),
|
||||
@@ -103,6 +117,7 @@ impl crate::commands::AsyncCliCommand for CmdAppLogs {
|
||||
from,
|
||||
self.until,
|
||||
self.watch,
|
||||
Some(streams),
|
||||
)
|
||||
.await;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user