Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit aac8efa

Browse files
authoredMay 29, 2024··
Merge branch 'main' into trace-set-resource
2 parents 300d6d0 + 2dd47fd commit aac8efa

File tree

5 files changed

+16
-25
lines changed

5 files changed

+16
-25
lines changed
 

‎opentelemetry-prometheus/tests/integration_test.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -406,18 +406,18 @@ fn gather_and_compare(registry: prometheus::Registry, expected: String, name: &'
406406
let metric_families = registry.gather();
407407
encoder.encode(&metric_families, &mut output).unwrap();
408408

409+
let expected = get_platform_specific_string(expected);
409410
let output_string = get_platform_specific_string(String::from_utf8(output).unwrap());
410411

411412
assert_eq!(output_string, expected, "{name}");
412413
}
413414

414415
/// Returns a String which uses the platform specific new line feed character.
415416
fn get_platform_specific_string(input: String) -> String {
416-
if cfg!(windows) {
417-
input.replace('\n', "\r\n")
418-
} else {
419-
input
417+
if cfg!(windows) && !input.ends_with("\r\n") && input.ends_with('\n') {
418+
return input.replace('\n', "\r\n");
420419
}
420+
input
421421
}
422422

423423
#[test]
@@ -812,6 +812,7 @@ fn duplicate_metrics() {
812812
.expected_files
813813
.into_iter()
814814
.map(|f| fs::read_to_string(Path::new("./tests/data").join(f)).expect(f))
815+
.map(get_platform_specific_string)
815816
.collect();
816817
gather_and_compare_multi(registry, possible_matches, tc.name);
817818
}

‎opentelemetry-proto/tests/grpc_build.rs

+5-6
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ const TONIC_INCLUDES: &[&str] = &["src/proto/opentelemetry-proto", "src/proto"];
1818

1919
#[test]
2020
fn build_tonic() {
21-
let before_build = build_content_map(TONIC_OUT_DIR, false);
21+
let before_build = build_content_map(TONIC_OUT_DIR, true);
2222

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

@@ -130,13 +130,12 @@ fn build_content_map(path: impl AsRef<Path>, normalize_line_feed: bool) -> HashM
130130
.collect()
131131
}
132132

133-
/// Returns a String with the platform specific new line feed character.
133+
/// Returns a String which uses the platform specific new line feed character.
134134
fn get_platform_specific_string(input: String) -> String {
135-
if cfg!(windows) {
136-
input.replace('\n', "\r\n")
137-
} else {
138-
input
135+
if cfg!(windows) && !input.ends_with("\r\n") && input.ends_with('\n') {
136+
return input.replace('\n', "\r\n");
139137
}
138+
input
140139
}
141140

142141
fn ensure_files_are_same(

‎stress/src/metrics_counter.rs

+2-5
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use rand::{
1616
rngs::{self},
1717
Rng, SeedableRng,
1818
};
19-
use std::{borrow::Cow, cell::RefCell};
19+
use std::cell::RefCell;
2020

2121
mod throughput;
2222

@@ -28,10 +28,7 @@ lazy_static! {
2828
"value1", "value2", "value3", "value4", "value5", "value6", "value7", "value8", "value9",
2929
"value10"
3030
];
31-
static ref COUNTER: Counter<u64> = PROVIDER
32-
.meter(<&str as Into<Cow<'static, str>>>::into("test"))
33-
.u64_counter("hello")
34-
.init();
31+
static ref COUNTER: Counter<u64> = PROVIDER.meter("test").u64_counter("hello").init();
3532
}
3633

3734
thread_local! {

‎stress/src/metrics_histogram.rs

+2-5
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use rand::{
1616
rngs::{self},
1717
Rng, SeedableRng,
1818
};
19-
use std::{borrow::Cow, cell::RefCell};
19+
use std::cell::RefCell;
2020

2121
mod throughput;
2222

@@ -28,10 +28,7 @@ lazy_static! {
2828
"value1", "value2", "value3", "value4", "value5", "value6", "value7", "value8", "value9",
2929
"value10"
3030
];
31-
static ref HISTOGRAM: Histogram<u64> = PROVIDER
32-
.meter(<&str as Into<Cow<'static, str>>>::into("test"))
33-
.u64_histogram("hello")
34-
.init();
31+
static ref HISTOGRAM: Histogram<u64> = PROVIDER.meter("test").u64_histogram("hello").init();
3532
}
3633

3734
thread_local! {

‎stress/src/metrics_overflow.rs

+2-5
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,15 @@ use rand::{
1616
rngs::{self},
1717
Rng, SeedableRng,
1818
};
19-
use std::{borrow::Cow, cell::RefCell};
19+
use std::cell::RefCell;
2020

2121
mod throughput;
2222

2323
lazy_static! {
2424
static ref PROVIDER: SdkMeterProvider = SdkMeterProvider::builder()
2525
.with_reader(ManualReader::builder().build())
2626
.build();
27-
static ref COUNTER: Counter<u64> = PROVIDER
28-
.meter(<&str as Into<Cow<'static, str>>>::into("test"))
29-
.u64_counter("hello")
30-
.init();
27+
static ref COUNTER: Counter<u64> = PROVIDER.meter("test").u64_counter("hello").init();
3128
}
3229

3330
thread_local! {

0 commit comments

Comments
 (0)
Please sign in to comment.