Skip to content

Commit

Permalink
chore!:remove deprecated 'to_timestamp' function (#452)
Browse files Browse the repository at this point in the history
  • Loading branch information
pront authored Sep 21, 2023
1 parent bf955f6 commit 9d2d5af
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 347 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
- updated aws vpc flow log parsing to include version 5 fields (https://github.com/vectordotdev/vrl/issues/227)
- `parse_aws_vpc_flow_log` now handles account-id value as a string, avoiding loss of leading zeros and case where value is `unknown` (https://github.com/vectordotdev/vrl/issues/263)
- added `community_id` function for generation of [V1 Community IDs](https://github.com/corelight/community-id-spec) (https://github.com/vectordotdev/vrl/pull/360).
- removed deprecated `to_timestamp` function (https://github.com/vectordotdev/vrl/pull/452)

## `0.6.0` (2023-08-02)

Expand Down
25 changes: 3 additions & 22 deletions benches/stdlib.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
#![allow(deprecated)]

use crate::value::Value;
use chrono::{DateTime, Datelike, TimeZone, Utc};
use criterion::{criterion_group, criterion_main, Criterion};
use regex::Regex;
use vrl::compiler::prelude::*;

use vrl::compiler::prelude::*;
use vrl::{bench_function, btreemap, func_args, value};

use crate::value::Value;

criterion_group!(
name = benches;
// encapsulates CI noise we saw in
Expand Down Expand Up @@ -145,7 +146,6 @@ criterion_group!(
to_syslog_facility,
to_syslog_level,
to_syslog_severity,
to_timestamp,
to_unix_timestamp,
truncate,
unique,
Expand Down Expand Up @@ -2603,25 +2603,6 @@ bench_function! {
}
}

bench_function! {
to_timestamp => vrl::stdlib::ToTimestamp;

string {
args: func_args![value: "2001-07-08T00:34:60.026490+09:30"],
want: Ok(DateTime::parse_from_rfc3339("2001-07-08T00:34:60.026490+09:30").unwrap().with_timezone(&Utc))
}

int {
args: func_args![value: 1612814266],
want: Ok(DateTime::parse_from_rfc3339("2021-02-08T19:57:46+00:00").unwrap().with_timezone(&Utc))
}

float {
args: func_args![value: 1612814266.1],
want: Ok(DateTime::parse_from_rfc3339("2021-02-08T19:57:46.099999905+00:00").unwrap().with_timezone(&Utc))
}
}

bench_function! {
to_unix_timestamp => vrl::stdlib::ToUnixTimestamp;

Expand Down
16 changes: 0 additions & 16 deletions lib/tests/tests/diagnostics/deprecation_to_timestamp.vrl

This file was deleted.

43 changes: 14 additions & 29 deletions src/compiler/compiler.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,3 @@
use crate::path::PathPrefix;

use crate::diagnostic::{DiagnosticList, DiagnosticMessage, Note, Severity};
use crate::parser::ast::{self, Node, QueryTarget};
use crate::path::{OwnedTargetPath, OwnedValuePath};
use crate::value::Value;

use super::state::TypeState;
use crate::compiler::{
expression::{
assignment, function_call, literal, predicate, query, Abort, Array, Assignment, Block,
Expand All @@ -14,9 +6,16 @@ use crate::compiler::{
},
parser::ast::RootExpr,
program::ProgramInfo,
CompileConfig, DeprecationWarning, Function, Program, TypeDef,
CompileConfig, Function, Program, TypeDef,
};
use crate::diagnostic::{DiagnosticList, DiagnosticMessage};
use crate::parser::ast::{self, Node, QueryTarget};
use crate::path::PathPrefix;
use crate::path::{OwnedTargetPath, OwnedValuePath};
use crate::prelude::ArgumentList;
use crate::value::Value;

use super::state::TypeState;

pub(crate) type Diagnostics = Vec<Box<dyn DiagnosticMessage>>;

Expand Down Expand Up @@ -83,7 +82,10 @@ impl<'a> Compiler<'a> {

let (errors, warnings): (Vec<_>, Vec<_>) =
compiler.diagnostics.into_iter().partition(|diagnostic| {
matches!(diagnostic.severity(), Severity::Bug | Severity::Error)
matches!(
diagnostic.severity(),
crate::diagnostic::Severity::Bug | crate::diagnostic::Severity::Error
)
});

if !errors.is_empty() {
Expand Down Expand Up @@ -587,25 +589,8 @@ impl<'a> Compiler<'a> {
Some(target)
}

pub(crate) fn check_function_deprecations(
&mut self,
func: &FunctionCall,
_args: &ArgumentList,
) {
if func.ident == "to_timestamp" {
self.diagnostics.push(Box::new(
DeprecationWarning::new("the `to_timestamp` function")
.with_span(func.span)
.with_notes(Note::solution(
r#"using another timestamp parsing function instead"#,
vec![
r#"for integer values, use `from_unix_timestamp`"#,
r#"for all other value types, use `parse_timestamp`"#,
],
)),
));
}
}
#[allow(clippy::unused_self)]
pub(crate) fn check_function_deprecations(&self, _func: &FunctionCall, _args: &ArgumentList) {}

fn compile_function_call(
&mut self,
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/expression/function_call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1126,7 +1126,7 @@ impl DiagnosticMessage for Error {
} else if kind.is_boolean() {
Some(format!("to_bool({argument}) ?? false"))
} else if kind.is_timestamp() {
Some(format!("to_timestamp({argument}) ?? now()"))
Some(format!("to_unix_timestamp({argument}) ?? now()"))
} else {
None
};
Expand Down
3 changes: 0 additions & 3 deletions src/stdlib/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,6 @@ cfg_if::cfg_if! {
mod to_syslog_facility;
mod to_syslog_level;
mod to_syslog_severity;
mod to_timestamp;
mod to_unix_timestamp;
mod community_id;
mod truncate;
Expand Down Expand Up @@ -340,7 +339,6 @@ cfg_if::cfg_if! {
pub use to_syslog_facility::ToSyslogFacility;
pub use to_syslog_level::ToSyslogLevel;
pub use to_syslog_severity::ToSyslogSeverity;
pub use to_timestamp::ToTimestamp;
pub use to_unix_timestamp::ToUnixTimestamp;
pub use truncate::Truncate;
pub use type_def::TypeDef;
Expand Down Expand Up @@ -507,7 +505,6 @@ pub fn all() -> Vec<Box<dyn Function>> {
Box::new(ToSyslogFacility),
Box::new(ToSyslogLevel),
Box::new(ToSyslogSeverity),
Box::new(ToTimestamp),
Box::new(ToUnixTimestamp),
Box::new(CommunityID),
Box::new(Truncate),
Expand Down
Loading

0 comments on commit 9d2d5af

Please sign in to comment.