-
Notifications
You must be signed in to change notification settings - Fork 482
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
[Metric SDK] - Avoid exposing AttributeSet to exporters - Part1 #1792
Changes from all commits
715e7ff
ee3ddfb
54df301
2cb2477
89e2a64
5c842a8
ab8994a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
use std::sync::atomic::{AtomicBool, Ordering}; | ||
use std::vec; | ||
use std::{ | ||
collections::{hash_map::Entry, HashMap}, | ||
sync::Mutex, | ||
|
@@ -7,6 +8,7 @@ | |
|
||
use crate::attributes::AttributeSet; | ||
use crate::metrics::data::{self, Aggregation, DataPoint, Temporality}; | ||
use opentelemetry::KeyValue; | ||
use opentelemetry::{global, metrics::MetricsError}; | ||
|
||
use super::{ | ||
|
@@ -131,7 +133,7 @@ | |
.swap(false, Ordering::AcqRel) | ||
{ | ||
s_data.data_points.push(DataPoint { | ||
attributes: AttributeSet::default(), | ||
attributes: vec![], | ||
start_time: Some(prev_start), | ||
time: Some(t), | ||
value: self.value_map.no_attribute_value.get_and_reset_value(), | ||
|
@@ -141,7 +143,10 @@ | |
|
||
for (attrs, value) in values.drain() { | ||
s_data.data_points.push(DataPoint { | ||
attributes: attrs, | ||
attributes: attrs | ||
.iter() | ||
.map(|(k, v)| KeyValue::new(k.clone(), v.clone())) | ||
.collect(), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not worried about the extra cost here, as this is in collect() path only, to focus on fixing the hot path first. The collect() path can be refactored afterwards. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can implement |
||
start_time: Some(prev_start), | ||
time: Some(t), | ||
value, | ||
|
@@ -201,7 +206,7 @@ | |
.load(Ordering::Acquire) | ||
{ | ||
s_data.data_points.push(DataPoint { | ||
attributes: AttributeSet::default(), | ||
attributes: vec![], | ||
start_time: Some(prev_start), | ||
time: Some(t), | ||
value: self.value_map.no_attribute_value.get_value(), | ||
|
@@ -215,7 +220,10 @@ | |
// overload the system. | ||
for (attrs, value) in values.iter() { | ||
s_data.data_points.push(DataPoint { | ||
attributes: attrs.clone(), | ||
attributes: attrs | ||
.iter() | ||
.map(|(k, v)| KeyValue::new(k.clone(), v.clone())) | ||
.collect(), | ||
start_time: Some(prev_start), | ||
time: Some(t), | ||
value: *value, | ||
|
@@ -297,7 +305,7 @@ | |
.swap(false, Ordering::AcqRel) | ||
{ | ||
s_data.data_points.push(DataPoint { | ||
attributes: AttributeSet::default(), | ||
attributes: vec![], | ||
start_time: Some(prev_start), | ||
time: Some(t), | ||
value: self.value_map.no_attribute_value.get_and_reset_value(), | ||
|
@@ -312,7 +320,10 @@ | |
new_reported.insert(attrs.clone(), value); | ||
} | ||
s_data.data_points.push(DataPoint { | ||
attributes: attrs.clone(), | ||
attributes: attrs | ||
.iter() | ||
.map(|(k, v)| KeyValue::new(k.clone(), v.clone())) | ||
.collect(), | ||
start_time: Some(prev_start), | ||
time: Some(t), | ||
value: delta, | ||
|
@@ -379,7 +390,7 @@ | |
.load(Ordering::Acquire) | ||
{ | ||
s_data.data_points.push(DataPoint { | ||
attributes: AttributeSet::default(), | ||
attributes: vec![], | ||
start_time: Some(prev_start), | ||
time: Some(t), | ||
value: self.value_map.no_attribute_value.get_value(), | ||
|
@@ -394,7 +405,10 @@ | |
new_reported.insert(attrs.clone(), *value); | ||
} | ||
s_data.data_points.push(DataPoint { | ||
attributes: attrs.clone(), | ||
attributes: attrs | ||
.iter() | ||
.map(|(k, v)| KeyValue::new(k.clone(), v.clone())) | ||
.collect(), | ||
start_time: Some(prev_start), | ||
time: Some(t), | ||
value: delta, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we use a boxed slice instead of a Vec? It would save 8 bytes (
usize
length) per instance since unlikeVec
we wouldn't need an additional pointer to track the capacity. That could save a considerable amount of memory if we are going to have a lot of theseDataPoints
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As mentioned in the PR desc, will revisit the public APIs. This PR is to unblock the unwanted exposure of
AttributeSet
outside of core sdk.