Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(841)

Side by Side Diff: remoting/webapp/crd/js/log_to_server.js

Issue 855003008: Log signal strategy progress to server. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase. Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 /** 5 /**
6 * @fileoverview 6 * @fileoverview
7 * Module for sending log entries to the server. 7 * Module for sending log entries to the server.
8 */ 8 */
9 9
10 'use strict'; 10 'use strict';
(...skipping 14 matching lines...) Expand all
25 /** @private */ 25 /** @private */
26 this.sessionIdGenerationTime_ = 0; 26 this.sessionIdGenerationTime_ = 0;
27 /** @private */ 27 /** @private */
28 this.sessionStartTime_ = 0; 28 this.sessionStartTime_ = 0;
29 /** @private */ 29 /** @private */
30 this.signalStrategy_ = signalStrategy; 30 this.signalStrategy_ = signalStrategy;
31 /** @private */ 31 /** @private */
32 this.mode_ = mode; 32 this.mode_ = mode;
33 /** @type {string} @private */ 33 /** @type {string} @private */
34 this.connectionType_ = ''; 34 this.connectionType_ = '';
35
36 this.setSessionId_();
37 signalStrategy.sendConnectionSetupResults(this);
35 }; 38 };
36 39
37 // Constants used for generating a session ID. 40 // Constants used for generating a session ID.
38 /** @private */ 41 /** @private */
39 remoting.LogToServer.SESSION_ID_ALPHABET_ = 42 remoting.LogToServer.SESSION_ID_ALPHABET_ =
40 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890'; 43 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890';
41 /** @private */ 44 /** @private */
42 remoting.LogToServer.SESSION_ID_LEN_ = 20; 45 remoting.LogToServer.SESSION_ID_LEN_ = 20;
43 46
44 // The maximum age of a session ID, in milliseconds. 47 // The maximum age of a session ID, in milliseconds.
45 remoting.LogToServer.MAX_SESSION_ID_AGE = 24 * 60 * 60 * 1000; 48 remoting.LogToServer.MAX_SESSION_ID_AGE = 24 * 60 * 60 * 1000;
46 49
47 // The time over which to accumulate connection statistics before logging them 50 // The time over which to accumulate connection statistics before logging them
48 // to the server, in milliseconds. 51 // to the server, in milliseconds.
49 remoting.LogToServer.CONNECTION_STATS_ACCUMULATE_TIME = 60 * 1000; 52 remoting.LogToServer.CONNECTION_STATS_ACCUMULATE_TIME = 60 * 1000;
50 53
51 /** 54 /**
52 * Logs a client session state change. 55 * Logs a client session state change.
53 * 56 *
54 * @param {remoting.ClientSession.State} state 57 * @param {remoting.ClientSession.State} state
55 * @param {remoting.Error} connectionError 58 * @param {remoting.Error} connectionError
56 */ 59 */
57 remoting.LogToServer.prototype.logClientSessionStateChange = 60 remoting.LogToServer.prototype.logClientSessionStateChange =
58 function(state, connectionError) { 61 function(state, connectionError) {
59 this.maybeExpireSessionId(); 62 this.maybeExpireSessionId_();
60 // Maybe set the session ID and start time. 63 // Set the session start time if we haven't done so already.
61 if (remoting.LogToServer.isStartOfSession(state)) { 64 if (remoting.LogToServer.isStartOfSession_(state)) {
62 if (this.sessionId_ == '') {
63 this.setSessionId();
64 }
65 if (this.sessionStartTime_ == 0) { 65 if (this.sessionStartTime_ == 0) {
66 this.sessionStartTime_ = new Date().getTime(); 66 this.sessionStartTime_ = new Date().getTime();
67 } 67 }
68 } 68 }
69 // Log the session state change. 69 // Log the session state change.
70 var entry = remoting.ServerLogEntry.makeClientSessionStateChange( 70 var entry = remoting.ServerLogEntry.makeClientSessionStateChange(
71 state, connectionError, this.mode_); 71 state, connectionError, this.mode_);
72 entry.addHostFields(); 72 entry.addHostFields();
73 entry.addChromeVersionField(); 73 entry.addChromeVersionField();
74 entry.addWebappVersionField(); 74 entry.addWebappVersionField();
75 entry.addSessionIdField(this.sessionId_); 75 entry.addSessionIdField(this.sessionId_);
76 // Maybe clear the session start time, and log the session duration. 76 // Maybe clear the session start time, and log the session duration.
77 if (remoting.LogToServer.shouldAddDuration(state) && 77 if (remoting.LogToServer.shouldAddDuration_(state) &&
78 (this.sessionStartTime_ != 0)) { 78 (this.sessionStartTime_ != 0)) {
79 entry.addSessionDurationField( 79 entry.addSessionDurationField(
80 (new Date().getTime() - this.sessionStartTime_) / 1000.0); 80 (new Date().getTime() - this.sessionStartTime_) / 1000.0);
81 if (remoting.LogToServer.isEndOfSession(state)) { 81 if (remoting.LogToServer.isEndOfSession_(state)) {
82 this.sessionStartTime_ = 0; 82 this.sessionStartTime_ = 0;
83 } 83 }
84 } 84 }
85 this.log(entry); 85 this.log_(entry);
86 // Don't accumulate connection statistics across state changes. 86 // Don't accumulate connection statistics across state changes.
87 this.logAccumulatedStatistics(); 87 this.logAccumulatedStatistics_();
88 this.statsAccumulator_.empty(); 88 this.statsAccumulator_.empty();
89 // Maybe clear the session ID. 89 // Maybe clear the session ID.
90 if (remoting.LogToServer.isEndOfSession(state)) { 90 if (remoting.LogToServer.isEndOfSession_(state)) {
91 this.clearSessionId(); 91 this.clearSessionId_();
92 } 92 }
93 }; 93 };
94 94
95 /** 95 /**
96 * Set the connection type (direct, stun relay). 96 * Set the connection type (direct, stun relay).
97 * 97 *
98 * @param {string} connectionType 98 * @param {string} connectionType
99 */ 99 */
100 remoting.LogToServer.prototype.setConnectionType = function(connectionType) { 100 remoting.LogToServer.prototype.setConnectionType = function(connectionType) {
101 this.connectionType_ = connectionType; 101 this.connectionType_ = connectionType;
102 }; 102 };
103 103
104 /** 104 /**
105 * @param {remoting.SignalStrategy.Type} strategyType
106 * @param {remoting.FallbackSignalStrategy.Progress} progress
107 * @param {number} elapsedTimeInMs
108 */
109 remoting.LogToServer.prototype.logSignalStrategyProgress =
110 function(strategyType, progress, elapsedTimeInMs) {
111 this.maybeExpireSessionId_();
112 var entry = remoting.ServerLogEntry.makeSignalStrategyProgress(
113 this.sessionId_, strategyType, progress, elapsedTimeInMs);
114 this.log_(entry);
115 };
116
117 /**
105 * Whether a session state is one of the states that occurs at the start of 118 * Whether a session state is one of the states that occurs at the start of
106 * a session. 119 * a session.
107 * 120 *
108 * @private 121 * @private
109 * @param {remoting.ClientSession.State} state 122 * @param {remoting.ClientSession.State} state
110 * @return {boolean} 123 * @return {boolean}
111 */ 124 */
112 remoting.LogToServer.isStartOfSession = function(state) { 125 remoting.LogToServer.isStartOfSession_ = function(state) {
113 return ((state == remoting.ClientSession.State.CONNECTING) || 126 return ((state == remoting.ClientSession.State.CONNECTING) ||
114 (state == remoting.ClientSession.State.INITIALIZING) || 127 (state == remoting.ClientSession.State.INITIALIZING) ||
115 (state == remoting.ClientSession.State.CONNECTED)); 128 (state == remoting.ClientSession.State.CONNECTED));
116 }; 129 };
117 130
118 /** 131 /**
119 * Whether a session state is one of the states that occurs at the end of 132 * Whether a session state is one of the states that occurs at the end of
120 * a session. 133 * a session.
121 * 134 *
122 * @private 135 * @private
123 * @param {remoting.ClientSession.State} state 136 * @param {remoting.ClientSession.State} state
124 * @return {boolean} 137 * @return {boolean}
125 */ 138 */
126 remoting.LogToServer.isEndOfSession = function(state) { 139 remoting.LogToServer.isEndOfSession_ = function(state) {
127 return ((state == remoting.ClientSession.State.CLOSED) || 140 return ((state == remoting.ClientSession.State.CLOSED) ||
128 (state == remoting.ClientSession.State.FAILED) || 141 (state == remoting.ClientSession.State.FAILED) ||
129 (state == remoting.ClientSession.State.CONNECTION_DROPPED) || 142 (state == remoting.ClientSession.State.CONNECTION_DROPPED) ||
130 (state == remoting.ClientSession.State.CONNECTION_CANCELED)); 143 (state == remoting.ClientSession.State.CONNECTION_CANCELED));
131 }; 144 };
132 145
133 /** 146 /**
134 * Whether the duration should be added to the log entry for this state. 147 * Whether the duration should be added to the log entry for this state.
135 * 148 *
136 * @private 149 * @private
137 * @param {remoting.ClientSession.State} state 150 * @param {remoting.ClientSession.State} state
138 * @return {boolean} 151 * @return {boolean}
139 */ 152 */
140 remoting.LogToServer.shouldAddDuration = function(state) { 153 remoting.LogToServer.shouldAddDuration_ = function(state) {
141 // Duration is added to log entries at the end of the session, as well as at 154 // Duration is added to log entries at the end of the session, as well as at
142 // some intermediate states where it is relevant (e.g. to determine how long 155 // some intermediate states where it is relevant (e.g. to determine how long
143 // it took for a session to become CONNECTED). 156 // it took for a session to become CONNECTED).
144 return (remoting.LogToServer.isEndOfSession(state) || 157 return (remoting.LogToServer.isEndOfSession_(state) ||
145 (state == remoting.ClientSession.State.CONNECTED)); 158 (state == remoting.ClientSession.State.CONNECTED));
146 }; 159 };
147 160
148 /** 161 /**
149 * Logs connection statistics. 162 * Logs connection statistics.
150 * @param {Object.<string, number>} stats The connection statistics 163 * @param {Object.<string, number>} stats The connection statistics
151 */ 164 */
152 remoting.LogToServer.prototype.logStatistics = function(stats) { 165 remoting.LogToServer.prototype.logStatistics = function(stats) {
153 this.maybeExpireSessionId(); 166 this.maybeExpireSessionId_();
154 // Store the statistics. 167 // Store the statistics.
155 this.statsAccumulator_.add(stats); 168 this.statsAccumulator_.add(stats);
156 // Send statistics to the server if they've been accumulating for at least 169 // Send statistics to the server if they've been accumulating for at least
157 // 60 seconds. 170 // 60 seconds.
158 if (this.statsAccumulator_.getTimeSinceFirstValue() >= 171 if (this.statsAccumulator_.getTimeSinceFirstValue() >=
159 remoting.LogToServer.CONNECTION_STATS_ACCUMULATE_TIME) { 172 remoting.LogToServer.CONNECTION_STATS_ACCUMULATE_TIME) {
160 this.logAccumulatedStatistics(); 173 this.logAccumulatedStatistics_();
161 } 174 }
162 }; 175 };
163 176
164 /** 177 /**
165 * Moves connection statistics from the accumulator to the log server. 178 * Moves connection statistics from the accumulator to the log server.
166 * 179 *
167 * If all the statistics are zero, then the accumulator is still emptied, 180 * If all the statistics are zero, then the accumulator is still emptied,
168 * but the statistics are not sent to the log server. 181 * but the statistics are not sent to the log server.
169 * 182 *
170 * @private 183 * @private
171 */ 184 */
172 remoting.LogToServer.prototype.logAccumulatedStatistics = function() { 185 remoting.LogToServer.prototype.logAccumulatedStatistics_ = function() {
173 var entry = remoting.ServerLogEntry.makeStats(this.statsAccumulator_, 186 var entry = remoting.ServerLogEntry.makeStats(this.statsAccumulator_,
174 this.connectionType_, 187 this.connectionType_,
175 this.mode_); 188 this.mode_);
176 if (entry) { 189 if (entry) {
177 entry.addHostFields(); 190 entry.addHostFields();
178 entry.addChromeVersionField(); 191 entry.addChromeVersionField();
179 entry.addWebappVersionField(); 192 entry.addWebappVersionField();
180 entry.addSessionIdField(this.sessionId_); 193 entry.addSessionIdField(this.sessionId_);
181 this.log(entry); 194 this.log_(entry);
182 } 195 }
183 this.statsAccumulator_.empty(); 196 this.statsAccumulator_.empty();
184 }; 197 };
185 198
186 /** 199 /**
187 * Sends a log entry to the server. 200 * Sends a log entry to the server.
188 * 201 *
189 * @private 202 * @private
190 * @param {remoting.ServerLogEntry} entry 203 * @param {remoting.ServerLogEntry} entry
191 */ 204 */
192 remoting.LogToServer.prototype.log = function(entry) { 205 remoting.LogToServer.prototype.log_ = function(entry) {
193 // Send the stanza to the debug log. 206 // Send the stanza to the debug log.
194 console.log('Enqueueing log entry:'); 207 console.log('Enqueueing log entry:');
195 entry.toDebugLog(1); 208 entry.toDebugLog(1);
196 209
197 var stanza = '<cli:iq to="' + remoting.settings.DIRECTORY_BOT_JID + '" ' + 210 var stanza = '<cli:iq to="' + remoting.settings.DIRECTORY_BOT_JID + '" ' +
198 'type="set" xmlns:cli="jabber:client">' + 211 'type="set" xmlns:cli="jabber:client">' +
199 '<gr:log xmlns:gr="google:remoting">' + 212 '<gr:log xmlns:gr="google:remoting">' +
200 entry.toStanza() + 213 entry.toStanza() +
201 '</gr:log>' + 214 '</gr:log>' +
202 '</cli:iq>'; 215 '</cli:iq>';
203 this.signalStrategy_.sendMessage(stanza); 216 this.signalStrategy_.sendMessage(stanza);
204 }; 217 };
205 218
206 /** 219 /**
207 * Sets the session ID to a random string. 220 * Sets the session ID to a random string.
208 * 221 *
209 * @private 222 * @private
210 */ 223 */
211 remoting.LogToServer.prototype.setSessionId = function() { 224 remoting.LogToServer.prototype.setSessionId_ = function() {
212 this.sessionId_ = remoting.LogToServer.generateSessionId(); 225 this.sessionId_ = remoting.LogToServer.generateSessionId_();
213 this.sessionIdGenerationTime_ = new Date().getTime(); 226 this.sessionIdGenerationTime_ = new Date().getTime();
214 }; 227 };
215 228
216 /** 229 /**
217 * Clears the session ID. 230 * Clears the session ID.
218 * 231 *
219 * @private 232 * @private
220 */ 233 */
221 remoting.LogToServer.prototype.clearSessionId = function() { 234 remoting.LogToServer.prototype.clearSessionId_ = function() {
222 this.sessionId_ = ''; 235 this.sessionId_ = '';
223 this.sessionIdGenerationTime_ = 0; 236 this.sessionIdGenerationTime_ = 0;
224 }; 237 };
225 238
226 /** 239 /**
227 * Sets a new session ID, if the current session ID has reached its maximum age. 240 * Sets a new session ID, if the current session ID has reached its maximum age.
228 * 241 *
229 * This method also logs the old and new session IDs to the server, in separate 242 * This method also logs the old and new session IDs to the server, in separate
230 * log entries. 243 * log entries.
231 * 244 *
232 * @private 245 * @private
233 */ 246 */
234 remoting.LogToServer.prototype.maybeExpireSessionId = function() { 247 remoting.LogToServer.prototype.maybeExpireSessionId_ = function() {
235 if ((this.sessionId_ != '') && 248 if ((this.sessionId_ != '') &&
236 (new Date().getTime() - this.sessionIdGenerationTime_ >= 249 (new Date().getTime() - this.sessionIdGenerationTime_ >=
237 remoting.LogToServer.MAX_SESSION_ID_AGE)) { 250 remoting.LogToServer.MAX_SESSION_ID_AGE)) {
238 // Log the old session ID. 251 // Log the old session ID.
239 var entry = remoting.ServerLogEntry.makeSessionIdOld(this.sessionId_, 252 var entry = remoting.ServerLogEntry.makeSessionIdOld(this.sessionId_,
240 this.mode_); 253 this.mode_);
241 this.log(entry); 254 this.log_(entry);
242 // Generate a new session ID. 255 // Generate a new session ID.
243 this.setSessionId(); 256 this.setSessionId_();
244 // Log the new session ID. 257 // Log the new session ID.
245 entry = remoting.ServerLogEntry.makeSessionIdNew(this.sessionId_, 258 entry = remoting.ServerLogEntry.makeSessionIdNew(this.sessionId_,
246 this.mode_); 259 this.mode_);
247 this.log(entry); 260 this.log_(entry);
248 } 261 }
249 }; 262 };
250 263
251 /** 264 /**
252 * Generates a string that can be used as a session ID. 265 * Generates a string that can be used as a session ID.
253 * 266 *
254 * @private 267 * @private
255 * @return {string} a session ID 268 * @return {string} a session ID
256 */ 269 */
257 remoting.LogToServer.generateSessionId = function() { 270 remoting.LogToServer.generateSessionId_ = function() {
258 var idArray = []; 271 var idArray = [];
259 for (var i = 0; i < remoting.LogToServer.SESSION_ID_LEN_; i++) { 272 for (var i = 0; i < remoting.LogToServer.SESSION_ID_LEN_; i++) {
260 var index = 273 var index =
261 Math.random() * remoting.LogToServer.SESSION_ID_ALPHABET_.length; 274 Math.random() * remoting.LogToServer.SESSION_ID_ALPHABET_.length;
262 idArray.push( 275 idArray.push(
263 remoting.LogToServer.SESSION_ID_ALPHABET_.slice(index, index + 1)); 276 remoting.LogToServer.SESSION_ID_ALPHABET_.slice(index, index + 1));
264 } 277 }
265 return idArray.join(''); 278 return idArray.join('');
266 }; 279 };
OLDNEW
« no previous file with comments | « remoting/webapp/crd/js/fallback_signal_strategy.js ('k') | remoting/webapp/crd/js/server_log_entry.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698