mirror of
https://github.com/grafana/grafana.git
synced 2025-02-13 00:55:47 -06:00
* add uninstall flow * add install flow * small cleanup * smaller-footprint solution * cleanup + make bp start auto * fix interface contract * improve naming * accept version arg * ensure use of shared logger * make installer a field * add plugin decommissioning * add basic error checking * fix api docs * making initialization idempotent * add mutex * fix comment * fix test * add test for decommission * improve existing test * add more test coverage * more tests * change test func to use read lock * refactoring + adding test asserts * improve purging old install flow * improve dupe checking * change log name * skip over dupe scanned * make test assertion more flexible * remove trailing line * fix pointer receiver name * update comment * add context to API * add config flag * add base http api test + fix update functionality * simplify existing check * clean up test * refactor tests based on feedback * add single quotes to errs * use gcmp in tests + fix logo issue * make plugin list testing more flexible * address feedback * fix API test * fix linter * undo preallocate * Update docs/sources/administration/configuration.md Co-authored-by: achatterjee-grafana <70489351+achatterjee-grafana@users.noreply.github.com> * Update docs/sources/administration/configuration.md Co-authored-by: achatterjee-grafana <70489351+achatterjee-grafana@users.noreply.github.com> * Update docs/sources/administration/configuration.md Co-authored-by: achatterjee-grafana <70489351+achatterjee-grafana@users.noreply.github.com> * fix linting issue in test * add docs placeholder * update install notes * Update docs/sources/plugins/marketplace.md Co-authored-by: Marcus Olsson <marcus.olsson@hey.com> * update access wording * add more placeholder docs * add link to more info * PR feedback - improved errors, refactor, lock fix * improve err details * propagate plugin version errors * don't autostart renderer * add H1 * fix imports * feat(bundled-plugins): introduce marketplace-app to the repo * chore(marketplace-app): remove backend * feat(marketplace): nav is only visible to admins * feat(marketplace): use gnet api * refactor(marketplace): move styles to theme2 move card concerns to card component * feat(marketplace): introduce loaders, clean up styles * refactor(marketplace): wip - debugging for api endpoints * feat(grafana-ui): introduce height prop to Layout components * refactor(marketplace): clean up org details component * fix(marketplace): display search results without active filters * refactor(marketplace): use grafana api for install/uninstall * refactor(marketplace): remove pluginDir * feat(marketplace): clean up Library page * fix(plugins): get panel plugins from meta for newly installed plugins * fix(marketplace): fix multiple renders of InstallControls when installing/uninstalling plugins * refactor(marketplace): componentise the loader * chore(marketplace): remove unsigned plugins option * refactor(marketplace): remove includeUnsigned from codebase * refactor(marketplace): prefer useStyles over useTheme * docs(marketplace): remove changelog and update readme * Apply suggestions from code review Co-authored-by: Hugo Häggmark <hugo.haggmark@grafana.com> Co-authored-by: Dominik Prokop <dominik.prokop@grafana.com> * refactor(marketplace): prefer module over class for api * refactor(marketplace): move updatePlugin to api * refactor(marketplace): add PluginMeta to api to please TS * feat(marketplace): always include pre-release in semver check * chore(marketplace): remove redundant arch install code. backend handles it now * feat(marketplace): add a link to browse page if library is empty * refactor(marketplace): replace status with isLoading boolean for hooks * refactor(marketplace): clean up async functions in InstallControls * fix(marketplace): setInstalled false on successful uninstall * include marketplace in bundled plugin test Co-authored-by: Will Browne <will.browne@grafana.com> Co-authored-by: Will Browne <wbrowne@users.noreply.github.com> Co-authored-by: achatterjee-grafana <70489351+achatterjee-grafana@users.noreply.github.com> Co-authored-by: Marcus Olsson <marcus.olsson@hey.com> Co-authored-by: Hugo Häggmark <hugo.haggmark@grafana.com> Co-authored-by: Dominik Prokop <dominik.prokop@grafana.com>
270 lines
8.4 KiB
TypeScript
270 lines
8.4 KiB
TypeScript
// eslint-disable-next-line lodash/import-scope
|
|
import _ from 'lodash';
|
|
import * as sdk from 'app/plugins/sdk';
|
|
import kbn from 'app/core/utils/kbn';
|
|
import moment from 'moment'; // eslint-disable-line no-restricted-imports
|
|
import angular from 'angular';
|
|
import jquery from 'jquery';
|
|
|
|
// Experimental module exports
|
|
import prismjs from 'prismjs';
|
|
import slate from 'slate';
|
|
// @ts-ignore
|
|
import slateReact from '@grafana/slate-react';
|
|
// @ts-ignore
|
|
import slatePlain from 'slate-plain-serializer';
|
|
import react from 'react';
|
|
import reactDom from 'react-dom';
|
|
import * as reactRedux from 'react-redux';
|
|
import * as redux from 'redux';
|
|
|
|
import config from 'app/core/config';
|
|
import TimeSeries from 'app/core/time_series2';
|
|
import TableModel from 'app/core/table_model';
|
|
import { coreModule, appEvents, contextSrv } from 'app/core/core';
|
|
import * as flatten from 'app/core/utils/flatten';
|
|
import * as ticks from 'app/core/utils/ticks';
|
|
import { BackendSrv, getBackendSrv } from 'app/core/services/backend_srv';
|
|
import { promiseToDigest } from 'app/core/utils/promiseToDigest';
|
|
import impressionSrv from 'app/core/services/impression_srv';
|
|
import builtInPlugins from './built_in_plugins';
|
|
import * as d3 from 'd3';
|
|
import * as emotion from '@emotion/css';
|
|
import * as grafanaData from '@grafana/data';
|
|
import * as grafanaUIraw from '@grafana/ui';
|
|
import * as grafanaRuntime from '@grafana/runtime';
|
|
|
|
// Help the 6.4 to 6.5 migration
|
|
// The base classes were moved from @grafana/ui to @grafana/data
|
|
// This exposes the same classes on both import paths
|
|
const grafanaUI = grafanaUIraw as any;
|
|
grafanaUI.PanelPlugin = grafanaData.PanelPlugin;
|
|
grafanaUI.DataSourcePlugin = grafanaData.DataSourcePlugin;
|
|
grafanaUI.AppPlugin = grafanaData.AppPlugin;
|
|
grafanaUI.DataSourceApi = grafanaData.DataSourceApi;
|
|
|
|
// rxjs
|
|
import * as rxjs from 'rxjs';
|
|
import * as rxjsOperators from 'rxjs/operators';
|
|
|
|
// add cache busting
|
|
const bust = `?_cache=${Date.now()}`;
|
|
function locate(load: { address: string }) {
|
|
return load.address + bust;
|
|
}
|
|
|
|
grafanaRuntime.SystemJS.registry.set('plugin-loader', grafanaRuntime.SystemJS.newModule({ locate: locate }));
|
|
|
|
grafanaRuntime.SystemJS.config({
|
|
baseURL: 'public',
|
|
defaultExtension: 'js',
|
|
packages: {
|
|
plugins: {
|
|
defaultExtension: 'js',
|
|
},
|
|
},
|
|
map: {
|
|
text: 'vendor/plugin-text/text.js',
|
|
css: 'vendor/plugin-css/css.js',
|
|
},
|
|
meta: {
|
|
'/*': {
|
|
esModule: true,
|
|
authorization: true,
|
|
loader: 'plugin-loader',
|
|
},
|
|
},
|
|
});
|
|
|
|
function exposeToPlugin(name: string, component: any) {
|
|
grafanaRuntime.SystemJS.registerDynamic(name, [], true, (require: any, exports: any, module: { exports: any }) => {
|
|
module.exports = component;
|
|
});
|
|
}
|
|
|
|
exposeToPlugin('@grafana/data', grafanaData);
|
|
exposeToPlugin('@grafana/ui', grafanaUI);
|
|
exposeToPlugin('@grafana/runtime', grafanaRuntime);
|
|
exposeToPlugin('lodash', _);
|
|
exposeToPlugin('moment', moment);
|
|
exposeToPlugin('jquery', jquery);
|
|
exposeToPlugin('angular', angular);
|
|
exposeToPlugin('d3', d3);
|
|
exposeToPlugin('rxjs', rxjs);
|
|
exposeToPlugin('rxjs/operators', rxjsOperators);
|
|
|
|
// Experimental modules
|
|
exposeToPlugin('prismjs', prismjs);
|
|
exposeToPlugin('slate', slate);
|
|
exposeToPlugin('@grafana/slate-react', slateReact);
|
|
exposeToPlugin('slate-plain-serializer', slatePlain);
|
|
exposeToPlugin('react', react);
|
|
exposeToPlugin('react-dom', reactDom);
|
|
exposeToPlugin('react-redux', reactRedux);
|
|
exposeToPlugin('redux', redux);
|
|
exposeToPlugin('emotion', emotion);
|
|
exposeToPlugin('@emotion/css', emotion);
|
|
|
|
exposeToPlugin('app/features/dashboard/impression_store', {
|
|
impressions: impressionSrv,
|
|
__esModule: true,
|
|
});
|
|
|
|
/**
|
|
* NOTE: this is added temporarily while we explore a long term solution
|
|
* If you use this export, only use the:
|
|
* get/delete/post/patch/request methods
|
|
*/
|
|
exposeToPlugin('app/core/services/backend_srv', {
|
|
BackendSrv,
|
|
getBackendSrv,
|
|
});
|
|
|
|
exposeToPlugin('app/plugins/sdk', sdk);
|
|
exposeToPlugin('app/core/utils/datemath', grafanaData.dateMath);
|
|
exposeToPlugin('app/core/utils/flatten', flatten);
|
|
exposeToPlugin('app/core/utils/kbn', kbn);
|
|
exposeToPlugin('app/core/utils/ticks', ticks);
|
|
exposeToPlugin('app/core/utils/promiseToDigest', {
|
|
promiseToDigest: promiseToDigest,
|
|
__esModule: true,
|
|
});
|
|
|
|
exposeToPlugin('app/core/config', config);
|
|
exposeToPlugin('app/core/time_series', TimeSeries);
|
|
exposeToPlugin('app/core/time_series2', TimeSeries);
|
|
exposeToPlugin('app/core/table_model', TableModel);
|
|
exposeToPlugin('app/core/app_events', appEvents);
|
|
exposeToPlugin('app/core/core_module', coreModule);
|
|
exposeToPlugin('app/core/core', {
|
|
coreModule: coreModule,
|
|
appEvents: appEvents,
|
|
contextSrv: contextSrv,
|
|
__esModule: true,
|
|
});
|
|
|
|
import 'vendor/flot/jquery.flot';
|
|
import 'vendor/flot/jquery.flot.selection';
|
|
import 'vendor/flot/jquery.flot.time';
|
|
import 'vendor/flot/jquery.flot.stack';
|
|
import 'vendor/flot/jquery.flot.stackpercent';
|
|
import 'vendor/flot/jquery.flot.fillbelow';
|
|
import 'vendor/flot/jquery.flot.crosshair';
|
|
import 'vendor/flot/jquery.flot.dashes';
|
|
import 'vendor/flot/jquery.flot.gauge';
|
|
|
|
const flotDeps = [
|
|
'jquery.flot',
|
|
'jquery.flot.pie',
|
|
'jquery.flot.time',
|
|
'jquery.flot.fillbelow',
|
|
'jquery.flot.crosshair',
|
|
'jquery.flot.stack',
|
|
'jquery.flot.selection',
|
|
'jquery.flot.stackpercent',
|
|
'jquery.flot.events',
|
|
'jquery.flot.gauge',
|
|
];
|
|
|
|
for (const flotDep of flotDeps) {
|
|
exposeToPlugin(flotDep, { fakeDep: 1 });
|
|
}
|
|
|
|
export async function importPluginModule(path: string): Promise<any> {
|
|
const builtIn = builtInPlugins[path];
|
|
if (builtIn) {
|
|
// for handling dynamic imports
|
|
if (typeof builtIn === 'function') {
|
|
return await builtIn();
|
|
} else {
|
|
return Promise.resolve(builtIn);
|
|
}
|
|
}
|
|
return grafanaRuntime.SystemJS.import(path);
|
|
}
|
|
|
|
export function importDataSourcePlugin(meta: grafanaData.DataSourcePluginMeta): Promise<GenericDataSourcePlugin> {
|
|
return importPluginModule(meta.module).then((pluginExports) => {
|
|
if (pluginExports.plugin) {
|
|
const dsPlugin = pluginExports.plugin as GenericDataSourcePlugin;
|
|
dsPlugin.meta = meta;
|
|
return dsPlugin;
|
|
}
|
|
|
|
if (pluginExports.Datasource) {
|
|
const dsPlugin = new grafanaData.DataSourcePlugin<
|
|
grafanaData.DataSourceApi<grafanaData.DataQuery, grafanaData.DataSourceJsonData>,
|
|
grafanaData.DataQuery,
|
|
grafanaData.DataSourceJsonData
|
|
>(pluginExports.Datasource);
|
|
dsPlugin.setComponentsFromLegacyExports(pluginExports);
|
|
dsPlugin.meta = meta;
|
|
return dsPlugin;
|
|
}
|
|
|
|
throw new Error('Plugin module is missing DataSourcePlugin or Datasource constructor export');
|
|
});
|
|
}
|
|
|
|
export function importAppPlugin(meta: grafanaData.PluginMeta): Promise<grafanaData.AppPlugin> {
|
|
return importPluginModule(meta.module).then((pluginExports) => {
|
|
const plugin = pluginExports.plugin ? (pluginExports.plugin as grafanaData.AppPlugin) : new grafanaData.AppPlugin();
|
|
plugin.init(meta);
|
|
plugin.meta = meta;
|
|
plugin.setComponentsFromLegacyExports(pluginExports);
|
|
return plugin;
|
|
});
|
|
}
|
|
|
|
import { getPanelPluginLoadError } from '../dashboard/dashgrid/PanelPluginError';
|
|
import { GenericDataSourcePlugin } from '../datasources/settings/PluginSettings';
|
|
|
|
interface PanelCache {
|
|
[key: string]: Promise<grafanaData.PanelPlugin>;
|
|
}
|
|
const panelCache: PanelCache = {};
|
|
|
|
export function importPanelPlugin(id: string): Promise<grafanaData.PanelPlugin> {
|
|
const loaded = panelCache[id];
|
|
if (loaded) {
|
|
return loaded;
|
|
}
|
|
|
|
const meta = config.panels[id];
|
|
|
|
if (!meta) {
|
|
throw new Error(`Plugin ${id} not found`);
|
|
}
|
|
|
|
panelCache[id] = getPanelPlugin(meta);
|
|
|
|
return panelCache[id];
|
|
}
|
|
|
|
export function importPanelPluginFromMeta(meta: grafanaData.PanelPluginMeta): Promise<grafanaData.PanelPlugin> {
|
|
return getPanelPlugin(meta);
|
|
}
|
|
|
|
function getPanelPlugin(meta: grafanaData.PanelPluginMeta): Promise<grafanaData.PanelPlugin> {
|
|
return importPluginModule(meta.module)
|
|
.then((pluginExports) => {
|
|
if (pluginExports.plugin) {
|
|
return pluginExports.plugin as grafanaData.PanelPlugin;
|
|
} else if (pluginExports.PanelCtrl) {
|
|
const plugin = new grafanaData.PanelPlugin(null);
|
|
plugin.angularPanelCtrl = pluginExports.PanelCtrl;
|
|
return plugin;
|
|
}
|
|
throw new Error('missing export: plugin or PanelCtrl');
|
|
})
|
|
.then((plugin) => {
|
|
plugin.meta = meta;
|
|
return plugin;
|
|
})
|
|
.catch((err) => {
|
|
// TODO, maybe a different error plugin
|
|
console.warn('Error loading panel plugin: ' + meta.id, err);
|
|
return getPanelPluginLoadError(meta, err);
|
|
});
|
|
}
|