Skip to content

Commit

Permalink
Merge branch 'main' into fix--put-upgrade-guide-to-rename-propagator-…
Browse files Browse the repository at this point in the history
…in-correct-section
  • Loading branch information
NathanielRN authored Nov 2, 2021
2 parents 7fbb62a + 0d0b668 commit 747273f
Show file tree
Hide file tree
Showing 11 changed files with 5 additions and 495 deletions.
56 changes: 1 addition & 55 deletions examples/metrics/metrics/observer.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,66 +27,12 @@ meter.createObservableGauge('cpu_core_usage', {
description: 'Example of a sync observable gauge with callback',
}, async (observableResult) => { // this callback is called once per each interval
await new Promise((resolve) => {
setTimeout(()=> {resolve()}, 50);
setTimeout(() => { resolve(); }, 50);
});
observableResult.observe(getRandomValue(), { core: '1' });
observableResult.observe(getRandomValue(), { core: '2' });
});

// no callback as they will be updated in batch observer
const tempMetric = meter.createObservableGauge('cpu_temp_per_app', {
description: 'Example of sync observable gauge used with async batch observer',
});

// no callback as they will be updated in batch observer
const cpuUsageMetric = meter.createObservableGauge('cpu_usage_per_app', {
description: 'Example of sync observable gauge used with async batch observer',
});

meter.createBatchObserver((batchObserverResult) => {
Promise.all([
someAsyncMetrics(),
// simulate waiting
new Promise((resolve, reject) => {
setTimeout(resolve, 300);
}),
]).then(([apps, waiting]) => {
apps.forEach(app => {
batchObserverResult.observe({ app: app.name, core: '1' }, [
tempMetric.observation(app.core1.temp),
cpuUsageMetric.observation(app.core1.usage),
]);
batchObserverResult.observe({ app: app.name, core: '2' }, [
tempMetric.observation(app.core2.temp),
cpuUsageMetric.observation(app.core2.usage),
]);
});
});
}, {
maxTimeoutUpdateMS: 500,
},
);

function someAsyncMetrics() {
return new Promise((resolve) => {
setTimeout(() => {
const stats = [
{
name: 'app1',
core1: { usage: getRandomValue(), temp: getRandomValue() * 100 },
core2: { usage: getRandomValue(), temp: getRandomValue() * 100 },
},
{
name: 'app2',
core1: { usage: getRandomValue(), temp: getRandomValue() * 100 },
core2: { usage: getRandomValue(), temp: getRandomValue() * 100 },
},
];
resolve(stats);
}, 200);
});
}

function getRandomValue() {
return Math.random();
}
22 changes: 4 additions & 18 deletions experimental/packages/opentelemetry-api-metrics/src/NoopMeter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
* limitations under the License.
*/

import { BatchObserverResult } from './types/BatchObserverResult';
import { Meter } from './types/Meter';
import {
MetricOptions,
Expand Down Expand Up @@ -105,17 +104,6 @@ export class NoopMeter implements Meter {
): ObservableUpDownCounter {
return NOOP_OBSERVABLE_UP_DOWN_COUNTER_METRIC;
}

/**
* Returns constant noop batch observer.
* @param name the name of the metric.
* @param callback the batch observer callback
*/
createBatchObserver(
_callback: (batchObserverResult: BatchObserverResult) => void
): NoopBatchObserver {
return NOOP_BATCH_OBSERVER;
}
}

export class NoopMetric {}
Expand All @@ -141,16 +129,14 @@ export class NoopObservableBaseMetric extends NoopMetric implements ObservableBa
}
}

export class NoopBatchObserver {}

export const NOOP_METER = new NoopMeter();

// Synchronous instruments
export const NOOP_COUNTER_METRIC = new NoopCounterMetric();
export const NOOP_UP_DOWN_COUNTER_METRIC = new NoopUpDownCounterMetric();
export const NOOP_HISTOGRAM_METRIC = new NoopHistogramMetric();
export const NOOP_UP_DOWN_COUNTER_METRIC = new NoopUpDownCounterMetric();

// Asynchronous instruments
export const NOOP_OBSERVABLE_COUNTER_METRIC = new NoopObservableBaseMetric();
export const NOOP_OBSERVABLE_GAUGE_METRIC = new NoopObservableBaseMetric();
export const NOOP_OBSERVABLE_UP_DOWN_COUNTER_METRIC = new NoopObservableBaseMetric();
export const NOOP_OBSERVABLE_COUNTER_METRIC = new NoopObservableBaseMetric();

export const NOOP_BATCH_OBSERVER = new NoopBatchObserver();
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

export * from './NoopMeter';
export * from './NoopMeterProvider';
export * from './types/BatchObserverResult';
export * from './types/Meter';
export * from './types/MeterProvider';
export * from './types/Metric';
Expand Down

This file was deleted.

13 changes: 0 additions & 13 deletions experimental/packages/opentelemetry-api-metrics/src/types/Meter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,11 @@
* limitations under the License.
*/

import { BatchObserverResult } from './BatchObserverResult';
import {
MetricOptions,
Counter,
Histogram,
ObservableGauge,
BatchObserverOptions,
UpDownCounter,
ObservableCounter,
ObservableUpDownCounter,
Expand Down Expand Up @@ -115,15 +113,4 @@ export interface Meter {
options?: MetricOptions,
callback?: (observableResult: ObservableResult) => void
): ObservableUpDownCounter;

/**
* Creates a new `BatchObserver`, can be used to update many metrics
* at the same time and when operations needs to be async
* @param callback the batch observer callback
* @param [options] the batch observer options.
*/
createBatchObserver(
callback: (batchObserverResult: BatchObserverResult) => void,
options?: BatchObserverOptions
): void;
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,6 @@ export interface MetricOptions {
aggregationTemporality?: AggregationTemporality;
}

export interface BatchObserverOptions {
/**
* Indicates how long the batch metric should wait to update before cancel
*/
maxTimeoutUpdateMS?: number;
}

/** The Type of value. It describes how the data is reported. */
export enum ValueType {
INT,
Expand Down
54 changes: 0 additions & 54 deletions experimental/packages/opentelemetry-sdk-metrics-base/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -183,60 +183,6 @@ function getRandomValue() {
}
```

### Batch Observer

Choose this kind of metric when you need to update multiple observables with the results of a single async calculation.

```js
const { MeterProvider } = require('@opentelemetry/sdk-metrics-base');
const { PrometheusExporter } = require('@opentelemetry/exporter-prometheus');

const exporter = new PrometheusExporter(
{
startServer: true,
},
() => {
console.log('prometheus scrape endpoint: http://localhost:9464/metrics');
},
);

const meter = new MeterProvider({
exporter,
interval: 3000,
}).getMeter('example-observer');

const cpuUsageMetric = meter.createObservableGauge('cpu_usage_per_app', {
description: 'CPU',
});

const MemUsageMetric = meter.createObservableGauge('mem_usage_per_app', {
description: 'Memory',
});

meter.createBatchObserver((batchObserverResult) => {
getSomeAsyncMetrics().then(metrics => {
batchObserverResult.observe({ app: 'myApp' }, [
cpuUsageMetric.observation(metrics.value1),
MemUsageMetric.observation(metrics.value2)
]);
});
});

function getSomeAsyncMetrics() {
return new Promise((resolve, reject) => {
setTimeout(() => {
resolve({
value1: Math.random(),
value2: Math.random(),
});
}, 100)
});
}

```

See [examples/prometheus](https://github.com/open-telemetry/opentelemetry-js/tree/main/examples/prometheus) for a short example.

### Histogram

`Histogram` is a non-additive synchronous instrument useful for recording any non-additive number, positive or negative.
Expand Down

This file was deleted.

This file was deleted.

Loading

0 comments on commit 747273f

Please sign in to comment.