Skip to content
This repository was archived by the owner on Oct 3, 2023. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,24 @@ All notable changes to this project will be documented in this file.
- Add support for supplying instrumentation configuration via tracing option. Option argument added to instrumentation interface.
- Add ignoreIncomingPaths and ignoreOutgoingUrls support to the http and https tracing instrumentations.

**Contains API breaking changes for trace implementations**
**This release has multiple breaking changes. Please test your code accordingly after upgrading.**

- Modify `Logger` interface: `level` made optional, `silly` removed.
- The ```new Stats()``` has been deprecated on Stats class. The global singleton ```stats``` object should be used instead.

##### Old code
```js
const { Stats } = require("@opencensus/core");
const stats = new Stats();
stats.createView(...);
```

##### New code
```js
// Get the global singleton stats object
const { stats } = require("@opencensus/core");
stats.createView(...);
```

## 0.0.8 - 2018-12-14
**Contains API breaking changes for stats/metrics implementations**
Expand Down
6 changes: 5 additions & 1 deletion packages/opencensus-core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ export * from './exporters/console-exporter';
// STATS CLASSES

// classes
export * from './stats/stats';
export * from './stats/view';
export * from './stats/recorder';
export * from './stats/bucket-boundaries';
Expand All @@ -90,3 +89,8 @@ export * from './metrics/metric-registry';
// GAUGES CLASSES
export * from './metrics/gauges/derived-gauge';
export * from './metrics/gauges/gauge';

// Stats singleton instance
import {Stats} from './stats/stats';
const stats = Stats.instance;
export {stats};
17 changes: 12 additions & 5 deletions packages/opencensus-core/src/stats/stats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@
import * as defaultLogger from '../common/console-logger';
import * as loggerTypes from '../common/types';
import {StatsEventListener} from '../exporters/types';
import {MetricProducer} from '../metrics/export/types';
import {Metric} from '../metrics/export/types';
import {Metrics} from '../metrics/metrics';
import {MetricProducerForStats} from './metric-producer';

import {AggregationType, Measure, Measurement, MeasureType, MeasureUnit, View} from './types';
import {BaseView} from './view';
Expand All @@ -29,6 +32,8 @@ export class Stats {
private registeredViews: {[key: string]: View[]} = {};
/** An object to log information to */
private logger: loggerTypes.Logger;
/** Singleton instance */
private static singletonInstance: Stats;

/**
* Creates stats
Expand All @@ -37,13 +42,15 @@ export class Stats {
constructor(logger = defaultLogger) {
this.logger = logger.logger();

// TODO (mayurkale): Decide how to inject MetricProducerForStats.
// It should be something like below, but looks like not the right place.

// Create a new MetricProducerForStats and register it to
// MetricProducerManager when Stats is initialized.
// const metricProducer: MetricProducer = new MetricProducerForStats(this);
// Metrics.getMetricProducerManager().add(metricProducer);
const metricProducer: MetricProducer = new MetricProducerForStats(this);
Metrics.getMetricProducerManager().add(metricProducer);
}

/** Gets the stats instance. */
static get instance(): Stats {
return this.singletonInstance || (this.singletonInstance = new this());
}

/**
Expand Down
3 changes: 1 addition & 2 deletions packages/opencensus-core/test/test-metric-producer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,11 @@
*/

import * as assert from 'assert';
import {AggregationType, Measurement, MeasureUnit, Stats, Tags, View} from '../src';
import {AggregationType, Measurement, MeasureUnit, stats, Tags, View} from '../src';
import {LabelKey, LabelValue, MetricDescriptorType} from '../src/metrics/export/types';
import {MetricProducerForStats} from '../src/stats/metric-producer';

describe('Metric producer for stats', () => {
const stats = new Stats();
const metricProducerForStats = new MetricProducerForStats(stats);

// constants for view name
Expand Down
20 changes: 19 additions & 1 deletion packages/opencensus-core/test/test-stats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
*/

import * as assert from 'assert';
import {BaseView, Stats, StatsEventListener} from '../src';
import {BaseView, StatsEventListener} from '../src';
import {Stats} from '../src/stats/stats';
import {AggregationType, LastValueData, Measure, Measurement, MeasureType, MeasureUnit, View} from '../src/stats/types';

class TestExporter implements StatsEventListener {
Expand Down Expand Up @@ -54,6 +55,23 @@ describe('Stats', () => {
const measureUnit = MeasureUnit.UNIT;
const description = 'test description';

/** Should create a Stats instance */
describe('new Stats()', () => {
it('should create a Stats instance', () => {
const stats = new Stats();
assert.ok(stats instanceof Stats);
});
});


/** Should get the singleton stats instance. */
describe('static get instance()', () => {
it('should get the singleton stats instance', () => {
const stats = Stats.instance;
assert.ok(stats instanceof Stats);
});
});

describe('createMeasureDouble()', () => {
it('should create a measure of type double', () => {
const measureDouble =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

import {AggregationType, Measure, MeasureUnit, Stats} from '@opencensus/core';
import {AggregationType, Measure, MeasureUnit, stats} from '@opencensus/core';
import * as assert from 'assert';
import * as http from 'http';
import {PrometheusStatsExporter} from '../src/';
Expand All @@ -26,10 +26,8 @@ describe('Prometheus Stats Exporter', () => {
const tagKeys = Object.keys(tags);
let exporter: PrometheusStatsExporter;
let measure: Measure;
let stats: Stats;

beforeEach((done) => {
stats = new Stats();
measure = stats.createMeasureDouble('testMeasureDouble', MeasureUnit.UNIT);
exporter = new PrometheusStatsExporter(options);
stats.registerExporter(exporter);
Expand Down Expand Up @@ -195,10 +193,8 @@ describe('Prometheus Stats Exporter with prefix option', () => {
const tagKeys = Object.keys(tags);
let exporter: PrometheusStatsExporter;
let measure: Measure;
let stats: Stats;

beforeEach((done) => {
stats = new Stats();
measure = stats.createMeasureDouble('testMeasureDouble', MeasureUnit.UNIT);
exporter = new PrometheusStatsExporter(options);
stats.registerExporter(exporter);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

import {AggregationType, BaseView, logger, Logger, Measurement, MeasureUnit, Stats} from '@opencensus/core';
import {AggregationType, BaseView, logger, Logger, Measurement, MeasureUnit, stats} from '@opencensus/core';
import * as assert from 'assert';
import * as fs from 'fs';
import * as nock from 'nock';
Expand Down Expand Up @@ -60,7 +60,6 @@ describe('Stackdriver Stats Exporter', function() {
const exporterTestLogger = new ExporterTestLogger();
let exporterOptions: StackdriverExporterOptions;
let exporter: StackdriverStatsExporter;
const stats = new Stats();

const tags = {tagKey1: 'valueKey1'};
const tagKeys = Object.keys(tags);
Expand Down
43 changes: 33 additions & 10 deletions packages/opencensus-exporter-zpages/test/test-zpages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

import {AggregationType, CountData, DistributionData, Measure, Measurement, MeasureUnit, RootSpan, Stats, SumData, Tags, TracerConfig} from '@opencensus/core';
import {AggregationType, CountData, DistributionData, Measure, Measurement, MeasureUnit, RootSpan, SumData, Tags, TracerConfig} from '@opencensus/core';
import * as assert from 'assert';
import axios from 'axios';
import * as http from 'http';
Expand Down Expand Up @@ -243,20 +243,13 @@ describe('Zpages Exporter', () => {
return tags[tagKey];
});
let zpages: ZpagesExporter;
let stats: Stats;
let measure: Measure;
let zpagesData: StatsViewData;
let measurement: Measurement;
let measurement2: Measurement;

beforeEach((done) => {
stats = new Stats();
zpages = new ZpagesExporter(options);
stats.registerExporter(zpages);
measure = stats.createMeasureDouble(
'testMeasureDouble', MeasureUnit.UNIT, 'A test measure');
measurement = {measure, tags, value: 22};
measurement2 = {measure, tags, value: 11};
zpages.startServer(done);
});

Expand All @@ -265,7 +258,15 @@ describe('Zpages Exporter', () => {
});

describe('with COUNT aggregation type', () => {
/** Creating here because stats is a singleton */
const {stats} = require('@opencensus/core');
measure = stats.createMeasureDouble(
'testMeasureDouble', MeasureUnit.UNIT, 'A test measure');
measurement = {measure, tags, value: 22};
measurement2 = {measure, tags, value: 11};

it('should get view information', async () => {
stats.registerExporter(zpages);
stats.createView(
'test/CountView', measure, AggregationType.COUNT, tagKeys,
'A count test', null);
Expand All @@ -280,6 +281,7 @@ describe('Zpages Exporter', () => {
});

it('should get stats for view', async () => {
stats.registerExporter(zpages);
stats.createView(
'test/CountView', measure, AggregationType.COUNT, tagKeys,
'A count test', null);
Expand All @@ -298,6 +300,12 @@ describe('Zpages Exporter', () => {
});

describe('with SUM aggregation type', () => {
/** Creating here because stats is a singleton */
const {stats} = require('@opencensus/core');
measure = stats.createMeasureDouble(
'testMeasureDouble', MeasureUnit.UNIT, 'A test measure');
measurement = {measure, tags, value: 22};
measurement2 = {measure, tags, value: 11};
it('should get view information', async () => {
stats.registerExporter(zpages);
stats.createView(
Expand Down Expand Up @@ -334,6 +342,13 @@ describe('Zpages Exporter', () => {
});

describe('with LAST VALUE aggregation type', () => {
/** Creating here because stats is a singleton */
const {stats} = require('@opencensus/core');
measure = stats.createMeasureDouble(
'testMeasureDouble', MeasureUnit.UNIT, 'A test measure');
measurement = {measure, tags, value: 22};
measurement2 = {measure, tags, value: 11};

it('should get view information', async () => {
stats.registerExporter(zpages);
stats.createView(
Expand Down Expand Up @@ -370,6 +385,13 @@ describe('Zpages Exporter', () => {
});

describe('with DISTRIBUTION aggregation type', () => {
/** Creating here because stats is a singleton */
const {stats} = require('@opencensus/core');
measure = stats.createMeasureDouble(
'testMeasureDouble', MeasureUnit.UNIT, 'A test measure');
measurement = {measure, tags, value: 22};
measurement2 = {measure, tags, value: 11};

it('should get view information', async () => {
const boundaries = [10, 20, 30, 40];
stats.registerExporter(zpages);
Expand Down Expand Up @@ -414,12 +436,13 @@ describe('Zpages Exporter', () => {

describe('when a view is accessed in rpcz page', () => {
let zpages: ZpagesExporter;
let stats: Stats;
let rpczData: RpczData;
const boundaries = [10, 20, 30, 40];
/** Creating here because stats is a singleton */
const {stats} = require('@opencensus/core');


beforeEach((done) => {
stats = new Stats();
zpages = new ZpagesExporter(options);
stats.registerExporter(zpages);
zpages.startServer(done);
Expand Down