|
1 | 1 | // Copyright The OpenTelemetry Authors
|
2 | 2 | // SPDX-License-Identifier: Apache-2.0
|
3 | 3 |
|
| 4 | +#if EXPOSE_EXPERIMENTAL_FEATURES && NET8_0_OR_GREATER |
| 5 | +using System.Diagnostics.CodeAnalysis; |
| 6 | +#endif |
4 | 7 | using OpenTelemetry.Internal;
|
5 | 8 |
|
6 | 9 | namespace OpenTelemetry.Metrics;
|
7 | 10 |
|
8 |
| -internal abstract class FixedSizeExemplarReservoir : ExemplarReservoir |
| 11 | +#if EXPOSE_EXPERIMENTAL_FEATURES |
| 12 | +/// <summary> |
| 13 | +/// An <see cref="ExemplarReservoir"/> implementation which contains a fixed |
| 14 | +/// number of <see cref="Exemplar"/>s. |
| 15 | +/// </summary> |
| 16 | +/// <remarks><inheritdoc cref="ExemplarReservoir" path="/remarks/para[@experimental-warning='true']"/></remarks> |
| 17 | +#if NET8_0_OR_GREATER |
| 18 | +[Experimental(DiagnosticDefinitions.ExemplarReservoirExperimentalApi, UrlFormat = DiagnosticDefinitions.ExperimentalApiUrlFormat)] |
| 19 | +#endif |
| 20 | +public |
| 21 | +#else |
| 22 | +internal |
| 23 | +#endif |
| 24 | + abstract class FixedSizeExemplarReservoir : ExemplarReservoir |
9 | 25 | {
|
10 | 26 | private readonly Exemplar[] runningExemplars;
|
11 | 27 | private readonly Exemplar[] snapshotExemplars;
|
12 | 28 |
|
| 29 | + /// <summary> |
| 30 | + /// Initializes a new instance of the <see cref="FixedSizeExemplarReservoir"/> class. |
| 31 | + /// </summary> |
| 32 | + /// <param name="capacity">The capacity (number of <see cref="Exemplar"/>s) |
| 33 | + /// to be contained in the reservoir.</param> |
| 34 | +#pragma warning disable RS0022 // Constructor make noninheritable base class inheritable |
13 | 35 | protected FixedSizeExemplarReservoir(int capacity)
|
| 36 | +#pragma warning restore RS0022 // Constructor make noninheritable base class inheritable |
14 | 37 | {
|
| 38 | + // Note: RS0022 is suppressed because we do want to allow custom |
| 39 | + // ExemplarReservoir implementations to be created by deriving from |
| 40 | + // FixedSizeExemplarReservoir. |
| 41 | + |
15 | 42 | Guard.ThrowIfOutOfRange(capacity, min: 1);
|
16 | 43 |
|
17 | 44 | this.runningExemplars = new Exemplar[capacity];
|
18 | 45 | this.snapshotExemplars = new Exemplar[capacity];
|
19 | 46 | this.Capacity = capacity;
|
20 | 47 | }
|
21 | 48 |
|
22 |
| - internal int Capacity { get; } |
| 49 | + /// <summary> |
| 50 | + /// Gets the capacity (number of <see cref="Exemplar"/>s) contained in the |
| 51 | + /// reservoir. |
| 52 | + /// </summary> |
| 53 | + public int Capacity { get; } |
23 | 54 |
|
24 | 55 | /// <summary>
|
25 | 56 | /// Collects all the exemplars accumulated by the Reservoir.
|
@@ -56,12 +87,48 @@ internal sealed override void Initialize(AggregatorStore aggregatorStore)
|
56 | 87 | base.Initialize(aggregatorStore);
|
57 | 88 | }
|
58 | 89 |
|
| 90 | + internal void UpdateExemplar<T>( |
| 91 | + int exemplarIndex, |
| 92 | + in ExemplarMeasurement<T> measurement) |
| 93 | + where T : struct |
| 94 | + { |
| 95 | + this.runningExemplars[exemplarIndex].Update(in measurement); |
| 96 | + } |
| 97 | + |
| 98 | + /// <summary> |
| 99 | + /// Fired when <see cref="Collect"/> has finished before returning a <see cref="ReadOnlyExemplarCollection"/>. |
| 100 | + /// </summary> |
| 101 | + /// <remarks> |
| 102 | + /// Note: This method is typically used to reset the state of reservoirs and |
| 103 | + /// is called regardless of the value of <see |
| 104 | + /// cref="ExemplarReservoir.ResetOnCollect"/>. |
| 105 | + /// </remarks> |
59 | 106 | protected virtual void OnCollected()
|
60 | 107 | {
|
61 | 108 | }
|
62 | 109 |
|
63 |
| - protected void UpdateExemplar<T>(int exemplarIndex, in ExemplarMeasurement<T> measurement) |
64 |
| - where T : struct |
| 110 | + /// <summary> |
| 111 | + /// Updates the <see cref="Exemplar"/> stored in the reservoir at the |
| 112 | + /// specified index with an <see cref="ExemplarMeasurement{T}"/>. |
| 113 | + /// </summary> |
| 114 | + /// <param name="exemplarIndex">Index of the <see cref="Exemplar"/> to update.</param> |
| 115 | + /// <param name="measurement"><see cref="ExemplarMeasurement{T}"/>.</param> |
| 116 | + protected void UpdateExemplar( |
| 117 | + int exemplarIndex, |
| 118 | + in ExemplarMeasurement<long> measurement) |
| 119 | + { |
| 120 | + this.runningExemplars[exemplarIndex].Update(in measurement); |
| 121 | + } |
| 122 | + |
| 123 | + /// <summary> |
| 124 | + /// Updates the <see cref="Exemplar"/> stored in the reservoir at the |
| 125 | + /// specified index with an <see cref="ExemplarMeasurement{T}"/>. |
| 126 | + /// </summary> |
| 127 | + /// <param name="exemplarIndex">Index of the <see cref="Exemplar"/> to update.</param> |
| 128 | + /// <param name="measurement"><see cref="ExemplarMeasurement{T}"/>.</param> |
| 129 | + protected void UpdateExemplar( |
| 130 | + int exemplarIndex, |
| 131 | + in ExemplarMeasurement<double> measurement) |
65 | 132 | {
|
66 | 133 | this.runningExemplars[exemplarIndex].Update(in measurement);
|
67 | 134 | }
|
|
0 commit comments