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

[kbn/test] add import/export support to KbnClient #92526

Merged
merged 28 commits into from
Feb 25, 2021

Conversation

spalger
Copy link
Contributor

@spalger spalger commented Feb 23, 2021

This PR implements a client for using the Saved Objects import and export APIs by writing exports to disk and loading imports from disk into Kibana. This client lives within the KbnClient, and is exposed to the FTR test via the kibanaServer service.

  • kibanaServer.importExport.save(name, { types, space }) - Save an export of saved objects of listed types (optionally specifying a space) to disk using the given name.
  • kibanaServer.importExport.load(name, { space }) - Load an export from disk by name into Kibana, optionally into a specific space.
  • kibanaServer.importExport.unload(name, { space }) - Delete the saved objects from Kibana which share a type and id with objects in the named export on disk.
  • kibanaServer.savedObjects.clean({ types, space }) - This method is a part of the existing kibanaServer.savedObjects API, but is new and used with the new import/export methods to delete all objects of specific types, optionally specifying something other than the default space

Additionally, node scripts/kbn_archiver exposes the kibanaServer.importExport API for creating/loading/unloading these exports before writing tests. The CLI functions very similarly to node scripts/es_archiver, here is the help text for the CLI:

$ node scripts/kbn_archiver.js --help

  node scripts/kbn_archiver.js [command] [...args]

  Import/export saved objects from archives, for testing

  Commands:
    save <name>
      export saved objects from Kibana to a file

      Options:
        --type             saved object type that should be fetched and stored in the archive, can
                             be specified multiple times or be a comma-separated list.

    load <name>
      import a saved export to Kibana

    unload <name>
      delete the saved objects saved in the archive from the Kibana index


  Global options:
    --space            space id to operate on, defaults to the default space
    --config           optional path to an FTR config file that will be parsed and used for defaults
    --kibana-url       set the url that kibana can be reached at, uses the "servers.kibana" setting from --config by default
    --dir              directory that contains exports to be imported, or where exports will be saved, uses the "kbnArchiver.directory"
                         setting from --config by default
    --verbose, -v      Log verbosely
    --debug            Log debug messages (less than verbose)
    --quiet            Only log errors
    --silent           Don't log anything
    --help             Show this message

Just like node scripts/es_archiver this script takes the --config param which reads an FTR config file to know how to talk to Kibana, including SSL certs and authentication and where the exports are stored on disk for that FTR config.

Thanks to @wayneseymour for getting things started in #90251

wayneseymour and others added 22 commits February 11, 2021 13:22
Add svc,
integrate into one test,
add exported saved objects,
add empty kibana call,
and update ftr schema...add data directory for the new svc.
Make public api take one argument.
Make typescript happier.
@spalger spalger added Team:Operations Team label for Operations Team v8.0.0 release_note:skip Skip the PR/issue when compiling release notes v7.12.0 v7.13.0 labels Feb 23, 2021
@spalger spalger marked this pull request as ready for review February 24, 2021 16:46
@spalger spalger requested a review from a team as a code owner February 24, 2021 16:46
@spalger
Copy link
Contributor Author

spalger commented Feb 24, 2021

I'm expecting we would likely use esArchiver.load('empty_kibana'); before loading SOs or as a cleanup step since the SO API doesn't really make that easy. Any problem with that?

Using the esArchiver to load an empty Kibana index requires that we recreate the index from scratch, including running migrations, which is time intensive and requires that the Kibana server works at some level with the Kibana index disappearing randomly. If we can get away from this I think it would be ideal.

In most cases I expect that we can use kibanaServer.savedObjects.clean({ types }) to make sure that saved objects of specific types are removed, so that lists of objects and such are limited just to the saved objects expected by the tests. I think this should work for nearly every testing scenario, do you?

@LeeDr
Copy link
Contributor

LeeDr commented Feb 24, 2021

I'm expecting we would likely use esArchiver.load('empty_kibana'); before loading SOs or as a cleanup step since the SO API doesn't really make that easy. Any problem with that?

Using the esArchiver to load an empty Kibana index requires that we recreate the index from scratch, including running migrations, which is time intensive and requires that the Kibana server works at some level with the Kibana index disappearing randomly. If we can get away from this I think it would be ideal.

In most cases I expect that we can use kibanaServer.savedObjects.clean({ types }) to make sure that saved objects of specific types are removed, so that lists of objects and such are limited just to the saved objects expected by the tests. I think this should work for nearly every testing scenario, do you?

I guess that .clean would work. In most cases it's just index-patterns, searches, visualizations, and dashboards. If we clean those before loading the test set, and clean again in the after method we'll probably be good. I'm OK with trying to move away from using esArchiver for that.

Copy link
Member

@jbudz jbudz left a comment

Choose a reason for hiding this comment

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

Thoughts on include docs similar to esArchiver in https://www.elastic.co/guide/en/kibana/master/development-tests.html?

I'd be interested in guidance on when to use esArchiver vs kbnArchiver and the new workflow expected for running functional tests

@spalger
Copy link
Contributor Author

spalger commented Feb 24, 2021

Thoughts on include docs similar to esArchiver in elastic.co/guide/en/kibana/master/development-tests.html?

👍 I think that's a great idea, will make sure this PR includes the docs before merge.

I'd be interested in guidance on when to use esArchiver vs kbnArchiver and the new workflow expected for running functional tests

The general plan is to migrate all Kibana Saved Objects interactions to the kbnArchiver where possible. Using the esArchiver needs to still work as long as there are scenarios that we can't test using the kbnArchiver, but I imagine we'll need to try migrating all the current .kibana + esArchiver usage to determine if we still need to support .kibana in the esArchiver.

@spalger spalger force-pushed the implement/kbn-client-import-export branch from b24dbcb to 21fe068 Compare February 24, 2021 20:41
@kibanamachine
Copy link
Contributor

💚 Build Succeeded

Metrics [docs]

✅ unchanged

History

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

Copy link
Member

@spong spong left a comment

Choose a reason for hiding this comment

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

Security Solution changes LGTM! 👍

@spalger spalger merged commit 0aabc31 into elastic:master Feb 25, 2021
@spalger spalger deleted the implement/kbn-client-import-export branch February 25, 2021 23:13
@spalger spalger added the auto-backport Deprecated - use backport:version if exact versions are needed label Feb 25, 2021
kibanamachine added a commit to kibanamachine/kibana that referenced this pull request Feb 25, 2021
Co-authored-by: Tre' Seymour <wayne.seymour@elastic.co>
Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
Co-authored-by: spalger <spalger@users.noreply.github.com>
kibanamachine added a commit to kibanamachine/kibana that referenced this pull request Feb 25, 2021
Co-authored-by: Tre' Seymour <wayne.seymour@elastic.co>
Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
Co-authored-by: spalger <spalger@users.noreply.github.com>
@kibanamachine
Copy link
Contributor

💚 Backport successful

7.12 / #92934
7.x / #92935

Successful backport PRs will be merged automatically after passing CI.

kibanamachine added a commit that referenced this pull request Feb 26, 2021
Co-authored-by: Tre' Seymour <wayne.seymour@elastic.co>
Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
Co-authored-by: spalger <spalger@users.noreply.github.com>

Co-authored-by: Spencer <email@spalger.com>
Co-authored-by: Tre' Seymour <wayne.seymour@elastic.co>
Co-authored-by: spalger <spalger@users.noreply.github.com>
kibanamachine added a commit that referenced this pull request Feb 26, 2021
Co-authored-by: Tre' Seymour <wayne.seymour@elastic.co>
Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
Co-authored-by: spalger <spalger@users.noreply.github.com>

Co-authored-by: Spencer <email@spalger.com>
Co-authored-by: Tre' Seymour <wayne.seymour@elastic.co>
Co-authored-by: spalger <spalger@users.noreply.github.com>
gmmorris added a commit to gmmorris/kibana that referenced this pull request Feb 26, 2021
…bana into task-manager/docs-monitoring

* 'task-manager/docs-monitoring' of github.com:gmmorris/kibana: (40 commits)
  [Security Solution][Case][Bug] Improve case logging (elastic#91924)
  [Alerts][Doc] Added README documentation for alerts plugin status and framework health checks configuration options. (elastic#92761)
  Add warning for EQL and Threshold rules if exception list contains value list items (elastic#92914)
  [Security Solution][Case] Fix subcases bugs on detections and case view (elastic#91836)
  [APM] Always allow access to Profiling via URL (elastic#92889)
  [Vega] Allow image loading without CORS policy by changing the default to crossOrigin=null (elastic#91991)
  skip flaky suite (elastic#92114)
  [APM] Fix for default fields in correlations view (elastic#91868) (elastic#92090)
  chore(NA): bump bazelisk to v1.7.5 (elastic#92905)
  [Maps] fix selecting EMS basemap does not populate input (elastic#92711)
  API docs (elastic#92827)
  [kbn/test] add import/export support to KbnClient (elastic#92526)
  Test fix management scripted field filter functional test and unskip it  (elastic#92756)
  [App Search] Create Curation view/functionality (elastic#92560)
  [Reporting/Discover] include the document's entire set of fields (elastic#92730)
  [Fleet] Add new index to fleet for artifacts being served out of fleet-server (elastic#92860)
  [Alerts][Doc] Added README documentation for API key invalidation configuration options. (elastic#92757)
  [Discover][docs] Add search for relevance (elastic#90611)
  [Alerts][Docs] Extended README.md and the user docs with the licensing information. (elastic#92564)
  [7.12][Telemetry] Security telemetry allowlist fix. (elastic#92850)
  ...
@rudolf
Copy link
Contributor

rudolf commented Mar 1, 2021

Closes #89368

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
auto-backport Deprecated - use backport:version if exact versions are needed release_note:skip Skip the PR/issue when compiling release notes Team:Operations Team label for Operations Team v7.12.0 v7.13.0 v8.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants