Skip to content
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: 1 addition & 2 deletions Cargo.lock

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

14 changes: 7 additions & 7 deletions quickwit-cli/src/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ use std::time::{Duration, Instant};
use std::{env, fmt, io};

use anyhow::{bail, Context};
use chrono::Utc;
use clap::{arg, ArgMatches, Command};
use colored::Colorize;
use humantime::format_duration;
Expand All @@ -48,6 +47,7 @@ use quickwit_search::{single_node_search, SearchResponseRest};
use quickwit_storage::{load_file, quickwit_storage_uri_resolver};
use quickwit_telemetry::payload::TelemetryEvent;
use thousands::Separable;
use time::OffsetDateTime;
use tracing::{debug, info, Level};

use crate::stats::{mean, percentile, std_deviation};
Expand Down Expand Up @@ -748,8 +748,8 @@ pub async fn create_index_cli(args: CreateIndexArgs) -> anyhow::Result<()> {
doc_mapping: index_config.doc_mapping,
indexing_settings: index_config.indexing_settings,
search_settings: index_config.search_settings,
create_timestamp: Utc::now().timestamp(),
update_timestamp: Utc::now().timestamp(),
create_timestamp: OffsetDateTime::now_utc().unix_timestamp(),
update_timestamp: OffsetDateTime::now_utc().unix_timestamp(),
};
create_index(&quickwit_config.metastore_uri(), index_metadata.clone()).await?;
println!("Index `{}` successfully created.", index_config.index_id);
Expand Down Expand Up @@ -1066,12 +1066,12 @@ fn display_statistics(
throughput_calculator: &mut ThroughputCalculator,
statistics: &IndexingStatistics,
) -> anyhow::Result<()> {
let elapsed_duration = chrono::Duration::from_std(throughput_calculator.elapsed_time())?;
let elapsed_duration = time::Duration::try_from(throughput_calculator.elapsed_time())?;
let elapsed_time = format!(
"{:02}:{:02}:{:02}",
elapsed_duration.num_hours(),
elapsed_duration.num_minutes() % 60,
elapsed_duration.num_seconds() % 60
elapsed_duration.whole_hours(),
elapsed_duration.whole_minutes() % 60,
elapsed_duration.whole_seconds() % 60
);
let throughput_mb_s = throughput_calculator.calculate(statistics.total_bytes_processed);
let mut printer = Printer { stdout };
Expand Down
56 changes: 33 additions & 23 deletions quickwit-cli/src/split.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ use std::ops::{Range, RangeInclusive};
use std::path::PathBuf;

use anyhow::{bail, Context};
use chrono::{NaiveDate, NaiveDateTime};
use clap::{arg, ArgMatches, Command};
use humansize::{file_size_opts, FileSize};
use itertools::Itertools;
Expand All @@ -33,6 +32,7 @@ use quickwit_directories::{
use quickwit_metastore::{quickwit_metastore_uri_resolver, Split, SplitState};
use quickwit_storage::{quickwit_storage_uri_resolver, BundleStorage, Storage};
use tabled::{Table, Tabled};
use time::{format_description, Date, OffsetDateTime, PrimitiveDateTime};
use tracing::debug;

use crate::{load_quickwit_config, make_table};
Expand Down Expand Up @@ -159,28 +159,31 @@ impl SplitCliCommand {
.into_iter()
.collect::<Result<Vec<_>, _>>()
.map_err(|err_str| anyhow::anyhow!(err_str))?;
let start_date = if let Some(date_str) = matches.value_of("start-date") {
let from_date_time = NaiveDate::parse_from_str(date_str, "%Y-%m-%d")
.map(|date| date.and_hms(0, 0, 0))
.or_else(|_err| NaiveDateTime::parse_from_str(date_str, "%Y-%m-%dT%H:%M:%S"))

let format1 = format_description::parse("[year]-[month]-[day]")?;
let format2 = format_description::parse("[year]-[month]-[day]T[hour]:[minute]:[second]")?;

let parse_date = |date_str: &str| {
Date::parse(date_str, &format1)
.map(|date| date.with_hms(0, 0, 0).expect("could not create date time"))
.or_else(|_err| PrimitiveDateTime::parse(date_str, &format2))
.map(|date| date.assume_utc())
.context(format!(
"'start-date' `{}` should be of the format `2020-10-31` or \
"'start/end-date' `{}` should be of the format `2020-10-31` or \
`2020-10-31T02:00:00`",
date_str
))?;
Some(from_date_time.timestamp())
))
};

let start_date = if let Some(date_str) = matches.value_of("start-date") {
let from_date_time = parse_date(date_str)?;
Some(from_date_time.unix_timestamp())
} else {
None
};
let end_date = if let Some(date_str) = matches.value_of("end-date") {
let to_date_time = NaiveDate::parse_from_str(date_str, "%Y-%m-%d")
.map(|date| date.and_hms(0, 0, 0))
.or_else(|_err| NaiveDateTime::parse_from_str(date_str, "%Y-%m-%dT%H:%M:%S"))
.context(format!(
"'end-date' `{}` should be of the format `2020-10-31` or `2020-10-31T02:00:00`",
date_str
))?;
Some(to_date_time.timestamp())
let to_date_time = parse_date(date_str)?;
Some(to_date_time.unix_timestamp())
} else {
None
};
Expand Down Expand Up @@ -427,8 +430,12 @@ fn make_list_splits_table(splits: Vec<Split>) -> Table {
id: split.split_metadata.split_id,
num_docs: split.split_metadata.num_docs,
size_mega_bytes: split.split_metadata.original_size_in_bytes / 1_000_000,
create_at: NaiveDateTime::from_timestamp(split.split_metadata.create_timestamp, 0),
updated_at: NaiveDateTime::from_timestamp(split.update_timestamp, 0),
create_at: OffsetDateTime::from_unix_timestamp(
split.split_metadata.create_timestamp,
)
.expect("could not create OffsetDateTime from timestamp"),
updated_at: OffsetDateTime::from_unix_timestamp(split.update_timestamp)
.expect("could not create OffsetDateTime from timestamp"),
time_range,
}
})
Expand Down Expand Up @@ -457,9 +464,9 @@ struct SplitRow {
#[header("Size (MB)")]
size_mega_bytes: u64,
#[header("Created At")]
create_at: NaiveDateTime,
create_at: OffsetDateTime,
#[header("Updated At")]
updated_at: NaiveDateTime,
updated_at: OffsetDateTime,
#[header("Time Range")]
time_range: String,
}
Expand All @@ -468,8 +475,8 @@ struct SplitRow {
mod tests {
use std::path::PathBuf;

use chrono::NaiveDateTime;
use quickwit_metastore::SplitMetadata;
use time::format_description;

use super::*;
use crate::cli::{build_cli, CliCommand};
Expand All @@ -494,14 +501,17 @@ mod tests {
"file:///config.yaml",
])?;
let command = CliCommand::parse_cli_args(&matches)?;
let format =
format_description::parse("[year]-[month]-[day]T[hour]:[minute]:[second]").unwrap();

assert!(matches!(
command,
CliCommand::Split(SplitCliCommand::List(ListSplitArgs {
index_id, states, start_date, end_date, tags, ..
})) if &index_id == "wikipedia"
&& states == vec![SplitState::Published, SplitState::Staged]
&& start_date == Some(NaiveDateTime::parse_from_str("2021-12-03T00:00:00", "%Y-%m-%dT%H:%M:%S").unwrap().timestamp())
&& end_date == Some(NaiveDateTime::parse_from_str("2021-12-05T00:30:25", "%Y-%m-%dT%H:%M:%S").unwrap().timestamp())
&& start_date == Some(PrimitiveDateTime::parse("2021-12-03T00:00:00", &format).unwrap().assume_utc().unix_timestamp())
&& end_date == Some(PrimitiveDateTime::parse("2021-12-05T00:30:25", &format).unwrap().assume_utc().unix_timestamp())
&& tags == BTreeSet::from(["foo:bar".to_string(), "bar:baz".to_string()])
));

Expand Down
2 changes: 1 addition & 1 deletion quickwit-directories/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ tracing = "0.1.29"
thiserror = "1"
anyhow = "1"
async-trait = "0.1"
time = { version = "0.3.7", features = ["std"] }
time = { version = "0.3.9", features = ["std"] }

[dev-dependencies]
tempfile = '3'
Expand Down
1 change: 0 additions & 1 deletion quickwit-doc-mapper/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ documentation = "https://quickwit.io/docs/"
[dependencies]
anyhow = "1"
base64 = "0.13"
chrono = "0.4"
dyn-clone = "1.0.4"
itertools = '0.10'
once_cell = "1.10"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -574,7 +574,6 @@ mod tests {
value, expected_json_paths_and_values
);
}
assert!(is_value_in_expected_values);
}
});
Ok(())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1362,9 +1362,8 @@ mod tests {
Date::from_calendar_date(2021, Month::December, 19).unwrap(),
Time::from_hms(17, 39, 57).unwrap(),
);
// let datetime = datetime!(2021-12-19 17:39:57);

let datetime_utc = DateTime::new_primitive(datetime); // Utc.from_utc_datetime(&datetime);
let datetime_utc = DateTime::new_primitive(datetime);
assert_eq!(parsed_value.len(), 1);
assert_eq!(parsed_value[0].1, Value::Date(datetime_utc));

Expand Down
2 changes: 1 addition & 1 deletion quickwit-indexing/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ tracing = "0.1.29"
ulid = "0.5"
tokio-stream = "0.1"
arc-swap = "1.4"
time = { version = "0.3.7", features = ["std"] }
time = { version = "0.3.9", features = ["std"] }


[features]
Expand Down
3 changes: 2 additions & 1 deletion quickwit-metastore/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ documentation = "https://quickwit.io/docs/"
anyhow = "1.0"
async-trait = "0.1"
byte-unit = { version = "4", default-features = false, features = ["serde"] }
chrono = "0.4"
time = { version = "0.3.9", features = ["std"] }
chrono = { version = "0.4" }
diesel = { version = "1.4", features = ["postgres", "chrono", "extras"], optional = true }
diesel_migrations = { version = "1.4", optional = true }
futures = "0.3.17"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@
use std::collections::HashMap;
use std::ops::{Range, RangeInclusive};

use chrono::Utc;
use itertools::Itertools;
use quickwit_config::SourceConfig;
use quickwit_doc_mapper::tag_pruning::TagFilterAst;
use serde::{Deserialize, Serialize};
use time::OffsetDateTime;

use crate::checkpoint::CheckpointDelta;
use crate::{IndexMetadata, MetastoreError, MetastoreResult, Split, SplitMetadata, SplitState};
Expand Down Expand Up @@ -161,7 +161,7 @@ impl FileBackedIndex {
});
}

let now_timestamp = Utc::now().timestamp();
let now_timestamp = OffsetDateTime::now_utc().unix_timestamp();
let metadata = Split {
split_state: SplitState::Staged,
update_timestamp: now_timestamp,
Expand Down Expand Up @@ -198,7 +198,8 @@ impl FileBackedIndex {
) -> MetastoreResult<bool> {
let mut is_modified = false;
let mut split_not_found_ids = vec![];
let now_timestamp = Utc::now().timestamp();
let now_timestamp = OffsetDateTime::now_utc().unix_timestamp();

for &split_id in split_ids {
// Check for the existence of split.
let metadata = match self.splits.get_mut(split_id) {
Expand Down Expand Up @@ -239,7 +240,7 @@ impl FileBackedIndex {
) -> MetastoreResult<()> {
let mut split_not_found_ids = vec![];
let mut split_not_staged_ids = vec![];
let now_timestamp = Utc::now().timestamp();
let now_timestamp = OffsetDateTime::now_utc().unix_timestamp();
for &split_id in split_ids {
// Check for the existence of split.
let metadata = match self.splits.get_mut(split_id) {
Expand Down Expand Up @@ -380,7 +381,7 @@ impl FileBackedIndex {
});
}

self.metadata.update_timestamp = Utc::now().timestamp();
self.metadata.update_timestamp = OffsetDateTime::now_utc().unix_timestamp();
Ok(())
}

Expand Down
6 changes: 3 additions & 3 deletions quickwit-metastore/src/metastore/file_backed_metastore/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -538,10 +538,10 @@ mod tests {
use std::path::Path;
use std::sync::Arc;

use chrono::Utc;
use futures::executor::block_on;
use quickwit_storage::{MockStorage, RamStorage, Storage, StorageErrorKind};
use rand::Rng;
use time::OffsetDateTime;
use tokio::time::Duration;

use super::lazy_file_backed_index::LazyFileBackedIndex;
Expand Down Expand Up @@ -623,7 +623,7 @@ mod tests {
// The file-backed metastore should not update its internal state if the storage fails.
let mut mock_storage = MockStorage::default();

let current_timestamp = Utc::now().timestamp();
let current_timestamp = OffsetDateTime::now_utc().unix_timestamp();

let ram_storage = RamStorage::default();
let ram_storage_clone = ram_storage.clone();
Expand Down Expand Up @@ -809,7 +809,7 @@ mod tests {
for i in 1..=20 {
let sleep_duration = Duration::from_millis(random_generator.gen_range(0..=200));
let metastore = metastore.clone();
let current_timestamp = Utc::now().timestamp();
let current_timestamp = OffsetDateTime::now_utc().unix_timestamp();
let handle = tokio::spawn(async move {
let split_metadata = SplitMetadata {
footer_offsets: 1000..2000,
Expand Down
4 changes: 2 additions & 2 deletions quickwit-metastore/src/split_metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ use std::collections::BTreeSet;
use std::ops::{Range, RangeInclusive};
use std::str::FromStr;

use chrono::Utc;
use serde::{Deserialize, Serialize};
use time::OffsetDateTime;

use crate::VersionedSplitMetadataDeserializeHelper;

Expand Down Expand Up @@ -167,6 +167,6 @@ pub fn utc_now_timestamp() -> i64 {
if cfg!(any(test, feature = "testsuite")) {
1640577000
} else {
Utc::now().timestamp()
OffsetDateTime::now_utc().unix_timestamp()
}
}
Loading