Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

livemetrics: add lastSendSucceeded to prevent permanent retries #504

Merged
merged 3 commits into from
Apr 5, 2019
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 8 additions & 3 deletions Library/QuickPulseStateManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class QuickPulseStateManager {
private _sender: QuickPulseSender;
private _isEnabled: boolean;
private _lastSuccessTime: number = Date.now();
private _lastSendSucceeded: boolean = true;
private _handle: NodeJS.Timer;
private _metrics: {[name: string]: Contracts.MetricQuickPulse} = {};
private _documents: Contracts.DocumentQuickPulse[] = [];
Expand Down Expand Up @@ -124,14 +125,15 @@ class QuickPulseStateManager {
}

let currentTimeout = QuickPulseStateManager._isCollectingData ? 1000 : 5000;
if (QuickPulseStateManager._isCollectingData && Date.now() - this._lastSuccessTime >= 20000) {
if (QuickPulseStateManager._isCollectingData && Date.now() - this._lastSuccessTime >= 20000 && !this._lastSendSucceeded) {
markwolff marked this conversation as resolved.
Show resolved Hide resolved
// Haven't posted successfully in 20 seconds, so wait 60 seconds and ping
QuickPulseStateManager._isCollectingData = false;
currentTimeout = 60000;
} else if (!QuickPulseStateManager._isCollectingData && Date.now() - this._lastSuccessTime >= 60000) {
} else if (!QuickPulseStateManager._isCollectingData && Date.now() - this._lastSuccessTime >= 60000 && !this._lastSendSucceeded) {
markwolff marked this conversation as resolved.
Show resolved Hide resolved
// Haven't pinged successfully in 60 seconds, so wait another 60 seconds
currentTimeout = 60000;
}
this._lastSendSucceeded = null;
markwolff marked this conversation as resolved.
Show resolved Hide resolved
this._handle = <any>setTimeout(this._goQuickPulse.bind(this), currentTimeout);
this._handle.unref(); // Don't block apps from terminating
}
Expand All @@ -144,7 +146,7 @@ class QuickPulseStateManager {
this._sender.post(envelope, this._quickPulseDone.bind(this));
}

private _quickPulseDone(shouldPOST: boolean, res: http.IncomingMessage): void {
private _quickPulseDone(shouldPOST: boolean, res: http.IncomingMessage | {statusCode: boolean}): void {
markwolff marked this conversation as resolved.
Show resolved Hide resolved
if (QuickPulseStateManager._isCollectingData !== shouldPOST) {
Logging.info("Live Metrics sending data", shouldPOST);
this.enableCollectors(shouldPOST);
Expand All @@ -153,6 +155,9 @@ class QuickPulseStateManager {

if (res.statusCode < 300 && res.statusCode >= 200) {
this._lastSuccessTime = Date.now();
this._lastSendSucceeded = true;
} else {
this._lastSendSucceeded = false;
}
}

Expand Down