Skip to content

Commit

Permalink
fix: tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
TommyCpp committed Jun 11, 2021
1 parent 123a42e commit a0b9539
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
22 changes: 11 additions & 11 deletions opentelemetry-prometheus/tests/integration_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ fn free_unused_instruments() {
counter.add(10.0, &labels);
counter.add(5.3, &labels);

expected.push(r#"counter{A="B",C="D",R="V"} 15.3"#);
expected.push(r#"counter{A="B",C="D",R="V",service_name="unknown_service"} 15.3"#);
}
// Standard export
compare_export(&exporter, expected.clone());
Expand Down Expand Up @@ -56,8 +56,8 @@ fn batch() {
}
});

expected.push(r#"uint_observer{A="B",R="V"} 2"#);
expected.push(r#"float_observer{A="B",R="V"} 3.1"#);
expected.push(r#"uint_observer{A="B",R="V",service_name="unknown_service"} 2"#);
expected.push(r#"float_observer{A="B",R="V",service_name="unknown_service"} 3.1"#);
compare_export(&exporter, expected);
}

Expand All @@ -81,7 +81,7 @@ fn test_add() {
counter.add(10.0, &labels);
counter.add(5.3, &labels);

expected.push(r#"counter{A="B",C="D",R="V"} 15.3"#);
expected.push(r#"counter{A="B",C="D",R="V",service_name="unknown_service"} 15.3"#);

let cb_labels = labels.clone();
let _observer = meter
Expand All @@ -90,23 +90,23 @@ fn test_add() {
})
.init();

expected.push(r#"intobserver{A="B",C="D",R="V"} 1"#);
expected.push(r#"intobserver{A="B",C="D",R="V",service_name="unknown_service"} 1"#);

value_recorder.record(-0.6, &labels);
value_recorder.record(-0.4, &labels);
value_recorder.record(0.6, &labels);
value_recorder.record(20.0, &labels);

expected.push(r#"value_recorder_bucket{A="B",C="D",R="V",le="+Inf"} 4"#);
expected.push(r#"value_recorder_bucket{A="B",C="D",R="V",le="-0.5"} 1"#);
expected.push(r#"value_recorder_bucket{A="B",C="D",R="V",le="1"} 3"#);
expected.push(r#"value_recorder_count{A="B",C="D",R="V"} 4"#);
expected.push(r#"value_recorder_sum{A="B",C="D",R="V"} 19.6"#);
expected.push(r#"value_recorder_bucket{A="B",C="D",R="V",service_name="unknown_service",le="+Inf"} 4"#);
expected.push(r#"value_recorder_bucket{A="B",C="D",R="V",service_name="unknown_service",le="-0.5"} 1"#);
expected.push(r#"value_recorder_bucket{A="B",C="D",R="V",service_name="unknown_service",le="1"} 3"#);
expected.push(r#"value_recorder_count{A="B",C="D",R="V",service_name="unknown_service"} 4"#);
expected.push(r#"value_recorder_sum{A="B",C="D",R="V",service_name="unknown_service"} 19.6"#);

up_down_counter.add(10.0, &labels);
up_down_counter.add(-3.2, &labels);

expected.push(r#"updowncounter{A="B",C="D",R="V"} 6.8"#);
expected.push(r#"updowncounter{A="B",C="D",R="V",service_name="unknown_service"} 6.8"#);

compare_export(&exporter, expected)
}
Expand Down
2 changes: 2 additions & 0 deletions opentelemetry/src/sdk/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ impl ResourceDetector for SdkProvidedResourceDetector {
"service.name",
env::var(OTEL_SERVICE_NAME)
.ok()
.filter(|s| !s.is_empty())
.unwrap_or_else(|| "unknown_service".to_string()),
)])
}
Expand Down Expand Up @@ -128,5 +129,6 @@ mod tests {
with_service.get(Key::from_static_str(SERVICE_NAME)),
Some(Value::from("test service")),
);
env::set_var(OTEL_SERVICE_NAME, ""); // clear the env var
}
}

0 comments on commit a0b9539

Please sign in to comment.