Skip to content

Commit

Permalink
fixup!
Browse files Browse the repository at this point in the history
  • Loading branch information
legendecas committed Dec 8, 2021
1 parent f7a09a2 commit 236463e
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import {

/** Basic aggregator for None which keeps no recorded value. */
export class DropAggregator implements Aggregator<undefined> {
kind: AggregatorKind.NONE = AggregatorKind.NONE;
kind: AggregatorKind.DROP = AggregatorKind.DROP;

createAccumulation() {
return undefined;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@ import {
AccumulationRecord,
Aggregator,
AggregatorKind,
Histogram,
} from './types';
import { Histogram, HistogramMetricData, PointDataType } from '../export/MetricData';
import { HistogramMetricData, PointDataType } from '../export/MetricData';
import { Resource } from '@opentelemetry/resources';
import { InstrumentationLibrary } from '@opentelemetry/core';
import { HrTime } from '@opentelemetry/api';
Expand All @@ -40,7 +41,10 @@ function createNewEmptyCheckpoint(boundaries: number[]): Histogram {
}

export class HistogramAccumulation implements Accumulation {
constructor(private readonly _boundaries: number[], private _current: Histogram = createNewEmptyCheckpoint(_boundaries)) {}
constructor(
private readonly _boundaries: number[],
private _current: Histogram = createNewEmptyCheckpoint(_boundaries)
) {}

record(value: number): void {
this._current.count += 1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,31 +19,54 @@ import { Attributes } from '@opentelemetry/api-metrics';
import { InstrumentationLibrary } from '@opentelemetry/core';
import { Resource } from '@opentelemetry/resources';
import { AggregationTemporality } from '../export/AggregationTemporality';
import { Histogram, MetricData } from '../export/MetricData';
import { MetricData } from '../export/MetricData';
import { InstrumentDescriptor } from '../InstrumentDescriptor';
import { Maybe } from '../utils';

/** The kind of aggregator. */
export enum AggregatorKind {
NONE,
DROP,
SUM,
LAST_VALUE,
HISTOGRAM,
}

/** Sum returns an aggregated sum. */
/** Point type for SumAggregation. */
export type Sum = number;

/** LastValue returns last value. */
/** Point type for LastValueAggregation. */
export type LastValue = number;

export type PointValueType = Sum | LastValue | Histogram;
/** Point type for HistogramAggregation. */
export interface Histogram {
/**
* Buckets are implemented using two different arrays:
* - boundaries: contains every finite bucket boundary, which are inclusive lower bounds
* - counts: contains event counts for each bucket
*
* Note that we'll always have n+1 buckets, where n is the number of boundaries.
* This is because we need to count events that are below the lowest boundary.
*
* Example: if we measure the values: [5, 30, 5, 40, 5, 15, 15, 15, 25]
* with the boundaries [ 10, 20, 30 ], we will have the following state:
*
* buckets: {
* boundaries: [10, 20, 30],
* counts: [3, 3, 1, 2],
* }
*/
buckets: {
boundaries: number[];
counts: number[];
};
sum: number;
count: number;
}

/**
* An Aggregator accumulation state.
*/
export interface Accumulation {
// TODO: attributes and context for `ExemplarReservoir.offer`.
record(value: number): void;
}

Expand Down Expand Up @@ -89,7 +112,7 @@ export interface Aggregator<T> {
* @param resource the resource producing the metric.
* @param instrumentationLibrary the library that instrumented the metric
* @param instrumentDescriptor the metric instrument descriptor.
* @param accumulationByAttributes the array of attributes and accumulation pair.
* @param accumulationByAttributes the array of attributes and accumulation pairs.
* @param temporality the temporality of the accumulation.
* @param sdkStartTime the start time of the sdk.
* @param lastCollectionTime the last collection time of the instrument.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,31 +19,7 @@ import { Attributes } from '@opentelemetry/api-metrics';
import { InstrumentationLibrary } from '@opentelemetry/core';
import { Resource } from '@opentelemetry/resources';
import { InstrumentDescriptor } from '../InstrumentDescriptor';

export interface Histogram {
/**
* Buckets are implemented using two different arrays:
* - boundaries: contains every finite bucket boundary, which are inclusive lower bounds
* - counts: contains event counts for each bucket
*
* Note that we'll always have n+1 buckets, where n is the number of boundaries.
* This is because we need to count events that are below the lowest boundary.
*
* Example: if we measure the values: [5, 30, 5, 40, 5, 15, 15, 15, 25]
* with the boundaries [ 10, 20, 30 ], we will have the following state:
*
* buckets: {
* boundaries: [10, 20, 30],
* counts: [3, 3, 1, 2],
* }
*/
buckets: {
boundaries: number[];
counts: number[];
};
sum: number;
count: number;
}
import { Histogram } from '../aggregator/types';

export interface BaseMetricData {
readonly resource: Resource;
Expand Down Expand Up @@ -73,20 +49,21 @@ export enum PointDataType {
export interface PointData<T> {
/**
* The start epoch timestamp of the PointData, usually the time when
* the metric was created or an aggregation was enabled.
* the metric was created when the preferred AggregationTemporality is
* CUMULATIVE, or last collection time otherwise.
*/
readonly startTime: HrTime;
/**
* The end epoch timestamp when data were collected, usually it represents the moment
* when `Meter.collectAndReset` was called.
* The end epoch timestamp when data were collected, usually it represents
* the moment when `MetricReader.collect` was called.
*/
readonly endTime: HrTime;
/**
* The attributes associated with this PointData.
*/
readonly attributes: Attributes;
/**
* The data {@link PointData}s for this metric, or empty {@code Collection} if no points.
* The data points for this metric.
*/
readonly point: T;
}

0 comments on commit 236463e

Please sign in to comment.