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

Use Saved Objects API for exporting and importing dashboards #27220

Merged
merged 27 commits into from
Aug 16, 2021

Conversation

kvch
Copy link
Contributor

@kvch kvch commented Aug 3, 2021

What does this PR do?

This PR adopts the Saved Objects API for exporting and importing dashboards and index templates. We have agreed to provide essential support, so there are a few limitations:

  • You can only import assets they have exported using Beats 7.15 and the assets we ship with Beats.
  • You can only export new assets, not legacy format.

TODO

  • migrate dashboards of Winlogbeat
  • add a few sections to Beats developer guide to explain how to migrate existing assets
  • revisit modify JSON functions
  • follow up in dashboards end to end test

Why is it important?

We have to move forward to let Kibana remove the old API.

Checklist

  • My code follows the style guidelines of this project
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
    - [ ] I have made corresponding change to the default configuration files
  • I have added tests that prove my fix is effective or that my feature works
  • I have added an entry in CHANGELOG.next.asciidoc or CHANGELOG-developer.next.asciidoc.

How to test this PR locally

Try to setup the dashboards of a Beat:

./filebeat setup --dashboards

Export dashboards:

./filebeat export dashboard --id {my-id}

and:

go run dev-tools/cmd/dashboards/export_dashboards.go -dashboard {my-id}

Notes to the reviewer

The changeset is huge, but most of it comes from converting the dashboards. I suggest you use the file filter and disable json, ndjson and yml files. The changes are moving json to ndjson format and changing the extensions in the module.yml files from json to ndjson.

Please also test it manually with both the setup command and export_dashboards.go.

Related issues

Closes #20672

@botelastic botelastic bot added the needs_team Indicates that the issue/PR needs a Team:* label label Aug 3, 2021
@elasticmachine
Copy link
Collaborator

elasticmachine commented Aug 3, 2021

💚 Build Succeeded

the below badges are clickable and redirect to their specific view in the CI or DOCS
Pipeline View Test View Changes Artifacts preview preview

Expand to view the summary

Build stats

  • Start Time: 2021-08-13T15:52:41.507+0000

  • Duration: 160 min 59 sec

  • Commit: 5541d2d

Test stats 🧪

Test Results
Failed 0
Passed 53106
Skipped 5320
Total 58426

Trends 🧪

Image of Build Times

Image of Tests

💚 Flaky test report

Tests succeeded.

Expand to view the summary

Test stats 🧪

Test Results
Failed 0
Passed 53106
Skipped 5320
Total 58426

@kvch kvch force-pushed the feature-libbeat-import-objects branch from e8e9a47 to 1d96f7f Compare August 4, 2021 17:59
@kvch kvch force-pushed the feature-libbeat-import-objects branch from 1d96f7f to 2d44a6c Compare August 4, 2021 18:07
@kvch kvch requested a review from urso August 4, 2021 18:14
@kvch kvch changed the title Feature libbeat import objects Use Saved Objects API for exporting and importing dashboards Aug 4, 2021
@kvch kvch added the Team:Elastic-Agent Label for the Agent team label Aug 4, 2021
@botelastic botelastic bot removed the needs_team Indicates that the issue/PR needs a Team:* label label Aug 4, 2021
@kvch kvch marked this pull request as ready for review August 5, 2021 16:37
@kvch kvch requested a review from a team as a code owner August 5, 2021 16:37
@elasticmachine
Copy link
Collaborator

Pinging @elastic/agent (Team:Agent)

@kvch kvch added the backport-v7.15.0 Automated backport with mergify label Aug 5, 2021
@exekias
Copy link
Contributor

exekias commented Aug 9, 2021

@mtojek once this goes in it will affect the beats import script, as this is already converting dashboards. On the other side, I don't think we are using the same format, thoughts?

@kvch
Copy link
Contributor Author

kvch commented Aug 9, 2021

IIUC this means that Beats 7.15 will no longer import dashboards to 7.14. Did I get that right? If so does that match with what's in the support matrix? I think this it would be helpful to call that out in the changelog/release notes.

I gave the Go code a quick pass. I didn't try running it.

I have added it to our development documentation. Let me know if that is not clear. Also, I am adding it to the changelog soon.

@andrewkroh
Copy link
Member

I have added it to our development documentation. Let me know if that is not clear. Also, I am adding it to the changelog soon.

That sounds good. Any idea about the support matrix? I'm having a hard time interpreting what compatibility guarantees are made there.

@kvch
Copy link
Contributor Author

kvch commented Aug 9, 2021

I have added it to our development documentation. Let me know if that is not clear. Also, I am adding it to the changelog soon.

That sounds good. Any idea about the support matrix? I'm having a hard time interpreting what compatibility guarantees are made there.

Well, what I inferred from the support matrix is that version(Beats) <= version(Elasticsearch): https://www.elastic.co/support/matrix#matrix_compatibility

This is also what we agreed on in: #20672 (comment)

@kvch
Copy link
Contributor Author

kvch commented Aug 11, 2021

jenkins run tests

1 similar comment
@kvch
Copy link
Contributor Author

kvch commented Aug 12, 2021

jenkins run tests

}
}

func decodeLine(line []byte) []byte {
Copy link
Member

Choose a reason for hiding this comment

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

I think json.Unmarshal will return an error if you try to decode an empty slice.

You might want to do a if len(bytes.TrimSpace(line)) == 0 { return }. This handles both empty slices and blank lines (which are allowable per the NDJSON spec you linked to.)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍 I have added this check to more functions that needed it.

@kvch
Copy link
Contributor Author

kvch commented Aug 16, 2021

Failing test is unrelated.

@kvch kvch merged commit 099dfa3 into elastic:master Aug 16, 2021
kvch added a commit that referenced this pull request Aug 16, 2021
This PR adopts the Saved Objects API for exporting and importing dashboards and index templates. We have agreed to provide essential support, so there are a few limitations:

* You can only import assets they have exported using Beats 7.15 and the assets we ship with Beats.
* You can only export new assets, not legacy format.

We have to move forward to let Kibana remove the old API.

Try to setup the dashboards of a Beat:

```sh
./filebeat setup --dashboards
```

Export dashboards:

```sh
./filebeat export dashboard --id {my-id}
```
and:

```sh
go run dev-tools/cmd/dashboards/export_dashboards.go -dashboard {my-id}
```

The changeset is huge, but most of it comes from converting the dashboards. I suggest you use the file filter and disable json, ndjson and yml files. The changes are moving json to ndjson format and changing the extensions in the module.yml files from json to ndjson.

Please also test it manually with both the setup command and `export_dashboards.go`.

Closes #20672
kvch added a commit that referenced this pull request Aug 16, 2021
…#27398)

This PR adopts the Saved Objects API for exporting and importing dashboards and index templates. We have agreed to provide essential support, so there are a few limitations:

* You can only import assets they have exported using Beats 7.15 and the assets we ship with Beats.
* You can only export new assets, not legacy format.

We have to move forward to let Kibana remove the old API.

Try to setup the dashboards of a Beat:

```sh
./filebeat setup --dashboards
```

Export dashboards:

```sh
./filebeat export dashboard --id {my-id}
```
and:

```sh
go run dev-tools/cmd/dashboards/export_dashboards.go -dashboard {my-id}
```

The changeset is huge, but most of it comes from converting the dashboards. I suggest you use the file filter and disable json, ndjson and yml files. The changes are moving json to ndjson format and changing the extensions in the module.yml files from json to ndjson.

Please also test it manually with both the setup command and `export_dashboards.go`.

Closes #20672

Co-authored-by: Noémi Ványi <kvch@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport-v7.15.0 Automated backport with mergify Team:Elastic-Agent Label for the Agent team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Migrate from deprecated Kibana dashboard import API to general Saved Objects import API
4 participants