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 java.lang.Object implements SynchronousMetricStorage
Stores aggregatedMetricDatafor 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 Classes Modifier and Type Class Description private static classDefaultSynchronousMetricStorage.AggregatorHolder<T extends PointData,U extends ExemplarData>
-
Field Summary
Fields Modifier and Type Field Description private AggregationTemporalityaggregationTemporalityprivate Aggregator<T,U>aggregatorprivate java.util.concurrent.ConcurrentLinkedQueue<AggregatorHandle<T,U>>aggregatorHandlePoolprivate DefaultSynchronousMetricStorage.AggregatorHolder<T,U>aggregatorHolderprivate AttributesProcessorattributesProcessorprivate static java.util.logging.LoggerinternalLoggerprivate ThrottlingLoggerloggerprivate intmaxCardinalityThis field is set to 1 less than the actual intended cardinality limit, allowing the last slot to be filled by theMetricStorage.CARDINALITY_OVERFLOWseries.private MemoryModememoryModeprivate MetricDescriptormetricDescriptorprivate java.util.concurrent.ConcurrentHashMap<Attributes,AggregatorHandle<T,U>>previousCollectionAggregatorHandlesprivate RegisteredReaderregisteredReaderprivate java.util.ArrayList<T>reusableResultList-
Fields inherited from interface io.opentelemetry.sdk.metrics.internal.state.MetricStorage
CARDINALITY_OVERFLOW, DEFAULT_MAX_CARDINALITY
-
-
Constructor Summary
Constructors Constructor Description DefaultSynchronousMetricStorage(RegisteredReader registeredReader, MetricDescriptor metricDescriptor, Aggregator<T,U> aggregator, AttributesProcessor attributesProcessor, int maxCardinality)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description MetricDatacollect(Resource resource, InstrumentationScopeInfo instrumentationScopeInfo, long startEpochNanos, long epochNanos)Collects the metrics from this storage.private AggregatorHandle<T,U>getAggregatorHandle(java.util.concurrent.ConcurrentHashMap<Attributes,AggregatorHandle<T,U>> aggregatorHandles, Attributes attributes, Context context)(package private) java.util.Queue<AggregatorHandle<T,U>>getAggregatorHandlePool()private DefaultSynchronousMetricStorage.AggregatorHolder<T,U>getHolderForRecord()Obtain the AggregatorHolder for recording measurements, re-reading the volatile this.aggregatorHolder until we access one where recordsInProgress is even.MetricDescriptorgetMetricDescriptor()Returns a description of the metric produced in this storage.booleanisEnabled()Returnstrueif the storage is actively recording measurements, andfalseotherwise (i.e.voidrecordDouble(double value, Attributes attributes, Context context)Records a measurement.voidrecordLong(long value, Attributes attributes, Context context)Records a measurement.private voidreleaseHolderForRecord(DefaultSynchronousMetricStorage.AggregatorHolder<T,U> aggregatorHolder)Called on theDefaultSynchronousMetricStorage.AggregatorHolderobtained 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 Detail
-
internalLogger
private static final java.util.logging.Logger internalLogger
-
logger
private final ThrottlingLogger logger
-
registeredReader
private final RegisteredReader registeredReader
-
metricDescriptor
private final MetricDescriptor metricDescriptor
-
aggregationTemporality
private final AggregationTemporality aggregationTemporality
-
aggregator
private final Aggregator<T extends PointData,U extends ExemplarData> aggregator
-
aggregatorHolder
private volatile DefaultSynchronousMetricStorage.AggregatorHolder<T extends PointData,U extends ExemplarData> aggregatorHolder
-
attributesProcessor
private final AttributesProcessor attributesProcessor
-
memoryMode
private final MemoryMode memoryMode
-
previousCollectionAggregatorHandles
private volatile java.util.concurrent.ConcurrentHashMap<Attributes,AggregatorHandle<T extends PointData,U extends ExemplarData>> previousCollectionAggregatorHandles
-
maxCardinality
private final int maxCardinality
This field is set to 1 less than the actual intended cardinality limit, allowing the last slot to be filled by theMetricStorage.CARDINALITY_OVERFLOWseries.
-
aggregatorHandlePool
private final java.util.concurrent.ConcurrentLinkedQueue<AggregatorHandle<T extends PointData,U extends ExemplarData>> aggregatorHandlePool
-
-
Constructor Detail
-
DefaultSynchronousMetricStorage
DefaultSynchronousMetricStorage(RegisteredReader registeredReader, MetricDescriptor metricDescriptor, Aggregator<T,U> aggregator, AttributesProcessor attributesProcessor, int maxCardinality)
-
-
Method Detail
-
getAggregatorHandlePool
java.util.Queue<AggregatorHandle<T,U>> getAggregatorHandlePool()
-
recordLong
public void recordLong(long value, Attributes attributes, Context context)Description copied from interface:WriteableMetricStorageRecords a measurement.- Specified by:
recordLongin interfaceWriteableMetricStorage
-
recordDouble
public void recordDouble(double value, Attributes attributes, Context context)Description copied from interface:WriteableMetricStorageRecords a measurement.- Specified by:
recordDoublein interfaceWriteableMetricStorage
-
isEnabled
public boolean isEnabled()
Description copied from interface:WriteableMetricStorageReturnstrueif the storage is actively recording measurements, andfalseotherwise (i.e. noop / empty metric storage is installed).- Specified by:
isEnabledin interfaceWriteableMetricStorage
-
getHolderForRecord
private DefaultSynchronousMetricStorage.AggregatorHolder<T,U> 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.AggregatorHolderobtained fromgetHolderForRecord()to indicate that recording is complete, and it is safe to collect.
-
getAggregatorHandle
private AggregatorHandle<T,U> getAggregatorHandle(java.util.concurrent.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:MetricStorageCollects the metrics from this storage. If storingAggregationTemporality.DELTAmetrics, reset for the next collection period.Note: This is a stateful operation and will reset any interval-related state for the
collector.- Specified by:
collectin 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
MetricDatafrom this collection period.
-
getMetricDescriptor
public MetricDescriptor getMetricDescriptor()
Description copied from interface:MetricStorageReturns a description of the metric produced in this storage.- Specified by:
getMetricDescriptorin interfaceMetricStorage
-
-