Skip to content
This repository has been archived by the owner on Oct 3, 2023. It is now read-only.

Commit

Permalink
upgrade gts to 1.0 (#572)
Browse files Browse the repository at this point in the history
  • Loading branch information
mayurkale22 authored Jun 7, 2019
1 parent 075bebd commit ef5712f
Show file tree
Hide file tree
Showing 231 changed files with 12,285 additions and 10,249 deletions.
224 changes: 81 additions & 143 deletions packages/opencensus-core/package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion packages/opencensus-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
"@types/shimmer": "^1.0.1",
"@types/uuid": "^3.4.3",
"codecov": "^3.4.0",
"gts": "^0.9.0",
"gts": "^1.0.0",
"intercept-stdout": "^0.1.2",
"mocha": "^6.1.0",
"nyc": "14.1.1",
Expand Down
18 changes: 11 additions & 7 deletions packages/opencensus-core/src/common/console-logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,23 +31,25 @@ export class ConsoleLogger implements types.Logger {
* Constructs a new ConsoleLogger instance
* @param options A logger configuration object.
*/
constructor(options?: types.LoggerOptions|string|number) {
constructor(options?: types.LoggerOptions | string | number) {
let opt: types.LoggerOptions = {};
if (typeof options === 'number') {
if (options < 0) {
options = 0;
} else if (options > ConsoleLogger.LEVELS.length) {
options = ConsoleLogger.LEVELS.length - 1;
}
opt = {level: ConsoleLogger.LEVELS[options]};
opt = { level: ConsoleLogger.LEVELS[options] };
} else if (typeof options === 'string') {
opt = {level: options};
opt = { level: options };
} else {
opt = options || {};
}
if (opt.level) this.level = opt.level;
this.logger =
logDriver({levels: ConsoleLogger.LEVELS, level: opt.level || 'silent'});
this.logger = logDriver({
levels: ConsoleLogger.LEVELS,
level: opt.level || 'silent',
});
}

/**
Expand Down Expand Up @@ -96,8 +98,10 @@ export class ConsoleLogger implements types.Logger {
* https://github.com/cainus/logdriver/blob/bba1761737ca72f04d6b445629848538d038484a/index.js#L50
* @param options A logger options or strig to logger in console
*/
const logger = (options?: types.LoggerOptions|string|number): types.Logger => {
const logger = (
options?: types.LoggerOptions | string | number
): types.Logger => {
return new ConsoleLogger(options);
};

export {logger};
export { logger };
2 changes: 1 addition & 1 deletion packages/opencensus-core/src/common/noop-logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

import {Logger} from './types';
import { Logger } from './types';

/** No-op implementation of Logger */
class NoopLogger implements Logger {
Expand Down
10 changes: 5 additions & 5 deletions packages/opencensus-core/src/common/time-util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

import {Timestamp} from '../metrics/export/types';
import { Timestamp } from '../metrics/export/types';

const MILLIS_PER_SECOND = 1e3;
const NANOS_PER_MILLI = 1e3 * 1e3;
Expand Down Expand Up @@ -54,9 +54,9 @@ export function getTimestampWithProcessHRTime(): Timestamp {
const nanos = hrtimeRefNanos + offsetNanos;

if (nanos >= NANOS_PER_SECOND) {
return {seconds: seconds + 1, nanos: nanos % NANOS_PER_SECOND};
return { seconds: seconds + 1, nanos: nanos % NANOS_PER_SECOND };
}
return {seconds, nanos};
return { seconds, nanos };
}

/**
Expand All @@ -68,13 +68,13 @@ export function getTimestampWithProcessHRTime(): Timestamp {
export function timestampFromMillis(epochMilli: number): Timestamp {
return {
seconds: Math.floor(epochMilli / MILLIS_PER_SECOND),
nanos: (epochMilli % MILLIS_PER_SECOND) * NANOS_PER_MILLI
nanos: (epochMilli % MILLIS_PER_SECOND) * NANOS_PER_MILLI,
};
}

setHrtimeReference();

export const TEST_ONLY = {
setHrtimeReference,
resetHrtimeFunctionCache
resetHrtimeFunctionCache,
};
27 changes: 18 additions & 9 deletions packages/opencensus-core/src/common/validations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

import {LabelKey, LabelValue} from '../metrics/export/types';
import { LabelKey, LabelValue } from '../metrics/export/types';

/**
* Validates that an object reference passed as a parameter to the calling
Expand All @@ -38,17 +38,22 @@ export function validateNotNull<T>(reference: T, errorMessage: string): T {
* @param errorMessage The exception message to use if the check fails.
*/
export function validateArrayElementsNotNull<T>(
array: T[], errorMessage: string) {
array: T[],
errorMessage: string
) {
const areAllDefined = array.every(
element => element !== null && typeof element !== 'undefined');
element => element !== null && typeof element !== 'undefined'
);
if (!areAllDefined) {
throw new Error(`${errorMessage} elements should not be a NULL`);
}
}

/** Throws an error if any of the map elements is null. */
export function validateMapElementNotNull<K, V>(
map: Map<K, V>, errorMessage: string) {
map: Map<K, V>,
errorMessage: string
) {
for (const [key, value] of map.entries()) {
if (key == null || value == null) {
throw new Error(`${errorMessage} elements should not be a NULL`);
Expand All @@ -58,11 +63,15 @@ export function validateMapElementNotNull<K, V>(

/** Throws an error if any of the array element present in the map. */
export function validateDuplicateKeys(
keys: LabelKey[], constantLabels: Map<LabelKey, LabelValue>) {
const keysAndConstantKeys =
new Set([...keys, ...constantLabels.keys()].map(k => k.key));
if (keysAndConstantKeys.size !== (keys.length + constantLabels.size)) {
keys: LabelKey[],
constantLabels: Map<LabelKey, LabelValue>
) {
const keysAndConstantKeys = new Set(
[...keys, ...constantLabels.keys()].map(k => k.key)
);
if (keysAndConstantKeys.size !== keys.length + constantLabels.size) {
throw new Error(
`The keys from LabelKeys should not be present in constantLabels or LabelKeys should not contains duplicate keys`);
`The keys from LabelKeys should not be present in constantLabels or LabelKeys should not contains duplicate keys`
);
}
}
5 changes: 2 additions & 3 deletions packages/opencensus-core/src/common/version.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

/**
* Copyright 2018, OpenCensus Authors
*
Expand All @@ -15,9 +14,9 @@
* limitations under the License.
*/

type Package = {
interface Package {
version: string;
};
}

// Load the package details. Note that the `require` is performed at runtime,
// which means package.json will be relative to the location of this file.
Expand Down
39 changes: 21 additions & 18 deletions packages/opencensus-core/src/exporters/console-exporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,12 @@
*/

import * as loggerTypes from '../common/types';
import {Measurement, View} from '../stats/types';
import {TagKey, TagValue} from '../tags/types';
import { Measurement, View } from '../stats/types';
import { TagKey, TagValue } from '../tags/types';
import * as modelTypes from '../trace/model/types';
import {ExporterBuffer} from './exporter-buffer';
import {Exporter, ExporterConfig, StatsEventListener} from './types';
import { ExporterBuffer } from './exporter-buffer';
import * as logger from '../common/console-logger';
import { Exporter, ExporterConfig, StatsEventListener } from './types';

/** Do not send span data */
export class NoopExporter implements Exporter {
Expand All @@ -34,8 +35,7 @@ export class NoopExporter implements Exporter {
/** Format and sends span data to the console. */
export class ConsoleExporter implements Exporter {
/** Buffer object to store the spans. */
// @ts-ignore
private logger?: loggerTypes.Logger;
logger: loggerTypes.Logger;
private buffer: ExporterBuffer;

/**
Expand All @@ -45,7 +45,7 @@ export class ConsoleExporter implements Exporter {
*/
constructor(config: ExporterConfig) {
this.buffer = new ExporterBuffer(this, config);
this.logger = config.logger;
this.logger = config.logger || logger.logger();
}

onStartSpan(span: modelTypes.Span) {}
Expand All @@ -66,17 +66,16 @@ export class ConsoleExporter implements Exporter {
* @param spans A list of spans to publish.
*/
publish(spans: modelTypes.Span[]) {
spans.map((span) => {
spans.map(span => {
const ROOT_STR = `RootSpan: {traceId: ${span.traceId}, spanId: ${
span.id}, name: ${span.name} }`;
const SPANS_STR: string[] = span.spans.map(
(child) => [`\t\t{spanId: ${child.id}, name: ${child.name}}`].join(
'\n'));
span.id
}, name: ${span.name} }`;
const SPANS_STR: string[] = span.spans.map(child =>
[`\t\t{spanId: ${child.id}, name: ${child.name}}`].join('\n')
);

const result: string[] = [];
result.push(
ROOT_STR + '\n\tChildSpans:\n' +
`${SPANS_STR.join('\n')}`);
result.push(ROOT_STR + '\n\tChildSpans:\n' + `${SPANS_STR.join('\n')}`);
console.log(`${result}`);
});
return Promise.resolve();
Expand All @@ -90,8 +89,9 @@ export class ConsoleStatsExporter implements StatsEventListener {
* @param view registered view
*/
onRegisterView(view: View) {
console.log(`View registered: ${view.name}, Measure registered: ${
view.measure.name}`);
console.log(
`View registered: ${view.name}, Measure registered: ${view.measure.name}`
);
}
/**
* Event called when a measurement is recorded
Expand All @@ -100,7 +100,10 @@ export class ConsoleStatsExporter implements StatsEventListener {
* @param tags The tags to which the value is applied
*/
onRecord(
views: View[], measurement: Measurement, tags: Map<TagKey, TagValue>) {
views: View[],
measurement: Measurement,
tags: Map<TagKey, TagValue>
) {
console.log(`Measurement recorded: ${measurement.measure.name}`);
}

Expand Down
12 changes: 6 additions & 6 deletions packages/opencensus-core/src/exporters/exporter-buffer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,12 @@ export class ExporterBuffer {
constructor(exporter: types.Exporter, config: configTypes.BufferConfig) {
this.exporter = exporter;
this.logger = config.logger || logger.logger();
this.bufferSize = isNaN(Number(config.bufferSize)) ?
DEFAULT_BUFFER_SIZE :
Number(config.bufferSize);
this.bufferTimeout = isNaN(Number(config.bufferTimeout)) ?
DEFAULT_BUFFER_TIMEOUT :
Number(config.bufferTimeout);
this.bufferSize = isNaN(Number(config.bufferSize))
? DEFAULT_BUFFER_SIZE
: Number(config.bufferSize);
this.bufferTimeout = isNaN(Number(config.bufferTimeout))
? DEFAULT_BUFFER_TIMEOUT
: Number(config.bufferTimeout);
return this;
}

Expand Down
12 changes: 7 additions & 5 deletions packages/opencensus-core/src/exporters/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
* limitations under the License.
*/

import {Measurement, View} from '../stats/types';
import {TagKey, TagValue} from '../tags/types';
import { Measurement, View } from '../stats/types';
import { TagKey, TagValue } from '../tags/types';
import * as configTypes from '../trace/config/types';
import * as modelTypes from '../trace/model/types';

Expand All @@ -25,7 +25,7 @@ export interface Exporter extends modelTypes.SpanEventListener {
* Sends a list of spans to the service.
* @param spans A list of spans to publish.
*/
publish(spans: modelTypes.Span[]): Promise<number|string|void>;
publish(spans: modelTypes.Span[]): Promise<number | string | void>;
}

/**
Expand All @@ -48,8 +48,10 @@ export interface StatsEventListener {
* @param tags The tags to which the value is applied
*/
onRecord(
views: View[], measurement: Measurement,
tags: Map<TagKey, TagValue>): void;
views: View[],
measurement: Measurement,
tags: Map<TagKey, TagValue>
): void;

/**
* Starts the exporter that polls Metric from Metrics library and send
Expand Down
31 changes: 25 additions & 6 deletions packages/opencensus-core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,26 @@ export * from './common/types';
export * from './metrics/types';
export * from './metrics/cumulative/types';
export * from './metrics/gauges/types';
export {Metric, MetricDescriptor, TimeSeries, MetricDescriptorType, LabelKey, LabelValue, Point as TimeSeriesPoint, DistributionValue, BucketOptions, Bucket as DistributionBucket, SummaryValue, Explicit, Exemplar, Timestamp, Snapshot, ValueAtPercentile, MetricProducerManager, MetricProducer} from './metrics/export/types';
export {
Metric,
MetricDescriptor,
TimeSeries,
MetricDescriptorType,
LabelKey,
LabelValue,
Point as TimeSeriesPoint,
DistributionValue,
BucketOptions,
Bucket as DistributionBucket,
SummaryValue,
Explicit,
Exemplar,
Timestamp,
Snapshot,
ValueAtPercentile,
MetricProducerManager,
MetricProducer,
} from './metrics/export/types';

// classes

Expand Down Expand Up @@ -59,12 +78,12 @@ export * from './resource/resource';

// interfaces
export * from './stats/types';
export {TagKey, TagValue, TagMetadata, TagTtl} from './tags/types';
export { TagKey, TagValue, TagMetadata, TagTtl } from './tags/types';
export * from './resource/types';

// logger
import * as logger from './common/console-logger';
export {logger};
export { logger };

// version
export * from './common/version';
Expand All @@ -83,7 +102,7 @@ export * from './metrics/gauges/derived-gauge';
export * from './metrics/gauges/gauge';

// Stats singleton instance
import {BaseStats} from './stats/stats';
import {Stats} from './stats/types';
import { BaseStats } from './stats/stats';
import { Stats } from './stats/types';
const globalStats: Stats = BaseStats.instance;
export {globalStats};
export { globalStats };
Loading

0 comments on commit ef5712f

Please sign in to comment.