Skip to content

Commit

Permalink
Report 'timer' metrics of request processing durations
Browse files Browse the repository at this point in the history
  • Loading branch information
leonerd committed Dec 8, 2016
1 parent 05c89c9 commit 9dc1980
Showing 1 changed file with 28 additions and 1 deletion.
29 changes: 28 additions & 1 deletion lib/bridge/IrcBridge.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ function IrcBridge(config, registration) {
}
});

this._timers = null; // lazy map of Histogram instances used as metrics
if (this.config.ircService.metrics && this.config.ircService.metrics.enabled) {
this._initialiseMetrics();
}
Expand Down Expand Up @@ -115,7 +116,8 @@ function IrcBridge(config, registration) {
IrcBridge.prototype._initialiseMetrics = function() {
var zeroAge = new AgeCounters();

this._bridge.getPrometheusMetrics();
var metrics = this._bridge.getPrometheusMetrics();

this._bridge.registerBridgeGauges(() => {
return {
// TODO(paul): actually fill these in
Expand All @@ -135,6 +137,19 @@ IrcBridge.prototype._initialiseMetrics = function() {
remoteUsersByAge: zeroAge,
};
});

var timers = this._timers = {};

timers.matrix_requests = metrics.addTimer({
name: "matrix_requests",
help: "Histogram of processing durations of received Matrix messages",
labels: ["outcome"],
});
timers.remote_requests = metrics.addTimer({
name: "remote_requests",
help: "Histogram of processing durations of received remote messages",
labels: ["outcome"],
});
};

IrcBridge.prototype.getAppServiceUserId = function() {
Expand Down Expand Up @@ -226,6 +241,10 @@ IrcBridge.prototype.run = Promise.coroutine(function*(port) {
this.onLog("[" + req.getId() + "] DEAD (" + req.getDuration() + "ms)");
var isFromIrc = Boolean((req.getData() || {}).isFromIrc);
stats.request(isFromIrc, "fail", req.getDuration());
if (this._timers) {
var timer = this._timers[isFromIrc ? "remote_requests" : "matrix_requests"];
timer.observe({outcome: "fail"}, req.getDuration() / 1000);
}
}, DEAD_TIME_MS);
this._bridge.getRequestFactory().addDefaultResolveCallback((req, res) => {
if (res === BridgeRequest.ERR_VIRTUAL_USER) {
Expand All @@ -238,10 +257,18 @@ IrcBridge.prototype.run = Promise.coroutine(function*(port) {
}
var isFromIrc = Boolean((req.getData() || {}).isFromIrc);
stats.request(isFromIrc, "success", req.getDuration());
if (this._timers) {
var timer = this._timers[isFromIrc ? "remote_requests" : "matrix_requests"];
timer.observe({outcome: "success"}, req.getDuration() / 1000);
}
});
this._bridge.getRequestFactory().addDefaultRejectCallback((req) => {
var isFromIrc = Boolean((req.getData() || {}).isFromIrc);
stats.request(isFromIrc, "fail", req.getDuration());
if (this._timers) {
var timer = this._timers[isFromIrc ? "remote_requests" : "matrix_requests"];
timer.observe({outcome: "fail"}, req.getDuration() / 1000);
}
});

if (this.config.appService) {
Expand Down

0 comments on commit 9dc1980

Please sign in to comment.