-
Notifications
You must be signed in to change notification settings - Fork 821
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(sdk-metrics-base): per metric-reader aggregation
- Loading branch information
1 parent
3cca2ce
commit df29111
Showing
44 changed files
with
771 additions
and
399 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
experimental/packages/opentelemetry-exporter-metrics-otlp-http/src/AggregationSelector.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
import { getEnv } from '@opentelemetry/core'; | ||
import { Aggregation, AggregationSelector, AggregationTemporality, AggregationTemporalitySelector, InstrumentType } from '@opentelemetry/sdk-metrics-base'; | ||
|
||
/** | ||
* Default {@link AggregationTemporalitySelector} when the OTLP Metrics Exporter is configured with environ `OTEL_METRICS_EXPORTER`. | ||
*/ | ||
const CumulativeTemporalitySelector: AggregationTemporalitySelector = () => AggregationTemporality.CUMULATIVE; | ||
|
||
/** | ||
* Default {@link AggregationSelector} when the OTLP Metrics Exporter is configured with environ `OTEL_METRICS_EXPORTER`. | ||
*/ | ||
const DeltaTemporalitySelector: AggregationTemporalitySelector = (instrumentType: InstrumentType) => { | ||
switch (instrumentType) { | ||
case InstrumentType.COUNTER: | ||
case InstrumentType.OBSERVABLE_COUNTER: | ||
case InstrumentType.HISTOGRAM: | ||
case InstrumentType.OBSERVABLE_GAUGE: | ||
return AggregationTemporality.DELTA; | ||
case InstrumentType.UP_DOWN_COUNTER: | ||
case InstrumentType.OBSERVABLE_UP_DOWN_COUNTER: | ||
return AggregationTemporality.CUMULATIVE; | ||
} | ||
}; | ||
|
||
function chooseTemporalitySelector(temporalityPreference?: AggregationTemporality): AggregationTemporalitySelector { | ||
if (temporalityPreference === AggregationTemporality.DELTA) { | ||
return DeltaTemporalitySelector; | ||
} | ||
|
||
return CumulativeTemporalitySelector; | ||
} | ||
|
||
/** | ||
* Get the default {@link AggregationTemporalitySelector} based on the environ `OTEL_EXPORTER_OTLP_METRICS_TEMPORALITY_PREFERENCE`. | ||
*/ | ||
export function getDefaultAggregationTemporalitySelector(): AggregationTemporalitySelector { | ||
const env = getEnv(); | ||
const temporalityPreference = env.OTEL_EXPORTER_OTLP_METRICS_TEMPORALITY_PREFERENCE !== 'cumulative' ? AggregationTemporality.DELTA : AggregationTemporality.CUMULATIVE; | ||
return chooseTemporalitySelector(temporalityPreference); | ||
} | ||
|
||
/** | ||
* Get the default {@link AggregationSelector} based on the environ `OTEL_EXPORTER_OTLP_METRICS_DEFAULT_HISTOGRAM_AGGREGATION`. | ||
*/ | ||
export function getDefaultAggregationSelector(): AggregationSelector { | ||
// TODO(legendecas): exponential bucket histogram support. | ||
return Aggregation.Default; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.