Skip to content

Commit

Permalink
chore(deps): Drop use of once_cell::{sync,unsync}::OnceCell (vector…
Browse files Browse the repository at this point in the history
…dotdev#17621)

* chore(deps): Drop use of `once_cell::{sync,unsync}::OnceCell`

This is now part of `std::cell` and `std::sync`. This bumps the MSRV to 1.70.0
which is when those features were stabilized.

* Fix `const fn` lint

* Another const lint

* Fix more uses

* Deny `once_cell::sync::OnceCell` with clippy
  • Loading branch information
bruceg authored Aug 30, 2023
1 parent c07c99d commit f2cd59a
Show file tree
Hide file tree
Showing 14 changed files with 36 additions and 34 deletions.
1 change: 0 additions & 1 deletion Cargo.lock

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

5 changes: 5 additions & 0 deletions clippy.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,8 @@ cognitive-complexity-threshold = 75
disallowed-methods = [
{ path = "std::io::Write::write", reason = "This doesn't handle short writes, use `write_all` instead." },
]

disallowed-types = [
{ path = "once_cell::sync::OnceCell", reason = "Use `std::sync::OnceLock` instead." },
{ path = "once_cell::unsync::OnceCell", reason = "Use `std::cell::OnceCell` instead." },
]
1 change: 0 additions & 1 deletion lib/vector-config/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ indexmap = { version = "2.0", default-features = false, features = ["std"] }
inventory = { version = "0.3" }
no-proxy = { version = "0.3.4", default-features = false, features = ["serialize"] }
num-traits = { version = "0.2.16", default-features = false }
once_cell = { version = "1", default-features = false }
serde = { version = "1.0", default-features = false }
serde_json = { version = "1.0", default-features = false, features = ["std"] }
serde_with = { version = "3.3.0", default-features = false, features = ["std"] }
Expand Down
7 changes: 3 additions & 4 deletions lib/vector-config/src/schema/parser/query.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use std::{fs::File, io::BufReader, path::Path};
use std::{fs::File, io::BufReader, path::Path, sync::OnceLock};

use once_cell::sync::OnceCell;
use serde_json::Value;
use snafu::Snafu;
use vector_config_common::{
Expand Down Expand Up @@ -415,8 +414,8 @@ impl<'a> QueryableSchema for SimpleSchema<'a> {
}

fn schema_to_simple_schema(schema: &Schema) -> SimpleSchema<'_> {
static TRUE_SCHEMA_OBJECT: OnceCell<SchemaObject> = OnceCell::new();
static FALSE_SCHEMA_OBJECT: OnceCell<SchemaObject> = OnceCell::new();
static TRUE_SCHEMA_OBJECT: OnceLock<SchemaObject> = OnceLock::new();
static FALSE_SCHEMA_OBJECT: OnceLock<SchemaObject> = OnceLock::new();

let schema_object = match schema {
Schema::Bool(bool) => {
Expand Down
6 changes: 4 additions & 2 deletions lib/vector-core/src/config/log_schema.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
use std::sync::OnceLock;

use lookup::lookup_v2::OptionalTargetPath;
use lookup::{OwnedTargetPath, OwnedValuePath};
use once_cell::sync::{Lazy, OnceCell};
use once_cell::sync::Lazy;
use vector_config::configurable_component;

static LOG_SCHEMA: OnceCell<LogSchema> = OnceCell::new();
static LOG_SCHEMA: OnceLock<LogSchema> = OnceLock::new();
static LOG_SCHEMA_DEFAULT: Lazy<LogSchema> = Lazy::new(LogSchema::default);

const MESSAGE: &str = "message";
Expand Down
6 changes: 4 additions & 2 deletions lib/vector-core/src/config/telemetry.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
use once_cell::sync::{Lazy, OnceCell};
use std::sync::OnceLock;

use once_cell::sync::Lazy;
use vector_common::request_metadata::GroupedCountByteSize;
use vector_config::configurable_component;

static TELEMETRY: OnceCell<Telemetry> = OnceCell::new();
static TELEMETRY: OnceLock<Telemetry> = OnceLock::new();
static TELEMETRY_DEFAULT: Lazy<Telemetry> = Lazy::new(Telemetry::default);

/// Loads the telemetry options from configurations and sets the global options.
Expand Down
5 changes: 2 additions & 3 deletions lib/vector-core/src/metrics/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@ mod recency;
mod recorder;
mod storage;

use std::time::Duration;
use std::{sync::OnceLock, time::Duration};

use chrono::Utc;
use metrics::Key;
use metrics_tracing_context::TracingContextLayer;
use metrics_util::layers::Layer;
use once_cell::sync::OnceCell;
use snafu::Snafu;

pub use self::ddsketch::{AgentDDSketch, BinMap, Config};
Expand All @@ -29,7 +28,7 @@ pub enum Error {
TimeoutMustBePositive { timeout: f64 },
}

static CONTROLLER: OnceCell<Controller> = OnceCell::new();
static CONTROLLER: OnceLock<Controller> = OnceLock::new();

// Cardinality counter parameters, expose the internal metrics registry
// cardinality. Useful for the end users to help understand the characteristics
Expand Down
3 changes: 1 addition & 2 deletions lib/vector-core/src/metrics/recorder.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
use std::sync::{atomic::Ordering, Arc, RwLock};
use std::time::Duration;
use std::{cell::OnceCell, time::Duration};

use chrono::Utc;
use metrics::{Counter, Gauge, Histogram, Key, KeyName, Recorder, SharedString, Unit};
use metrics_util::{registry::Registry as MetricsRegistry, MetricKindMask};
use once_cell::unsync::OnceCell;
use quanta::Clock;

use super::recency::{GenerationalStorage, Recency};
Expand Down
5 changes: 2 additions & 3 deletions src/aws/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use std::error::Error;
use std::future::Future;
use std::pin::Pin;
use std::sync::atomic::{AtomicUsize, Ordering};
use std::sync::Arc;
use std::sync::{Arc, OnceLock};
use std::task::{Context, Poll};
use std::time::SystemTime;

Expand All @@ -27,7 +27,6 @@ use aws_types::SdkConfig;
use bytes::Bytes;
use http::HeaderMap;
use http_body::Body;
use once_cell::sync::OnceCell;
use pin_project::pin_project;
use regex::RegexSet;
pub use region::RegionOrEndpoint;
Expand All @@ -38,7 +37,7 @@ use crate::http::{build_proxy_connector, build_tls_connector};
use crate::internal_events::AwsBytesSent;
use crate::tls::{MaybeTlsSettings, TlsConfig};

static RETRIABLE_CODES: OnceCell<RegexSet> = OnceCell::new();
static RETRIABLE_CODES: OnceLock<RegexSet> = OnceLock::new();

pub fn is_retriable_error<T>(error: &SdkError<T>) -> bool {
match error {
Expand Down
5 changes: 3 additions & 2 deletions src/proto/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@ pub mod vector;

#[cfg(feature = "sinks-datadog_metrics")]
pub mod fds {
use once_cell::sync::OnceCell;
use std::sync::OnceLock;

use prost_reflect::DescriptorPool;

pub fn protobuf_descriptors() -> &'static DescriptorPool {
static PROTOBUF_FDS: OnceCell<DescriptorPool> = OnceCell::new();
static PROTOBUF_FDS: OnceLock<DescriptorPool> = OnceLock::new();
PROTOBUF_FDS.get_or_init(|| {
DescriptorPool::decode(include_bytes!(concat!(env!("OUT_DIR"), "/protobuf-fds.bin")).as_ref())
.expect("should not fail to decode protobuf file descriptor set generated from build script")
Expand Down
5 changes: 2 additions & 3 deletions src/sinks/datadog/metrics/encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@ use std::{
cmp,
io::{self, Write},
mem,
sync::Arc,
sync::{Arc, OnceLock},
};

use bytes::{BufMut, Bytes};
use chrono::{DateTime, Utc};
use once_cell::sync::OnceCell;
use prost::Message;
use snafu::{ResultExt, Snafu};
use vector_common::request_metadata::GroupedCountByteSize;
Expand Down Expand Up @@ -372,7 +371,7 @@ impl DatadogMetricsEncoder {
}

fn get_sketch_payload_sketches_field_number() -> u32 {
static SKETCH_PAYLOAD_SKETCHES_FIELD_NUM: OnceCell<u32> = OnceCell::new();
static SKETCH_PAYLOAD_SKETCHES_FIELD_NUM: OnceLock<u32> = OnceLock::new();
*SKETCH_PAYLOAD_SKETCHES_FIELD_NUM.get_or_init(|| {
let descriptors = protobuf_descriptors();
let descriptor = descriptors
Expand Down
5 changes: 2 additions & 3 deletions src/sources/kafka.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::{
collections::{BTreeMap, HashMap},
io::Cursor,
sync::Arc,
sync::{Arc, OnceLock},
time::Duration,
};

Expand All @@ -14,7 +14,6 @@ use codecs::{
};
use futures::{Stream, StreamExt};
use lookup::{lookup_v2::OptionalValuePath, owned_value_path, path, OwnedValuePath};
use once_cell::sync::OnceCell;
use rdkafka::{
consumer::{CommitMode, Consumer, ConsumerContext, Rebalance, StreamConsumer},
message::{BorrowedMessage, Headers as _, Message},
Expand Down Expand Up @@ -727,7 +726,7 @@ fn create_consumer(config: &KafkaSourceConfig) -> crate::Result<StreamConsumer<C
#[derive(Default)]
struct CustomContext {
stats: kafka::KafkaStatisticsContext,
finalizer: OnceCell<Arc<OrderedFinalizer<FinalizerEntry>>>,
finalizer: OnceLock<Arc<OrderedFinalizer<FinalizerEntry>>>,
}

impl CustomContext {
Expand Down
5 changes: 2 additions & 3 deletions src/trace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,13 @@ use std::{
str::FromStr,
sync::{
atomic::{AtomicBool, Ordering},
Mutex, MutexGuard,
Mutex, MutexGuard, OnceLock,
},
};

use futures_util::{future::ready, Stream, StreamExt};
use lookup::event_path;
use metrics_tracing_context::MetricsLayer;
use once_cell::sync::OnceCell;
use tokio::sync::{
broadcast::{self, Receiver, Sender},
oneshot,
Expand Down Expand Up @@ -51,7 +50,7 @@ static SUBSCRIBERS: Mutex<Option<Vec<oneshot::Sender<Vec<LogEvent>>>>> =

/// SENDER holds the sender/receiver handle that will receive a copy of all the internal log events *after* the topology
/// has been initialized.
static SENDER: OnceCell<Sender<LogEvent>> = OnceCell::new();
static SENDER: OnceLock<Sender<LogEvent>> = OnceLock::new();

fn metrics_layer_enabled() -> bool {
!matches!(std::env::var("DISABLE_INTERNAL_METRICS_TRACING_INTEGRATION"), Ok(x) if x == "true")
Expand Down
11 changes: 6 additions & 5 deletions vdev/src/app.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
use std::ffi::{OsStr, OsString};
pub use std::process::Command;
use std::{
borrow::Cow, env, io::Read, path::PathBuf, process::ExitStatus, process::Stdio, time::Duration,
borrow::Cow, env, io::Read, path::PathBuf, process::ExitStatus, process::Stdio, sync::OnceLock,
time::Duration,
};

use anyhow::{bail, Context as _, Result};
use indicatif::{ProgressBar, ProgressStyle};
use log::LevelFilter;
use once_cell::sync::{Lazy, OnceCell};
use once_cell::sync::Lazy;

use crate::{config::Config, git, platform, util};

Expand All @@ -25,9 +26,9 @@ const DEFAULT_SHELL: &str = "/bin/sh";
pub static SHELL: Lazy<OsString> =
Lazy::new(|| (env::var_os("SHELL").unwrap_or_else(|| DEFAULT_SHELL.into())));

static VERBOSITY: OnceCell<LevelFilter> = OnceCell::new();
static CONFIG: OnceCell<Config> = OnceCell::new();
static PATH: OnceCell<String> = OnceCell::new();
static VERBOSITY: OnceLock<LevelFilter> = OnceLock::new();
static CONFIG: OnceLock<Config> = OnceLock::new();
static PATH: OnceLock<String> = OnceLock::new();

pub fn verbosity() -> &'static LevelFilter {
VERBOSITY.get().expect("verbosity is not initialized")
Expand Down

0 comments on commit f2cd59a

Please sign in to comment.