commit/galaxy-central: carlfeberhard: Metrics: remove double parsing of JSON from server-side, add GalaxyApp object with config and user, tie metrics-logger to GalaxyApp
1 new commit in galaxy-central: https://bitbucket.org/galaxy/galaxy-central/commits/4131de825802/ Changeset: 4131de825802 User: carlfeberhard Date: 2014-04-14 19:00:06 Summary: Metrics: remove double parsing of JSON from server-side, add GalaxyApp object with config and user, tie metrics-logger to GalaxyApp Affected #: 10 files diff -r 3e054419aca1d5831d65fcaccccf1dae16dfb279 -r 4131de825802f46ff97194d02b25739a20856b17 lib/galaxy/webapps/galaxy/api/metrics.py --- a/lib/galaxy/webapps/galaxy/api/metrics.py +++ b/lib/galaxy/webapps/galaxy/api/metrics.py @@ -100,7 +100,7 @@ time = self._deserialize_isoformat_date( metric[ 'time' ] ) kwargs = { 'level' : metric[ 'level' ], - 'args' : json.from_json_string( metric[ 'args' ] ), + 'args' : metric[ 'args' ], 'user' : user_id, 'session' : session_id } diff -r 3e054419aca1d5831d65fcaccccf1dae16dfb279 -r 4131de825802f46ff97194d02b25739a20856b17 static/scripts/galaxy-app-base.js --- /dev/null +++ b/static/scripts/galaxy-app-base.js @@ -0,0 +1,83 @@ +define([ + 'mvc/user/user-model', + 'utils/metrics-logger', + 'utils/add-logging' +], function( userModel, metricsLogger, addLogging ){ +// ============================================================================ +/** + * + */ +function GalaxyApp( options ){ + var self = this; + return self._init( options || {} ); +} +addLogging( GalaxyApp, 'GalaxyApp' ); + +/** */ +GalaxyApp.defaultOptions = { + // move to self.root? + root : '/' +}; + +/** */ +GalaxyApp.prototype._init = function init( options ){ + var self = this; + + self._initLogger( options.loggerOptions || {} ); + self.debug( 'GalaxyApp.logger: ', self.logger ); + + self._processOptions( options ); + self.debug( 'GalaxyApp.options: ', self.options ); + + self.config = options.config || {}; + self.debug( 'GalaxyApp.config: ', self.config ); + + self._initUser( options.userJSON || {} ); + self.debug( 'GalaxyApp.user: ', self.user ); + + return self; +}; + +/** */ +GalaxyApp.prototype._processOptions = function _processOptions( options ){ + var self = this, + defaults = GalaxyApp.defaultOptions; + self.debug( '_processOptions: ', options ); + + self.options = {}; + for( var k in defaults ){ + if( defaults.hasOwnProperty( k ) ){ + self.options[ k ] = ( options.hasOwnProperty( k ) )?( options[ k ] ):( defaults[ k ] ); + } + } + return self; +}; + +/** */ +GalaxyApp.prototype._initUser = function _initUser( userJSON ){ + var self = this; + self.debug( '_initUser:', userJSON ); + self.user = new userModel.User( userJSON ); + return self; +}; + +/** */ +GalaxyApp.prototype._initLogger = function _initLogger( loggerOptions ){ + var self = this; + self.debug( '_initLogger:', loggerOptions ); + self.logger = new metricsLogger.MetricsLogger( loggerOptions ); + return self; +}; + +/** */ +GalaxyApp.prototype.toString = function toString(){ + var userEmail = this.user.get( 'email' ) || '(anonymous)'; + return 'GalaxyApp(' + userEmail + ')'; +}; + + +// ============================================================================ + return { + GalaxyApp : GalaxyApp + }; +}); diff -r 3e054419aca1d5831d65fcaccccf1dae16dfb279 -r 4131de825802f46ff97194d02b25739a20856b17 static/scripts/mvc/base-mvc.js --- a/static/scripts/mvc/base-mvc.js +++ b/static/scripts/mvc/base-mvc.js @@ -1,5 +1,6 @@ define([ -], function(){ + 'utils/add-logging' +], function( addLogging ){ //ASSUMES: backbone //============================================================================== /** @class Mixin to add logging capabilities to an object. @@ -29,7 +30,8 @@ * messages. Null will supress all logging. Commonly set to console. */ // replace null with console (if available) to see all logs - logger : null, + logger : null, + _logNamespace : '?', /** Output log messages/arguments to logger. * @param {Arguments} ... (this function is variadic) @@ -46,6 +48,7 @@ return undefined; } }; +addLogging( LoggableMixin ); //============================================================================== diff -r 3e054419aca1d5831d65fcaccccf1dae16dfb279 -r 4131de825802f46ff97194d02b25739a20856b17 static/scripts/packed/galaxy-app-base.js --- /dev/null +++ b/static/scripts/packed/galaxy-app-base.js @@ -0,0 +1,1 @@ +define(["mvc/user/user-model","utils/metrics-logger","utils/add-logging"],function(a,c,e){function f(k){var j=this;return j._init(k||{})}e(f,"GalaxyApp");f.defaultOptions={root:"/"};f.prototype._init=function h(k){var j=this;j._initLogger(k.loggerOptions||{});j.debug("GalaxyApp.logger: ",j.logger);j._processOptions(k);j.debug("GalaxyApp.options: ",j.options);j.config=k.config||{};j.debug("GalaxyApp.config: ",j.config);j._initUser(k.userJSON||{});j.debug("GalaxyApp.user: ",j.user);return j};f.prototype._processOptions=function d(m){var l=this,n=f.defaultOptions;l.debug("_processOptions: ",m);l.options={};for(var j in n){if(n.hasOwnProperty(j)){l.options[j]=(m.hasOwnProperty(j))?(m[j]):(n[j])}}return l};f.prototype._initUser=function g(k){var j=this;j.debug("_initUser:",k);j.user=new a.User(k);return j};f.prototype._initLogger=function i(k){var j=this;j.debug("_initLogger:",k);j.logger=new c.MetricsLogger(k);return j};f.prototype.toString=function b(){var j=this.user.get("email")||"(anonymous)";return"GalaxyApp("+j+")"};return{GalaxyApp:f}}); \ No newline at end of file diff -r 3e054419aca1d5831d65fcaccccf1dae16dfb279 -r 4131de825802f46ff97194d02b25739a20856b17 static/scripts/packed/mvc/base-mvc.js --- a/static/scripts/packed/mvc/base-mvc.js +++ b/static/scripts/packed/mvc/base-mvc.js @@ -1,1 +1,1 @@ -define([],function(){var c={logger:null,log:function(){if(this.logger){var d=this.logger.log;if(typeof this.logger.log==="object"){d=Function.prototype.bind.call(this.logger.log,this.logger)}return d.apply(this.logger,arguments)}return undefined}};var a=Backbone.Model.extend({initialize:function(e){this._checkEnabledSessionStorage();if(!e.id){throw new Error("SessionStorageModel requires an id in the initial attributes")}this.id=e.id;var d=(!this.isNew())?(this._read(this)):({});this.clear({silent:true});this.save(_.extend({},this.defaults,d,e),{silent:true});this.on("change",function(){this.save()})},_checkEnabledSessionStorage:function(){try{return sessionStorage.length}catch(d){alert("Please enable cookies in your browser for this Galaxy site");return false}},sync:function(g,e,d){if(!d.silent){e.trigger("request",e,{},d)}var f;switch(g){case"create":f=this._create(e);break;case"read":f=this._read(e);break;case"update":f=this._update(e);break;case"delete":f=this._delete(e);break}if(f!==undefined||f!==null){if(d.success){d.success()}}else{if(d.error){d.error()}}return f},_create:function(d){var e=d.toJSON(),f=sessionStorage.setItem(d.id,JSON.stringify(e));return(f===null)?(f):(e)},_read:function(d){return JSON.parse(sessionStorage.getItem(d.id))},_update:function(d){return d._create(d)},_delete:function(d){return sessionStorage.removeItem(d.id)},isNew:function(){return !sessionStorage.hasOwnProperty(this.id)},_log:function(){return JSON.stringify(this.toJSON(),null," ")},toString:function(){return"SessionStorageModel("+this.id+")"}});(function(){a.prototype=_.omit(a.prototype,"url","urlRoot")}());var b={hiddenUntilActivated:function(d,f){f=f||{};this.HUAVOptions={$elementShown:this.$el,showFn:jQuery.prototype.toggle,showSpeed:"fast"};_.extend(this.HUAVOptions,f||{});this.HUAVOptions.hasBeenShown=this.HUAVOptions.$elementShown.is(":visible");this.hidden=this.isHidden();if(d){var e=this;d.on("click",function(g){e.toggle(e.HUAVOptions.showSpeed)})}},isHidden:function(){return(this.HUAVOptions.$elementShown.is(":hidden"))},toggle:function(){if(this.hidden){if(!this.HUAVOptions.hasBeenShown){if(_.isFunction(this.HUAVOptions.onshowFirstTime)){this.HUAVOptions.hasBeenShown=true;this.HUAVOptions.onshowFirstTime.call(this)}}if(_.isFunction(this.HUAVOptions.onshow)){this.HUAVOptions.onshow.call(this);this.trigger("hiddenUntilActivated:shown",this)}this.hidden=false}else{if(_.isFunction(this.HUAVOptions.onhide)){this.HUAVOptions.onhide.call(this);this.trigger("hiddenUntilActivated:hidden",this)}this.hidden=true}return this.HUAVOptions.showFn.apply(this.HUAVOptions.$elementShown,arguments)}};return{LoggableMixin:c,SessionStorageModel:a,HiddenUntilActivatedViewMixin:b}}); \ No newline at end of file +define(["utils/add-logging"],function(c){var d={logger:null,_logNamespace:"?",log:function(){if(this.logger){var e=this.logger.log;if(typeof this.logger.log==="object"){e=Function.prototype.bind.call(this.logger.log,this.logger)}return e.apply(this.logger,arguments)}return undefined}};c(d);var a=Backbone.Model.extend({initialize:function(f){this._checkEnabledSessionStorage();if(!f.id){throw new Error("SessionStorageModel requires an id in the initial attributes")}this.id=f.id;var e=(!this.isNew())?(this._read(this)):({});this.clear({silent:true});this.save(_.extend({},this.defaults,e,f),{silent:true});this.on("change",function(){this.save()})},_checkEnabledSessionStorage:function(){try{return sessionStorage.length}catch(e){alert("Please enable cookies in your browser for this Galaxy site");return false}},sync:function(h,f,e){if(!e.silent){f.trigger("request",f,{},e)}var g;switch(h){case"create":g=this._create(f);break;case"read":g=this._read(f);break;case"update":g=this._update(f);break;case"delete":g=this._delete(f);break}if(g!==undefined||g!==null){if(e.success){e.success()}}else{if(e.error){e.error()}}return g},_create:function(e){var f=e.toJSON(),g=sessionStorage.setItem(e.id,JSON.stringify(f));return(g===null)?(g):(f)},_read:function(e){return JSON.parse(sessionStorage.getItem(e.id))},_update:function(e){return e._create(e)},_delete:function(e){return sessionStorage.removeItem(e.id)},isNew:function(){return !sessionStorage.hasOwnProperty(this.id)},_log:function(){return JSON.stringify(this.toJSON(),null," ")},toString:function(){return"SessionStorageModel("+this.id+")"}});(function(){a.prototype=_.omit(a.prototype,"url","urlRoot")}());var b={hiddenUntilActivated:function(e,g){g=g||{};this.HUAVOptions={$elementShown:this.$el,showFn:jQuery.prototype.toggle,showSpeed:"fast"};_.extend(this.HUAVOptions,g||{});this.HUAVOptions.hasBeenShown=this.HUAVOptions.$elementShown.is(":visible");this.hidden=this.isHidden();if(e){var f=this;e.on("click",function(h){f.toggle(f.HUAVOptions.showSpeed)})}},isHidden:function(){return(this.HUAVOptions.$elementShown.is(":hidden"))},toggle:function(){if(this.hidden){if(!this.HUAVOptions.hasBeenShown){if(_.isFunction(this.HUAVOptions.onshowFirstTime)){this.HUAVOptions.hasBeenShown=true;this.HUAVOptions.onshowFirstTime.call(this)}}if(_.isFunction(this.HUAVOptions.onshow)){this.HUAVOptions.onshow.call(this);this.trigger("hiddenUntilActivated:shown",this)}this.hidden=false}else{if(_.isFunction(this.HUAVOptions.onhide)){this.HUAVOptions.onhide.call(this);this.trigger("hiddenUntilActivated:hidden",this)}this.hidden=true}return this.HUAVOptions.showFn.apply(this.HUAVOptions.$elementShown,arguments)}};return{LoggableMixin:d,SessionStorageModel:a,HiddenUntilActivatedViewMixin:b}}); \ No newline at end of file diff -r 3e054419aca1d5831d65fcaccccf1dae16dfb279 -r 4131de825802f46ff97194d02b25739a20856b17 static/scripts/packed/utils/add-logging.js --- /dev/null +++ b/static/scripts/packed/utils/add-logging.js @@ -0,0 +1,1 @@ +define([],function(){function a(c,b){if(b!==undefined){c._logNamespace=b}["debug","info","warn","error","metric"].forEach(function(d){(c.prototype||c)[d]=function(){if(!this.logger){return undefined}if(this.logger.emit){return this.logger.emit(d,this._logNamespace,arguments)}if(this.logger[d]){return this.logger[d].apply(this.logger,arguments)}return undefined}});return c}return a}); \ No newline at end of file diff -r 3e054419aca1d5831d65fcaccccf1dae16dfb279 -r 4131de825802f46ff97194d02b25739a20856b17 static/scripts/packed/utils/metrics-logger.js --- a/static/scripts/packed/utils/metrics-logger.js +++ b/static/scripts/packed/utils/metrics-logger.js @@ -1,1 +1,1 @@ -define([],function(){function h(z){z=z||{};var y=this;y.consoleLogger=z.consoleLogger||null;y._init(z);return y}h.ALL=0;h.DEBUG=10;h.INFO=20;h.WARN=30;h.ERROR=40;h.METRIC=50;h.NONE=100;h.defaultOptions={logLevel:h.INFO,consoleLevel:h.NONE,defaultNamespace:"Galaxy",clientPrefix:"client.",maxCacheSize:3000,postSize:1000,addTime:true,postUrl:"/api/metrics",postOnUnload:true,getPingData:undefined,onServerResponse:undefined};h.prototype._init=function i(A){var z=this;z.options={};for(var y in h.defaultOptions){if(h.defaultOptions.hasOwnProperty(y)){z.options[y]=(A.hasOwnProperty(y))?(A[y]):(h.defaultOptions[y])}}z.options.logLevel=z._parseLevel(z.options.logLevel);z.options.consoleLevel=z._parseLevel(z.options.consoleLevel);z._sending=false;z._postSize=z.options.postSize;z._initCache();if(z.options.postOnUnload){z.onpageunload=function B(C){C.preventDefault();z._postCache({count:z.cache.length()})};window.addEventListener("unload",z.onpageunload)}return z};h.prototype._initCache=function a(){this.cache=new w({maxSize:this.options.maxCacheSize})};h.prototype._parseLevel=function j(A){var z=typeof A;if(z==="number"){return A}if(z==="string"){var y=A.toUpperCase();if(h.hasOwnProperty(y)){return h[y]}}throw new Error("Unknown log level: "+A)};h.prototype.emit=function m(B,A,z){var y=this;A=A||y.options.defaultNamespace;if(!B||!z){return y}B=y._parseLevel(B);if(B>=y.options.logLevel){y._addToCache(B,A,z)}if(y.consoleLogger&&B>=y.options.consoleLevel){y._emitToConsole(B,A,z)}return y};h.prototype._addToCache=function b(D,A,z){this._emitToConsole("debug","MetricsLogger",["_addToCache:",arguments,this.options.addTime,this.cache.length()]);var y=this;try{var C=y.cache.add(y._buildEntry(D,A,z));if(C>=y._postSize){y._postCache()}}catch(B){if(y.options.consoleLevel<=h.WARN){console.warn("Metrics logger could not stringify logArguments:",A,z);console.error(B)}}return y};h.prototype._buildEntry=function r(B,z,y){this._emitToConsole("debug","MetricsLogger",["_buildEntry:",arguments]);var A={level:B,namespace:this.options.clientPrefix+z,args:y};if(this.options.addTime){A.time=new Date().toISOString()}return A};h.prototype._postCache=function s(B){B=B||{};this._emitToConsole("info","MetricsLogger",["_postCache",B,this._postSize]);if(!this.options.postUrl||this._sending){return jQuery.when({})}var A=this,D=B.count||A._postSize,y=A.cache.get(D),C=y.length,z=(typeof A.options.getPingData==="function")?(A.options.getPingData()):({});z.metrics=A._preprocessCache(y);A._sending=true;return jQuery.post(A.options.postUrl,z).always(function(){A._sending=false}).fail(function(){A._postSize=A.options.maxCacheSize}).done(function(E){if(typeof A.options.onServerResponse==="function"){A.options.onServerResponse(E)}A.cache.remove(C);console.debug("removed entries:",C,"size now:",A.cache.length());A._postSize=A.options.postSize})};h.prototype._preprocessCache=function f(y){return["[",(y.join(",\n")),"]"].join("\n")};h.prototype._emitToConsole=function c(C,B,A){var y=this;if(!y.consoleLogger){return y}var z=Array.prototype.slice.call(A,0);z.unshift(B);if(C>=h.METRIC&&typeof(y.consoleLogger.info)==="function"){return y.consoleLogger.info.apply(y.consoleLogger,z)}else{if(C>=h.ERROR&&typeof(y.consoleLogger.error)==="function"){return y.consoleLogger.error.apply(y.consoleLogger,z)}else{if(C>=h.WARN&&typeof(y.consoleLogger.warn)==="function"){y.consoleLogger.warn.apply(y.consoleLogger,z)}else{if(C>=h.INFO&&typeof(y.consoleLogger.info)==="function"){y.consoleLogger.info.apply(y.consoleLogger,z)}else{if(C>=h.DEBUG&&typeof(y.consoleLogger.debug)==="function"){y.consoleLogger.debug.apply(y.consoleLogger,z)}else{if(typeof(y.consoleLogger.log)==="function"){y.consoleLogger.log.apply(y.consoleLogger,z)}}}}}}return y};h.prototype.debug=function l(){this.emit(h.DEBUG,this.options.defaultNamespace,arguments)};h.prototype.log=function g(){this.emit(1,this.options.defaultNamespace,arguments)};h.prototype.info=function u(){this.emit(h.INFO,this.options.defaultNamespace,arguments)};h.prototype.warn=function t(){this.emit(h.WARN,this.options.defaultNamespace,arguments)};h.prototype.error=function p(){this.emit(h.ERROR,this.options.defaultNamespace,arguments)};h.prototype.metric=function n(){this.emit(h.METRIC,this.options.defaultNamespace,arguments)};function w(z){var y=this;y._cache=[];return y._init(z||{})}w.defaultOptions={maxSize:5000};w.prototype._init=function i(y){this.maxSize=y.maxSize||w.defaultOptions.maxSize;return this};w.prototype.add=function k(A){var z=this,y=(z.length()+1)-z.maxSize;if(y>0){z.remove(y)}z._cache.push(z._preprocessEntry(A));return z.length()};w.prototype._preprocessEntry=function q(y){return JSON.stringify(y)};w.prototype.length=function e(){return this._cache.length};w.prototype.get=function v(y){return this._cache.slice(0,y)};w.prototype.remove=function x(y){return this._cache.splice(0,y)};w.prototype.stringify=function o(y){return["[",(this.get(y).join(",\n")),"]"].join("\n")};w.prototype.print=function d(){this._cache.forEach(function(y){console.log(y)})};return{MetricsLogger:h,LoggingCache:w}}); \ No newline at end of file +define([],function(){function h(z){z=z||{};var y=this;y.consoleLogger=z.consoleLogger||null;y._init(z);return y}h.ALL=0;h.DEBUG=10;h.INFO=20;h.WARN=30;h.ERROR=40;h.METRIC=50;h.NONE=100;h.defaultOptions={logLevel:h.NONE,consoleLevel:h.NONE,defaultNamespace:"Galaxy",clientPrefix:"client.",maxCacheSize:3000,postSize:1000,addTime:true,postUrl:"/api/metrics",getPingData:undefined,onServerResponse:undefined};h.prototype._init=function i(A){var z=this;z.options={};for(var y in h.defaultOptions){if(h.defaultOptions.hasOwnProperty(y)){z.options[y]=(A.hasOwnProperty(y))?(A[y]):(h.defaultOptions[y])}}z.options.logLevel=z._parseLevel(z.options.logLevel);z.options.consoleLevel=z._parseLevel(z.options.consoleLevel);z._sending=false;z._postSize=z.options.postSize;z._initCache();return z};h.prototype._initCache=function a(){this.cache=new w({maxSize:this.options.maxCacheSize})};h.prototype._parseLevel=function j(A){var z=typeof A;if(z==="number"){return A}if(z==="string"){var y=A.toUpperCase();if(h.hasOwnProperty(y)){return h[y]}}throw new Error("Unknown log level: "+A)};h.prototype.emit=function m(B,A,z){var y=this;A=A||y.options.defaultNamespace;if(!B||!z){return y}B=y._parseLevel(B);if(B>=y.options.logLevel){y._addToCache(B,A,z)}if(y.consoleLogger&&B>=y.options.consoleLevel){y._emitToConsole(B,A,z)}return y};h.prototype._addToCache=function b(D,A,z){this._emitToConsole("debug","MetricsLogger",["_addToCache:",arguments,this.options.addTime,this.cache.length()]);var y=this;try{var C=y.cache.add(y._buildEntry(D,A,z));if(C>=y._postSize){y._postCache()}}catch(B){if(y.options.consoleLevel<=h.WARN){console.warn("Metrics logger could not stringify logArguments:",A,z);console.error(B)}}return y};h.prototype._buildEntry=function r(B,z,y){this._emitToConsole("debug","MetricsLogger",["_buildEntry:",arguments]);var A={level:B,namespace:this.options.clientPrefix+z,args:y};if(this.options.addTime){A.time=new Date().toISOString()}return A};h.prototype._postCache=function s(B){B=B||{};this._emitToConsole("info","MetricsLogger",["_postCache",B,this._postSize]);if(!this.options.postUrl||this._sending){return jQuery.when({})}var A=this,D=B.count||A._postSize,y=A.cache.get(D),C=y.length,z=(typeof A.options.getPingData==="function")?(A.options.getPingData()):({});z.metrics=A._preprocessCache(y);A._sending=true;return jQuery.post(A.options.postUrl,z).always(function(){A._sending=false}).fail(function(){A._postSize=A.options.maxCacheSize}).done(function(E){if(typeof A.options.onServerResponse==="function"){A.options.onServerResponse(E)}A.cache.remove(C);console.debug("removed entries:",C,"size now:",A.cache.length());A._postSize=A.options.postSize})};h.prototype._preprocessCache=function f(y){return["[",(y.join(",\n")),"]"].join("\n")};h.prototype._emitToConsole=function c(C,B,A){var y=this;if(!y.consoleLogger){return y}var z=Array.prototype.slice.call(A,0);z.unshift(B);if(C>=h.METRIC&&typeof(y.consoleLogger.info)==="function"){return y.consoleLogger.info.apply(y.consoleLogger,z)}else{if(C>=h.ERROR&&typeof(y.consoleLogger.error)==="function"){return y.consoleLogger.error.apply(y.consoleLogger,z)}else{if(C>=h.WARN&&typeof(y.consoleLogger.warn)==="function"){y.consoleLogger.warn.apply(y.consoleLogger,z)}else{if(C>=h.INFO&&typeof(y.consoleLogger.info)==="function"){y.consoleLogger.info.apply(y.consoleLogger,z)}else{if(C>=h.DEBUG&&typeof(y.consoleLogger.debug)==="function"){y.consoleLogger.debug.apply(y.consoleLogger,z)}else{if(typeof(y.consoleLogger.log)==="function"){y.consoleLogger.log.apply(y.consoleLogger,z)}}}}}}return y};h.prototype.debug=function l(){this.emit(h.DEBUG,this.options.defaultNamespace,arguments)};h.prototype.log=function g(){this.emit(1,this.options.defaultNamespace,arguments)};h.prototype.info=function u(){this.emit(h.INFO,this.options.defaultNamespace,arguments)};h.prototype.warn=function t(){this.emit(h.WARN,this.options.defaultNamespace,arguments)};h.prototype.error=function p(){this.emit(h.ERROR,this.options.defaultNamespace,arguments)};h.prototype.metric=function n(){this.emit(h.METRIC,this.options.defaultNamespace,arguments)};function w(z){var y=this;y._cache=[];return y._init(z||{})}w.defaultOptions={maxSize:5000};w.prototype._init=function i(y){this.maxSize=y.maxSize||w.defaultOptions.maxSize;return this};w.prototype.add=function k(A){var z=this,y=(z.length()+1)-z.maxSize;if(y>0){z.remove(y)}z._cache.push(z._preprocessEntry(A));return z.length()};w.prototype._preprocessEntry=function q(y){return JSON.stringify(y)};w.prototype.length=function e(){return this._cache.length};w.prototype.get=function v(y){return this._cache.slice(0,y)};w.prototype.remove=function x(y){return this._cache.splice(0,y)};w.prototype.stringify=function o(y){return["[",(this.get(y).join(",\n")),"]"].join("\n")};w.prototype.print=function d(){this._cache.forEach(function(y){console.log(y)})};return{MetricsLogger:h,LoggingCache:w}}); \ No newline at end of file diff -r 3e054419aca1d5831d65fcaccccf1dae16dfb279 -r 4131de825802f46ff97194d02b25739a20856b17 static/scripts/utils/add-logging.js --- /dev/null +++ b/static/scripts/utils/add-logging.js @@ -0,0 +1,26 @@ +define([ +], function(){ +//============================================================================== +function addLogging( obj, namespace ){ + if( namespace !== undefined ){ + obj._logNamespace = namespace; + } + + [ 'debug', 'info', 'warn', 'error', 'metric' ].forEach( function( logFn ){ + ( obj.prototype || obj )[ logFn ] = function(){ + if( !this.logger ){ return undefined; } + if( this.logger.emit ){ + return this.logger.emit( logFn, this._logNamespace, arguments ); + } + if( this.logger[ logFn ] ){ + return this.logger[ logFn ].apply( this.logger, arguments ); + } + return undefined; + }; + }); + return obj; +} + +//============================================================================== +return addLogging; +}); diff -r 3e054419aca1d5831d65fcaccccf1dae16dfb279 -r 4131de825802f46ff97194d02b25739a20856b17 static/scripts/utils/metrics-logger.js --- a/static/scripts/utils/metrics-logger.js +++ b/static/scripts/utils/metrics-logger.js @@ -58,7 +58,7 @@ /** default options - override these through the constructor */ MetricsLogger.defaultOptions = { /** if an incoming message has a level >= this, it will be cached - can also be a string (e.g. 'debug') */ - logLevel : MetricsLogger.INFO, + logLevel : MetricsLogger.NONE, /** if an incoming message has a level >= this, it will be output to the console */ consoleLevel : MetricsLogger.NONE, /** the default 'namespace' or label associated with an incoming message (if none is passed) */ @@ -76,9 +76,6 @@ /** the relative url to post messages to */ postUrl : '/api/metrics', - /** post when the page is unloaded? */// needs to be true if using the LoggingCache (for now) - postOnUnload : true, - /** an (optional) function that should return an object; used to send additional data with the metrics */ getPingData : undefined, /** an (optional) function that will handle the servers response after successfully posting messages */ @@ -103,15 +100,6 @@ self._postSize = self.options.postSize; self._initCache(); - // post the entire cache on unload (since LoggingCache isn't persistent ATM) - if( self.options.postOnUnload ){ - self.onpageunload = function onpageunload( ev ){ - ev.preventDefault(); - self._postCache({ count: self.cache.length() }); - }; - window.addEventListener( 'unload', self.onpageunload ); - } - return self; }; diff -r 3e054419aca1d5831d65fcaccccf1dae16dfb279 -r 4131de825802f46ff97194d02b25739a20856b17 templates/galaxy_client_app.mako --- /dev/null +++ b/templates/galaxy_client_app.mako @@ -0,0 +1,79 @@ + +## ============================================================================ +<%def name="bootstrap()"> + ## Bootstap dictionaries for GalaxyApp object's JSON, create GalaxyApp, + ## and steal existing attributes from plain objects already created + <% + config_dict = ( trans.webapp.api_controllers[ 'configuration' ] + .get_config_dict( trans.app.config, trans.user_is_admin() ) ) + #import pprint + #pprint.pprint( config_dict ) + + user_dict = self.get_user_dict() + #pprint.pprint( user_dict ) + + # genomes + # datatypes + %> + <script type="text/javascript"> + require([ 'galaxy-app-base' ], function( app ){ + galaxy = new app.GalaxyApp({ + config : ${ h.to_json_string( config_dict ) }, + userJSON : ${ get_user_json() }, + root : '${h.url_for( "/" )}', + //TODO: get these options from the server + loggerOptions : { + } + }); + // in case req or plain script tag order has created a prev. version of the Galaxy obj... + if( window.Galaxy ){ + // ...(for now) monkey patch any added attributes that the previous Galaxy may have had + //TODO: move those attributes to more formal assignment in GalaxyApp + for( var k in window.Galaxy ){ + if( window.Galaxy.hasOwnProperty( k ) ){ + galaxy.debug( 'patching in ' + k + ' to Galaxy' ) + galaxy[ k ] = window.Galaxy[ k ]; + } + } + } + window.Galaxy = galaxy; + }); + + </script> +</%def> + +## ---------------------------------------------------------------------------- +<%def name="get_user_dict()"> + ## Return a dictionary of user or anonymous user data including: + ## email, id, disk space used, quota percent, and tags used + <% + if trans.user: + user_dict = trans.user.to_dict( view='element', + value_mapper={ 'id': trans.security.encode_id, 'total_disk_usage': float } ) + user_dict[ 'quota_percent' ] = trans.app.quota_agent.get_percent( trans=trans ) + + # tags used + users_api_controller = trans.webapp.api_controllers[ 'users' ] + user_dict[ 'tags_used' ] = users_api_controller.get_user_tags_used( trans, user=trans.user ) + return user_dict + + usage = 0 + percent = None + try: + usage = trans.app.quota_agent.get_usage( trans, history=trans.history ) + percent = trans.app.quota_agent.get_percent( trans=trans, usage=usage ) + except AssertionError, assertion: + # no history for quota_agent.get_usage assertion + pass + return { + 'total_disk_usage' : int( usage ), + 'nice_total_disk_usage' : util.nice_size( usage ), + 'quota_percent' : percent + } + %> +</%def> + +<%def name="get_user_json()"> + ## Conv. fn to write as JSON +${ h.to_json_string( get_user_dict() )} +</%def> Repository URL: https://bitbucket.org/galaxy/galaxy-central/ -- This is a commit notification from bitbucket.org. You are receiving this because you have the service enabled, addressing the recipient of this email.
participants (1)
-
commits-noreply@bitbucket.org