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
2 changes: 1 addition & 1 deletion Cargo.lock

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

4 changes: 2 additions & 2 deletions lib/codecs/src/decoding/format/protobuf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ mod tests {
assert_eq!(log["name"], "someone".into());
assert_eq!(
log["phones"].as_array().unwrap()[0].as_object().unwrap()["number"]
.as_str()
.to_str_lossy()
.unwrap(),
"123456"
);
Expand All @@ -278,7 +278,7 @@ mod tests {
assert_eq!(log["name"], "someone".into());
assert_eq!(
log["phones"].as_array().unwrap()[0].as_object().unwrap()["number"]
.as_str()
.to_str_lossy()
.unwrap(),
"1234"
);
Expand Down
2 changes: 1 addition & 1 deletion lib/vector-vrl/functions/src/get_secret.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use vrl::prelude::*;
reason = "Keep the fallible return convention used by VRL runtime helpers."
)]
fn get_secret(ctx: &mut Context, key: Value) -> std::result::Result<Value, ExpressionError> {
let key_str = key.as_str().expect("argument must be a string");
let key_str = key.to_str_lossy().expect("argument must be a string");
let value = match ctx.target().get_secret(key_str.as_ref()) {
Some(secret) => secret.into(),
None => Value::Null,
Expand Down
2 changes: 1 addition & 1 deletion lib/vector-vrl/functions/src/remove_secret.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use vrl::prelude::*;
reason = "Keep the fallible return convention used by VRL runtime helpers."
)]
fn remove_secret(ctx: &mut Context, key: Value) -> std::result::Result<Value, ExpressionError> {
let key_str = key.as_str().expect("argument must be a string");
let key_str = key.to_str_lossy().expect("argument must be a string");
ctx.target_mut().remove_secret(key_str.as_ref());
Ok(Value::Null)
}
Expand Down
4 changes: 2 additions & 2 deletions lib/vector-vrl/functions/src/set_secret.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ fn set_secret(
key: Value,
secret: Value,
) -> std::result::Result<Value, ExpressionError> {
let key_str = key.as_str().expect("key must be a string");
let secret_str = secret.as_str().expect("secret must be a string");
let key_str = key.to_str_lossy().expect("key must be a string");
let secret_str = secret.to_str_lossy().expect("secret must be a string");

ctx.target_mut()
.insert_secret(key_str.as_ref(), secret_str.as_ref());
Expand Down
2 changes: 1 addition & 1 deletion lib/vector-vrl/metrics/src/aggregate_vector_metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ fn aggregate_metrics(
key: Value,
tags: BTreeMap<String, String>,
) -> Result<Value, ExpressionError> {
let key_str = key.as_str().expect("argument must be a string");
let key_str = key.to_str_lossy().expect("argument must be a string");
let metrics = metrics_storage.find_metrics(&key_str, tags);

let metric_values = metrics.into_iter().filter_map(|m| match m.value() {
Expand Down
6 changes: 3 additions & 3 deletions lib/vector-vrl/metrics/src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ pub(crate) fn resolve_tags(
v.resolve(ctx).and_then(|v| {
Ok((
k.clone().into(),
v.as_str().ok_or("Tag must be a string")?.into_owned(),
v.to_str_lossy().ok_or("Tag must be a string")?.into_owned(),
))
})
})
Expand Down Expand Up @@ -267,7 +267,7 @@ mod tests {
value: f64,
tags: Option<Vec<(&str, &str)>>,
) {
assert_eq!(metric.get("name").unwrap().as_str().unwrap(), name);
assert_eq!(metric.get("name").unwrap().to_str_lossy().unwrap(), name);
assert_eq!(
metric.get("value").unwrap().as_float().unwrap(),
NotNan::new(value).unwrap()
Expand All @@ -283,7 +283,7 @@ mod tests {
.as_array_unwrap()
.first()
.unwrap()
.as_str()
.to_str_lossy()
.unwrap(),
value
);
Expand Down
2 changes: 1 addition & 1 deletion lib/vector-vrl/metrics/src/find_vector_metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ fn find_metrics(
key: Value,
tags: BTreeMap<String, String>,
) -> Result<Value, ExpressionError> {
let key_str = key.as_str().expect("argument must be a string");
let key_str = key.to_str_lossy().expect("argument must be a string");
Ok(Value::Array(
metrics_storage
.find_metrics(&key_str, tags)
Expand Down
2 changes: 1 addition & 1 deletion lib/vector-vrl/metrics/src/get_vector_metric.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ fn get_metric(
key: Value,
tags: BTreeMap<String, String>,
) -> Result<Value, ExpressionError> {
let key_str = key.as_str().expect("argument must be a string");
let key_str = key.to_str_lossy().expect("argument must be a string");
let value = match metrics_storage.get_metric(&key_str, tags) {
Some(value) => metric_into_vrl(&value),
None => Value::Null,
Expand Down
2 changes: 1 addition & 1 deletion src/sinks/elasticsearch/sink.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ pub(super) fn process_log(

let id = id_key_field
.and_then(|key| log.remove((PathPrefix::Event, key)))
.and_then(|id| id.as_str().map(Into::into));
.and_then(|id| id.to_str_lossy().map(Into::into));
let document_metadata = match (id, mode.version_type(), mode.version(&log)) {
(None, _, _) => DocumentMetadata::WithoutId,
(Some(id), None, None) | (Some(id), None, Some(_)) | (Some(id), Some(_), None) => {
Expand Down
2 changes: 1 addition & 1 deletion src/sinks/postgres/integration_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ async fn extra_fields_are_ignored() {
let expected_value = input_log_event
.get_message()
.unwrap()
.as_str()
.to_str_lossy()
.unwrap()
.into_owned();

Expand Down
2 changes: 1 addition & 1 deletion src/sinks/splunk_hec/logs/sink.rs
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ impl Partitioner for EventPartitioner {
log_schema().host_key_target_path(),
)
.and_then(|path| item.event.get(&path))
.and_then(|value| value.as_str().map(|s| s.to_string()));
.and_then(|value| value.to_str_lossy().map(|s| s.to_string()));

Some(Partitioned {
token: item.event.metadata().splunk_hec_token(),
Expand Down
2 changes: 1 addition & 1 deletion src/sources/docker_logs/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -584,7 +584,7 @@ mod integration_tests {
.iter()
.map(|event| {
definition.assert_valid_for_event(event);
event.as_log()[&message_key].as_str().unwrap()
event.as_log()[&message_key].to_str_lossy().unwrap()
})
.unique()
.sorted()
Expand Down
9 changes: 6 additions & 3 deletions src/sources/http_client/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -560,7 +560,7 @@ async fn post_with_body() {
// Verify the body was echoed back correctly
for log in logs {
assert_eq!(
log.get(event_path!("key")).unwrap().as_str().unwrap(),
log.get(event_path!("key")).unwrap().to_str_lossy().unwrap(),
"value"
);
let number = log.get(event_path!("number")).unwrap();
Expand Down Expand Up @@ -671,7 +671,10 @@ async fn post_with_vrl_body() {
// Verify VRL was evaluated correctly
for log in logs {
assert_eq!(
log.get(event_path!("message")).unwrap().as_str().unwrap(),
log.get(event_path!("message"))
.unwrap()
.to_str_lossy()
.unwrap(),
"HELLO"
);
let value = log.get(event_path!("value")).unwrap();
Expand Down Expand Up @@ -824,7 +827,7 @@ async fn requests_through_authenticated_proxy() {
.into_log()
.get(event_path!("data"))
.unwrap()
.as_str()
.to_str_lossy()
.unwrap(),
"foo"
);
Expand Down
2 changes: 1 addition & 1 deletion src/sources/http_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -981,7 +981,7 @@ mod tests {
let source_type_key_value = log
.get((PathPrefix::Event, log_schema().source_type_key().unwrap()))
.unwrap()
.as_str()
.to_str_lossy()
.unwrap();
assert_eq!(source_type_key_value, SimpleHttpConfig::NAME);
assert_eq!(log["http_path"], "/".into());
Expand Down
2 changes: 1 addition & 1 deletion src/sources/journald.rs
Original file line number Diff line number Diff line change
Expand Up @@ -874,7 +874,7 @@ fn enrich_log_event(log: &mut LogEvent, log_namespace: LogNamespace) {

let timestamp = timestamp_value
.filter(|&ts| ts.is_bytes())
.and_then(|ts| ts.as_str().unwrap().parse::<u64>().ok())
.and_then(|ts| ts.to_str_lossy().unwrap().parse::<u64>().ok())
.map(|ts| {
chrono::Utc
.timestamp_opt((ts / 1_000_000) as i64, (ts % 1_000_000) as u32 * 1_000)
Expand Down
2 changes: 1 addition & 1 deletion src/sources/kubernetes_logs/parser/docker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ fn normalize_event(
if let Some(timestamp_key) = timestamp_key {
let time = log.remove(&timestamp_key).context(TimeFieldMissingSnafu)?;
let time = time
.as_str()
.to_str_lossy()
.ok_or(NormalizationError::TimeValueUnexpectedType)?;
let time = DateTime::parse_from_rfc3339(time.as_ref()).context(TimeParsingSnafu)?;
log_namespace.insert_source_metadata(
Expand Down
2 changes: 1 addition & 1 deletion src/sources/kubernetes_logs/partial_events_merger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ fn merge_partial_events_with_custom_expiration(

let file = event
.get(&file_path)
.and_then(|x| x.as_str())
.and_then(|x| x.to_str_lossy())
.map(|x| x.to_string())
.unwrap_or_default();

Expand Down
6 changes: 3 additions & 3 deletions src/sources/okta/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ async fn okta_compliance() {
log_event
.get(vrl::event_path!("data"))
.expect("data must be available")
.as_str()
.to_str_lossy()
.unwrap(),
"foo"
);
Expand Down Expand Up @@ -175,8 +175,8 @@ async fn okta_follows_rel() {
OktaConfig::NAME.into()
);
}
assert_eq!(events[0].as_log()["data"].as_str().unwrap(), "foo");
assert_eq!(events[1].as_log()["data"].as_str().unwrap(), "bar");
assert_eq!(events[0].as_log()["data"].to_str_lossy().unwrap(), "foo");
assert_eq!(events[1].as_log()["data"].to_str_lossy().unwrap(), "bar");
}

#[tokio::test]
Expand Down
4 changes: 2 additions & 2 deletions src/topology/test/reload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -525,7 +525,7 @@ async fn topology_reload_preserves_enrichment_table_state() {
let events = events.expect("must get event to output");
let events = events.into_events().collect::<Vec<_>>();
assert_eq!(events.len(), 2);
let message = events.into_iter().filter_map(|e| e.into_log().value().clone().into_object()).find(|e| e.get("key").is_some_and(|k| k.as_str().is_some_and(|k| k == "message")))
let message = events.into_iter().filter_map(|e| e.into_log().value().clone().into_object()).find(|e| e.get("key").is_some_and(|k| k.to_str_lossy().is_some_and(|k| k == "message")))
.and_then(|entry| {
entry
.get("value")
Expand All @@ -550,7 +550,7 @@ async fn topology_reload_preserves_enrichment_table_state() {
let events = events.expect("must get event to output");
let events = events.into_events().collect::<Vec<_>>();
assert_eq!(events.len(), 2);
let message = events.into_iter().filter_map(|e| e.into_log().value().clone().into_object()).find(|e| e.get("key").is_some_and(|k| k.as_str().is_some_and(|k| k == "message")))
let message = events.into_iter().filter_map(|e| e.into_log().value().clone().into_object()).find(|e| e.get("key").is_some_and(|k| k.to_str_lossy().is_some_and(|k| k == "message")))
.and_then(|entry| {
entry
.get("value")
Expand Down
Loading