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

[D&D] Save index pattern using proper saved object structure #2218

Merged

Conversation

abbyhu2000
Copy link
Member

@abbyhu2000 abbyhu2000 commented Aug 29, 2022

Description

Previously the index pattern is only saved as an id in the visualization state. This PR saves the index pattern using proper saved object structure: by saving a indexRefName in the searchSourceJSON in kibanaSavedObjectMeta and also saving the name, type and id of the index pattern as a reference object.

Before:

"wizard" : {
            "title" : "ecommerce_wizard",
            "description" : "",
            "visualizationState" : """{"searchField":"","activeVisualization":{"name":"metric","aggConfigParams":[{"id":"1","enabled":true,"type":"cardinality","params":{"field":"category.keyword"},"schema":"metric"},{"id":"2","enabled":true,"type":"cardinality","params":{"field":"customer_birth_date"},"schema":"metric"},{"id":"3","enabled":true,"type":"terms","params":{"field":"customer_gender","order":"desc","size":5,"otherBucket":false,"otherBucketLabel":"Other","missingBucket":false,"missingBucketLabel":"Missing"},"schema":"group"}]},"indexPattern":"ff959d40-b880-11e8-a6d9-e546fe2bba5f"}""",
            "styleState" : """{"addTooltip":true,"addLegend":false,"type":"metric","metric":{"percentageMode":false,"useRanges":false,"colorSchema":"Green to Red","metricColorMode":"None","colorsRange":[{"from":0,"to":10000}],"labels":{"show":true},"invertColors":false,"style":{"bgFill":"#000","bgColor":false,"labelColor":false,"subText":"","fontSize":60}}}""",
            "version" : 1
          },
          "type" : "wizard",
          "references" : [ ],
          "updated_at" : "2022-08-24T17:47:38.274Z"
        }

Should be:

"wizard" : {
            "title" : "ecommerce_wizard",
            "description" : "",
            "visualizationState" : """{"searchField":"","activeVisualization":{"name":"metric","aggConfigParams":[{"id":"1","enabled":true,"type":"cardinality","params":{"field":"category.keyword"},"schema":"metric"},{"id":"2","enabled":true,"type":"cardinality","params":{"field":"customer_birth_date"},"schema":"metric"},{"id":"3","enabled":true,"type":"terms","params":{"field":"customer_gender","order":"desc","size":5,"otherBucket":false,"otherBucketLabel":"Other","missingBucket":false,"missingBucketLabel":"Missing"},"schema":"group"}]}}""",
            "styleState" : """{"addTooltip":true,"addLegend":false,"type":"metric","metric":{"percentageMode":false,"useRanges":false,"colorSchema":"Green to Red","metricColorMode":"None","colorsRange":[{"from":0,"to":10000}],"labels":{"show":true},"invertColors":false,"style":{"bgFill":"#000","bgColor":false,"labelColor":false,"subText":"","fontSize":60}}}""",
            "version" : 1,
            "kibanaSavedObjectMeta" : {
              "searchSourceJSON" : """{"indexRefName":"kibanaSavedObjectMeta.searchSourceJSON.index"}"""
            },
          },
          "type" : "wizard",
          "references" : [ 
           {
              "name" : "kibanaSavedObjectMeta.searchSourceJSON.index",
              "type" : "index-pattern",
              "id" : "ff959d40-b880-11e8-a6d9-e546fe2bba5f"
            }
           ],
          "updated_at" : "2022-08-24T17:47:38.274Z"
        }

Issues Resolved

resolves #1878

Check List

  • New functionality includes testing.
    • All tests pass
      • yarn test:jest
      • yarn test:jest_integration
      • yarn test:ftr
  • New functionality has been documented.
  • Commits are signed per the DCO using --signoff

@abbyhu2000 abbyhu2000 changed the title Save index pattern as a proper saved object relationship, previously … Save index pattern using proper saved object structure Aug 29, 2022
@abbyhu2000 abbyhu2000 self-assigned this Aug 29, 2022
@abbyhu2000 abbyhu2000 force-pushed the DND_save_index_properly branch from 4fca6c9 to 200708f Compare August 30, 2022 00:31
@abbyhu2000 abbyhu2000 changed the title Save index pattern using proper saved object structure [D&D] Save index pattern using proper saved object structure Aug 30, 2022
@abbyhu2000 abbyhu2000 marked this pull request as ready for review August 30, 2022 00:35
@abbyhu2000 abbyhu2000 requested a review from a team as a code owner August 30, 2022 00:35
@codecov-commenter
Copy link

codecov-commenter commented Aug 30, 2022

Codecov Report

Merging #2218 (00b1812) into main (b961263) will decrease coverage by 0.00%.
The diff coverage is 58.33%.

@@            Coverage Diff             @@
##             main    #2218      +/-   ##
==========================================
- Coverage   66.78%   66.78%   -0.01%     
==========================================
  Files        3131     3133       +2     
  Lines       60057    60079      +22     
  Branches     9150     9153       +3     
==========================================
+ Hits        40109    40123      +14     
- Misses      17759    17766       +7     
- Partials     2189     2190       +1     
Impacted Files Coverage Δ
...rd/public/application/utils/get_top_nav_config.tsx 3.03% <0.00%> (-0.31%) ⬇️
...blic/application/utils/use/use_saved_wizard_vis.ts 3.33% <0.00%> (-0.12%) ⬇️
...s/wizard/public/saved_visualizations/_saved_vis.ts 0.00% <ø> (ø)
...d_visualizations/saved_visualization_references.ts 0.00% <0.00%> (ø)
...ns/wizard/server/saved_objects/wizard_migration.ts 87.50% <87.50%> (ø)

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

yarn.lock Outdated Show resolved Hide resolved
Copy link
Member

@ashwin-pc ashwin-pc left a comment

Choose a reason for hiding this comment

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

Love the PR as a whole. Very surgical. Just a few high level callouts:

  1. We should be removign the index pattern from the visualization state
  2. we should be writing migrations for existing saved objects that have the older version of the saved object
  3. We should have backward compatibility tests/migration tests e.g. https://github.com/opensearch-project/OpenSearch-Dashboards/blob/2.2/src/plugins/visualizations/server/saved_objects/visualization_migrations.ts#L35 and its associated test do something identical to this.

A guide to saved object migrations: https://github.com/opensearch-project/OpenSearch-Dashboards/blob/2.2/src/core/server/saved_objects/migrations/README.md

Copy link
Member

@joshuarrrr joshuarrrr left a comment

Choose a reason for hiding this comment

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

This is awesome, a really clean implementation! Did you verify that now the references render correctly in the Saved Object Management UI (feature parity with other visualization types)?

@abbyhu2000
Copy link
Member Author

Removed index pattern from the visualizatonState when we save. Added migration for existing wizard saved object and unit tests.

…it is only saved as an id in the visualizationState.

Signed-off-by: abbyhu2000 <abigailhu2000@gmail.com>
Signed-off-by: abbyhu2000 <abigailhu2000@gmail.com>
Signed-off-by: abbyhu2000 <abigailhu2000@gmail.com>
Signed-off-by: abbyhu2000 <abigailhu2000@gmail.com>
Copy link
Member

@ashwin-pc ashwin-pc left a comment

Choose a reason for hiding this comment

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

Love the changes, nice job Abby! Left a few more comments. Also

  1. Can we update the default version of the doc to 2 in wizard/public/saved_visualizations/_saved_vis.ts
  2. Have you verified that the migration works with an actual doc with did not have the references? Since this is the first migration we have since we forked, I just want to make sure that migrations still work for us.

yarn.lock Outdated Show resolved Hide resolved
@abbyhu2000 abbyhu2000 force-pushed the DND_save_index_properly branch from cf927fe to 5dbbd1e Compare September 2, 2022 21:10
joshuarrrr
joshuarrrr previously approved these changes Sep 2, 2022
Copy link
Member

@joshuarrrr joshuarrrr left a comment

Choose a reason for hiding this comment

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

Some general comments, but all the functionality looks great, and a big improvement!

Signed-off-by: abbyhu2000 <abigailhu2000@gmail.com>
@abbyhu2000 abbyhu2000 force-pushed the DND_save_index_properly branch from c5089e6 to 00b1812 Compare September 3, 2022 00:14
Copy link
Member

@ashwin-pc ashwin-pc left a comment

Choose a reason for hiding this comment

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

Ship it! 🚢

@abbyhu2000
Copy link
Member Author

Migration tested: Checked out the main branch and created some wizards that only saves index pattern id in the visualization attribute; checked out the new branch and restart opensearch dashboard without restarting opensearch. The migration will trigger. There are no problems with viewing and editing those old wizards and their saved objects have been altered to the new proper way as well (refname has been saved in kibanaSavedObjectMeta and index pattern object has been pushed to the reference array)

Copy link
Member

@kavilla kavilla left a comment

Choose a reason for hiding this comment

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

Awesome!

@joshuarrrr joshuarrrr merged commit 428e832 into opensearch-project:main Sep 6, 2022
opensearch-trigger-bot bot pushed a commit that referenced this pull request Sep 6, 2022
* Save index pattern as a proper saved object relationship, previously it is only saved as an id in the visualizationState.

Signed-off-by: abbyhu2000 <abigailhu2000@gmail.com>

* remove index id from visualization when saving & add comments

Signed-off-by: abbyhu2000 <abigailhu2000@gmail.com>

* add migration for existing wizard

Signed-off-by: abbyhu2000 <abigailhu2000@gmail.com>

* add migration unit test

Signed-off-by: abbyhu2000 <abigailhu2000@gmail.com>

* change wizard doc version to 2; change migration version to 2.3.0

Signed-off-by: abbyhu2000 <abigailhu2000@gmail.com>

Signed-off-by: abbyhu2000 <abigailhu2000@gmail.com>
(cherry picked from commit 428e832)
joshuarrrr pushed a commit that referenced this pull request Sep 6, 2022
* Save index pattern as a proper saved object relationship, previously it is only saved as an id in the visualizationState.

Signed-off-by: abbyhu2000 <abigailhu2000@gmail.com>

* remove index id from visualization when saving & add comments

Signed-off-by: abbyhu2000 <abigailhu2000@gmail.com>

* add migration for existing wizard

Signed-off-by: abbyhu2000 <abigailhu2000@gmail.com>

* add migration unit test

Signed-off-by: abbyhu2000 <abigailhu2000@gmail.com>

* change wizard doc version to 2; change migration version to 2.3.0

Signed-off-by: abbyhu2000 <abigailhu2000@gmail.com>

Signed-off-by: abbyhu2000 <abigailhu2000@gmail.com>
(cherry picked from commit 428e832)
kavilla pushed a commit that referenced this pull request Sep 7, 2022
…2271)

* Save index pattern as a proper saved object relationship, previously it is only saved as an id in the visualizationState.

Signed-off-by: abbyhu2000 <abigailhu2000@gmail.com>

* remove index id from visualization when saving & add comments

Signed-off-by: abbyhu2000 <abigailhu2000@gmail.com>

* add migration for existing wizard

Signed-off-by: abbyhu2000 <abigailhu2000@gmail.com>

* add migration unit test

Signed-off-by: abbyhu2000 <abigailhu2000@gmail.com>

* change wizard doc version to 2; change migration version to 2.3.0

Signed-off-by: abbyhu2000 <abigailhu2000@gmail.com>

Signed-off-by: abbyhu2000 <abigailhu2000@gmail.com>
(cherry picked from commit 428e832)

Co-authored-by: Qingyang(Abby) Hu <abigailhu2000@gmail.com>
@abbyhu2000 abbyhu2000 deleted the DND_save_index_properly branch June 30, 2023 17:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[D&D] Ensure relationships to index patterns are saved correctly
6 participants