-
Notifications
You must be signed in to change notification settings - Fork 494
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
424 additions
and
139 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
use crate::get_attrs; | ||
use opentelemetry::Key; | ||
use opentelemetry_sdk::Resource; | ||
use prometheus::proto::LabelPair; | ||
use std::collections::HashSet; | ||
|
||
/// `ResourceSelector` is used to select which resource to export with every metrics. | ||
/// | ||
/// By default, the exporter will only export resource as `target_info` metrics but not inline in every | ||
/// metrics. You can disable this behavior by calling [`without_target_info`](crate::ExporterBuilder::without_target_info) | ||
/// | ||
/// You can add resource to every metrics by set `ResourceSelector` to anything other than `None`. | ||
/// | ||
/// By default, ResourceSelector is `None`, meaning resource will not be attributes of every metrics. | ||
#[derive(Debug, Default)] | ||
#[non_exhaustive] | ||
pub enum ResourceSelector { | ||
/// Export all resource attributes with every metrics. | ||
All, | ||
/// Do not export any resource attributes with every metrics. | ||
#[default] | ||
None, | ||
/// Export only the resource attributes in the allow list with every metrics. | ||
KeyAllowList(HashSet<Key>), | ||
} | ||
|
||
impl From<HashSet<Key>> for ResourceSelector { | ||
fn from(keys: HashSet<Key>) -> Self { | ||
ResourceSelector::KeyAllowList(keys) | ||
} | ||
} | ||
|
||
impl ResourceSelector { | ||
pub(crate) fn select(&self, resource: &Resource) -> Vec<LabelPair> { | ||
match self { | ||
ResourceSelector::All => get_attrs(&mut resource.iter(), &[]), | ||
ResourceSelector::None => Vec::new(), | ||
ResourceSelector::KeyAllowList(keys) => { | ||
get_attrs(&mut resource.iter().filter(|(k, _)| keys.contains(k)), &[]) | ||
} | ||
} | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
opentelemetry-prometheus/tests/data/resource_in_every_metrics.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# HELP bar_ratio a fun little gauge | ||
# TYPE bar_ratio gauge | ||
bar_ratio{A="B",C="D",otel_scope_name="testmeter",otel_scope_version="v0.1.0",service_name="prometheus_test",telemetry_sdk_language="rust",telemetry_sdk_name="opentelemetry",telemetry_sdk_version="latest"} 1 | ||
# HELP otel_scope_info Instrumentation Scope metadata | ||
# TYPE otel_scope_info gauge | ||
otel_scope_info{otel_scope_name="testmeter",otel_scope_version="v0.1.0"} 1 | ||
# HELP target_info Target metadata | ||
# TYPE target_info gauge | ||
target_info{service_name="prometheus_test",telemetry_sdk_language="rust",telemetry_sdk_name="opentelemetry",telemetry_sdk_version="latest"} 1 |
9 changes: 9 additions & 0 deletions
9
opentelemetry-prometheus/tests/data/select_resource_in_every_metrics.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# HELP bar_ratio a fun little gauge | ||
# TYPE bar_ratio gauge | ||
bar_ratio{A="B",C="D",otel_scope_name="testmeter",otel_scope_version="v0.1.0",service_name="prometheus_test"} 1 | ||
# HELP otel_scope_info Instrumentation Scope metadata | ||
# TYPE otel_scope_info gauge | ||
otel_scope_info{otel_scope_name="testmeter",otel_scope_version="v0.1.0"} 1 | ||
# HELP target_info Target metadata | ||
# TYPE target_info gauge | ||
target_info{service_name="prometheus_test",telemetry_sdk_language="rust",telemetry_sdk_name="opentelemetry",telemetry_sdk_version="latest"} 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.