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

[Logs UI] Allow for plugins to inject internal source configurations #36066

Merged
merged 12 commits into from
May 10, 2019

Conversation

weltenwort
Copy link
Member

@weltenwort weltenwort commented May 3, 2019

Summary

This exposes an API on the Kibana server object (old platform style) to define internal source configurations, which can not be edited by the user and take precedence above any stored configurations.

The API consists of the server.plugins.infra.defineInternalSourceConfiguration(sourceId, sourceProperties) function, which is supposed to be called from the init or postInit callback of plugins to define the source configuration with a unique source id. This source id can then be used when linking to the Logs UI to enforce usage of the internal source configuration without interference by other user-defined configurations. If it is not specified, the usual "default" source configuration will be used.

More specifically, the link-to log routes now support specifying a source id in the url as in /link-to/:sourceId/logs and /link-to/:sourceId/(host|pod|container)-logs. For these log links, this is turned into the appropriate url params. It is implemented for the snapshot and metrics redirects until these pages fully support referencing non-default sources.

closes #30792

Example Usage

In a plugin definition, the postInit callback could look something like this:

const MY_PLUGIN_INFRA_SOURCE_ID = 'internal-my-plugin';

export const myPlugin = kibana => new kibana.Plugin({
  // ...
  postInit(server) {
    const infraPlugin = server.plugins.infra;
    if (infraPlugin) { // the infra plugin might not be present
      infraPlugin.defineInternalSourceConfiguration(MY_PLUGIN_INFRA_SOURCE_ID, {
        name: 'Special Logs',
        logAlias: 'a-special-filebeat-index-*',
		fields: {
          timestamp: 'a.different.timestamp.field',
        },
        logColumns: [
          {
            timestampColumn: {
              id: '5e7f964a-be8a-40d8-88d2-fbcfbdca0e2f',
            },
          },
          {
            fieldColumn: {
              id: '6ba2855d-e2b7-4f1d-aa3c-aedabee25427',
              field: 'a.special.field',
            },
          },
          {
            messageColumn: {
              id: 'b645d6da-824b-4723-9a2a-e8cece1645c0',
            },
          },
        ]
      });
    }
  },
  // ...
});

Then on the front-end, the plugin's UI could link to that source:

<a href={`${basePath}/app/infra#/link-to/${MY_PLUGIN_INFRA_SOURCE_ID}/logs?filter=${specialFilter}`}>View special logs</a>

The user would not be able to change the configuration through the configuration UI, because it would be fully controlled by the plugin.

Review Notes

  • This introduces a use_url_state hook, which is essentially a port of the previous <UrlStateContainer> component to hooks, but simpler. It behaves similar to a setState hook backed by the rison-encoded url. It doesn't provide any imperative onChange callback anymore, because that can be easily be imitated using useEffect. Both the hook and the old container component use the same encoding and can be used simultaneously.
  • The old react-router v4 package we're using doesn't support new-style context. In order to support access to the location, the history object is therefore now also made available via the context using HistoryContext.Provider.
  • Since the log entry state and loading side-effects are still managed in redux while the sourceId state is managed via hooks, I added a bridge component on the logs page to inject the sourceId into redux land via a simple setSourceId action.
  • The source configuration datastructure now has an additional property origin, which is one of internal, fallback or stored, to indicate where the configuration comes from. If it is internal, then saving through the configuration flyout is disabled.

Testing

One possibility to test whether using an internal source actually works is to add something like shown in the example usage above to one of the other x-pack plugins and directly visit the corresponding link-to route in the browser.

It's also important to ensure that not specifying any source id defaults to the "default" source id and preserves the previous behaviour.

Checklist

For maintainers

@weltenwort weltenwort added [zube]: In Progress v8.0.0 Feature:Logs UI Logs UI feature Team:Infra Monitoring UI - DEPRECATED DEPRECATED - Label for the Infra Monitoring UI team. Use Team:obs-ux-infra_services v7.2.0 labels May 3, 2019
@weltenwort weltenwort self-assigned this May 3, 2019
@elasticmachine
Copy link
Contributor

Pinging @elastic/infrastructure-ui

@elasticmachine
Copy link
Contributor

💚 Build Succeeded

@weltenwort weltenwort force-pushed the logs-ui-add-internal-source-api branch from adbc04c to 3887f6d Compare May 6, 2019 22:03
@elasticmachine
Copy link
Contributor

💔 Build Failed

@elasticmachine
Copy link
Contributor

💚 Build Succeeded

@weltenwort weltenwort force-pushed the logs-ui-add-internal-source-api branch from c2c8a2a to 4a7039b Compare May 7, 2019 11:42
@elasticmachine
Copy link
Contributor

💔 Build Failed

@weltenwort weltenwort force-pushed the logs-ui-add-internal-source-api branch from 19f6c19 to f351d81 Compare May 7, 2019 18:53
@elasticmachine
Copy link
Contributor

💚 Build Succeeded

@elasticmachine
Copy link
Contributor

💚 Build Succeeded

@weltenwort weltenwort marked this pull request as ready for review May 8, 2019 12:57
@weltenwort
Copy link
Member Author

Sorry to any reviewers who might have already started taking a look at this. Just after ending the draft state of this PR I noticed that I should really improve and simplify the "link-to" urls. I switched them around from /:sourceId/link-to/ to /link-to/:sourceId for aesthetic reasons and because I could ensure that the URL didn't accidentally cover the node-details redirects too.

The change was local to the link-to page components and didn't impact the rest of the changes.

@elasticmachine
Copy link
Contributor

💔 Build Failed

@weltenwort
Copy link
Member Author

jenkins, test this

@elasticmachine
Copy link
Contributor

💔 Build Failed

@weltenwort weltenwort force-pushed the logs-ui-add-internal-source-api branch from ccd58b4 to 1e25978 Compare May 9, 2019 08:35
@elasticmachine
Copy link
Contributor

💚 Build Succeeded

@weltenwort
Copy link
Member Author

The CI failure seems to have been unrelated and a rebase on master resolved it. Ready for review (again).

Copy link
Member

@simianhacker simianhacker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM... @weltenwort and I discussed adding a follow up PR to add some tests around useUrlState hook. I also set up a custom source and used it with in the app and everything worked as expected. Good Job!

@weltenwort weltenwort merged commit 07824d2 into elastic:master May 10, 2019
weltenwort added a commit to weltenwort/kibana that referenced this pull request May 10, 2019
…lastic#36066)

This exposes an API on the Kibana server object (old platform style) to define internal source configurations, which can not be edited by the user and take precedence above any stored configurations.
weltenwort added a commit that referenced this pull request May 10, 2019
…tions (#36066) (#36470)

Backports the following commits to 7.x:
 - [Logs UI] Allow for plugins to inject internal source configurations  (#36066)
@weltenwort weltenwort added the non-issue Indicates to automation that a pull request should not appear in the release notes label May 23, 2019
github-merge-queue bot pushed a commit that referenced this pull request Nov 7, 2023
…nfiguration code (#169430)

Resolves #168240

### Changes

- Removes `fields.message` from the `infrastructure-ui-source` saved
object who's value was being populated by
`xpack.infra.sources.default.fields.message` from config. See
https://www.elastic.co/guide/en/kibana/master/logs-ui-settings-kb.html
- Removes `getInternalSourceConfiguration` and
`defineInternalSourceConfiguration` functions introduced in
#36066 as I cannot see them being
used anywhere. Stops exposing `defineInternalSourceConfiguration` as
part of server plugin interface.
- Removes `getStaticDefaultSourceConfiguration` from InfraSources class
as we aren't using `sources` from kibana config in source configuration
anymore.
- Removes deprecations warning of removal in 8.0 for other fields
belonging to config xpack.infra.sources.* introduced in
#115103
- Removes `getAllSourceConfigurations` used only in removed deprecations
file
f427278#diff-081721894fc437938eb652beae0a0640ddeee532ec5e48af1f3093c8074f1eecL195
- Removed `getAllSavedSourceConfigurations` only used in
`getAllSourceConfigurations`

### How to test 
- `infrastructure-ui-source` saved object no longer has `fields`
attributes
- in kibana.yml set `xpack.infra.sources.default.fields.message:
['testmessage', '@testmessage']`
  - go to Infra -> Settings
  - Change the name and save the form
- view the `infrastructure-ui-source` saved object and no `fields`
attribute should exist (unless it previously existed in an already
existing `infrastructure-ui-source` saved object
- changes do not affect`fields.message` is used in logs_shared plugin
- i'm not sure how to easily test this and relying on someone with more
Logs knowledge to help out, but from what I can see logs accesses the
config directly (`xpack.infra.sources.default.fields.message`) and never
uses the saved object field being removed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature:Logs UI Logs UI feature non-issue Indicates to automation that a pull request should not appear in the release notes review Team:Infra Monitoring UI - DEPRECATED DEPRECATED - Label for the Infra Monitoring UI team. Use Team:obs-ux-infra_services v7.2.0 v8.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Logs UI] Allow other Kibana apps to define and link to custom log sources
4 participants