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::{
|
types::{
|
||||||
self, CreateNamespaceVars, DeployApp, DeployAppConnection, DeployAppVersion,
|
self, CreateNamespaceVars, DeployApp, DeployAppConnection, DeployAppVersion,
|
||||||
DeployAppVersionConnection, GetDeployAppAndVersion, GetDeployAppVersionsVars,
|
DeployAppVersionConnection, GetDeployAppAndVersion, GetDeployAppVersionsVars,
|
||||||
GetNamespaceAppsVars, Log, PackageVersionConnection, PublishDeployAppVars,
|
GetNamespaceAppsVars, Log, LogStream, PackageVersionConnection, PublishDeployAppVars,
|
||||||
},
|
},
|
||||||
GraphQLApiFailure, WasmerClient,
|
GraphQLApiFailure, WasmerClient,
|
||||||
};
|
};
|
||||||
@@ -679,6 +679,7 @@ fn get_app_logs(
|
|||||||
start: OffsetDateTime,
|
start: OffsetDateTime,
|
||||||
end: Option<OffsetDateTime>,
|
end: Option<OffsetDateTime>,
|
||||||
watch: bool,
|
watch: bool,
|
||||||
|
streams: Option<Vec<LogStream>>,
|
||||||
) -> impl futures::Stream<Item = Result<Vec<Log>, anyhow::Error>> + '_ {
|
) -> impl futures::Stream<Item = Result<Vec<Log>, anyhow::Error>> + '_ {
|
||||||
// Note: the backend will limit responses to a certain number of log
|
// 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
|
// 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),
|
first: Some(10),
|
||||||
starting_from: unix_timestamp(start),
|
starting_from: unix_timestamp(start),
|
||||||
until: end.map(unix_timestamp),
|
until: end.map(unix_timestamp),
|
||||||
|
streams: streams.clone(),
|
||||||
};
|
};
|
||||||
|
|
||||||
let fut = async move {
|
let fut = async move {
|
||||||
@@ -766,8 +768,9 @@ pub async fn get_app_logs_paginated(
|
|||||||
start: OffsetDateTime,
|
start: OffsetDateTime,
|
||||||
end: Option<OffsetDateTime>,
|
end: Option<OffsetDateTime>,
|
||||||
watch: bool,
|
watch: bool,
|
||||||
|
streams: Option<Vec<LogStream>>,
|
||||||
) -> impl futures::Stream<Item = Result<Vec<Log>, anyhow::Error>> + '_ {
|
) -> 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| {
|
stream.map(|res| {
|
||||||
let mut logs = Vec::new();
|
let mut logs = Vec::new();
|
||||||
|
|||||||
@@ -591,6 +591,12 @@ mod queries {
|
|||||||
pub token: String,
|
pub token: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(cynic::Enum, Clone, Copy, Debug)]
|
||||||
|
pub enum LogStream {
|
||||||
|
Stdout,
|
||||||
|
Stderr,
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(cynic::QueryVariables, Debug, Clone)]
|
#[derive(cynic::QueryVariables, Debug, Clone)]
|
||||||
pub struct GetDeployAppLogsVars {
|
pub struct GetDeployAppLogsVars {
|
||||||
pub name: String,
|
pub name: String,
|
||||||
@@ -605,6 +611,8 @@ mod queries {
|
|||||||
/// epoch.
|
/// epoch.
|
||||||
pub until: Option<f64>,
|
pub until: Option<f64>,
|
||||||
pub first: Option<i32>,
|
pub first: Option<i32>,
|
||||||
|
|
||||||
|
pub streams: Option<Vec<LogStream>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(cynic::QueryFragment, Debug)]
|
#[derive(cynic::QueryFragment, Debug)]
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ use comfy_table::Table;
|
|||||||
use edge_schema::pretty_duration::parse_timestamp_or_relative_time;
|
use edge_schema::pretty_duration::parse_timestamp_or_relative_time;
|
||||||
use futures::StreamExt;
|
use futures::StreamExt;
|
||||||
use time::{format_description::well_known::Rfc3339, OffsetDateTime};
|
use time::{format_description::well_known::Rfc3339, OffsetDateTime};
|
||||||
use wasmer_api::types::Log;
|
use wasmer_api::types::{Log, LogStream};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
opts::{ApiOpts, ListFormatOpts},
|
opts::{ApiOpts, ListFormatOpts},
|
||||||
@@ -59,6 +59,14 @@ pub struct CmdAppLogs {
|
|||||||
/// - namespace/name
|
/// - namespace/name
|
||||||
/// - namespace/name@version
|
/// - namespace/name@version
|
||||||
ident: Identifier,
|
ident: Identifier,
|
||||||
|
|
||||||
|
/// Enables STDOUT log stream
|
||||||
|
#[clap(long)]
|
||||||
|
stdout: bool,
|
||||||
|
|
||||||
|
/// Enables STDERR log stream
|
||||||
|
#[clap(long)]
|
||||||
|
stderr: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[async_trait::async_trait]
|
#[async_trait::async_trait]
|
||||||
@@ -95,6 +103,12 @@ impl crate::commands::AsyncCliCommand for CmdAppLogs {
|
|||||||
"Fetching logs",
|
"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(
|
let logs_stream = wasmer_api::query::get_app_logs_paginated(
|
||||||
&client,
|
&client,
|
||||||
name.clone(),
|
name.clone(),
|
||||||
@@ -103,6 +117,7 @@ impl crate::commands::AsyncCliCommand for CmdAppLogs {
|
|||||||
from,
|
from,
|
||||||
self.until,
|
self.until,
|
||||||
self.watch,
|
self.watch,
|
||||||
|
Some(streams),
|
||||||
)
|
)
|
||||||
.await;
|
.await;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user