Skip to content
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

Code changes for the new Clippy version and running test on Windows #1704

Merged
merged 13 commits into from
May 6, 2024
Merged
Show file tree
Hide file tree
Changes from 8 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 opentelemetry-jaeger/src/exporter/thrift/agent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

#![allow(unused_imports)]
#![allow(unused_extern_crates)]
#![cfg_attr(clippy, allow(clippy::too_many_arguments, clippy::type_complexity))]
#![allow(clippy::too_many_arguments, clippy::type_complexity)]
#![cfg_attr(rustfmt, rustfmt_skip)]

extern crate thrift;
Expand Down
2 changes: 1 addition & 1 deletion opentelemetry-jaeger/src/exporter/thrift/jaeger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

#![allow(unused_imports)]
#![allow(unused_extern_crates)]
#![cfg_attr(clippy, allow(clippy::too_many_arguments, clippy::type_complexity))]
#![allow(clippy::too_many_arguments, clippy::type_complexity)]
#![cfg_attr(rustfmt, rustfmt_skip)]

extern crate thrift;
Expand Down
2 changes: 1 addition & 1 deletion opentelemetry-jaeger/src/exporter/thrift/zipkincore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

#![allow(unused_imports)]
#![allow(unused_extern_crates)]
#![cfg_attr(clippy, allow(clippy::too_many_arguments, clippy::type_complexity))]
#![allow(clippy::too_many_arguments, clippy::type_complexity)]
#![cfg_attr(rustfmt, rustfmt_skip)]

extern crate thrift;
Expand Down
4 changes: 2 additions & 2 deletions opentelemetry-otlp/examples/basic-otlp-http/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ static COMMON_ATTRIBUTES: Lazy<[KeyValue; 4]> = Lazy::new(|| {

#[tokio::main]
async fn main() -> Result<(), Box<dyn Error + Send + Sync + 'static>> {
let _ = init_tracer()?;
let _ = init_metrics()?;
init_tracer()?;
init_metrics()?;
// Opentelemetry will not provide a global API to manage the logger provider. Application users must manage the lifecycle of the logger provider on their own. Dropping logger providers will disable log emitting.
let logger_provider = init_logs().unwrap();

Expand Down
4 changes: 2 additions & 2 deletions opentelemetry-otlp/examples/basic-otlp/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ async fn main() -> Result<(), Box<dyn Error + Send + Sync + 'static>> {
// By binding the result to an unused variable, the lifetime of the variable
// matches the containing block, reporting traces and metrics during the whole
// execution.
let _ = init_tracer()?;
let _ = init_metrics()?;
init_tracer()?;
init_metrics()?;

// Initialize logs, which sets the global loggerprovider.
let logger_provider = init_logs().unwrap();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![cfg(unix)]
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These tests use use std::os::unix::fs::PermissionsExt which cannot be used on Windows.


use integration_test_runner::images::Collector;
use std::fs::File;
use std::os::unix::fs::PermissionsExt;
Expand Down
2 changes: 2 additions & 0 deletions opentelemetry-otlp/tests/integration_test/tests/traces.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![cfg(unix)]

use integration_test_runner::asserter::{read_spans_from_json, TraceAsserter};
use opentelemetry::global;
use opentelemetry::global::shutdown_tracer_provider;
Expand Down
14 changes: 12 additions & 2 deletions opentelemetry-prometheus/tests/integration_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,12 @@ fn gather_and_compare(registry: prometheus::Registry, expected: String, name: &'
let encoder = TextEncoder::new();
let metric_families = registry.gather();
encoder.encode(&metric_families, &mut output).unwrap();
let output_string = String::from_utf8(output).unwrap();

let output_string = if cfg!(windows) {
String::from_utf8(output).unwrap().replace('\n', "\r\n")
} else {
String::from_utf8(output).unwrap()
};

assert_eq!(output_string, expected, "{name}");
}
Expand Down Expand Up @@ -816,7 +821,12 @@ fn gather_and_compare_multi(
let encoder = TextEncoder::new();
let metric_families = registry.gather();
encoder.encode(&metric_families, &mut output).unwrap();
let output_string = String::from_utf8(output).unwrap();

let output_string = if cfg!(windows) {
String::from_utf8(output).unwrap().replace('\n', "\r\n")
} else {
String::from_utf8(output).unwrap()
};

assert!(
expected.contains(&output_string),
Expand Down
21 changes: 14 additions & 7 deletions opentelemetry-proto/tests/grpc_build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const TONIC_INCLUDES: &[&str] = &["src/proto/opentelemetry-proto", "src/proto"];

#[test]
fn build_tonic() {
let before_build = build_content_map(TONIC_OUT_DIR);
let before_build = build_content_map(TONIC_OUT_DIR, false);

let out_dir = TempDir::new().expect("failed to create temp dir to store the generated files");

Expand Down Expand Up @@ -95,11 +95,11 @@ fn build_tonic() {
.compile(TONIC_PROTO_FILES, TONIC_INCLUDES)
.expect("cannot compile protobuf using tonic");

let after_build = build_content_map(out_dir.path());
let after_build = build_content_map(out_dir.path(), true);
ensure_files_are_same(before_build, after_build, TONIC_OUT_DIR);
}

fn build_content_map(path: impl AsRef<Path>) -> HashMap<String, String> {
fn build_content_map(path: impl AsRef<Path>, normalize_line_feed: bool) -> HashMap<String, String> {
std::fs::read_dir(path)
.expect("cannot open dictionary of generated files")
.flatten()
Expand All @@ -108,10 +108,17 @@ fn build_content_map(path: impl AsRef<Path>) -> HashMap<String, String> {
let file_name = path
.file_name()
.expect("file name should always exist for generated files");
(
file_name.to_string_lossy().to_string(),
std::fs::read_to_string(path).expect("cannot read from existing generated file"),
)

let file_contents = if normalize_line_feed && cfg!(windows) {
std::fs::read_to_string(path.clone())
.expect("cannot read from existing generated file")
.replace('\n', "\r\n")
} else {
std::fs::read_to_string(path.clone())
.expect("cannot read from existing generated file")
};

(file_name.to_string_lossy().to_string(), file_contents)
})
.collect()
}
Expand Down
8 changes: 5 additions & 3 deletions opentelemetry-sdk/src/metrics/periodic_reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use futures_util::{
future::{self, Either},
pin_mut,
stream::{self, FusedStream},
Stream, StreamExt,
StreamExt,
};
use opentelemetry::{
global,
Expand Down Expand Up @@ -290,7 +290,7 @@ impl<RT: Runtime> PeriodicReaderWorker<RT> {
true
}

async fn run(mut self, mut messages: impl Stream<Item = Message> + Unpin + FusedStream) {
async fn run(mut self, mut messages: impl Unpin + FusedStream<Item = Message>) {
while let Some(message) = messages.next().await {
if !self.process_message(message).await {
break;
Expand Down Expand Up @@ -435,9 +435,11 @@ mod tests {
})
.expect("callback registration should succeed");

_ = meter_provider.force_flush();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why force_flush here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to trigger the callback code deterministically. This lets us assert things on the receiver end with certainty instead of waiting for interval * 2 milliseconds and hoping that the sender sends the data in that time.


// Assert
receiver
.recv_timeout(interval * 2)
.try_recv()
.expect("message should be available in channel, indicating a collection occurred");
}

Expand Down
6 changes: 3 additions & 3 deletions opentelemetry-sdk/src/metrics/pipeline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,9 +165,9 @@ impl SdkProducer for Pipeline {
// previous aggregation was of a different type
prev_agg.data = data;
}
prev_agg.name = inst.name.clone();
prev_agg.description = inst.description.clone();
prev_agg.unit = inst.unit.clone();
prev_agg.name.clone_from(&inst.name);
prev_agg.description.clone_from(&inst.description);
prev_agg.unit.clone_from(&inst.unit);
}
_ => continue,
}
Expand Down
4 changes: 2 additions & 2 deletions opentelemetry-sdk/src/trace/span_processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ use futures_util::{
future::{self, BoxFuture, Either},
select,
stream::{self, FusedStream, FuturesUnordered},
Stream, StreamExt as _,
StreamExt as _,
};
use opentelemetry::global;
use opentelemetry::{
Expand Down Expand Up @@ -399,7 +399,7 @@ impl<R: RuntimeChannel> BatchSpanProcessorInternal<R> {
})
}

async fn run(mut self, mut messages: impl Stream<Item = BatchMessage> + Unpin + FusedStream) {
async fn run(mut self, mut messages: impl Unpin + FusedStream<Item = BatchMessage>) {
loop {
select! {
// FuturesUnordered implements Fuse intelligently such that it
Expand Down
Loading