Skip to content

Commit

Permalink
Merge branch 'master' into prom_readme
Browse files Browse the repository at this point in the history
  • Loading branch information
mayurkale22 authored Nov 12, 2019
2 parents 957fa2b + f15dedb commit e9d2c3d
Show file tree
Hide file tree
Showing 29 changed files with 199 additions and 63 deletions.
61 changes: 54 additions & 7 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,40 @@ postgres_service: &postgres_service
POSTGRES_USER: postgres
POSTGRES_DB: circle_database

cache_1: &cache_1
key: npm-cache-01-{{ .Environment.CIRCLE_JOB }}-{{ checksum "/tmp/checksums.txt" }}-1
paths:
- ./node_modules
- ./yarn.lock
- packages/opentelemetry-base/node_modules
- packages/opentelemetry-scope-base/node_modules
- packages/opentelemetry-types/node_modules
- packages/opentelemetry-scope-async-hooks/node_modules
- packages/opentelemetry-core/node_modules
- packages/opentelemetry-exporter-prometheus/node_modules
- packages/opentelemetry-metrics/node_modules
- packages/opentelemetry-tracing/node_modules
- packages/opentelemetry-exporter-jaeger/node_modules
- packages/opentelemetry-exporter-zipkin/node_modules
- packages/opentelemetry-node/node_modules
- packages/opentelemetry-shim-opentracing/node_modules
- packages/opentelemetry-web/node_modules
- packages/opentelemetry-plugin-dns/node_modules

cache_2: &cache_2
key: npm-cache-02-{{ .Environment.CIRCLE_JOB }}-{{ checksum "/tmp/checksums.txt" }}-2
paths:
- packages/opentelemetry-plugin-grpc/node_modules
- packages/opentelemetry-plugin-http/node_modules
- packages/opentelemetry-plugin-http2/node_modules
- packages/opentelemetry-plugin-mongodb/node_modules
- packages/opentelemetry-plugin-redis/node_modules
- packages/opentelemetry-plugin-postgres/opentelemetry-plugin-pg/node_modules
- packages/opentelemetry-plugin-document-load/node_modules
- packages/opentelemetry-plugin-https/node_modules
- packages/opentelemetry-plugin-postgres/opentelemetry-plugin-pg-pool/node_modules
- packages/opentelemetry-exporter-prometheus/node_modules

node_unit_tests: &node_unit_tests
steps:
- checkout
Expand All @@ -31,17 +65,17 @@ node_unit_tests: &node_unit_tests
echo "CIRCLE_NODE_VERSION=${CIRCLE_NODE_VERSION}"
- restore_cache:
keys:
- npm-cache-{{ checksum "/tmp/checksums.txt" }}
- npm-cache-01-{{ .Environment.CIRCLE_JOB }}-{{ checksum "/tmp/checksums.txt" }}-1
- restore_cache:
keys:
- npm-cache-02-{{ .Environment.CIRCLE_JOB }}-{{ checksum "/tmp/checksums.txt" }}-2
- run:
name: Install Dependencies
command: yarn install
- save_cache:
key: npm-cache-{{ checksum "/tmp/checksums.txt" }}
paths:
- ./node_modules
- ./yarn.lock
- ./packages/*/node_modules
- ./packages/*/yarn.lock
<<: *cache_1
- save_cache:
<<: *cache_2
- run:
name: Compile code
command: yarn compile
Expand All @@ -55,6 +89,9 @@ node_unit_tests: &node_unit_tests
browsers_unit_tests: &browsers_unit_tests
steps:
- checkout
- run:
name: Create Checksum
command: sh .circleci/checksum.sh /tmp/checksums.txt
- run:
name: Setup environment variables
command: |
Expand All @@ -65,9 +102,19 @@ browsers_unit_tests: &browsers_unit_tests
command: |
node --version
echo "CIRCLE_NODE_VERSION=${CIRCLE_NODE_VERSION}"
- restore_cache:
keys:
- npm-cache-01-{{ .Environment.CIRCLE_JOB }}-{{ checksum "/tmp/checksums.txt" }}-1
- restore_cache:
keys:
- npm-cache-02-{{ .Environment.CIRCLE_JOB }}-{{ checksum "/tmp/checksums.txt" }}-1
- run:
name: Install Dependencies
command: yarn install
- save_cache:
<<: *cache_1
- save_cache:
<<: *cache_2
- run:
name: Compile code
command: yarn compile
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"@commitlint/config-conventional": "^8.2.0",
"beautify-benchmark": "^0.2.4",
"benchmark": "^2.1.4",
"gts": "^1.0.0",
"gts": "^1.1.0",
"husky": "^3.0.9",
"lerna": "^3.17.0",
"lerna-changelog": "^0.8.2",
Expand Down
6 changes: 3 additions & 3 deletions packages/opentelemetry-base/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@opentelemetry/base",
"version": "0.2.0",
"description": "OpenTelemetry base",
"description": "OpenTelemetry base provides base code for the SDK packages",
"main": "build/src/index.js",
"types": "build/src/index.d.ts",
"repository": "open-telemetry/opentelemetry-js",
Expand Down Expand Up @@ -43,8 +43,8 @@
"devDependencies": {
"@types/mocha": "^5.2.5",
"@types/node": "^12.6.8",
"codecov": "^3.1.0",
"gts": "^1.0.0",
"codecov": "^3.6.1",
"gts": "^1.1.0",
"mocha": "^6.1.0",
"nyc": "^14.1.1",
"rimraf": "^3.0.0",
Expand Down
6 changes: 3 additions & 3 deletions packages/opentelemetry-core/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@opentelemetry/core",
"version": "0.2.0",
"description": "OpenTelemetry Core",
"description": "OpenTelemetry Core provides default and no-op implementations of the OpenTelemetry types for trace and metrics",
"main": "build/src/index.js",
"browser": {
"./src/platform/index.ts": "./src/platform/browser/index.ts",
Expand Down Expand Up @@ -54,8 +54,8 @@
"@types/semver": "^6.2.0",
"@types/sinon": "^7.0.13",
"@types/webpack-env": "1.13.9",
"codecov": "^3.1.0",
"gts": "^1.0.0",
"codecov": "^3.6.1",
"gts": "^1.1.0",
"istanbul-instrumenter-loader": "^3.0.1",
"karma": "^4.4.1",
"karma-chrome-launcher": "^3.1.0",
Expand Down
43 changes: 36 additions & 7 deletions packages/opentelemetry-core/src/metrics/NoopMeter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
Meter,
Metric,
MetricOptions,
MetricUtils,
MeasureHandle,
SpanContext,
LabelSet,
Expand Down Expand Up @@ -110,6 +111,38 @@ export class NoopMetric<T> implements Metric<T> {
}
}

export class NoopCounterMetric extends NoopMetric<CounterHandle>
implements Pick<MetricUtils, 'add'> {
add(value: number, labelSet: LabelSet) {
this.getHandle(labelSet).add(value);
}
}

export class NoopGaugeMetric extends NoopMetric<GaugeHandle>
implements Pick<MetricUtils, 'set'> {
set(value: number, labelSet: LabelSet) {
this.getHandle(labelSet).set(value);
}
}

export class NoopMeasureMetric extends NoopMetric<MeasureHandle>
implements Pick<MetricUtils, 'record'> {
record(
value: number,
labelSet: LabelSet,
distContext?: DistributedContext,
spanContext?: SpanContext
) {
if (typeof distContext === 'undefined') {
this.getHandle(labelSet).record(value);
} else if (typeof spanContext === 'undefined') {
this.getHandle(labelSet).record(value, distContext);
} else {
this.getHandle(labelSet).record(value, distContext, spanContext);
}
}
}

export class NoopCounterHandle implements CounterHandle {
add(value: number): void {
return;
Expand All @@ -133,16 +166,12 @@ export class NoopMeasureHandle implements MeasureHandle {
}

export const NOOP_GAUGE_HANDLE = new NoopGaugeHandle();
export const NOOP_GAUGE_METRIC = new NoopMetric<GaugeHandle>(NOOP_GAUGE_HANDLE);
export const NOOP_GAUGE_METRIC = new NoopGaugeMetric(NOOP_GAUGE_HANDLE);

export const NOOP_COUNTER_HANDLE = new NoopCounterHandle();
export const NOOP_COUNTER_METRIC = new NoopMetric<CounterHandle>(
NOOP_COUNTER_HANDLE
);
export const NOOP_COUNTER_METRIC = new NoopCounterMetric(NOOP_COUNTER_HANDLE);

export const NOOP_MEASURE_HANDLE = new NoopMeasureHandle();
export const NOOP_MEASURE_METRIC = new NoopMetric<MeasureHandle>(
NOOP_MEASURE_HANDLE
);
export const NOOP_MEASURE_METRIC = new NoopMeasureMetric(NOOP_MEASURE_HANDLE);

export const NOOP_LABEL_SET = {} as LabelSet;
2 changes: 1 addition & 1 deletion packages/opentelemetry-exporter-jaeger/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
"devDependencies": {
"@types/mocha": "^5.2.7",
"@types/node": "^12.6.9",
"codecov": "^3.5.0",
"codecov": "^3.6.1",
"gts": "^1.1.0",
"mocha": "^6.2.0",
"nyc": "^14.1.1",
Expand Down
2 changes: 1 addition & 1 deletion packages/opentelemetry-exporter-prometheus/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
"devDependencies": {
"@types/mocha": "^5.2.7",
"@types/node": "^12.6.9",
"codecov": "^3.5.0",
"codecov": "^3.6.1",
"gts": "^1.1.0",
"mocha": "^6.2.2",
"nyc": "^14.1.1",
Expand Down
2 changes: 1 addition & 1 deletion packages/opentelemetry-exporter-zipkin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
"@types/mocha": "^5.2.7",
"@types/nock": "^10.0.3",
"@types/node": "^12.6.9",
"codecov": "^3.5.0",
"codecov": "^3.6.1",
"gts": "^1.1.0",
"mocha": "^6.2.0",
"nock": "^11.0.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/opentelemetry-metrics/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
"@types/mocha": "^5.2.7",
"@types/node": "^12.6.9",
"@types/sinon": "^7.0.13",
"codecov": "^3.5.0",
"codecov": "^3.6.1",
"gts": "^1.1.0",
"mocha": "^6.2.0",
"nyc": "^14.1.1",
Expand Down
9 changes: 0 additions & 9 deletions packages/opentelemetry-metrics/src/LabelSet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,3 @@ export class LabelSet implements types.LabelSet {
this.labels = labels;
}
}

/**
* Type guard to remove nulls from arrays
*
* @param value value to be checked for null equality
*/
export function notNull<T>(value: T | null): value is T {
return value !== null;
}
24 changes: 22 additions & 2 deletions packages/opentelemetry-metrics/src/Metric.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,8 @@ export abstract class Metric<T extends BaseHandle> implements types.Metric<T> {
}

/** This is a SDK implementation of Counter Metric. */
export class CounterMetric extends Metric<CounterHandle> {
export class CounterMetric extends Metric<CounterHandle>
implements Pick<types.MetricUtils, 'add'> {
constructor(
name: string,
options: MetricOptions,
Expand All @@ -145,10 +146,20 @@ export class CounterMetric extends Metric<CounterHandle> {
this._onUpdate
);
}

/**
* Adds the given value to the current value. Values cannot be negative.
* @param value the value to add.
* @param labelSet the canonicalized LabelSet used to associate with this metric's handle.
*/
add(value: number, labelSet: types.LabelSet) {
this.getHandle(labelSet).add(value);
}
}

/** This is a SDK implementation of Gauge Metric. */
export class GaugeMetric extends Metric<GaugeHandle> {
export class GaugeMetric extends Metric<GaugeHandle>
implements Pick<types.MetricUtils, 'set'> {
constructor(
name: string,
options: MetricOptions,
Expand All @@ -172,4 +183,13 @@ export class GaugeMetric extends Metric<GaugeHandle> {
this._onUpdate
);
}

/**
* Sets the given value. Values can be negative.
* @param value the new value.
* @param labelSet the canonicalized LabelSet used to associate with this metric's handle.
*/
set(value: number, labelSet: types.LabelSet) {
this.getHandle(labelSet).set(value);
}
}
16 changes: 16 additions & 0 deletions packages/opentelemetry-metrics/test/Meter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,14 @@ describe('Meter', () => {
assert.ok(counter instanceof Metric);
});

it('should be able to call add() directly on counter', () => {
const counter = meter.createCounter('name') as CounterMetric;
counter.add(10, labelSet);
assert.strictEqual(counter.getHandle(labelSet)['_data'], 10);
counter.add(10, labelSet);
assert.strictEqual(counter.getHandle(labelSet)['_data'], 20);
});

describe('.getHandle()', () => {
it('should create a counter handle', () => {
const counter = meter.createCounter('name') as CounterMetric;
Expand Down Expand Up @@ -229,6 +237,14 @@ describe('Meter', () => {
assert.ok(gauge instanceof Metric);
});

it('should be able to call set() directly on gauge', () => {
const gauge = meter.createGauge('name') as GaugeMetric;
gauge.set(10, labelSet);
assert.strictEqual(gauge.getHandle(labelSet)['_data'], 10);
gauge.set(250, labelSet);
assert.strictEqual(gauge.getHandle(labelSet)['_data'], 250);
});

describe('.getHandle()', () => {
it('should create a gauge handle', () => {
const gauge = meter.createGauge('name') as GaugeMetric;
Expand Down
4 changes: 2 additions & 2 deletions packages/opentelemetry-node/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@
"@types/node": "^12.6.8",
"@types/semver": "^6.0.1",
"@types/shimmer": "^1.0.1",
"codecov": "^3.1.0",
"gts": "^1.0.0",
"codecov": "^3.6.1",
"gts": "^1.1.0",
"mocha": "^6.1.0",
"nyc": "^14.1.1",
"rimraf": "^3.0.0",
Expand Down
4 changes: 2 additions & 2 deletions packages/opentelemetry-plugin-document-load/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@
"@types/sinon": "^7.0.13",
"@types/webpack-env": "1.13.9",
"babel-loader": "^8.0.6",
"codecov": "^3.1.0",
"gts": "^1.0.0",
"codecov": "^3.6.1",
"gts": "^1.1.0",
"istanbul-instrumenter-loader": "^3.0.1",
"karma": "^4.4.1",
"karma-chrome-launcher": "^3.1.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/opentelemetry-plugin-grpc/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
"@types/semver": "^6.2.0",
"@types/shimmer": "^1.0.1",
"@types/sinon": "^7.0.13",
"codecov": "^3.5.0",
"codecov": "^3.6.1",
"grpc": "^1.23.3",
"gts": "^1.1.0",
"mocha": "^6.2.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/opentelemetry-plugin-http2/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
"devDependencies": {
"@types/mocha": "^5.2.7",
"@types/node": "^12.6.9",
"codecov": "^3.5.0",
"codecov": "^3.6.1",
"gts": "^1.1.0",
"mocha": "^6.2.0",
"nyc": "^14.1.1",
Expand Down
2 changes: 1 addition & 1 deletion packages/opentelemetry-plugin-mongodb/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
"devDependencies": {
"@types/mocha": "^5.2.7",
"@types/node": "^12.6.9",
"codecov": "^3.5.0",
"codecov": "^3.6.1",
"gts": "^1.1.0",
"mocha": "^6.2.0",
"nyc": "^14.1.1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@
"@types/pg": "^7.11.2",
"@types/shimmer": "^1.0.1",
"@types/pg-pool": "^2.0.1",
"codecov": "^3.5.0",
"gts": "^1.0.0",
"codecov": "^3.6.1",
"gts": "^1.1.0",
"mocha": "^6.2.0",
"nyc": "^14.1.1",
"rimraf": "^3.0.0",
Expand Down
Loading

0 comments on commit e9d2c3d

Please sign in to comment.