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

Prototype exposing the exemplar reservoir for upcoming spec changes #5960

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

jsuereth
Copy link
Contributor

@jsuereth jsuereth commented Nov 3, 2023

  • Create ExemplarReservoirFactory to help abstract over Double/Long hell
  • Create AggregationExtension that allows specifying an exemplar reservoir factory
  • Add a test which hacks RNG to make sure this all works correctly.

This is for open discussion on how we want to expose customization of ExemplarReservoir to users. One of the two remaining blockers for stabilizing Exemplar specification.

cc @jack-berg

- Create ExemplarReservoirFactory to help abstract over Double/Long hell
- Create AggregationExtension that allows specifying an exemplar reservoir factory
- Add a test which hacks RNG to make sure this all works correctly.
Copy link

codecov bot commented Nov 3, 2023

Codecov Report

Attention: 14 lines in your changes are missing coverage. Please review.

Files Coverage Δ
...etry/sdk/metrics/internal/view/SumAggregation.java 92.30% <100.00%> (+1.39%) ⬆️
...nal/view/Base2ExponentialHistogramAggregation.java 95.45% <88.88%> (-4.55%) ⬇️
...try/sdk/metrics/internal/view/DropAggregation.java 66.66% <0.00%> (-13.34%) ⬇️
...ernal/view/ExplicitBucketHistogramAggregation.java 94.73% <87.50%> (-5.27%) ⬇️
...dk/metrics/internal/view/LastValueAggregation.java 82.35% <91.66%> (+7.35%) ⬆️
...cs/internal/exemplar/ExemplarReservoirFactory.java 66.66% <66.66%> (ø)
.../sdk/metrics/internal/view/DefaultAggregation.java 70.37% <66.66%> (-12.97%) ⬇️

... and 5 files with indirect coverage changes

📢 Thoughts on this report? Let us know!.

View.builder()
.setAggregation(
((AggregationExtension) Aggregation.sum())
.setExemplarReservoirFactory(reservoirFactory))
Copy link
Member

Choose a reason for hiding this comment

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

Should exemplar reservoir be a configuration parameter that hangs off an aggregation or a top level view config option? I.e. View.builder.setExemplarReservoirFactory(...).setAggregation(..)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is one of the things we need to decide.

  • Right now, ExemplarReservoir (defaults) are decided by aggregation.
  • If a user wanted to leverage "default" aggregation, but different reservoir by-instrument type or aggregator choice, we're actually lacking an interplay between those two. E.g. trying to ensure Explicit buckets are the same between exemplars + histograms.

Personally, I think we could go either way here. I'm happy to extract it out further if we want.

Copy link
Member

Choose a reason for hiding this comment

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

Another interesting side affect of having exemplar reservoir be a configurable property of Aggregation is that it causes the reservoir be something that MetricReader / MetricExporter have influence over, since MetricReader / MetricExporter can dictate the default Aggregation as a function of instrument kind.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I actually really like that interaction. It allows exporters to optimise exemplar choice for the backend they speak to. Do you think we should encode this in the specification?

Copy link
Member

Choose a reason for hiding this comment

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

I think it ought to be in the spec if we're going to allow that type of configuration in the java implementation.

Another thought: I think we probably should introduce an AggregationBuilder instead of allowing Aggregation instances to be mutated after instantiation with setAggregation.

I propose we add new method static AggregationBuilder Aggregation#builder() for accessing an AggregationBuilder, defined as follows:

public interface AggregationBuilder {

  // Configure aggregation
  AggregationBuilder setDrop();
  AggregationBuilder setSum();
  AggregationBuilder setLastValue();
  AggregationBuilder setExplicitBucketHistogram();
  AggregationBuilder setExplicitBucketHistogram(List<Double> bucketBoundaries);
  AggregationBuilder setBase2ExponentialHistogram();
  AggregationBuilder setBase2ExponentialHistogram(int maxBuckets, int maxScale);

  // Configure reservoir
  AggregationBuilder setExemplarReservoirFactory(Supplier<ExemplarReservoir<?>> factory);

  Aggregation build();
  
}

Usage would be something like:

    SdkMeterProvider.builder()
        .registerView(
            InstrumentSelector.builder().build(),
            View.builder()
                .setAggregation(Aggregation.builder()
                    .setSum()
                    .setExemplarReservoirFactory(ExemplarReservoirFactory.noSamples())
                    .build())
                .build());

@jack-berg
Copy link
Member

Just the one comment but conceptually I think this makes sense.

@jsuereth
Copy link
Contributor Author

jsuereth commented Nov 3, 2023

Wanted to add another comment about things we should likely be exposing to users with this change (once specification is written and publicized):

  • ExemplarReservoirFactory would be exposed in some fashion. We can play with its final API to limit it if we'd like, or even expose it to InstrumentationDescriptor if we think that's necessary. I like keeping it simple, as it is today.
  • ExemplarReservoir the interface would have to be exposed so you can implement it.
  • I also believe that due to the complexities in making an efficient reservoir, we should expose:
    • FixedSizeExemplarReservoir as the baseline abstraction users can use to build their own reservoirs. This would remain abstract.
    • ReservoirCellSelector as the key component a user would be overriding in most implementations.
    • ReservoirCell as the key mechanism to pre-allocate memory and avoid memory issues in reservoirs. This would be marked final.


@Override
public String toString() {
return "fixedSize(" + size + ")";
Copy link
Member

Choose a reason for hiding this comment

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

I'd like to see this split out into a class so we can provide a more conventional toString implementation:

Suggested change
return "fixedSize(" + size + ")";
return "FixedSizeReservoirFactory(" + size + ")";

this(
ExemplarReservoirFactory.fixedSize(
Clock.getDefault(),
Runtime.getRuntime().availableProcessors(),
Copy link
Member

Choose a reason for hiding this comment

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

Do we still think Runtime.getRuntime().availableProcessors() is best if the spec provides the new language:

the default size MAY be
the number of possible concurrent threads (e.g. numer of CPUs) to help reduce
contention. Otherwise, a default size of 1 SHOULD be used.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I wrote the specification with this bit of code in mind.... What would you instead like to see?

The rationale here was a measurable difference in contention.

return new ExplicitBucketHistogramAggregation(bucketBoundaries);
return new ExplicitBucketHistogramAggregation(
bucketBoundaries,
ExemplarReservoirFactory.histogramBucket(Clock.getDefault(), bucketBoundaries));
Copy link
Member

Choose a reason for hiding this comment

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

I realized that we need to use fixed size by default if bucketBoundaries.size() == 0.

View.builder()
.setAggregation(
((AggregationExtension) Aggregation.sum())
.setExemplarReservoirFactory(reservoirFactory))
Copy link
Member

Choose a reason for hiding this comment

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

I think it ought to be in the spec if we're going to allow that type of configuration in the java implementation.

Another thought: I think we probably should introduce an AggregationBuilder instead of allowing Aggregation instances to be mutated after instantiation with setAggregation.

I propose we add new method static AggregationBuilder Aggregation#builder() for accessing an AggregationBuilder, defined as follows:

public interface AggregationBuilder {

  // Configure aggregation
  AggregationBuilder setDrop();
  AggregationBuilder setSum();
  AggregationBuilder setLastValue();
  AggregationBuilder setExplicitBucketHistogram();
  AggregationBuilder setExplicitBucketHistogram(List<Double> bucketBoundaries);
  AggregationBuilder setBase2ExponentialHistogram();
  AggregationBuilder setBase2ExponentialHistogram(int maxBuckets, int maxScale);

  // Configure reservoir
  AggregationBuilder setExemplarReservoirFactory(Supplier<ExemplarReservoir<?>> factory);

  Aggregation build();
  
}

Usage would be something like:

    SdkMeterProvider.builder()
        .registerView(
            InstrumentSelector.builder().build(),
            View.builder()
                .setAggregation(Aggregation.builder()
                    .setSum()
                    .setExemplarReservoirFactory(ExemplarReservoirFactory.noSamples())
                    .build())
                .build());

carlosalberto pushed a commit to open-telemetry/opentelemetry-specification that referenced this pull request Jan 31, 2024
Fixes #2922
Fixes #3812 
Related to #3756

## Changes

- Cleans up language around exposing `ExemplarReservoir`. (Remove TODO,
e.g.)
- Remove `ExemplarFilter` interface but keep configuration options. (see
#3812)
- Clarify / simplify Spec Compliance matrix for existing state of the
Exemplar Specification.


Prototype in java:
open-telemetry/opentelemetry-java#5960
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.

None yet

2 participants