Skip to content
Open
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
11 changes: 11 additions & 0 deletions quickwit/quickwit-cli/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

use anyhow::{Context, bail};
use clap::{Arg, ArgAction, ArgMatches, Command, arg};
use quickwit_common::uri::Uri;
use quickwit_serve::EnvFilterReloadFn;
use tracing::Level;

Expand Down Expand Up @@ -95,4 +96,14 @@ impl CliCommand {
CliCommand::Tool(subcommand) => subcommand.execute().await,
}
}

pub fn config_uri(&self) -> Option<&Uri> {
match self {
CliCommand::Run(run) => Some(&run.config_uri),
CliCommand::Index(_) => None,
CliCommand::Source(_) => None,
CliCommand::Split(_) => None,
CliCommand::Tool(tools) => tools.config_uri(),
}
}
}
2 changes: 1 addition & 1 deletion quickwit/quickwit-cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ pub fn start_actor_runtimes(
}

/// Loads a node config located at `config_uri` with the default storage configuration.
async fn load_node_config(config_uri: &Uri) -> anyhow::Result<NodeConfig> {
pub async fn load_node_config(config_uri: &Uri) -> anyhow::Result<NodeConfig> {
let config_content = load_file(&StorageResolver::unconfigured(), config_uri)
.await
.context("failed to load node config")?;
Expand Down
2 changes: 2 additions & 0 deletions quickwit/quickwit-cli/src/logger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ pub fn setup_logging_and_tracing(
level: Level,
ansi_colors: bool,
build_info: &BuildInfo,
node_name: String,
) -> anyhow::Result<EnvFilterReloadFn> {
#[cfg(feature = "tokio-console")]
{
Expand Down Expand Up @@ -112,6 +113,7 @@ pub fn setup_logging_and_tracing(
.with_resource(Resource::new([
KeyValue::new("service.name", "quickwit"),
KeyValue::new("service.version", build_info.version.clone()),
KeyValue::new("service.node", node_name),
]))
.build();
let tracer = provider.tracer("quickwit");
Expand Down
26 changes: 23 additions & 3 deletions quickwit/quickwit-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ use std::collections::BTreeMap;
use anyhow::Context;
use colored::Colorize;
use opentelemetry::global;
use quickwit_cli::busy_detector;
use quickwit_cli::checklist::RED_COLOR;
use quickwit_cli::cli::{CliCommand, build_cli};
#[cfg(feature = "jemalloc")]
use quickwit_cli::jemalloc::start_jemalloc_metrics_loop;
use quickwit_cli::logger::setup_logging_and_tracing;
use quickwit_cli::{busy_detector, load_node_config};
use quickwit_common::runtimes::scrape_tokio_runtime_metrics;
use quickwit_serve::BuildInfo;
use tracing::error;
Expand Down Expand Up @@ -101,8 +101,28 @@ async fn main_impl() -> anyhow::Result<()> {
start_jemalloc_metrics_loop();

let build_info = BuildInfo::get();
let env_filter_reload_fn =
setup_logging_and_tracing(command.default_log_level(), ansi_colors, build_info)?;

// we need this value very early to use it in otel, but this is so early we haven't setup
// logging yet. What we do is read the config, and if it fails, provide a default value.
// Except for race conditions, an error will get logged the 2nd time the config is read,
// inside the command. In case of race condition, we just don't know the node id for tracing
// purpose
let node_id = {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see. I suggest we do simpler... but less correct.
Just use the QW_NODE_ID env variable here.

It won't capture people using the node_id config value, and it will break if we change the helm chart, but it has the merit of not adding the extra complexity in this PR (loading the config twice, etc.)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(your call though)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i prefer reading the config: not all deployments of quickwit uses an helm chart
i'd argue that our configuration loading process is complexe, but well encapsulated, so loading the config twice doesn't harm code maintainability

async || {
let config_uri = command.config_uri()?;
let config = load_node_config(config_uri).await.ok()?;
Some(config.node_id.take())
}
}()
.await
.unwrap_or_else(|| "unknown".to_string());
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should the default value contain a random number in it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think it won't be useful because the 2 situations where this is emitted should be:

  • the command is not one that behave like a node at all
  • we couldn't read the config file, and assuming that stays true, the node will crash shortly

but there is little harm at doing it, so why not


let env_filter_reload_fn = setup_logging_and_tracing(
command.default_log_level(),
ansi_colors,
build_info,
node_id,
)?;

let return_code: i32 = if let Err(command_error) = command.execute(env_filter_reload_fn).await {
error!(error=%command_error, "command failed");
Expand Down
10 changes: 10 additions & 0 deletions quickwit/quickwit-cli/src/tool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,16 @@ impl ToolCliCommand {
Self::ExtractSplit(args) => extract_split_cli(args).await,
}
}

pub fn config_uri(&self) -> Option<&Uri> {
match self {
Self::GarbageCollect(args) => Some(&args.config_uri),
Self::LocalIngest(args) => Some(&args.config_uri),
Self::LocalSearch(args) => Some(&args.config_uri),
Self::Merge(args) => Some(&args.config_uri),
Self::ExtractSplit(args) => Some(&args.config_uri),
}
}
}

pub async fn local_ingest_docs_cli(args: LocalIngestDocsArgs) -> anyhow::Result<()> {
Expand Down
Loading