This repository has been archived by the owner on Aug 3, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 337
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
wrangler tail using WebSockets (#2005)
`wrangler tail` will no longer use `cloudflared`, instead it will make a WebSocket connection to an endpoint, powered by Durable Objects, to receive a stream of logs. This also adds support for filtering logs, which we will be announced soon.
- Loading branch information
1 parent
8907b12
commit de00b8b
Showing
19 changed files
with
889 additions
and
775 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
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,25 +1,69 @@ | ||
use super::Cli; | ||
use crate::commands; | ||
use crate::commands::tail::filter::*; | ||
use crate::commands::tail::websocket::{TailFormat, TailOptions}; | ||
use crate::settings::{global_user::GlobalUser, toml::Manifest}; | ||
|
||
use anyhow::Result; | ||
use url::Url; | ||
|
||
#[allow(clippy::too_many_arguments)] | ||
pub fn tail( | ||
format: String, | ||
tunnel_port: Option<u16>, | ||
metrics_port: Option<u16>, | ||
name: Option<String>, | ||
url: Option<Url>, | ||
format: TailFormat, | ||
once: bool, | ||
sampling_rate: f64, | ||
outcomes: Vec<String>, | ||
methods: Vec<String>, | ||
headers: Vec<String>, | ||
client_ips: Vec<String>, | ||
search: Option<String>, | ||
cli_params: &Cli, | ||
) -> Result<()> { | ||
let user = GlobalUser::new()?; | ||
|
||
// FIXME: If `name` is defined, allow the command to be run outside a `wrangler.toml` directory. | ||
let manifest = Manifest::new(&cli_params.config)?; | ||
let target = manifest.get_target(cli_params.environment.as_deref(), false)?; | ||
let user = GlobalUser::new()?; | ||
let account_id = target.account_id.load()?.to_string(); | ||
let script_name = name.unwrap_or(target.name); | ||
|
||
let mut filters: Vec<Box<dyn TraceFilter>> = vec![]; | ||
if !outcomes.is_empty() { | ||
filters.push(Box::new(OutcomeFilter::from(outcomes))); | ||
} | ||
if !methods.is_empty() { | ||
filters.push(Box::new(MethodFilter::from(methods))); | ||
} | ||
if !client_ips.is_empty() { | ||
filters.push(Box::new(ClientIpFilter::from(client_ips))); | ||
} | ||
for header in headers.into_iter() { | ||
filters.push(Box::new(HeaderFilter::from(header))) | ||
} | ||
if let Some(query) = search { | ||
filters.push(Box::new(QueryFilter::from(query))); | ||
}; | ||
if sampling_rate < 1.0 && sampling_rate > 0.0 { | ||
filters.push(Box::new(SamplingRateFilter::from(sampling_rate))); // Should always be last | ||
}; | ||
|
||
let tail = commands::tail::run( | ||
user, | ||
account_id, | ||
script_name, | ||
url, | ||
TailOptions { | ||
once, | ||
format, | ||
filters, | ||
}, | ||
); | ||
|
||
commands::tail::start( | ||
&target, | ||
&user, | ||
format, | ||
tunnel_port, | ||
metrics_port, | ||
cli_params.verbose, | ||
) | ||
tokio::runtime::Builder::new_current_thread() | ||
.enable_all() | ||
.build() | ||
.unwrap() | ||
.block_on(tail) | ||
} |
Oops, something went wrong.