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

[opentelemetry-prometheus]: Prepare 0.17.0 release using opentelemetry 0.24 #1957

Merged
merged 1 commit into from
Jul 24, 2024
Merged
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
8 changes: 8 additions & 0 deletions opentelemetry-prometheus/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@

## vNext

## v0.17.0

### Changed

- Update `opentelemetry` dependency version to 0.24
- Update `opentelemetry_sdk` dependency version to 0.24
- Update `opentelemetry-semantic-conventions` dependency version to 0.16

## v0.16.0

### Added
Expand Down
8 changes: 4 additions & 4 deletions opentelemetry-prometheus/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "opentelemetry-prometheus"
version = "0.16.0"
version = "0.17.0"
description = "Prometheus exporter for OpenTelemetry"
homepage = "https://github.com/open-telemetry/opentelemetry-rust"
repository = "https://github.com/open-telemetry/opentelemetry-rust"
Expand All @@ -21,13 +21,13 @@ rustdoc-args = ["--cfg", "docsrs"]

[dependencies]
once_cell = { workspace = true }
opentelemetry = { version = "0.23", default-features = false, features = ["metrics"] }
opentelemetry_sdk = { version = "0.23", default-features = false, features = ["metrics"] }
opentelemetry = { version = "0.24", default-features = false, features = ["metrics"] }
opentelemetry_sdk = { version = "0.24", default-features = false, features = ["metrics"] }
prometheus = "0.13"
protobuf = "2.14"

[dev-dependencies]
opentelemetry-semantic-conventions = { version = "0.15" }
opentelemetry-semantic-conventions = { version = "0.16" }
http-body-util = { workspace = true }
hyper = { workspace = true, features = ["full"] }
hyper-util = { workspace = true, features = ["full"] }
Expand Down
2 changes: 1 addition & 1 deletion opentelemetry-prometheus/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
[`Prometheus`] integration for applications instrumented with [`OpenTelemetry`].

**The development of prometheus exporter has halt until the Opentelemetry metrics API and SDK reaches 1.0. Current
implementation is based on Opentelemetry API and SDK 0.23**.
implementation is based on Opentelemetry API and SDK 0.24**.

[![Crates.io: opentelemetry-prometheus](https://img.shields.io/crates/v/opentelemetry-prometheus.svg)](https://crates.io/crates/opentelemetry-prometheus)
[![Documentation](https://docs.rs/opentelemetry-prometheus/badge.svg)](https://docs.rs/opentelemetry-prometheus)
Expand Down
6 changes: 3 additions & 3 deletions opentelemetry-prometheus/examples/hyper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use hyper::{
use hyper_util::rt::{TokioExecutor, TokioIo};
use once_cell::sync::Lazy;
use opentelemetry::{
metrics::{Counter, Histogram, MeterProvider as _, Unit},
metrics::{Counter, Histogram, MeterProvider as _},
KeyValue,
};
use opentelemetry_sdk::metrics::SdkMeterProvider;
Expand Down Expand Up @@ -88,12 +88,12 @@ pub async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
.init(),
http_body_gauge: meter
.u64_histogram("example.http_response_size")
.with_unit(Unit::new("By"))
.with_unit("By")
.with_description("The metrics HTTP response sizes in bytes.")
.init(),
http_req_histogram: meter
.f64_histogram("example.http_request_duration")
.with_unit(Unit::new("ms"))
.with_unit("ms")
.with_description("The HTTP request latencies in milliseconds.")
.init(),
});
Expand Down
15 changes: 12 additions & 3 deletions opentelemetry-prometheus/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,10 @@
// See: https://github.com/tikv/rust-prometheus/issues/393

for dp in &histogram.data_points {
let kvs = get_attrs(&mut dp.attributes.iter(), extra);
let kvs = get_attrs(
&mut dp.attributes.iter().map(|kv| (&kv.key, &kv.value)),
extra,
);
let bounds_len = dp.bounds.len();
let (bucket, _) = dp.bounds.iter().enumerate().fold(
(Vec::with_capacity(bounds_len), 0),
Expand Down Expand Up @@ -503,7 +506,10 @@
};

for dp in &sum.data_points {
let kvs = get_attrs(&mut dp.attributes.iter(), extra);
let kvs = get_attrs(
&mut dp.attributes.iter().map(|kv| (&kv.key, &kv.value)),
extra,
);

let mut pm = prometheus::proto::Metric::default();
pm.set_label(protobuf::RepeatedField::from_vec(kvs));
Expand Down Expand Up @@ -535,7 +541,10 @@
name: Cow<'static, str>,
) {
for dp in &gauge.data_points {
let kvs = get_attrs(&mut dp.attributes.iter(), extra);
let kvs = get_attrs(
&mut dp.attributes.iter().map(|kv| (&kv.key, &kv.value)),
extra,
);

Check warning on line 547 in opentelemetry-prometheus/src/lib.rs

View check run for this annotation

Codecov / codecov/patch

opentelemetry-prometheus/src/lib.rs#L544-L547

Added lines #L544 - L547 were not covered by tests

let mut g = prometheus::proto::Gauge::default();
g.set_value(dp.value.as_f64());
Expand Down
2 changes: 1 addition & 1 deletion opentelemetry-prometheus/src/resource_selector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ impl ResourceSelector {
ResourceSelector::All => get_attrs(&mut resource.iter(), &[]),
ResourceSelector::None => Vec::new(),
ResourceSelector::KeyAllowList(keys) => {
get_attrs(&mut resource.iter().filter(|(k, _)| keys.contains(k)), &[])
get_attrs(&mut resource.iter().filter(|(k, _)| keys.contains(*k)), &[])
}
}
}
Expand Down
14 changes: 6 additions & 8 deletions opentelemetry-prometheus/src/utils.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
use opentelemetry::metrics::Unit;
use std::borrow::Cow;

const NON_APPLICABLE_ON_PER_UNIT: [&str; 8] = ["1", "d", "h", "min", "s", "ms", "us", "ns"];

pub(crate) fn get_unit_suffixes(unit: &Unit) -> Option<Cow<'static, str>> {
pub(crate) fn get_unit_suffixes(unit: &str) -> Option<Cow<'static, str>> {
// no unit return early
if unit.as_str().is_empty() {
if unit.is_empty() {
return None;
}

// direct match with known units
if let Some(matched) = get_prom_units(unit.as_str()) {
if let Some(matched) = get_prom_units(unit) {
return Some(Cow::Borrowed(matched));
}

Expand All @@ -20,7 +19,7 @@ pub(crate) fn get_unit_suffixes(unit: &Unit) -> Option<Cow<'static, str>> {
// e.g
// "test/y" => "per_year"
// "km/s" => "kilometers_per_second"
if let Some((first, second)) = unit.as_str().split_once('/') {
if let Some((first, second)) = unit.split_once('/') {
return match (
NON_APPLICABLE_ON_PER_UNIT.contains(&first),
get_prom_units(first),
Expand Down Expand Up @@ -193,9 +192,8 @@ mod tests {
// annotations
("{request}", None),
];
for (unit_str, expected_suffix) in test_cases {
let unit = Unit::new(unit_str);
assert_eq!(get_unit_suffixes(&unit), expected_suffix);
for (unit, expected_suffix) in test_cases {
assert_eq!(get_unit_suffixes(unit), expected_suffix);
}
}
}
Loading
Loading