Commit d5121f3b authored by jamiewalch's avatar jamiewalch Committed by Commit bot

Add connection type to connection stats:

* Move the connection mode into the LogToServer ctor, since it never changes.
* Parse log messages, since we don't have an explicit message for connection type.
* Save the most-recent connection type for any channel, and send it with stats logs (we only know how to parse one connection type field, so this seems like the best we're going to get).

Review URL: https://codereview.chromium.org/689473004

Cr-Commit-Position: refs/heads/master@{#302760}
parent 5fa344e7
...@@ -106,7 +106,7 @@ remoting.ClientSession = function(signalStrategy, container, hostDisplayName, ...@@ -106,7 +106,7 @@ remoting.ClientSession = function(signalStrategy, container, hostDisplayName,
this.remapKeys_ = ''; this.remapKeys_ = '';
/** @private */ /** @private */
this.hasReceivedFrame_ = false; this.hasReceivedFrame_ = false;
this.logToServer = new remoting.LogToServer(signalStrategy); this.logToServer = new remoting.LogToServer(signalStrategy, mode);
/** @private */ /** @private */
this.signalStrategy_ = signalStrategy; this.signalStrategy_ = signalStrategy;
...@@ -528,11 +528,7 @@ remoting.ClientSession.prototype.onPluginInitialized_ = function(initialized) { ...@@ -528,11 +528,7 @@ remoting.ClientSession.prototype.onPluginInitialized_ = function(initialized) {
} }
this.plugin_.setOnOutgoingIqHandler(this.sendIq_.bind(this)); this.plugin_.setOnOutgoingIqHandler(this.sendIq_.bind(this));
this.plugin_.setOnDebugMessageHandler( this.plugin_.setOnDebugMessageHandler(this.onDebugMessage_.bind(this));
/** @param {string} msg */
function(msg) {
console.log('plugin: ' + msg.trimRight());
});
this.plugin_.setConnectionStatusUpdateHandler( this.plugin_.setConnectionStatusUpdateHandler(
this.onConnectionStatusUpdate_.bind(this)); this.onConnectionStatusUpdate_.bind(this));
...@@ -605,7 +601,7 @@ remoting.ClientSession.prototype.disconnect = function(error) { ...@@ -605,7 +601,7 @@ remoting.ClientSession.prototype.disconnect = function(error) {
// The plugin won't send a state change notification, so we explicitly log // The plugin won't send a state change notification, so we explicitly log
// the fact that the connection has closed. // the fact that the connection has closed.
this.logToServer.logClientSessionStateChange(state, error, this.mode_); this.logToServer.logClientSessionStateChange(state, error);
this.error_ = error; this.error_ = error;
this.setState_(state); this.setState_(state);
}; };
...@@ -836,6 +832,19 @@ remoting.ClientSession.prototype.sendIq_ = function(message) { ...@@ -836,6 +832,19 @@ remoting.ClientSession.prototype.sendIq_ = function(message) {
this.signalStrategy_.sendMessage(message); this.signalStrategy_.sendMessage(message);
}; };
/**
* @private
* @param {string} msg
*/
remoting.ClientSession.prototype.onDebugMessage_ = function(msg) {
var isConnectionTypeMessage = msg.match(
/^Channel (.*) using (.*) connection.$/);
if (isConnectionTypeMessage) {
this.logToServer.setConnectionType(isConnectionTypeMessage[2]);
}
console.log('plugin: ' + msg.trimRight());
};
/** /**
* @private * @private
* @param {Element} message * @param {Element} message
...@@ -1035,7 +1044,7 @@ remoting.ClientSession.prototype.setState_ = function(newState) { ...@@ -1035,7 +1044,7 @@ remoting.ClientSession.prototype.setState_ = function(newState) {
this.state_ == remoting.ClientSession.State.FAILED) { this.state_ == remoting.ClientSession.State.FAILED) {
state = remoting.ClientSession.State.CONNECTION_DROPPED; state = remoting.ClientSession.State.CONNECTION_DROPPED;
} }
this.logToServer.logClientSessionStateChange(state, this.error_, this.mode_); this.logToServer.logClientSessionStateChange(state, this.error_);
if (this.state_ == remoting.ClientSession.State.CONNECTED) { if (this.state_ == remoting.ClientSession.State.CONNECTED) {
this.createGnubbyAuthHandler_(); this.createGnubbyAuthHandler_();
this.createCastExtensionHandler_(); this.createCastExtensionHandler_();
...@@ -1226,7 +1235,7 @@ remoting.ClientSession.prototype.getPerfStats = function() { ...@@ -1226,7 +1235,7 @@ remoting.ClientSession.prototype.getPerfStats = function() {
* @param {remoting.ClientSession.PerfStats} stats * @param {remoting.ClientSession.PerfStats} stats
*/ */
remoting.ClientSession.prototype.logStatistics = function(stats) { remoting.ClientSession.prototype.logStatistics = function(stats) {
this.logToServer.logStatistics(stats, this.mode_); this.logToServer.logStatistics(stats);
}; };
/** /**
......
...@@ -14,9 +14,10 @@ var remoting = remoting || {}; ...@@ -14,9 +14,10 @@ var remoting = remoting || {};
/** /**
* @param {remoting.SignalStrategy} signalStrategy Signal strategy. * @param {remoting.SignalStrategy} signalStrategy Signal strategy.
* @param {remoting.ClientSession.Mode} mode The mode of this connection.
* @constructor * @constructor
*/ */
remoting.LogToServer = function(signalStrategy) { remoting.LogToServer = function(signalStrategy, mode) {
/** @private */ /** @private */
this.statsAccumulator_ = new remoting.StatsAccumulator(); this.statsAccumulator_ = new remoting.StatsAccumulator();
/** @private */ /** @private */
...@@ -27,6 +28,10 @@ remoting.LogToServer = function(signalStrategy) { ...@@ -27,6 +28,10 @@ remoting.LogToServer = function(signalStrategy) {
this.sessionStartTime_ = 0; this.sessionStartTime_ = 0;
/** @private */ /** @private */
this.signalStrategy_ = signalStrategy; this.signalStrategy_ = signalStrategy;
/** @private */
this.mode_ = mode;
/** @type {string} @private */
this.connectionType_ = '';
}; };
// Constants used for generating a session ID. // Constants used for generating a session ID.
...@@ -48,11 +53,10 @@ remoting.LogToServer.CONNECTION_STATS_ACCUMULATE_TIME = 60 * 1000; ...@@ -48,11 +53,10 @@ remoting.LogToServer.CONNECTION_STATS_ACCUMULATE_TIME = 60 * 1000;
* *
* @param {remoting.ClientSession.State} state * @param {remoting.ClientSession.State} state
* @param {remoting.Error} connectionError * @param {remoting.Error} connectionError
* @param {remoting.ClientSession.Mode} mode
*/ */
remoting.LogToServer.prototype.logClientSessionStateChange = remoting.LogToServer.prototype.logClientSessionStateChange =
function(state, connectionError, mode) { function(state, connectionError) {
this.maybeExpireSessionId(mode); this.maybeExpireSessionId();
// Maybe set the session ID and start time. // Maybe set the session ID and start time.
if (remoting.LogToServer.isStartOfSession(state)) { if (remoting.LogToServer.isStartOfSession(state)) {
if (this.sessionId_ == '') { if (this.sessionId_ == '') {
...@@ -64,7 +68,7 @@ remoting.LogToServer.prototype.logClientSessionStateChange = ...@@ -64,7 +68,7 @@ remoting.LogToServer.prototype.logClientSessionStateChange =
} }
// Log the session state change. // Log the session state change.
var entry = remoting.ServerLogEntry.makeClientSessionStateChange( var entry = remoting.ServerLogEntry.makeClientSessionStateChange(
state, connectionError, mode); state, connectionError, this.mode_);
entry.addHostFields(); entry.addHostFields();
entry.addChromeVersionField(); entry.addChromeVersionField();
entry.addWebappVersionField(); entry.addWebappVersionField();
...@@ -80,7 +84,7 @@ remoting.LogToServer.prototype.logClientSessionStateChange = ...@@ -80,7 +84,7 @@ remoting.LogToServer.prototype.logClientSessionStateChange =
} }
this.log(entry); this.log(entry);
// Don't accumulate connection statistics across state changes. // Don't accumulate connection statistics across state changes.
this.logAccumulatedStatistics(mode); this.logAccumulatedStatistics();
this.statsAccumulator_.empty(); this.statsAccumulator_.empty();
// Maybe clear the session ID. // Maybe clear the session ID.
if (remoting.LogToServer.isEndOfSession(state)) { if (remoting.LogToServer.isEndOfSession(state)) {
...@@ -88,6 +92,15 @@ remoting.LogToServer.prototype.logClientSessionStateChange = ...@@ -88,6 +92,15 @@ remoting.LogToServer.prototype.logClientSessionStateChange =
} }
}; };
/**
* Set the connection type (direct, stun relay).
*
* @param {string} connectionType
*/
remoting.LogToServer.prototype.setConnectionType = function(connectionType) {
this.connectionType_ = connectionType;
};
/** /**
* Whether a session state is one of the states that occurs at the start of * Whether a session state is one of the states that occurs at the start of
* a session. * a session.
...@@ -134,18 +147,17 @@ remoting.LogToServer.shouldAddDuration = function(state) { ...@@ -134,18 +147,17 @@ remoting.LogToServer.shouldAddDuration = function(state) {
/** /**
* Logs connection statistics. * Logs connection statistics.
* @param {Object.<string, number>} stats the connection statistics * @param {Object.<string, number>} stats The connection statistics
* @param {remoting.ClientSession.Mode} mode
*/ */
remoting.LogToServer.prototype.logStatistics = function(stats, mode) { remoting.LogToServer.prototype.logStatistics = function(stats) {
this.maybeExpireSessionId(mode); this.maybeExpireSessionId();
// Store the statistics. // Store the statistics.
this.statsAccumulator_.add(stats); this.statsAccumulator_.add(stats);
// Send statistics to the server if they've been accumulating for at least // Send statistics to the server if they've been accumulating for at least
// 60 seconds. // 60 seconds.
if (this.statsAccumulator_.getTimeSinceFirstValue() >= if (this.statsAccumulator_.getTimeSinceFirstValue() >=
remoting.LogToServer.CONNECTION_STATS_ACCUMULATE_TIME) { remoting.LogToServer.CONNECTION_STATS_ACCUMULATE_TIME) {
this.logAccumulatedStatistics(mode); this.logAccumulatedStatistics();
} }
}; };
...@@ -156,10 +168,11 @@ remoting.LogToServer.prototype.logStatistics = function(stats, mode) { ...@@ -156,10 +168,11 @@ remoting.LogToServer.prototype.logStatistics = function(stats, mode) {
* but the statistics are not sent to the log server. * but the statistics are not sent to the log server.
* *
* @private * @private
* @param {remoting.ClientSession.Mode} mode
*/ */
remoting.LogToServer.prototype.logAccumulatedStatistics = function(mode) { remoting.LogToServer.prototype.logAccumulatedStatistics = function() {
var entry = remoting.ServerLogEntry.makeStats(this.statsAccumulator_, mode); var entry = remoting.ServerLogEntry.makeStats(this.statsAccumulator_,
this.connectionType_,
this.mode_);
if (entry) { if (entry) {
entry.addHostFields(); entry.addHostFields();
entry.addChromeVersionField(); entry.addChromeVersionField();
...@@ -217,19 +230,20 @@ remoting.LogToServer.prototype.clearSessionId = function() { ...@@ -217,19 +230,20 @@ remoting.LogToServer.prototype.clearSessionId = function() {
* log entries. * log entries.
* *
* @private * @private
* @param {remoting.ClientSession.Mode} mode
*/ */
remoting.LogToServer.prototype.maybeExpireSessionId = function(mode) { remoting.LogToServer.prototype.maybeExpireSessionId = function() {
if ((this.sessionId_ != '') && if ((this.sessionId_ != '') &&
(new Date().getTime() - this.sessionIdGenerationTime_ >= (new Date().getTime() - this.sessionIdGenerationTime_ >=
remoting.LogToServer.MAX_SESSION_ID_AGE)) { remoting.LogToServer.MAX_SESSION_ID_AGE)) {
// Log the old session ID. // Log the old session ID.
var entry = remoting.ServerLogEntry.makeSessionIdOld(this.sessionId_, mode); var entry = remoting.ServerLogEntry.makeSessionIdOld(this.sessionId_,
this.mode_);
this.log(entry); this.log(entry);
// Generate a new session ID. // Generate a new session ID.
this.setSessionId(); this.setSessionId();
// Log the new session ID. // Log the new session ID.
entry = remoting.ServerLogEntry.makeSessionIdNew(this.sessionId_, mode); entry = remoting.ServerLogEntry.makeSessionIdNew(this.sessionId_,
this.mode_);
this.log(entry); this.log(entry);
} }
}; };
......
...@@ -23,19 +23,17 @@ remoting.ServerLogEntry = function() { ...@@ -23,19 +23,17 @@ remoting.ServerLogEntry = function() {
/** @private */ /** @private */
remoting.ServerLogEntry.KEY_EVENT_NAME_ = 'event-name'; remoting.ServerLogEntry.KEY_EVENT_NAME_ = 'event-name';
/** @private */ /** @private */
remoting.ServerLogEntry.VALUE_EVENT_NAME_SESSION_STATE_ = remoting.ServerLogEntry.VALUE_EVENT_NAME_SESSION_STATE_ = 'session-state';
'session-state';
/** @private */ /** @private */
remoting.ServerLogEntry.KEY_SESSION_ID_ = 'session-id'; remoting.ServerLogEntry.KEY_SESSION_ID_ = 'session-id';
/** @private */ /** @private */
remoting.ServerLogEntry.KEY_ROLE_ = 'role'; remoting.ServerLogEntry.KEY_ROLE_ = 'role';
/** @private */ /** @private */
remoting.ServerLogEntry.VALUE_ROLE_CLIENT_ = 'client'; remoting.ServerLogEntry.VALUE_ROLE_CLIENT_ = 'client';
/** @private */ /** @private */
remoting.ServerLogEntry.KEY_SESSION_STATE_ = 'session-state'; remoting.ServerLogEntry.KEY_SESSION_STATE_ = 'session-state';
/** @private */
remoting.ServerLogEntry.KEY_CONNECTION_TYPE_ = 'connection-type';
/** /**
* @private * @private
...@@ -241,15 +239,22 @@ remoting.ServerLogEntry.prototype.addSessionDurationField = function( ...@@ -241,15 +239,22 @@ remoting.ServerLogEntry.prototype.addSessionDurationField = function(
* Returns null if all the statistics were zero. * Returns null if all the statistics were zero.
* *
* @param {remoting.StatsAccumulator} statsAccumulator * @param {remoting.StatsAccumulator} statsAccumulator
* @param {string} connectionType
* @param {remoting.ClientSession.Mode} mode * @param {remoting.ClientSession.Mode} mode
* @return {?remoting.ServerLogEntry} * @return {?remoting.ServerLogEntry}
*/ */
remoting.ServerLogEntry.makeStats = function(statsAccumulator, mode) { remoting.ServerLogEntry.makeStats = function(statsAccumulator,
connectionType,
mode) {
var entry = new remoting.ServerLogEntry(); var entry = new remoting.ServerLogEntry();
entry.set(remoting.ServerLogEntry.KEY_ROLE_, entry.set(remoting.ServerLogEntry.KEY_ROLE_,
remoting.ServerLogEntry.VALUE_ROLE_CLIENT_); remoting.ServerLogEntry.VALUE_ROLE_CLIENT_);
entry.set(remoting.ServerLogEntry.KEY_EVENT_NAME_, entry.set(remoting.ServerLogEntry.KEY_EVENT_NAME_,
remoting.ServerLogEntry.VALUE_EVENT_NAME_CONNECTION_STATISTICS_); remoting.ServerLogEntry.VALUE_EVENT_NAME_CONNECTION_STATISTICS_);
if (connectionType) {
entry.set(remoting.ServerLogEntry.KEY_CONNECTION_TYPE_,
connectionType);
}
entry.addModeField(mode); entry.addModeField(mode);
var nonZero = false; var nonZero = false;
nonZero |= entry.addStatsField( nonZero |= entry.addStatsField(
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment