Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple apps don't work anymore #57470

Closed
sergibondarenko opened this issue Feb 12, 2020 · 8 comments · Fixed by #57542
Closed

Multiple apps don't work anymore #57470

sergibondarenko opened this issue Feb 12, 2020 · 8 comments · Fixed by #57542
Labels
Team:Core Core services & architecture: plugins, logging, config, saved objects, http, ES client, i18n, etc v7.6.1 v7.7.0 v8.0.0

Comments

@sergibondarenko
Copy link

sergibondarenko commented Feb 12, 2020

Kibana version:
7.6.0

Elasticsearch version:
7.6.0

Server OS version:
Mac OS 10.15.3

Browser version:
Chrome 79

Browser OS version:
Mac OS 10.15.3

Original install method (e.g. download page, yum, from source, etc.):
From git branch: https://github.com/elastic/kibana/tree/7.6

Describe the bug:
Multiple apps registration doesn't work anymore. The code snippet:

index.js

...
    uiExports: {
      apps: [
        {
          id: 'app_a',
          title: 'app_a',
          description: 'An awesome Kibana plugin',
          main: 'plugins/aplugin/apps/app_a/app',
        },
        {
          id: 'app_b',
          title: 'app_b',
          description: 'An awesome Kibana plugin',
          main: 'plugins/aplugin/apps/app_b/app',
        },
      ],

The demo plugin can be found here https://github.com/sergibondarenko/kibana_multi_app_plugin_FAILS

Steps to reproduce:

  1. Install and run Elasticsearch 7.6.0 and Kibana 7.6.0
  2. Clone the demo plugin https://github.com/sergibondarenko/kibana_multi_app_plugin_FAILS
  3. Put it into "kibana/plugins" folder
  4. Wait until Kibana restarts. Then put the following string to your browser URL: http://localhost:5601
  5. See an error page saying
An application is already registered with the id "aplugin"

Expected behavior:
I should access Kibana with no error and see two new apps in the left nav bar: app_a and app_b.

Screenshots (if relevant):
Screenshot 2020-02-12 at 17 49 35

Errors in browser console (if relevant):

Uncaught (in promise) Error: An application is already registered with the id "aplugin"
    at Object.registerLegacyApp (application_service.tsx:276)
    at legacy_service.ts:64
    at Array.forEach (<anonymous>)
    at LegacyPlatformService.setup (legacy_service.ts:63)
    at CoreSystem.setup$ (core_system.ts:212)
    at tryCatch (runtime.js:45)
    at Generator.invoke [as _invoke] (runtime.js:271)
    at Generator.prototype.<computed> [as next] (runtime.js:97)
    at tryCatch (runtime.js:45)
    at invoke (runtime.js:135)
@cjcenizal cjcenizal added Team:Core Core services & architecture: plugins, logging, config, saved objects, http, ES client, i18n, etc triage_needed labels Feb 12, 2020
@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-platform (Team:Platform)

@pgayvallet
Copy link
Contributor

It seems the pluginId is prevalent to the actual declared application id when gathering the legacy navlinks/apps:

function getUiAppsNavLinks({ uiAppSpecs = [] }: LegacyUiExports, pluginSpecs: LegacyPluginSpec[]) {
return uiAppSpecs.flatMap(spec => {
if (!spec) {
return REMOVE_FROM_ARRAY;
}
const id = spec.pluginId || spec.id;
if (!id) {
throw new Error('Every app must specify an id');
}

which results in multiple apps with the same 'id' being registered twice:

registerLegacyApp: app => {
const appRoute = `/app/${app.id.split(':')[0]}`;
if (this.registrationClosed) {
throw new Error('Applications cannot be registered after "setup"');
} else if (this.apps.has(app.id)) {
throw new Error(`An application is already registered with the id "${app.id}"`);

need to investigate on what caused this, I'm not aware of any major changes in the way we were merging plugin specs in src/core/server/legacy/plugins/find_legacy_plugin_specs.ts

@sergibondarenko can you confirm this did work properly on a 7.5.x ?

@pgayvallet
Copy link
Contributor

Also, this seems to be still working with the kibana security plugin

apps: [
{
id: 'login',
title: 'Login',
main: 'plugins/security/views/login',
hidden: true,
},
{
id: 'overwritten_session',
title: 'Overwritten Session',
main: 'plugins/security/views/overwritten_session',
description:

@sergibondarenko
Copy link
Author

@pgayvallet I confirm, the app works in Kibana v7.5.x

@sergibondarenko
Copy link
Author

The plugin is loaded as expected in Kibana v7.6 if the line

const id = spec.pluginId || spec.id; 

is substituted by

const id = spec.id || spec.pluginId; 

in kibana/src/core/server/legacy/plugins/find_legacy_plugin_specs.ts

@pgayvallet
Copy link
Contributor

Reproduction confirmed on current master (c5a60b9)

Also it does work with security as all registered apps are hidden, and hidden apps are excluded from the navlink generation

if (spec.hidden || !listed) {
return REMOVE_FROM_ARRAY;
}

This was caused by #52161. Before that, the gathered apps were only using the id prop

kbnServer.uiApps = uiAppSpecs.map(spec => {
const app = new UiApp(kbnServer, spec);
const id = app.getId();
if (!existingIds.has(id)) {
existingIds.add(id);
} else {
throw new Error(`Unable to create two apps with the id ${id}.`);
}
if (app.isHidden()) {
hiddenAppsById.set(id, app);
} else {
appsById.set(id, app);
}
return app;
});

getId() {
return this._id;
}

@pgayvallet
Copy link
Contributor

@sergibondarenko thanks for the complete reproduction scenario. That helped a lot. On it.

@joshdover
Copy link
Contributor

Removing the regression label since this is a break on an experimental, unsupported API.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Team:Core Core services & architecture: plugins, logging, config, saved objects, http, ES client, i18n, etc v7.6.1 v7.7.0 v8.0.0
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants