Class DefaultSynchronousMetricStorage<T extends PointData,U extends ExemplarData>
java.lang.Object
io.opentelemetry.sdk.metrics.internal.state.DefaultSynchronousMetricStorage<T,U>
- All Implemented Interfaces:
MetricStorage
,SynchronousMetricStorage
,WriteableMetricStorage
public final class DefaultSynchronousMetricStorage<T extends PointData,U extends ExemplarData>
extends Object
implements SynchronousMetricStorage
Stores aggregated
MetricData
for synchronous instruments.
This class is internal and is hence not for public use. Its APIs are unstable and can change at any time.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static class
DefaultSynchronousMetricStorage.AggregatorHolder<T extends PointData,
U extends ExemplarData> -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final AggregationTemporality
private final Aggregator
<T, U> private final ConcurrentLinkedQueue
<AggregatorHandle<T, U>> private final AttributesProcessor
private static final Logger
private final ThrottlingLogger
private final int
This field is set to 1 less than the actual intended cardinality limit, allowing the last slot to be filled by theMetricStorage.CARDINALITY_OVERFLOW
series.private final MemoryMode
private final MetricDescriptor
private ConcurrentHashMap
<Attributes, AggregatorHandle<T, U>> private final RegisteredReader
Fields inherited from interface io.opentelemetry.sdk.metrics.internal.state.MetricStorage
CARDINALITY_OVERFLOW, DEFAULT_MAX_CARDINALITY
-
Constructor Summary
ConstructorsConstructorDescriptionDefaultSynchronousMetricStorage
(RegisteredReader registeredReader, MetricDescriptor metricDescriptor, Aggregator<T, U> aggregator, AttributesProcessor attributesProcessor, int maxCardinality) -
Method Summary
Modifier and TypeMethodDescriptioncollect
(Resource resource, InstrumentationScopeInfo instrumentationScopeInfo, long startEpochNanos, long epochNanos) Collects the metrics from this storage.private AggregatorHandle
<T, U> getAggregatorHandle
(ConcurrentHashMap<Attributes, AggregatorHandle<T, U>> aggregatorHandles, Attributes attributes, Context context) (package private) Queue
<AggregatorHandle<T, U>> Obtain the AggregatorHolder for recording measurements, re-reading the volatile this.aggregatorHolder until we access one where recordsInProgress is even.Returns a description of the metric produced in this storage.boolean
Returnstrue
if the storage is actively recording measurements, andfalse
otherwise (i.e.void
recordDouble
(double value, Attributes attributes, Context context) Records a measurement.void
recordLong
(long value, Attributes attributes, Context context) Records a measurement.private void
releaseHolderForRecord
(DefaultSynchronousMetricStorage.AggregatorHolder<T, U> aggregatorHolder) Called on theDefaultSynchronousMetricStorage.AggregatorHolder
obtained fromgetHolderForRecord()
to indicate that recording is complete, and it is safe to collect.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface io.opentelemetry.sdk.metrics.internal.state.MetricStorage
isEmpty
-
Field Details
-
internalLogger
-
logger
-
registeredReader
-
metricDescriptor
-
aggregationTemporality
-
aggregator
-
aggregatorHolder
private volatile DefaultSynchronousMetricStorage.AggregatorHolder<T extends PointData,U extends ExemplarData> aggregatorHolder -
attributesProcessor
-
memoryMode
-
reusableResultList
-
previousCollectionAggregatorHandles
private volatile ConcurrentHashMap<Attributes,AggregatorHandle<T extends PointData, previousCollectionAggregatorHandlesU extends ExemplarData>> -
maxCardinality
private final int maxCardinalityThis field is set to 1 less than the actual intended cardinality limit, allowing the last slot to be filled by theMetricStorage.CARDINALITY_OVERFLOW
series. -
aggregatorHandlePool
private final ConcurrentLinkedQueue<AggregatorHandle<T extends PointData,U extends ExemplarData>> aggregatorHandlePool
-
-
Constructor Details
-
DefaultSynchronousMetricStorage
DefaultSynchronousMetricStorage(RegisteredReader registeredReader, MetricDescriptor metricDescriptor, Aggregator<T, U> aggregator, AttributesProcessor attributesProcessor, int maxCardinality)
-
-
Method Details
-
getAggregatorHandlePool
Queue<AggregatorHandle<T,U>> getAggregatorHandlePool() -
recordLong
Description copied from interface:WriteableMetricStorage
Records a measurement.- Specified by:
recordLong
in interfaceWriteableMetricStorage
-
recordDouble
Description copied from interface:WriteableMetricStorage
Records a measurement.- Specified by:
recordDouble
in interfaceWriteableMetricStorage
-
isEnabled
public boolean isEnabled()Description copied from interface:WriteableMetricStorage
Returnstrue
if the storage is actively recording measurements, andfalse
otherwise (i.e. noop / empty metric storage is installed).- Specified by:
isEnabled
in interfaceWriteableMetricStorage
-
getHolderForRecord
Obtain the AggregatorHolder for recording measurements, re-reading the volatile this.aggregatorHolder until we access one where recordsInProgress is even. Collect sets recordsInProgress to odd as a signal that AggregatorHolder is stale and is being replaced. Record operations increment recordInProgress by 2. Callers MUST callreleaseHolderForRecord(AggregatorHolder)
when record operation completes to signal to that its safe to proceed with Collect operations. -
releaseHolderForRecord
private void releaseHolderForRecord(DefaultSynchronousMetricStorage.AggregatorHolder<T, U> aggregatorHolder) Called on theDefaultSynchronousMetricStorage.AggregatorHolder
obtained fromgetHolderForRecord()
to indicate that recording is complete, and it is safe to collect. -
getAggregatorHandle
private AggregatorHandle<T,U> getAggregatorHandle(ConcurrentHashMap<Attributes, AggregatorHandle<T, U>> aggregatorHandles, Attributes attributes, Context context) -
collect
public MetricData collect(Resource resource, InstrumentationScopeInfo instrumentationScopeInfo, long startEpochNanos, long epochNanos) Description copied from interface:MetricStorage
Collects the metrics from this storage. If storingAggregationTemporality.DELTA
metrics, reset for the next collection period.Note: This is a stateful operation and will reset any interval-related state for the
collector
.- Specified by:
collect
in interfaceMetricStorage
- Parameters:
resource
- The resource associated with the metrics.instrumentationScopeInfo
- The instrumentation scope generating the metrics.startEpochNanos
- The start timestamp for this SDK.epochNanos
- The timestamp for this collection.- Returns:
- The
MetricData
from this collection period.
-
getMetricDescriptor
Description copied from interface:MetricStorage
Returns a description of the metric produced in this storage.- Specified by:
getMetricDescriptor
in interfaceMetricStorage
-