Skip to content

Conversation

@Sushisource
Copy link
Member

What was changed

Added CustomMetricAttributes trait / variant to MetricAttributes to allow langs to have a simple reference based approach to allocating their own attributes.

Why?

Allows destroying backing attributes on Drop of the thing implementing CustomMetricAttributes

Checklist

It may no longer be worth keeping a buffer at all, or, if we do, I need to re-implement it to work in terms of refs.

  1. Closes

  2. How was this tested:
    Existing tests

  3. Any docs updates needed?

@Sushisource Sushisource requested a review from a team as a code owner September 25, 2023 23:13
Comment on lines 175 to 177
new_hole: BufferAttributes,
existing_hole: Option<BufferAttributes>,
attributes: Vec<MetricKeyValue>,
Copy link
Member

@cretz cretz Sep 26, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
new_hole: BufferAttributes,
existing_hole: Option<BufferAttributes>,
attributes: Vec<MetricKeyValue>,
populate_into: BufferAttributes,
// Do not mutate append_from
append_from: Option<BufferAttributes>,
new_attributes: Vec<MetricKeyValue>,

Was a bit confused by terminology at first, but I think I have it right here (sorry the term "hole" confused me). Arguably we could split BufferAttributes into read/write traits, but I think this is fine.

I will have to see if I can use a https://docs.rs/pyo3/latest/pyo3/types/struct.PyDict.html based CustomMetricAttributes implementation to "set" here. I will have to think if I will just use a basic impl CustomMetricAttributes for HashMap<String, MetricValue> { (well map wrapper since I own neither side) or something more advanced. Probably the latter, so this code LGTM.

So I suppose when implementing, as I walk these events, it's at that time I will call populate_into.set.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that's when you'd do it.

/// implement this marker trait
pub trait BufferInstrumentRef {}
/// A lazy reference to a metrics buffer instrument
pub type LazyBufferInstrument<T> = LazyRef<Arc<T>>;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we put a type constraint on T that it has to implement BufferInstrumentRef? Or maybe I can have that constraint above? Or rather, is it at least expected that T implements BufferInstrumentRef?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

EDIT: Nevermind, I see this constraint is now available on the CoreMeter impl


impl<I> CoreMeter for MetricsCallBuffer<I>
where
I: Debug + Send + Sync + Clone + 'static,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hrmm, so I guess if I'm tying my non-cloneable Python metric's instrument instance to this, I will have to wrap it in Arc or similar? It doesn't seem like CustomMetricAttributes has to implement Clone. I don't think it's a problem though.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The trait doesn't require it, but the places where it's used do (when they need it) which is fairly typical practice

@Sushisource Sushisource enabled auto-merge (squash) September 26, 2023 22:04
@Sushisource Sushisource merged commit e9a6f06 into temporalio:master Sep 26, 2023
@Sushisource Sushisource deleted the metrics-api-refine branch September 26, 2023 23:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants