From 36496f63d0b4790415e28a4bec1b3f93dfe96823 Mon Sep 17 00:00:00 2001 From: Mayur Kale Date: Tue, 12 Nov 2019 12:06:29 -0800 Subject: [PATCH 1/4] chore: fix codecov path (#520) --- .../opentelemetry-plugin-pg/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/opentelemetry-plugin-postgres/opentelemetry-plugin-pg/package.json b/packages/opentelemetry-plugin-postgres/opentelemetry-plugin-pg/package.json index 1508e87784e..e432168127c 100644 --- a/packages/opentelemetry-plugin-postgres/opentelemetry-plugin-pg/package.json +++ b/packages/opentelemetry-plugin-postgres/opentelemetry-plugin-pg/package.json @@ -12,7 +12,7 @@ "test:local": "cross-env RUN_POSTGRES_TESTS_LOCAL=true yarn test", "tdd": "yarn test -- --watch-extensions ts --watch", "clean": "rimraf build/*", - "codecov": "nyc report --reporter=json && codecov -f coverage/*.json -p ../../", + "codecov": "nyc report --reporter=json && codecov -f coverage/*.json -p ../../../", "check": "gts check", "precompile": "tsc --version", "compile": "tsc -p .", From 57925939f0b7d41354ae2937ee84c8fd174a74ab Mon Sep 17 00:00:00 2001 From: Mayur Kale Date: Tue, 12 Nov 2019 13:23:12 -0800 Subject: [PATCH 2/4] chore: update dependency gts and codecov (#517) --- package.json | 2 +- packages/opentelemetry-base/package.json | 6 +++--- packages/opentelemetry-core/package.json | 6 +++--- packages/opentelemetry-exporter-jaeger/package.json | 2 +- packages/opentelemetry-exporter-prometheus/package.json | 2 +- packages/opentelemetry-exporter-zipkin/package.json | 2 +- packages/opentelemetry-metrics/package.json | 2 +- packages/opentelemetry-node/package.json | 4 ++-- packages/opentelemetry-plugin-document-load/package.json | 4 ++-- packages/opentelemetry-plugin-grpc/package.json | 2 +- packages/opentelemetry-plugin-http2/package.json | 2 +- packages/opentelemetry-plugin-mongodb/package.json | 2 +- .../opentelemetry-plugin-pg-pool/package.json | 4 ++-- .../opentelemetry-plugin-pg/package.json | 4 ++-- packages/opentelemetry-plugin-redis/package.json | 2 +- packages/opentelemetry-scope-async-hooks/package.json | 4 ++-- packages/opentelemetry-scope-base/package.json | 4 ++-- packages/opentelemetry-scope-zone-peer-dep/package.json | 4 ++-- packages/opentelemetry-scope-zone/package.json | 4 ++-- packages/opentelemetry-shim-opentracing/package.json | 2 +- packages/opentelemetry-tracing/package.json | 4 ++-- packages/opentelemetry-types/package.json | 2 +- packages/opentelemetry-web/package.json | 4 ++-- 23 files changed, 37 insertions(+), 37 deletions(-) diff --git a/package.json b/package.json index fa81f068915..120e8a4688a 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/packages/opentelemetry-base/package.json b/packages/opentelemetry-base/package.json index 42cf058b579..9ec79269e94 100644 --- a/packages/opentelemetry-base/package.json +++ b/packages/opentelemetry-base/package.json @@ -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", @@ -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", diff --git a/packages/opentelemetry-core/package.json b/packages/opentelemetry-core/package.json index 11a6a47364f..8b56e65d9c3 100644 --- a/packages/opentelemetry-core/package.json +++ b/packages/opentelemetry-core/package.json @@ -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", @@ -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", diff --git a/packages/opentelemetry-exporter-jaeger/package.json b/packages/opentelemetry-exporter-jaeger/package.json index 798368b9e41..0fe7d1f8c6f 100644 --- a/packages/opentelemetry-exporter-jaeger/package.json +++ b/packages/opentelemetry-exporter-jaeger/package.json @@ -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", diff --git a/packages/opentelemetry-exporter-prometheus/package.json b/packages/opentelemetry-exporter-prometheus/package.json index 4361f1bf519..ac3c74ae1a5 100644 --- a/packages/opentelemetry-exporter-prometheus/package.json +++ b/packages/opentelemetry-exporter-prometheus/package.json @@ -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", diff --git a/packages/opentelemetry-exporter-zipkin/package.json b/packages/opentelemetry-exporter-zipkin/package.json index 0e6c7f5c55c..8a79cf9dfec 100644 --- a/packages/opentelemetry-exporter-zipkin/package.json +++ b/packages/opentelemetry-exporter-zipkin/package.json @@ -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", diff --git a/packages/opentelemetry-metrics/package.json b/packages/opentelemetry-metrics/package.json index a7db5104296..1ce12779a99 100644 --- a/packages/opentelemetry-metrics/package.json +++ b/packages/opentelemetry-metrics/package.json @@ -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", diff --git a/packages/opentelemetry-node/package.json b/packages/opentelemetry-node/package.json index 48a5910427c..46c8d593c02 100644 --- a/packages/opentelemetry-node/package.json +++ b/packages/opentelemetry-node/package.json @@ -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", diff --git a/packages/opentelemetry-plugin-document-load/package.json b/packages/opentelemetry-plugin-document-load/package.json index a7f615440a8..f002a2bb013 100644 --- a/packages/opentelemetry-plugin-document-load/package.json +++ b/packages/opentelemetry-plugin-document-load/package.json @@ -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", diff --git a/packages/opentelemetry-plugin-grpc/package.json b/packages/opentelemetry-plugin-grpc/package.json index 9e14f27d0b5..a2f63e7348d 100644 --- a/packages/opentelemetry-plugin-grpc/package.json +++ b/packages/opentelemetry-plugin-grpc/package.json @@ -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", diff --git a/packages/opentelemetry-plugin-http2/package.json b/packages/opentelemetry-plugin-http2/package.json index 861e9b6d57b..063de1bcac5 100644 --- a/packages/opentelemetry-plugin-http2/package.json +++ b/packages/opentelemetry-plugin-http2/package.json @@ -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", diff --git a/packages/opentelemetry-plugin-mongodb/package.json b/packages/opentelemetry-plugin-mongodb/package.json index 1a78b4224e6..6c8b02219d7 100644 --- a/packages/opentelemetry-plugin-mongodb/package.json +++ b/packages/opentelemetry-plugin-mongodb/package.json @@ -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", diff --git a/packages/opentelemetry-plugin-postgres/opentelemetry-plugin-pg-pool/package.json b/packages/opentelemetry-plugin-postgres/opentelemetry-plugin-pg-pool/package.json index da7fbcca471..fc7aa348920 100644 --- a/packages/opentelemetry-plugin-postgres/opentelemetry-plugin-pg-pool/package.json +++ b/packages/opentelemetry-plugin-postgres/opentelemetry-plugin-pg-pool/package.json @@ -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", diff --git a/packages/opentelemetry-plugin-postgres/opentelemetry-plugin-pg/package.json b/packages/opentelemetry-plugin-postgres/opentelemetry-plugin-pg/package.json index e432168127c..09aefd38185 100644 --- a/packages/opentelemetry-plugin-postgres/opentelemetry-plugin-pg/package.json +++ b/packages/opentelemetry-plugin-postgres/opentelemetry-plugin-pg/package.json @@ -49,8 +49,8 @@ "@types/node": "^12.6.9", "@types/pg": "^7.11.2", "@types/shimmer": "^1.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", "pg": "^7.12.1", diff --git a/packages/opentelemetry-plugin-redis/package.json b/packages/opentelemetry-plugin-redis/package.json index 93af0e8e55c..baa86c0f4f5 100644 --- a/packages/opentelemetry-plugin-redis/package.json +++ b/packages/opentelemetry-plugin-redis/package.json @@ -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", diff --git a/packages/opentelemetry-scope-async-hooks/package.json b/packages/opentelemetry-scope-async-hooks/package.json index fd1a5f562cd..452ffb10f9c 100644 --- a/packages/opentelemetry-scope-async-hooks/package.json +++ b/packages/opentelemetry-scope-async-hooks/package.json @@ -43,8 +43,8 @@ "@types/mocha": "^5.2.5", "@types/node": "^12.6.8", "@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", diff --git a/packages/opentelemetry-scope-base/package.json b/packages/opentelemetry-scope-base/package.json index 635d10da61f..ef2733fffa3 100644 --- a/packages/opentelemetry-scope-base/package.json +++ b/packages/opentelemetry-scope-base/package.json @@ -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", diff --git a/packages/opentelemetry-scope-zone-peer-dep/package.json b/packages/opentelemetry-scope-zone-peer-dep/package.json index 0497800f462..81a3fbb9514 100644 --- a/packages/opentelemetry-scope-zone-peer-dep/package.json +++ b/packages/opentelemetry-scope-zone-peer-dep/package.json @@ -47,8 +47,8 @@ "@types/webpack-env": "1.13.9", "@types/zone.js": "^0.5.12", "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", diff --git a/packages/opentelemetry-scope-zone/package.json b/packages/opentelemetry-scope-zone/package.json index 537571c6a45..c9d2976506e 100644 --- a/packages/opentelemetry-scope-zone/package.json +++ b/packages/opentelemetry-scope-zone/package.json @@ -43,8 +43,8 @@ "@types/sinon": "^7.0.13", "@babel/core": "^7.6.0", "babel-loader": "^8.0.6", - "codecov": "^3.1.0", - "gts": "^1.0.0", + "codecov": "^3.6.1", + "gts": "^1.1.0", "karma": "^4.1.0", "karma-chrome-launcher": "^2.2.0", "karma-mocha": "^1.3.0", diff --git a/packages/opentelemetry-shim-opentracing/package.json b/packages/opentelemetry-shim-opentracing/package.json index 482dbbe3d3b..5d2af4213fc 100644 --- a/packages/opentelemetry-shim-opentracing/package.json +++ b/packages/opentelemetry-shim-opentracing/package.json @@ -40,7 +40,7 @@ "@opentelemetry/tracing": "^0.2.0", "@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", diff --git a/packages/opentelemetry-tracing/package.json b/packages/opentelemetry-tracing/package.json index ee8e205ddcb..6b0a1f3d540 100644 --- a/packages/opentelemetry-tracing/package.json +++ b/packages/opentelemetry-tracing/package.json @@ -50,8 +50,8 @@ "@types/node": "^12.6.8", "@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", diff --git a/packages/opentelemetry-types/package.json b/packages/opentelemetry-types/package.json index 58288c09c4b..4c5345abb54 100644 --- a/packages/opentelemetry-types/package.json +++ b/packages/opentelemetry-types/package.json @@ -41,7 +41,7 @@ "access": "public" }, "devDependencies": { - "gts": "^1.0.0", + "gts": "^1.1.0", "linkinator": "^1.5.0", "tslint-consistent-codestyle": "^1.15.1", "tslint-microsoft-contrib": "^6.2.0", diff --git a/packages/opentelemetry-web/package.json b/packages/opentelemetry-web/package.json index 188f0df5b37..08e9b3c99e9 100644 --- a/packages/opentelemetry-web/package.json +++ b/packages/opentelemetry-web/package.json @@ -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", From 668c3aa833707034569f3eb46f20fa2a9c0c0170 Mon Sep 17 00:00:00 2001 From: Xiao Date: Tue, 12 Nov 2019 13:40:54 -0800 Subject: [PATCH 3/4] feat: direct calling of metric instruments (#507) * feat: direct calling of metric instruments * fix: add interface in types->metric * fix: linting * fix: linting & docs * fix: add overloads for record in measure metric * fix: linting * fix: linting * fix: linting --- .../src/metrics/NoopMeter.ts | 43 ++++++++++++++++--- .../opentelemetry-metrics/src/LabelSet.ts | 9 ---- packages/opentelemetry-metrics/src/Metric.ts | 24 ++++++++++- .../opentelemetry-metrics/test/Meter.test.ts | 16 +++++++ .../opentelemetry-types/src/metrics/Metric.ts | 33 ++++++++++++++ 5 files changed, 107 insertions(+), 18 deletions(-) diff --git a/packages/opentelemetry-core/src/metrics/NoopMeter.ts b/packages/opentelemetry-core/src/metrics/NoopMeter.ts index 9f354cbaa07..6f2cb99507e 100644 --- a/packages/opentelemetry-core/src/metrics/NoopMeter.ts +++ b/packages/opentelemetry-core/src/metrics/NoopMeter.ts @@ -21,6 +21,7 @@ import { Meter, Metric, MetricOptions, + MetricUtils, MeasureHandle, SpanContext, LabelSet, @@ -110,6 +111,38 @@ export class NoopMetric implements Metric { } } +export class NoopCounterMetric extends NoopMetric + implements Pick { + add(value: number, labelSet: LabelSet) { + this.getHandle(labelSet).add(value); + } +} + +export class NoopGaugeMetric extends NoopMetric + implements Pick { + set(value: number, labelSet: LabelSet) { + this.getHandle(labelSet).set(value); + } +} + +export class NoopMeasureMetric extends NoopMetric + implements Pick { + 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; @@ -133,16 +166,12 @@ export class NoopMeasureHandle implements MeasureHandle { } export const NOOP_GAUGE_HANDLE = new NoopGaugeHandle(); -export const NOOP_GAUGE_METRIC = new NoopMetric(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( - 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( - NOOP_MEASURE_HANDLE -); +export const NOOP_MEASURE_METRIC = new NoopMeasureMetric(NOOP_MEASURE_HANDLE); export const NOOP_LABEL_SET = {} as LabelSet; diff --git a/packages/opentelemetry-metrics/src/LabelSet.ts b/packages/opentelemetry-metrics/src/LabelSet.ts index c17534c2e78..fb038384bf0 100644 --- a/packages/opentelemetry-metrics/src/LabelSet.ts +++ b/packages/opentelemetry-metrics/src/LabelSet.ts @@ -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(value: T | null): value is T { - return value !== null; -} diff --git a/packages/opentelemetry-metrics/src/Metric.ts b/packages/opentelemetry-metrics/src/Metric.ts index f3b50f2884a..e6bc268a80d 100644 --- a/packages/opentelemetry-metrics/src/Metric.ts +++ b/packages/opentelemetry-metrics/src/Metric.ts @@ -121,7 +121,8 @@ export abstract class Metric implements types.Metric { } /** This is a SDK implementation of Counter Metric. */ -export class CounterMetric extends Metric { +export class CounterMetric extends Metric + implements Pick { constructor( name: string, options: MetricOptions, @@ -145,10 +146,20 @@ export class CounterMetric extends Metric { 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 { +export class GaugeMetric extends Metric + implements Pick { constructor( name: string, options: MetricOptions, @@ -172,4 +183,13 @@ export class GaugeMetric extends Metric { 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); + } } diff --git a/packages/opentelemetry-metrics/test/Meter.test.ts b/packages/opentelemetry-metrics/test/Meter.test.ts index 06fd599abca..3e678d7ce4c 100644 --- a/packages/opentelemetry-metrics/test/Meter.test.ts +++ b/packages/opentelemetry-metrics/test/Meter.test.ts @@ -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; @@ -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; diff --git a/packages/opentelemetry-types/src/metrics/Metric.ts b/packages/opentelemetry-types/src/metrics/Metric.ts index 0c011d3811c..a1e18e4fadc 100644 --- a/packages/opentelemetry-types/src/metrics/Metric.ts +++ b/packages/opentelemetry-types/src/metrics/Metric.ts @@ -14,6 +14,9 @@ * limitations under the License. */ +import { DistributedContext } from '../distributed_context/DistributedContext'; +import { SpanContext } from '../trace/span_context'; + /** * Options needed for metric creation */ @@ -99,6 +102,36 @@ export interface Metric { setCallback(fn: () => void): void; } +export interface MetricUtils { + /** + * Adds the given value to the current value. Values cannot be negative. + */ + add(value: number, labelSet: LabelSet): void; + + /** + * Sets the given value. Values can be negative. + */ + set(value: number, labelSet: LabelSet): void; + + /** + * Records the given value to this measure. + */ + record(value: number, labelSet: LabelSet): void; + + record( + value: number, + labelSet: LabelSet, + distContext: DistributedContext + ): void; + + record( + value: number, + labelSet: LabelSet, + distContext: DistributedContext, + spanContext: SpanContext + ): void; +} + /** * key-value pairs passed by the user. */ From f15dedbc97127046b8ececae36cea577173a3cd0 Mon Sep 17 00:00:00 2001 From: Daniel Dyla Date: Tue, 12 Nov 2019 18:56:07 -0500 Subject: [PATCH 4/4] ci: enumerate caching paths manually (#514) * ci: enumerate caching paths manually * chore: lint fix * ci: share cache with browser too * chore: remove yarn.lock from cache * chore: add prometheus deps to cache * fix: cache path * ci: remove errant cache restore --- .circleci/config.yml | 61 +++++++++++++++++++++++++++++++++++++++----- 1 file changed, 54 insertions(+), 7 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 4134298bfa6..a52d62cdba1 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -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 @@ -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 @@ -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: | @@ -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