Skip to content

Create a SizedGenerator for use in OTel metrics#1355

Merged
blt merged 14 commits intomainfrom
blt/create_a_sizedgenerator_for_use_in_otel_metrics
May 16, 2025
Merged

Create a SizedGenerator for use in OTel metrics#1355
blt merged 14 commits intomainfrom
blt/create_a_sizedgenerator_for_use_in_otel_metrics

Conversation

@blt
Copy link
Copy Markdown
Collaborator

@blt blt commented May 13, 2025

What does this PR do?

This commit attempts to address the payload generation issues -- blocks
are too big to be useful, depending on user configuration -- by making the
Generator aware of the byte budget. This is still failing tests as of this
commit but it compiles.

Motivation

REF SMPTNG-659

@blt blt added the no-changelog label May 13, 2025 — with Graphite App
@blt blt force-pushed the blt/create_a_sizedgenerator_for_use_in_otel_metrics branch from e4db940 to e5b7497 Compare May 14, 2025 16:05
@blt blt force-pushed the blt/otel_metric_templates_are_direct_protobuf_types branch 2 times, most recently from 87fa48b to f24978e Compare May 14, 2025 16:15
@blt blt force-pushed the blt/create_a_sizedgenerator_for_use_in_otel_metrics branch from e5b7497 to 9fbe654 Compare May 14, 2025 16:15
@blt blt force-pushed the blt/otel_metric_templates_are_direct_protobuf_types branch from f24978e to e954798 Compare May 14, 2025 16:57
@blt blt force-pushed the blt/create_a_sizedgenerator_for_use_in_otel_metrics branch from 9fbe654 to ce2d61a Compare May 14, 2025 16:57
@blt blt force-pushed the blt/otel_metric_templates_are_direct_protobuf_types branch from e954798 to c631da0 Compare May 14, 2025 17:02
@blt blt force-pushed the blt/create_a_sizedgenerator_for_use_in_otel_metrics branch 2 times, most recently from 1712dab to 96508d5 Compare May 14, 2025 21:04
@blt blt force-pushed the blt/otel_metric_templates_are_direct_protobuf_types branch 2 times, most recently from 8dc968c to 04b3096 Compare May 14, 2025 22:02
@blt blt force-pushed the blt/create_a_sizedgenerator_for_use_in_otel_metrics branch from 96508d5 to c1d221c Compare May 14, 2025 22:03
@blt blt force-pushed the blt/otel_metric_templates_are_direct_protobuf_types branch from 04b3096 to c0ed5ff Compare May 14, 2025 22:05
@blt blt force-pushed the blt/create_a_sizedgenerator_for_use_in_otel_metrics branch 2 times, most recently from 287106d to 0e2b5e0 Compare May 14, 2025 22:14
@blt blt force-pushed the blt/otel_metric_templates_are_direct_protobuf_types branch 2 times, most recently from 1070aa3 to 30286ee Compare May 14, 2025 22:17
@blt blt force-pushed the blt/create_a_sizedgenerator_for_use_in_otel_metrics branch from 0e2b5e0 to b240441 Compare May 14, 2025 22:18
@blt blt force-pushed the blt/otel_metric_templates_are_direct_protobuf_types branch from 30286ee to 8f095f4 Compare May 14, 2025 22:36
@blt blt force-pushed the blt/create_a_sizedgenerator_for_use_in_otel_metrics branch from b240441 to 9fac6a2 Compare May 14, 2025 22:36
@blt blt marked this pull request as ready for review May 14, 2025 22:39
@blt blt requested a review from a team as a code owner May 14, 2025 22:39
@blt blt force-pushed the blt/otel_metric_templates_are_direct_protobuf_types branch from 8f095f4 to 9a1e8e2 Compare May 15, 2025 15:48
@blt blt force-pushed the blt/create_a_sizedgenerator_for_use_in_otel_metrics branch from 9fac6a2 to 97b5d15 Compare May 15, 2025 15:49
@blt blt force-pushed the blt/otel_metric_templates_are_direct_protobuf_types branch from 9a1e8e2 to 585b425 Compare May 15, 2025 16:00
@blt blt force-pushed the blt/create_a_sizedgenerator_for_use_in_otel_metrics branch from 97b5d15 to a586e7e Compare May 15, 2025 16:01
@blt blt force-pushed the blt/otel_metric_templates_are_direct_protobuf_types branch 2 times, most recently from e3a8386 to 867ab2b Compare May 15, 2025 23:44
@blt blt force-pushed the blt/create_a_sizedgenerator_for_use_in_otel_metrics branch from 19b629a to fb7a2b1 Compare May 15, 2025 23:44
@blt blt changed the base branch from blt/otel_metric_templates_are_direct_protobuf_types to graphite-base/1355 May 16, 2025 00:01
blt added 13 commits May 16, 2025 00:01
This commit attempts to address the payload generation issues -- blocks
are too big to be useful, depending on user configuration -- by making the
Generator aware of the byte budget. This is still failing tests as of this
commit but it compiles.

REF SMPTNG-659

Signed-off-by: Brian L. Troutwine <brian.troutwine@datadoghq.com>
Signed-off-by: Brian L. Troutwine <brian.troutwine@datadoghq.com>
Signed-off-by: Brian L. Troutwine <brian.troutwine@datadoghq.com>
Signed-off-by: Brian L. Troutwine <brian.troutwine@datadoghq.com>
Signed-off-by: Brian L. Troutwine <brian.troutwine@datadoghq.com>
Signed-off-by: Brian L. Troutwine <brian.troutwine@datadoghq.com>
Signed-off-by: Brian L. Troutwine <brian.troutwine@datadoghq.com>
Signed-off-by: Brian L. Troutwine <brian.troutwine@datadoghq.com>
Signed-off-by: Brian L. Troutwine <brian.troutwine@datadoghq.com>
Signed-off-by: Brian L. Troutwine <brian.troutwine@datadoghq.com>
Signed-off-by: Brian L. Troutwine <brian.troutwine@datadoghq.com>
Signed-off-by: Brian L. Troutwine <brian.troutwine@datadoghq.com>
Signed-off-by: Brian L. Troutwine <brian.troutwine@datadoghq.com>
@blt blt force-pushed the blt/create_a_sizedgenerator_for_use_in_otel_metrics branch from fb7a2b1 to 62c1fbf Compare May 16, 2025 00:01
@blt blt force-pushed the graphite-base/1355 branch from 867ab2b to 916579d Compare May 16, 2025 00:01
@graphite-app graphite-app bot changed the base branch from graphite-base/1355 to main May 16, 2025 00:02
Signed-off-by: Brian L. Troutwine <brian.troutwine@datadoghq.com>
@blt blt force-pushed the blt/create_a_sizedgenerator_for_use_in_otel_metrics branch from 62c1fbf to 7fe5e85 Compare May 16, 2025 00:02
@scottopell scottopell self-assigned this May 16, 2025
use super::templates::GeneratorError;
use crate::{Error, Generator, common::config::ConfRange, common::strings::Pool};
use opentelemetry_proto::tonic::common::v1::{AnyValue, KeyValue, any_value};
use prost::Message;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think you can remove this since you import in the test module

pub(crate) fn fetch<R>(
&mut self,
rng: &mut R,
budget: &mut usize,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

small suggestion for extra clarity

Suggested change
budget: &mut usize,
encoded_budget: &mut usize,


// Generate new instances until either context_cap is hit or the
// remaining space drops below our lookup interval.
if self.len < self.context_cap {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

the goal here is to "lazily" generate new contexts when needed rather than doing it entirely up front, and it seems like part of that motivation is so that we can call generator.generate() with the "updated" limit and ensure that the templates are as useful as possible

}
}

fn cut_data_points(metric: Metric) -> Metric {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

looks like this may have some allocations involved, could this take a mutable reference and modify it in-place?
or if the lifetimes are hard, maybe use std::mem::take to steal the memory?

/// Generate a new instance of `Self::Output`. Implementations MUST uphold
/// the following properties:
///
/// * `budget` is decremented if and only if return is Ok
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Non-blocking comment, but a suggestion for this API would be to return a tuple of Self::Output (the generated item) and usize (encoded size of generated item) and push this invariant up to the caller to do the accounting. Would slightly simplify the implementations of generate (which are already plenty complex)

@blt blt merged commit 3b56011 into main May 16, 2025
21 checks passed
Copy link
Copy Markdown
Collaborator Author

blt commented May 16, 2025

Merge activity

  • May 16, 12:55 PM EDT: @blt merged this pull request with Graphite.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants