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

fix: stackdriver monitoring send requests in order #136

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,15 @@ const monitoring = google.monitoring('v3');
/** Format and sends Stats to Stackdriver */
export class StackdriverStatsExporter implements StatsEventListener {
private projectId: string;
// tslint:disable-next-line:no-any
private lastRequest: Promise<any> = Promise.resolve();
private requestTimeout: number;
logger: Logger;

constructor(options: StackdriverExporterOptions) {
this.projectId = options.projectId;
this.logger = options.logger || logger.logger();
this.requestTimeout = options.requestTimeout || 1000;
}

/**
Expand Down Expand Up @@ -64,20 +68,21 @@ export class StackdriverStatsExporter implements StatsEventListener {
return this.createTimeSeriesData(view, measurement);
});

return this.authorize().then(authClient => {
const request = {
name: `projects/${this.projectId}`,
resource: {timeSeries},
auth: authClient
};

return new Promise((resolve, reject) => {
monitoring.projects.timeSeries.create(request, (err: Error) => {
this.logger.debug('sent time series', request.resource.timeSeries);
err ? reject(err) : resolve();
});
});
});
this.lastRequest = this.lastRequest.then(() => this.authorize())
.then(authClient => {
this.logger.debug('sent time series', timeSeries);
return monitoring.projects.timeSeries.create({
name: `projects/${this.projectId}`,
resource: {timeSeries},
auth: authClient
});
})
.then(() => {
return new Promise((resolve, reject) => {
setTimeout(resolve, this.requestTimeout);
});
});
return this.lastRequest;
}

/**
Expand Down Expand Up @@ -152,7 +157,8 @@ export class StackdriverStatsExporter implements StatsEventListener {
count: distribution.count.toString(),
mean: distribution.mean,
sumOfSquaredDeviation: distribution.sumSquaredDeviations,
range: {min: distribution.min, max: distribution.max},
// Distribution range is not yet supported
// range: {min: distribution.min, max: distribution.max},
bucketOptions: {
explicitBuckets:
{bounds: this.getBucketBoundaries(distribution.buckets)}
Expand Down
4 changes: 3 additions & 1 deletion packages/opencensus-exporter-stackdriver/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ export interface StackdriverExporterOptions extends ExporterConfig {
* projectId project id defined to stackdriver
*/
projectId: string;
/** The delay between cloud monitoring requests */
requestTimeout?: number;
}

export interface TracesWithCredentials {
Expand Down Expand Up @@ -85,7 +87,7 @@ export interface Distribution {
count: string;
mean: number;
sumOfSquaredDeviation: number;
range: {min: number; max: number;};
range?: {min: number; max: number;};
bucketOptions: {explicitBuckets: {bounds: number[];}};
bucketCounts: number[];
}
Expand Down