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

only log extended duration QPS errors #511

Merged
merged 4 commits into from
Apr 25, 2019
Merged
Changes from 3 commits
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
18 changes: 17 additions & 1 deletion Library/QuickPulseSender.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,15 @@ const QuickPulseConfig = {
};

class QuickPulseSender {
private static TAG = "QuickPulseSender";
private static MAX_QPS_FAILURES_BEFORE_WARN = 25;

private _config: Config;
private _consecutiveErrors: number;

constructor(config: Config) {
this._config = config;
this._consecutiveErrors = 0;
}

public ping(envelope: Contracts.EnvelopeQuickPulse, done: (shouldPOST: boolean, res?: http.IncomingMessage) => void): void {
Expand Down Expand Up @@ -47,12 +52,23 @@ class QuickPulseSender {

const req = https.request(options, (res: http.IncomingMessage) => {
const shouldPOSTData = res.headers[QuickPulseConfig.subscribed] === "true";
this._consecutiveErrors = 0;
done(shouldPOSTData, res);
});
req.on("error", (error: Error) => {
// Unable to contact qps endpoint.
// Do nothing for now.
Logging.warn("Unable to contact qps endpoint, dropping this Live Metrics packet", error);
this._consecutiveErrors++;

// LOG every error, but WARN instead when X number of consecutive errors occur
let notice = `Transient error connecting to the Live Metrics endpoint. This packet will not appear in your Live Metrics Stream. Error:`;
if (this._consecutiveErrors % QuickPulseSender.MAX_QPS_FAILURES_BEFORE_WARN === 0) {
notice = `Live Metrics endpoint could not be reached ${this._consecutiveErrors} consecutive times. Most recent error:`;
Logging.warn(QuickPulseSender.TAG, notice, error);
} else {
Logging.info(QuickPulseSender.TAG, notice, error);
}

done(false); // Stop POSTing QPS data
});

Expand Down