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

Commit

Permalink
Add start method to StatsEventListener (#259)
Browse files Browse the repository at this point in the history
With the current approach, we are calling onRegisterView (whenever a new view is registered) and onRecord (whenever a new measurement is recorded). With the new approach, plan is to start exporter that polls Metric from Metrics library and send batched data to backend.
  • Loading branch information
mayurkale22 committed Jan 7, 2019
1 parent c5c1c4c commit fed0ad4
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 0 deletions.
8 changes: 8 additions & 0 deletions packages/opencensus-core/src/exporters/console-exporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,4 +96,12 @@ export class ConsoleStatsExporter implements types.StatsEventListener {
onRecord(views: View[], measurement: Measurement) {
console.log(`Measurement recorded: ${measurement.measure.name}`);
}

/**
* Starts the Console exporter that polls Metric from Metrics library and
* shows in the log console..
*/
start(): void {
// TODO(mayurkale): dependency with PR#253.
}
}
8 changes: 8 additions & 0 deletions packages/opencensus-core/src/exporters/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,23 @@ export interface Exporter extends modelTypes.SpanEventListener {
export interface StatsEventListener {
/**
* Is called whenever a new view is registered
* @deprecated since version 0.0.9 - use {@link start} instead
* @param view The registered view
*/
onRegisterView(view: View): void;
/**
* Is called whenever a new measurement is recorded.
* @deprecated since version 0.0.9 - use {@link start} instead
* @param views The views related to the measurement
* @param measurement The recorded measurement
*/
onRecord(views: View[], measurement: Measurement): void;

/**
* Starts the exporter that polls Metric from Metrics library and send
* batched data to backend.
*/
start(): void;
}

export type ExporterConfig = configTypes.BufferConfig;
4 changes: 4 additions & 0 deletions packages/opencensus-core/src/stats/stats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,10 @@ export class Stats {
exporter.onRegisterView(view);
}
}

// dependency with PR#253 and once start method is implemented in all stats
// exporters
// exporter.start();
}

/**
Expand Down
4 changes: 4 additions & 0 deletions packages/opencensus-core/test/test-stats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ class TestExporter implements StatsEventListener {
this.recordedMeasurements.push(measurement);
}

start(): void {
// TODO(mayurkale): dependency with PR#253.
}

clean() {
this.registeredViews = [];
this.recordedMeasurements = [];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,15 @@ export class PrometheusStatsExporter implements StatsEventListener {
}
}

/**
* Starts the Prometheus exporter that polls Metric from Metrics library and
* send batched data to backend.
*/
start(): void {
// TODO(mayurkale): add setInterval here to poll Metric, transform and send
// // it to backend (dependency with PR#253).
}

/**
* Register or get a metric in Prometheus
* @param view View will be used to register the metric
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,15 @@ export class StackdriverStatsExporter implements StatsEventListener {
}
}

/**
* Starts the Stackdriver exporter that polls Metric from Metrics library and
* send batched data to backend.
*/
start(): void {
// TODO(mayurkale): add setInterval here to poll Metric, transform and send
// // it to backend (dependency with PR#253).
}

/**
* Clear the interval timer to stop uploading metrics. It should be called
* whenever the exporter is not needed anymore.
Expand Down
4 changes: 4 additions & 0 deletions packages/opencensus-exporter-zpages/src/zpages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,10 @@ export class ZpagesExporter implements Exporter, StatsEventListener {
});
}

start(): void {
// TODO(mayurkale): dependency with PR#253.
}

/**
* Send a trace to traces array
* @param trace the rootSpan to be sent to the array list
Expand Down

0 comments on commit fed0ad4

Please sign in to comment.