Report loaded plugins to analytics
Change-Id: Ic537084dc0304e8a151fe968e6510a04f04e0b6c
This commit is contained in:
parent
8eb1599e95
commit
c1c5f77fa6
@ -26,6 +26,13 @@
|
||||
PAGE_LOADED: 'Page Loaded',
|
||||
};
|
||||
|
||||
// Plugin-related reporting constants.
|
||||
const PLUGINS = {
|
||||
TYPE: 'lifecycle',
|
||||
// Reported events - alphabetize below.
|
||||
INSTALLED: 'Plugins installed',
|
||||
};
|
||||
|
||||
// Navigation reporting constants.
|
||||
const NAVIGATION = {
|
||||
TYPE: 'nav-report',
|
||||
@ -214,8 +221,10 @@
|
||||
}
|
||||
},
|
||||
|
||||
pluginsLoaded() {
|
||||
pluginsLoaded(pluginsList) {
|
||||
this.timeEnd(TIMER.PLUGINS_LOADED);
|
||||
this.reporter(
|
||||
PLUGINS.TYPE, PLUGINS.INSTALLED, (pluginsList || []).join(','));
|
||||
},
|
||||
|
||||
/**
|
||||
|
@ -162,6 +162,14 @@ limitations under the License.
|
||||
));
|
||||
});
|
||||
|
||||
test('pluginsLoaded reports plugins', () => {
|
||||
Gerrit._arePluginsLoaded.returns(true);
|
||||
element.pluginsLoaded(['foo', 'bar']);
|
||||
assert.isTrue(element.defaultReporter.calledWithExactly(
|
||||
'lifecycle', 'Plugins installed', 'foo,bar'
|
||||
));
|
||||
});
|
||||
|
||||
test('caches reports if plugins are not loaded', () => {
|
||||
Gerrit._arePluginsLoaded.returns(false);
|
||||
element.timeEnd('foo');
|
||||
|
@ -56,18 +56,16 @@ limitations under the License.
|
||||
stub('gr-endpoint-decorator', {
|
||||
_import: sandbox.stub().returns(Promise.resolve()),
|
||||
});
|
||||
// Since _endpoints are global, must reset state.
|
||||
Gerrit._endpoints = new GrPluginEndpoints();
|
||||
Gerrit._resetPlugins();
|
||||
container = fixture('basic');
|
||||
Gerrit.install(p => plugin = p, '0.1', 'http://some/plugin/url.html');
|
||||
hooks = [];
|
||||
// Decoration
|
||||
decorationHook = plugin.registerCustomComponent('first', 'some-module');
|
||||
// Replacement
|
||||
replacementHook = plugin.registerCustomComponent(
|
||||
'second', 'other-module', {replace: true});
|
||||
// Mimic all plugins loaded.
|
||||
Gerrit._setPluginsCount(0);
|
||||
Gerrit._setPluginsPending([]);
|
||||
flush(done);
|
||||
});
|
||||
|
||||
@ -88,8 +86,10 @@ limitations under the License.
|
||||
test('decoration', () => {
|
||||
const element =
|
||||
container.querySelector('gr-endpoint-decorator[name="first"]');
|
||||
const module = Polymer.dom(element.root).children.find(
|
||||
const modules = Polymer.dom(element.root).children.filter(
|
||||
element => element.nodeName === 'SOME-MODULE');
|
||||
assert.equal(modules.length, 1);
|
||||
const [module] = modules;
|
||||
assert.isOk(module);
|
||||
assert.equal(module['someparam'], 'barbar');
|
||||
return decorationHook.getLastAttached().then(element => {
|
||||
|
@ -52,8 +52,11 @@ breaking changes to gr-change-actions won’t be noticed.
|
||||
|
||||
suite('early init', () => {
|
||||
setup(() => {
|
||||
Gerrit._resetPlugins();
|
||||
Gerrit.install(p => { plugin = p; }, '0.1',
|
||||
'http://test.com/plugins/testplugin/static/test.js');
|
||||
// Mimic all plugins loaded.
|
||||
Gerrit._setPluginsPending([]);
|
||||
changeActions = plugin.changeActions();
|
||||
element = fixture('basic');
|
||||
});
|
||||
@ -71,6 +74,7 @@ breaking changes to gr-change-actions won’t be noticed.
|
||||
|
||||
suite('normal init', () => {
|
||||
setup(() => {
|
||||
Gerrit._resetPlugins();
|
||||
element = fixture('basic');
|
||||
sinon.stub(element, '_editStatusChanged');
|
||||
element.change = {};
|
||||
@ -78,6 +82,8 @@ breaking changes to gr-change-actions won’t be noticed.
|
||||
Gerrit.install(p => { plugin = p; }, '0.1',
|
||||
'http://test.com/plugins/testplugin/static/test.js');
|
||||
changeActions = plugin.changeActions();
|
||||
// Mimic all plugins loaded.
|
||||
Gerrit._setPluginsPending([]);
|
||||
});
|
||||
|
||||
teardown(() => {
|
||||
|
@ -320,15 +320,19 @@ limitations under the License.
|
||||
assert.isTrue(Gerrit._arePluginsLoaded());
|
||||
});
|
||||
|
||||
test('_pluginInstalled', done => {
|
||||
test('_pluginInstalled', () => {
|
||||
const pluginsLoadedStub = sandbox.stub();
|
||||
stub('gr-reporting', {
|
||||
pluginsLoaded() {
|
||||
done();
|
||||
},
|
||||
pluginsLoaded: (...args) => pluginsLoadedStub(...args),
|
||||
});
|
||||
Gerrit._setPluginsCount(2);
|
||||
Gerrit._pluginInstalled();
|
||||
Gerrit._pluginInstalled();
|
||||
const plugins = [
|
||||
'http://test.com/plugins/foo/static/test.js',
|
||||
'http://test.com/plugins/bar/static/test.js',
|
||||
];
|
||||
Gerrit._setPluginsPending(plugins);
|
||||
Gerrit._pluginInstalled(plugins[0]);
|
||||
Gerrit._pluginInstalled(plugins[1]);
|
||||
assert.isTrue(pluginsLoadedStub.calledWithExactly(['foo', 'bar']));
|
||||
});
|
||||
|
||||
test('install calls _pluginInstalled', () => {
|
||||
|
@ -27,8 +27,12 @@
|
||||
*/
|
||||
let _pluginsPending = {};
|
||||
|
||||
let _pluginsInstalled = [];
|
||||
|
||||
let _pluginsPendingCount = -1;
|
||||
|
||||
const UNKNOWN_PLUGIN = 'unknown';
|
||||
|
||||
const PANEL_ENDPOINTS_MAPPING = {
|
||||
CHANGE_SCREEN_BELOW_COMMIT_INFO_BLOCK: 'change-view-integration',
|
||||
CHANGE_SCREEN_BELOW_CHANGE_INFO_BLOCK: 'change-metadata-item',
|
||||
@ -37,6 +41,7 @@
|
||||
const PLUGIN_LOADING_TIMEOUT_MS = 10000;
|
||||
|
||||
let _restAPI;
|
||||
|
||||
const getRestAPI = () => {
|
||||
if (!_restAPI) {
|
||||
_restAPI = document.createElement('gr-rest-api-interface');
|
||||
@ -44,6 +49,14 @@
|
||||
return _restAPI;
|
||||
};
|
||||
|
||||
let _reporting;
|
||||
const getReporting = () => {
|
||||
if (!_reporting) {
|
||||
_reporting = document.createElement('gr-reporting');
|
||||
}
|
||||
return _reporting;
|
||||
};
|
||||
|
||||
// TODO (viktard): deprecate in favor of GrPluginRestApi.
|
||||
function send(method, url, opt_callback, opt_payload) {
|
||||
return getRestAPI().send(method, url, opt_payload).then(response => {
|
||||
@ -420,9 +433,13 @@
|
||||
if (!app) {
|
||||
// No gr-app found (running tests)
|
||||
Gerrit._resetPlugins = () => {
|
||||
_resolveAllPluginsLoaded = null;
|
||||
_allPluginsPromise = null;
|
||||
Gerrit._setPluginsPending([]);
|
||||
_pluginsInstalled = [];
|
||||
_pluginsPending = {};
|
||||
_pluginsPendingCount = -1;
|
||||
_reporting = null;
|
||||
_resolveAllPluginsLoaded = null;
|
||||
_restAPI = null;
|
||||
Gerrit._endpoints = new GrPluginEndpoints();
|
||||
for (const k of Object.keys(_plugins)) {
|
||||
delete _plugins[k];
|
||||
@ -558,7 +575,8 @@
|
||||
|
||||
Gerrit._setPluginsPending = function(plugins) {
|
||||
_pluginsPending = plugins.reduce((o, url) => {
|
||||
o[getPluginNameFromUrl(url)] = url;
|
||||
// TODO(viktard): Remove guard (@see Issue 8962)
|
||||
o[getPluginNameFromUrl(url) || UNKNOWN_PLUGIN] = url;
|
||||
return o;
|
||||
}, {});
|
||||
Gerrit._setPluginsCount(Object.keys(_pluginsPending).length);
|
||||
@ -567,7 +585,7 @@
|
||||
Gerrit._setPluginsCount = function(count) {
|
||||
_pluginsPendingCount = count;
|
||||
if (Gerrit._arePluginsLoaded()) {
|
||||
document.createElement('gr-reporting').pluginsLoaded();
|
||||
getReporting().pluginsLoaded(_pluginsInstalled);
|
||||
if (_resolveAllPluginsLoaded) {
|
||||
_resolveAllPluginsLoaded();
|
||||
}
|
||||
@ -585,17 +603,14 @@
|
||||
};
|
||||
|
||||
Gerrit._pluginInstalled = function(url) {
|
||||
const name = getPluginNameFromUrl(url);
|
||||
if (name && !_pluginsPending[name]) {
|
||||
console.warn(`Unexpected plugin from ${url}!`);
|
||||
const name = getPluginNameFromUrl(url) || UNKNOWN_PLUGIN;
|
||||
if (!_pluginsPending[name]) {
|
||||
console.warn(`Unexpected plugin ${name} installed from ${url}.`);
|
||||
} else {
|
||||
if (name) {
|
||||
delete _pluginsPending[name];
|
||||
console.log(`Plugin ${name} installed`);
|
||||
} else {
|
||||
console.log(`Plugin installed from ${url}`);
|
||||
}
|
||||
_pluginsInstalled.push(name);
|
||||
Gerrit._setPluginsCount(_pluginsPendingCount - 1);
|
||||
console.log(`Plugin ${name} installed.`);
|
||||
}
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user