Skip to content

Commit

Permalink
reduce cloudwatch throttling delay
Browse files Browse the repository at this point in the history
  • Loading branch information
eduardomourar committed Oct 24, 2020
1 parent 73afc2d commit 5075e27
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 31 deletions.
5 changes: 2 additions & 3 deletions src/log-delivery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ export class CloudWatchLogPublisher extends LogPublisher {
}
try {
// Delay to avoid throttling
await delay(0.25);
await delay(0.1);
const record: InputLogEvent = {
message,
timestamp: Math.round(eventTime.getTime()),
Expand Down Expand Up @@ -222,7 +222,6 @@ export class CloudWatchLogPublisher extends LogPublisher {
* * logs:CreateLogGroup
* * logs:CreateLogStream
* * logs:DescribeLogGroups
* * logs:DescribeLogStreams
*/
export class CloudWatchLogHelper {
private client: CloudWatchLogs;
Expand Down Expand Up @@ -262,7 +261,7 @@ export class CloudWatchLogHelper {
);
await this.emitMetricsForLoggingFailure(err);
}
return null;
return Promise.resolve(null);
}

private async doesLogGroupExist(): Promise<boolean> {
Expand Down
44 changes: 16 additions & 28 deletions src/metrics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,25 +200,19 @@ export class MetricsPublisherProxy {
timestamp: Date,
action: Action,
error: Error
): Promise<any> {
const promises: Array<Promise<void>> = this.publishers.map(
(publisher: MetricsPublisher) => {
return publisher.publishExceptionMetric(timestamp, action, error);
}
);
return await Promise.all(promises);
): Promise<void> {
for (const publisher of this.publishers) {
await publisher.publishExceptionMetric(timestamp, action, error);
}
}

/**
* Publishes a metric related to invocations to the list of publishers
*/
async publishInvocationMetric(timestamp: Date, action: Action): Promise<any> {
const promises: Array<Promise<void>> = this.publishers.map(
(publisher: MetricsPublisher) => {
return publisher.publishInvocationMetric(timestamp, action);
}
);
return await Promise.all(promises);
async publishInvocationMetric(timestamp: Date, action: Action): Promise<void> {
for (const publisher of this.publishers) {
await publisher.publishInvocationMetric(timestamp, action);
}
}

/**
Expand All @@ -228,13 +222,10 @@ export class MetricsPublisherProxy {
timestamp: Date,
action: Action,
milliseconds: number
): Promise<any> {
const promises: Array<Promise<void>> = this.publishers.map(
(publisher: MetricsPublisher) => {
return publisher.publishDurationMetric(timestamp, action, milliseconds);
}
);
return await Promise.all(promises);
): Promise<void> {
for (const publisher of this.publishers) {
await publisher.publishDurationMetric(timestamp, action, milliseconds);
}
}

/**
Expand All @@ -243,12 +234,9 @@ export class MetricsPublisherProxy {
async publishLogDeliveryExceptionMetric(
timestamp: Date,
error: Error
): Promise<any> {
const promises: Array<Promise<void>> = this.publishers.map(
(publisher: MetricsPublisher) => {
return publisher.publishLogDeliveryExceptionMetric(timestamp, error);
}
);
return await Promise.all(promises);
): Promise<void> {
for (const publisher of this.publishers) {
await publisher.publishLogDeliveryExceptionMetric(timestamp, error);
}
}
}

0 comments on commit 5075e27

Please sign in to comment.