-
Notifications
You must be signed in to change notification settings - Fork 454
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
chore: Test sync exporters #2455
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,7 +29,7 @@ pub mod hello_world { | |
|
||
struct MetadataMap<'a>(&'a tonic::metadata::MetadataMap); | ||
|
||
impl<'a> Extractor for MetadataMap<'a> { | ||
impl Extractor for MetadataMap<'_> { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ... and this one |
||
/// Get a value for a key from the MetadataMap. If the value can't be converted to &str, returns None | ||
fn get(&self, key: &str) -> Option<&str> { | ||
self.0.get(key).and_then(|metadata| metadata.to_str().ok()) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -239,7 +239,7 @@ mod any_value { | |
pub(crate) fn serialize(value: log::kv::Value) -> Option<AnyValue> { | ||
struct ValueVisitor(Option<AnyValue>); | ||
|
||
impl<'kvs> log::kv::VisitValue<'kvs> for ValueVisitor { | ||
impl log::kv::VisitValue<'_> for ValueVisitor { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ... and this one. |
||
fn visit_any(&mut self, value: log::kv::Value) -> Result<(), log::kv::Error> { | ||
self.0 = Some(AnyValue::String(StringValue::from(value.to_string()))); | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,19 +38,33 @@ fn init_logs() -> Result<sdklogs::LoggerProvider> { | |
mod logtests { | ||
use super::*; | ||
use integration_test_runner::logs_asserter::{read_logs_from_json, LogsAsserter}; | ||
use opentelemetry_appender_tracing::layer::OpenTelemetryTracingBridge; | ||
use std::{fs::File, time::Duration}; | ||
use tracing::info; | ||
use tracing_subscriber::layer::SubscriberExt; | ||
|
||
#[test] | ||
#[should_panic(expected = "assertion `left == right` failed: body does not match")] | ||
pub fn test_assert_logs_eq_failure() { | ||
let left = read_logs_from_json(File::open("./expected/logs.json").unwrap()); | ||
let right = read_logs_from_json(File::open("./expected/failed_logs.json").unwrap()); | ||
let left = read_logs_from_json( | ||
File::open("./expected/logs.json").expect("failed to open expected file"), | ||
) | ||
.expect("Failed to read logs from expected file"); | ||
|
||
let right = read_logs_from_json( | ||
File::open("./expected/failed_logs.json") | ||
.expect("failed to open expected failed log file"), | ||
) | ||
.expect("Failed to read logs from expected failed log file"); | ||
LogsAsserter::new(right, left).assert(); | ||
} | ||
|
||
#[test] | ||
pub fn test_assert_logs_eq() { | ||
let logs = read_logs_from_json(File::open("./expected/logs.json").unwrap()); | ||
pub fn test_assert_logs_eq() -> Result<()> { | ||
let logs = read_logs_from_json(File::open("./expected/logs.json")?)?; | ||
LogsAsserter::new(logs.clone(), logs).assert(); | ||
|
||
Ok(()) | ||
} | ||
|
||
#[tokio::test(flavor = "multi_thread", worker_threads = 4)] | ||
|
@@ -84,15 +98,44 @@ mod logtests { | |
|
||
Ok(()) | ||
} | ||
|
||
#[test] | ||
#[cfg(any(feature = "tonic-client", feature = "reqwest-blocking-client"))] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @cijothomas here's the new test. I took advantage of the temporary tokio runtime to setup the collector too. |
||
pub fn logs_batch_non_tokio_main() -> Result<()> { | ||
// Initialize the logger provider inside a tokio runtime | ||
// as this allows tonic client to capture the runtime, | ||
// but actual export occurs from the dedicated std::thread | ||
// created by BatchLogProcessor. | ||
let rt = tokio::runtime::Runtime::new()?; | ||
let logger_provider = rt.block_on(async { | ||
// While we're here setup our collector container too, as this needs tokio to run | ||
test_utils::start_collector_container().await?; | ||
init_logs() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit - will it make sense to have two different tests, with |
||
})?; | ||
|
||
info!("LoggerProvider created"); | ||
let layer = OpenTelemetryTracingBridge::new(&logger_provider); | ||
let subscriber = tracing_subscriber::registry().with(layer); | ||
{ | ||
let _guard = tracing::subscriber::set_default(subscriber); | ||
info!(target: "my-target", "hello from {}. My price is {}.", "banana", 2.99); | ||
} | ||
let _ = logger_provider.shutdown(); | ||
// tokio::time::sleep(Duration::from_secs(10)).await; | ||
assert_logs_results(test_utils::LOGS_FILE, "expected/logs.json"); | ||
|
||
Ok(()) | ||
} | ||
} | ||
|
||
pub fn assert_logs_results(result: &str, expected: &str) { | ||
let left = read_logs_from_json(File::open(expected).unwrap()); | ||
let right = read_logs_from_json(File::open(result).unwrap()); | ||
pub fn assert_logs_results(result: &str, expected: &str) -> Result<()> { | ||
let left = read_logs_from_json(File::open(expected)?)?; | ||
let right = read_logs_from_json(File::open(result)?)?; | ||
|
||
LogsAsserter::new(left, right).assert(); | ||
|
||
assert!(File::open(result).unwrap().metadata().unwrap().size() > 0) | ||
assert!(File::open(result).unwrap().metadata().unwrap().size() > 0); | ||
Ok(()) | ||
} | ||
|
||
/// | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -140,8 +140,8 @@ struct UnsafeSlice<'a> { | |
slice: &'a [UnsafeCell<WorkerStats>], | ||
} | ||
|
||
unsafe impl<'a> Send for UnsafeSlice<'a> {} | ||
unsafe impl<'a> Sync for UnsafeSlice<'a> {} | ||
unsafe impl Send for UnsafeSlice<'_> {} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. More elision |
||
unsafe impl Sync for UnsafeSlice<'_> {} | ||
|
||
impl<'a> UnsafeSlice<'a> { | ||
fn new(slice: &'a mut [WorkerStats]) -> Self { | ||
|
@@ -155,7 +155,7 @@ impl<'a> UnsafeSlice<'a> { | |
#[inline(always)] | ||
unsafe fn increment(&self, i: usize) { | ||
let value = self.slice[i].get(); | ||
(*value).count = (*value).count + 1; | ||
(*value).count += 1; | ||
} | ||
|
||
#[inline(always)] | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I applied clippy fixes and it wants to elide this lifecycle 🤷