From f217abf62ec14f83a401ffcc00992b27ef1cac68 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ensar=20Saraj=C4=8Di=C4=87?= Date: Thu, 24 Oct 2024 17:41:30 +0200 Subject: [PATCH] Remove initial implementation of VRL cache --- Cargo.lock | 12 -- Cargo.toml | 1 - lib/vector-lib/Cargo.toml | 1 - lib/vector-lib/src/lib.rs | 1 - lib/vector-vrl/tests/Cargo.toml | 1 - lib/vector-vrl/tests/src/main.rs | 2 - lib/vector-vrl/web-playground/Cargo.toml | 1 - lib/vector-vrl/web-playground/src/lib.rs | 1 - lib/vrl-cache/Cargo.toml | 11 -- lib/vrl-cache/src/cache_delete.rs | 167 ---------------- lib/vrl-cache/src/cache_get.rs | 185 ------------------ lib/vrl-cache/src/cache_put.rs | 148 -------------- lib/vrl-cache/src/caches.rs | 112 ----------- lib/vrl-cache/src/internal_events.rs | 164 ---------------- lib/vrl-cache/src/lib.rs | 20 -- lib/vrl-cache/src/vrl_util.rs | 35 ---- src/conditions/datadog_search.rs | 3 +- src/conditions/mod.rs | 11 +- src/conditions/vrl.rs | 7 +- src/config/builder.rs | 14 +- src/config/compiler.rs | 2 - src/config/graph.rs | 1 - src/config/mod.rs | 3 - src/config/transform.rs | 5 - src/config/unit_test/mod.rs | 2 +- src/config/vrl_cache.rs | 19 -- src/lib.rs | 1 - src/test_util/mock/transforms/basic.rs | 1 - .../mock/transforms/error_definitions.rs | 1 - src/test_util/mock/transforms/noop.rs | 1 - src/topology/builder.rs | 39 +--- src/topology/schema.rs | 71 ++----- src/transforms/aggregate.rs | 1 - src/transforms/aws_ec2_metadata.rs | 3 - src/transforms/dedupe/config.rs | 1 - src/transforms/filter.rs | 4 +- src/transforms/log_to_metric.rs | 1 - src/transforms/lua/mod.rs | 1 - src/transforms/metric_to_log.rs | 1 - src/transforms/reduce/config.rs | 4 +- src/transforms/reduce/transform.rs | 20 +- src/transforms/remap.rs | 48 ++--- src/transforms/route.rs | 3 +- src/transforms/sample/config.rs | 3 +- src/transforms/sample/transform.rs | 2 +- .../tag_cardinality_limit/config.rs | 1 - src/transforms/throttle.rs | 3 +- src/vrl_cache.rs | 35 ---- 48 files changed, 52 insertions(+), 1122 deletions(-) delete mode 100644 lib/vrl-cache/Cargo.toml delete mode 100644 lib/vrl-cache/src/cache_delete.rs delete mode 100644 lib/vrl-cache/src/cache_get.rs delete mode 100644 lib/vrl-cache/src/cache_put.rs delete mode 100644 lib/vrl-cache/src/caches.rs delete mode 100644 lib/vrl-cache/src/internal_events.rs delete mode 100644 lib/vrl-cache/src/lib.rs delete mode 100644 lib/vrl-cache/src/vrl_util.rs delete mode 100644 src/config/vrl_cache.rs delete mode 100644 src/vrl_cache.rs diff --git a/Cargo.lock b/Cargo.lock index b5cefeb5b4dee..97efcd250c674 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -10941,7 +10941,6 @@ dependencies = [ "vector-stream", "vector-tap", "vrl", - "vrl-cache", ] [[package]] @@ -11036,7 +11035,6 @@ dependencies = [ "tracing-subscriber", "vector-vrl-functions", "vrl", - "vrl-cache", ] [[package]] @@ -11051,7 +11049,6 @@ dependencies = [ "serde-wasm-bindgen", "vector-vrl-functions", "vrl", - "vrl-cache", "wasm-bindgen", ] @@ -11165,15 +11162,6 @@ dependencies = [ "zstd 0.13.2", ] -[[package]] -name = "vrl-cache" -version = "0.1.0" -dependencies = [ - "metrics", - "vector-common", - "vrl", -] - [[package]] name = "vsimd" version = "0.8.0" diff --git a/Cargo.toml b/Cargo.toml index de153ff9d5d93..9ca479bd290aa 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -129,7 +129,6 @@ members = [ "lib/vector-vrl/functions", "lib/vector-vrl/tests", "lib/vector-vrl/web-playground", - "lib/vrl-cache", "vdev", ] diff --git a/lib/vector-lib/Cargo.toml b/lib/vector-lib/Cargo.toml index 9d3b660591919..d274b123635c3 100644 --- a/lib/vector-lib/Cargo.toml +++ b/lib/vector-lib/Cargo.toml @@ -8,7 +8,6 @@ publish = false [dependencies] codecs = { path = "../codecs", default-features = false } enrichment = { path = "../enrichment" } -vrl-cache = { path = "../vrl-cache" } file-source = { path = "../file-source", optional = true } opentelemetry-proto = { path = "../opentelemetry-proto", optional = true } prometheus-parser = { path = "../prometheus-parser", optional = true } diff --git a/lib/vector-lib/src/lib.rs b/lib/vector-lib/src/lib.rs index 9370fd47a4de4..471c8737b11b2 100644 --- a/lib/vector-lib/src/lib.rs +++ b/lib/vector-lib/src/lib.rs @@ -25,7 +25,6 @@ pub use vector_core::{ pub use vector_lookup as lookup; pub use vector_stream as stream; pub use vector_tap as tap; -pub use vrl_cache; #[cfg(feature = "vrl")] pub use vrl; diff --git a/lib/vector-vrl/tests/Cargo.toml b/lib/vector-vrl/tests/Cargo.toml index d8ea57fad62d6..ec22d0754712b 100644 --- a/lib/vector-vrl/tests/Cargo.toml +++ b/lib/vector-vrl/tests/Cargo.toml @@ -8,7 +8,6 @@ publish = false [dependencies] chrono-tz.workspace = true enrichment = { path = "../../enrichment" } -vrl-cache = { path = "../../vrl-cache" } vrl.workspace = true vector-vrl-functions = { path = "../../vector-vrl/functions" } diff --git a/lib/vector-vrl/tests/src/main.rs b/lib/vector-vrl/tests/src/main.rs index fadcb67d1387f..962f68b2ef296 100644 --- a/lib/vector-vrl/tests/src/main.rs +++ b/lib/vector-vrl/tests/src/main.rs @@ -98,7 +98,6 @@ fn main() { let mut functions = vrl::stdlib::all(); functions.extend(vector_vrl_functions::all()); functions.extend(enrichment::vrl_functions()); - functions.extend(vrl_cache::vrl_functions()); run_tests( tests, @@ -133,7 +132,6 @@ fn get_tests(cmd: &Cmd) -> Vec { vector_vrl_functions::all() .into_iter() .chain(enrichment::vrl_functions()) - .chain(vrl_cache::vrl_functions()) .collect(), )) .filter(|test| { diff --git a/lib/vector-vrl/web-playground/Cargo.toml b/lib/vector-vrl/web-playground/Cargo.toml index fadaa61a3f60d..7159cd0ae4432 100644 --- a/lib/vector-vrl/web-playground/Cargo.toml +++ b/lib/vector-vrl/web-playground/Cargo.toml @@ -17,7 +17,6 @@ gloo-utils = { version = "0.2", features = ["serde"] } getrandom = { version = "0.2", features = ["js"] } vector-vrl-functions = { path = "../functions" } enrichment = { path = "../../enrichment" } -vrl-cache = { path = "../../vrl-cache" } [build-dependencies] cargo-lock = "10.0.0" diff --git a/lib/vector-vrl/web-playground/src/lib.rs b/lib/vector-vrl/web-playground/src/lib.rs index d59ae02695d15..a434050aefa3c 100644 --- a/lib/vector-vrl/web-playground/src/lib.rs +++ b/lib/vector-vrl/web-playground/src/lib.rs @@ -80,7 +80,6 @@ fn compile(mut input: Input) -> Result { let mut functions = vrl::stdlib::all(); functions.extend(vector_vrl_functions::all()); functions.extend(enrichment::vrl_functions()); - functions.extend(vrl_cache::vrl_functions()); let event = &mut input.event; let state = TypeState::default(); diff --git a/lib/vrl-cache/Cargo.toml b/lib/vrl-cache/Cargo.toml deleted file mode 100644 index b533145920801..0000000000000 --- a/lib/vrl-cache/Cargo.toml +++ /dev/null @@ -1,11 +0,0 @@ -[package] -name = "vrl-cache" -version = "0.1.0" -authors = ["Vector Contributors "] -edition = "2021" -publish = false - -[dependencies] -vrl.workspace = true -metrics.workspace = true -vector-common = { path = "../vector-common" } diff --git a/lib/vrl-cache/src/cache_delete.rs b/lib/vrl-cache/src/cache_delete.rs deleted file mode 100644 index 25b190bfa19e5..0000000000000 --- a/lib/vrl-cache/src/cache_delete.rs +++ /dev/null @@ -1,167 +0,0 @@ -use vrl::prelude::*; - -use crate::{caches::VrlCacheRegistry, vrl_util}; - -#[derive(Clone, Copy, Debug)] -pub struct CacheDelete; -impl Function for CacheDelete { - fn identifier(&self) -> &'static str { - "cache_delete" - } - - fn parameters(&self) -> &'static [Parameter] { - &[ - Parameter { - keyword: "cache", - kind: kind::BYTES, - required: true, - }, - Parameter { - keyword: "key", - kind: kind::BYTES, - required: true, - }, - ] - } - - fn examples(&self) -> &'static [Example] { - &[Example { - title: "delete from cache", - source: r#"cache_detel!("test_cache", "test_key")"#, - result: Ok(""), - }] - } - - fn compile( - &self, - state: &TypeState, - ctx: &mut FunctionCompileContext, - arguments: ArgumentList, - ) -> Compiled { - let registry = ctx - .get_external_context_mut::() - .ok_or(Box::new(vrl_util::Error::CachesNotLoaded) as Box)?; - - let caches = registry - .cache_ids() - .into_iter() - .map(Value::from) - .collect::>(); - - let cache = arguments - .required_enum("cache", &caches, state)? - .try_bytes_utf8_lossy() - .expect("cache is not valid utf8") - .into_owned(); - let key = arguments.required("key"); - - Ok(CacheDeleteFn { - cache, - key, - registry: registry.clone(), - } - .as_expr()) - } -} - -#[derive(Debug, Clone)] -pub struct CacheDeleteFn { - cache: String, - key: Box, - registry: VrlCacheRegistry, -} - -impl FunctionExpression for CacheDeleteFn { - fn resolve(&self, ctx: &mut Context) -> Resolved { - let key = self.key.resolve(ctx)?.try_bytes_utf8_lossy()?.into_owned(); - - Ok(self - .registry - .writer() - .delete_val(&self.cache, &key) - .ok_or_else(|| format!("key not found in cache: {key}"))?) - } - - fn type_def(&self, _: &TypeState) -> TypeDef { - TypeDef::any().impure().fallible() - } -} - -#[cfg(test)] -mod tests { - use std::collections::BTreeMap; - use vrl::compiler::prelude::TimeZone; - use vrl::compiler::state::RuntimeState; - use vrl::compiler::TargetValue; - use vrl::value; - use vrl::value::Secrets; - - use crate::caches::VrlCache; - - use super::*; - - fn get_cache_registry() -> VrlCacheRegistry { - let registry = VrlCacheRegistry::default(); - registry.insert_caches(BTreeMap::from([("test".to_string(), VrlCache::default())])); - registry - } - - #[test] - fn delete_val() { - let registry = get_cache_registry(); - registry - .writer() - .put_val("test", "test_key", Value::from("test_value")); - let func = CacheDeleteFn { - cache: "test".to_string(), - key: expr!("test_key"), - registry: registry.clone(), - }; - - let tz = TimeZone::default(); - let object: Value = BTreeMap::new().into(); - let mut target = TargetValue { - value: object, - metadata: value!({}), - secrets: Secrets::new(), - }; - let mut runtime_state = RuntimeState::default(); - let mut ctx = Context::new(&mut target, &mut runtime_state, &tz); - - let got = func.resolve(&mut ctx); - - assert_eq!(Ok(value!("test_value")), got); - assert_eq!(None, registry.as_readonly().get_val("test", "test_key")); - } - - #[test] - fn delete_val_key_not_found() { - let registry = get_cache_registry(); - let func = CacheDeleteFn { - cache: "test".to_string(), - key: expr!("test_key"), - registry: registry.clone(), - }; - - let tz = TimeZone::default(); - let object: Value = BTreeMap::new().into(); - let mut target = TargetValue { - value: object, - metadata: value!({}), - secrets: Secrets::new(), - }; - let mut runtime_state = RuntimeState::default(); - let mut ctx = Context::new(&mut target, &mut runtime_state, &tz); - - let got = func.resolve(&mut ctx); - - assert_eq!( - Err(ExpressionError::Error { - message: "key not found in cache: test_key".to_string(), - labels: vec![], - notes: vec![] - }), - got - ); - } -} diff --git a/lib/vrl-cache/src/cache_get.rs b/lib/vrl-cache/src/cache_get.rs deleted file mode 100644 index 0fb1d5cd71ad3..0000000000000 --- a/lib/vrl-cache/src/cache_get.rs +++ /dev/null @@ -1,185 +0,0 @@ -use vrl::{compiler::expression::Query, prelude::*}; - -use crate::{ - caches::{VrlCacheRegistry, VrlCacheSearch}, - vrl_util, -}; - -#[derive(Clone, Copy, Debug)] -pub struct CacheGet; -impl Function for CacheGet { - fn identifier(&self) -> &'static str { - "cache_get" - } - - fn parameters(&self) -> &'static [Parameter] { - &[ - Parameter { - keyword: "cache", - kind: kind::BYTES, - required: true, - }, - Parameter { - keyword: "key", - kind: kind::BYTES, - required: true, - }, - Parameter { - keyword: "ttl_target", - kind: kind::ANY, - required: true, - }, - ] - } - - fn examples(&self) -> &'static [Example] { - &[ - Example { - title: "read from cache", - source: r#"cache_get!("test_cache", "test_key")"#, - result: Ok(r#""test_value""#), - }, - Example { - title: "read from cache with TTL", - source: r#"cache_get!("test_cache", "test_key", ttl_target: .ttl)"#, - result: Ok(r#""test_value""#), - }, - ] - } - - fn compile( - &self, - state: &TypeState, - ctx: &mut FunctionCompileContext, - arguments: ArgumentList, - ) -> Compiled { - let registry = ctx - .get_external_context_mut::() - .ok_or(Box::new(vrl_util::Error::CachesNotLoaded) as Box)?; - - let caches = registry - .cache_ids() - .into_iter() - .map(Value::from) - .collect::>(); - - let cache = arguments - .required_enum("cache", &caches, state)? - .try_bytes_utf8_lossy() - .expect("cache is not valid utf8") - .into_owned(); - let key = arguments.required("key"); - let ttl = arguments.optional_query("ttl_target")?; - - Ok(CacheGetFn { - cache, - key, - _ttl: ttl, - registry: registry.as_readonly(), - } - .as_expr()) - } -} - -#[derive(Debug, Clone)] -pub struct CacheGetFn { - cache: String, - key: Box, - _ttl: Option, - registry: VrlCacheSearch, -} - -impl FunctionExpression for CacheGetFn { - fn resolve(&self, ctx: &mut Context) -> Resolved { - let key = self.key.resolve(ctx)?.try_bytes_utf8_lossy()?.into_owned(); - - Ok(self - .registry - .get_val(&self.cache, &key) - .ok_or_else(|| format!("key not found in cache: {key}"))?) - } - - fn type_def(&self, _: &TypeState) -> TypeDef { - TypeDef::any().fallible() - } -} - -#[cfg(test)] -mod tests { - use std::collections::BTreeMap; - use vrl::compiler::prelude::TimeZone; - use vrl::compiler::state::RuntimeState; - use vrl::compiler::TargetValue; - use vrl::value; - use vrl::value::Secrets; - - use crate::caches::VrlCache; - - use super::*; - - fn get_cache_registry() -> VrlCacheRegistry { - let registry = VrlCacheRegistry::default(); - registry.insert_caches(BTreeMap::from([("test".to_string(), VrlCache::default())])); - registry - } - - #[test] - fn get_val() { - let registry = get_cache_registry(); - registry - .writer() - .put_val("test", "test_key", Value::from("test_value")); - let func = CacheGetFn { - cache: "test".to_string(), - key: expr!("test_key"), - _ttl: None, - registry: registry.as_readonly(), - }; - - let tz = TimeZone::default(); - let object: Value = BTreeMap::new().into(); - let mut target = TargetValue { - value: object, - metadata: value!({}), - secrets: Secrets::new(), - }; - let mut runtime_state = RuntimeState::default(); - let mut ctx = Context::new(&mut target, &mut runtime_state, &tz); - - let got = func.resolve(&mut ctx); - - assert_eq!(Ok(value!("test_value")), got); - } - - #[test] - fn get_val_key_not_found() { - let registry = get_cache_registry(); - let func = CacheGetFn { - cache: "test".to_string(), - key: expr!("test_key"), - _ttl: None, - registry: registry.as_readonly(), - }; - - let tz = TimeZone::default(); - let object: Value = BTreeMap::new().into(); - let mut target = TargetValue { - value: object, - metadata: value!({}), - secrets: Secrets::new(), - }; - let mut runtime_state = RuntimeState::default(); - let mut ctx = Context::new(&mut target, &mut runtime_state, &tz); - - let got = func.resolve(&mut ctx); - - assert_eq!( - Err(ExpressionError::Error { - message: "key not found in cache: test_key".to_string(), - labels: vec![], - notes: vec![] - }), - got - ); - } -} diff --git a/lib/vrl-cache/src/cache_put.rs b/lib/vrl-cache/src/cache_put.rs deleted file mode 100644 index f7b8647955edd..0000000000000 --- a/lib/vrl-cache/src/cache_put.rs +++ /dev/null @@ -1,148 +0,0 @@ -use vrl::prelude::*; - -use crate::{caches::VrlCacheRegistry, vrl_util}; - -#[derive(Clone, Copy, Debug)] -pub struct CachePut; -impl Function for CachePut { - fn identifier(&self) -> &'static str { - "cache_put" - } - - fn parameters(&self) -> &'static [Parameter] { - &[ - Parameter { - keyword: "cache", - kind: kind::BYTES, - required: true, - }, - Parameter { - keyword: "key", - kind: kind::BYTES, - required: true, - }, - Parameter { - keyword: "value", - kind: kind::ANY, - required: true, - }, - ] - } - - fn examples(&self) -> &'static [Example] { - &[Example { - title: "write to cache", - source: r#"cache_put!("test_cache", "test_key", "test_value")"#, - result: Ok(""), - }] - } - - fn compile( - &self, - state: &TypeState, - ctx: &mut FunctionCompileContext, - arguments: ArgumentList, - ) -> Compiled { - let registry = ctx - .get_external_context_mut::() - .ok_or(Box::new(vrl_util::Error::CachesNotLoaded) as Box)?; - - let caches = registry - .cache_ids() - .into_iter() - .map(Value::from) - .collect::>(); - - let cache = arguments - .required_enum("cache", &caches, state)? - .try_bytes_utf8_lossy() - .expect("cache is not valid utf8") - .into_owned(); - let key = arguments.required("key"); - let value = arguments.required("value"); - - Ok(CachePutFn { - cache, - key, - value, - registry: registry.clone(), - } - .as_expr()) - } -} - -#[derive(Debug, Clone)] -pub struct CachePutFn { - cache: String, - key: Box, - value: Box, - registry: VrlCacheRegistry, -} - -impl FunctionExpression for CachePutFn { - fn resolve(&self, ctx: &mut Context) -> Resolved { - let key = self.key.resolve(ctx)?.try_bytes_utf8_lossy()?.into_owned(); - let value = self.value.resolve(ctx)?; - self.registry - .writer() - .put_val(&self.cache, &key, value.clone()); - Ok(value) - } - - fn type_def(&self, _: &TypeState) -> TypeDef { - TypeDef::null().impure().fallible() - } -} - -#[cfg(test)] -mod tests { - use std::collections::BTreeMap; - use vrl::compiler::prelude::TimeZone; - use vrl::compiler::state::RuntimeState; - use vrl::compiler::TargetValue; - use vrl::value; - use vrl::value::Secrets; - - use crate::caches::VrlCache; - - use super::*; - - fn get_cache_registry() -> VrlCacheRegistry { - let registry = VrlCacheRegistry::default(); - registry.insert_caches(BTreeMap::from([("test".to_string(), VrlCache::default())])); - registry - } - - #[test] - fn set_val() { - let registry = get_cache_registry(); - let func = CachePutFn { - cache: "test".to_string(), - key: expr!("test_key"), - value: expr!("test_value"), - registry: registry.clone(), - }; - - let tz = TimeZone::default(); - let object: Value = BTreeMap::new().into(); - let mut target = TargetValue { - value: object, - metadata: value!({}), - secrets: Secrets::new(), - }; - let mut runtime_state = RuntimeState::default(); - let mut ctx = Context::new(&mut target, &mut runtime_state, &tz); - - let got = func.resolve(&mut ctx); - - assert_eq!(Ok(value!("test_value")), got); - assert_eq!( - value!("test_value"), - registry - .as_readonly() - .get_val("test", "test_key") - .unwrap() - .clone() - ); - } -} diff --git a/lib/vrl-cache/src/caches.rs b/lib/vrl-cache/src/caches.rs deleted file mode 100644 index b7ed681b4a0b4..0000000000000 --- a/lib/vrl-cache/src/caches.rs +++ /dev/null @@ -1,112 +0,0 @@ -use std::{ - collections::BTreeMap, - sync::{Arc, RwLock}, -}; - -use vector_common::byte_size_of::ByteSizeOf; -use vector_common::internal_event::emit; -use vrl::core::Value; - -use crate::internal_events::{VrlCacheDeleted, VrlCacheInserted, VrlCacheRead, VrlCacheReadFailed}; - -type CacheMap = BTreeMap; - -#[derive(Default, Debug)] -pub struct VrlCache { - data: BTreeMap, -} - -#[derive(Clone, Default, Debug)] -pub struct VrlCacheRegistry { - caches: Arc>, -} - -/// Eq implementation for caching purposes -impl PartialEq for VrlCacheRegistry { - fn eq(&self, other: &Self) -> bool { - Arc::ptr_eq(&self.caches, &other.caches) - } -} -impl Eq for VrlCacheRegistry {} - -impl VrlCacheRegistry { - /// Return a list of the available caches we can read and write to. - /// - /// # Panics - /// - /// Panics if the RwLock is poisoned. - pub fn cache_ids(&self) -> Vec { - let locked = self.caches.read().unwrap(); - locked.iter().map(|(key, _)| key.clone()).collect() - } - - /// Returns a cheaply clonable struct through that provides lock free read - /// access to the cache. - pub fn as_readonly(&self) -> VrlCacheSearch { - VrlCacheSearch(self.caches.clone()) - } - - pub fn insert_caches(&self, new_caches: impl IntoIterator) { - let mut caches = self.caches.write().unwrap(); - caches.extend(new_caches); - } - - pub fn writer(&self) -> VrlCacheWriter { - VrlCacheWriter(self.caches.clone()) - } -} - -/// Provides read only access to VRL Caches -#[derive(Clone, Default, Debug)] -pub struct VrlCacheSearch(Arc>); - -impl VrlCacheSearch { - pub fn get_val(&self, cache: &str, key: &str) -> Option { - let locked = self.0.read().unwrap(); - let result = locked[cache].data.get(key).cloned(); - match result { - Some(_) => emit(VrlCacheRead { - cache: cache.to_string(), - key: key.to_string(), - }), - None => emit(VrlCacheReadFailed { - cache: cache.to_string(), - key: key.to_string(), - }), - } - result - } -} - -/// Provides write access to VRL caches -#[derive(Clone, Default, Debug)] -pub struct VrlCacheWriter(Arc>); - -impl VrlCacheWriter { - pub fn put_val(&self, cache: &str, key: &str, value: Value) { - let mut locked = self.0.write().unwrap(); - locked - .get_mut(cache) - .unwrap() - .data - .insert(key.to_string(), value); - emit(VrlCacheInserted { - cache: cache.to_string(), - key: key.to_string(), - new_objects_count: locked[cache].data.keys().len(), - new_byte_size: locked[cache].data.size_of(), - }); - } - - pub fn delete_val(&self, cache: &str, key: &str) -> Option { - let mut locked = self.0.write().unwrap(); - let result = locked.get_mut(cache).unwrap().data.remove(key); - emit(VrlCacheDeleted { - cache: cache.to_string(), - key: key.to_string(), - new_objects_count: locked[cache].data.keys().len(), - new_byte_size: locked[cache].data.size_of(), - }); - result - } -} diff --git a/lib/vrl-cache/src/internal_events.rs b/lib/vrl-cache/src/internal_events.rs deleted file mode 100644 index b8c728277c159..0000000000000 --- a/lib/vrl-cache/src/internal_events.rs +++ /dev/null @@ -1,164 +0,0 @@ -use metrics::{counter, gauge}; -use vector_common::internal_event::InternalEvent; - -#[derive(Debug)] -pub struct VrlCacheRead { - pub cache: String, - pub key: String, -} - -impl InternalEvent for VrlCacheRead { - fn emit(self) { - counter!( - "vrl_cache_reads_total", - "cache" => self.cache, - "key" => self.key - ) - .increment(1); - } - - fn name(&self) -> Option<&'static str> { - Some("VrlCacheRead") - } -} - -#[derive(Debug)] -pub struct VrlCacheInserted { - pub cache: String, - pub key: String, - pub new_objects_count: usize, - pub new_byte_size: usize, -} - -impl InternalEvent for VrlCacheInserted { - fn emit(self) { - counter!( - "vrl_cache_insertions_total", - "cache" => self.cache.clone(), - "key" => self.key - ) - .increment(1); - gauge!( - "vrl_cache_objects_count", - "cache" => self.cache.clone() - ) - .set(self.new_objects_count as f64); - gauge!( - "vrl_cache_byte_size", - "cache" => self.cache - ) - .set(self.new_byte_size as f64); - } - - fn name(&self) -> Option<&'static str> { - Some("VrlCacheInserted") - } -} - -#[derive(Debug)] -pub struct VrlCacheDeleted { - pub cache: String, - pub key: String, - pub new_objects_count: usize, - pub new_byte_size: usize, -} - -impl InternalEvent for VrlCacheDeleted { - fn emit(self) { - counter!( - "vrl_cache_deletions_total", - "cache" => self.cache.clone(), - "key" => self.key - ) - .increment(1); - gauge!( - "vrl_cache_objects_count", - "cache" => self.cache.clone() - ) - .set(self.new_objects_count as f64); - gauge!( - "vrl_cache_byte_size", - "cache" => self.cache - ) - .set(self.new_byte_size as f64); - } - - fn name(&self) -> Option<&'static str> { - Some("VrlCacheDeleted") - } -} - -#[derive(Debug)] -pub struct VrlCacheDeleteFailed { - pub cache: String, - pub key: String, -} - -impl InternalEvent for VrlCacheDeleteFailed { - fn emit(self) { - counter!( - "vrl_cache_failed_deletes", - "cache" => self.cache, - "key" => self.key - ) - .increment(1); - } - - fn name(&self) -> Option<&'static str> { - Some("VrlCacheDeleteFailed") - } -} - -#[derive(Debug)] -pub struct VrlCacheTtlExpired { - pub cache: String, - pub key: String, - pub new_objects_count: usize, - pub new_byte_size: usize, -} - -impl InternalEvent for VrlCacheTtlExpired { - fn emit(self) { - counter!( - "vrl_cache_ttl_expirations", - "cache" => self.cache.clone(), - "key" => self.key - ) - .increment(1); - gauge!( - "vrl_cache_objects_count", - "cache" => self.cache.clone() - ) - .set(self.new_objects_count as f64); - gauge!( - "vrl_cache_byte_size", - "cache" => self.cache - ) - .set(self.new_byte_size as f64); - } - - fn name(&self) -> Option<&'static str> { - Some("VrlCacheTtlExpired") - } -} - -#[derive(Debug)] -pub struct VrlCacheReadFailed { - pub cache: String, - pub key: String, -} - -impl InternalEvent for VrlCacheReadFailed { - fn emit(self) { - counter!( - "vrl_cache_failed_reads", - "cache" => self.cache, - "key" => self.key - ) - .increment(1); - } - - fn name(&self) -> Option<&'static str> { - Some("VrlCacheReadFailed") - } -} diff --git a/lib/vrl-cache/src/lib.rs b/lib/vrl-cache/src/lib.rs deleted file mode 100644 index 47d998fd4eb13..0000000000000 --- a/lib/vrl-cache/src/lib.rs +++ /dev/null @@ -1,20 +0,0 @@ -#![deny(warnings)] - -pub mod cache_delete; -pub mod cache_get; -pub mod cache_put; -pub mod caches; - -mod internal_events; -mod vrl_util; - -pub use caches::VrlCacheRegistry; -use vrl::compiler::Function; - -pub fn vrl_functions() -> Vec> { - vec![ - Box::new(cache_get::CacheGet) as _, - Box::new(cache_put::CachePut) as _, - Box::new(cache_delete::CacheDelete) as _, - ] -} diff --git a/lib/vrl-cache/src/vrl_util.rs b/lib/vrl-cache/src/vrl_util.rs deleted file mode 100644 index 1e7b57438a245..0000000000000 --- a/lib/vrl-cache/src/vrl_util.rs +++ /dev/null @@ -1,35 +0,0 @@ -//! Utilities shared between VRL functions. -use vrl::diagnostic::{Label, Span}; -use vrl::prelude::*; - -#[derive(Debug)] -pub enum Error { - CachesNotLoaded, -} - -impl fmt::Display for Error { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - match self { - Error::CachesNotLoaded => write!(f, "VRL caches not loaded"), - } - } -} - -impl std::error::Error for Error {} - -impl DiagnosticMessage for Error { - fn code(&self) -> usize { - 111 - } - - fn labels(&self) -> Vec