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

[MDS] Install Vega sample data #6218

Merged
merged 8 commits into from
Mar 29, 2024

Conversation

huyaboo
Copy link
Member

@huyaboo huyaboo commented Mar 19, 2024

Description

With #6123 and #5975 , MDS now fully supports Vega and importing. This PR will fix Vega visualizations when installing sample data. Specifically, the data_source_name field will be appended to each url body of the Vega spec and the datasource reference added to the saved object metadata.

Issues Resolved

Closes #5927

Screenshot

Screen.Recording.2024-03-19.at.4.47.35.PM.mov

Testing the changes

  1. Start with no sample data at all
  2. Add sample data from Data Source Sample
  3. Check Vega Visualizations to see that data_source_name: Data Source Sample was added to each url body of the Vega spec and the datasource reference is included in the saved object metadata.

Check List

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

Copy link

codecov bot commented Mar 20, 2024

Codecov Report

Attention: Patch coverage is 90.00000% with 1 lines in your changes are missing coverage. Please review.

Project coverage is 67.46%. Comparing base (40da92c) to head (3ac41a0).

Files Patch % Lines
...home/server/services/sample_data/data_sets/util.ts 87.50% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main    #6218   +/-   ##
=======================================
  Coverage   67.46%   67.46%           
=======================================
  Files        3368     3368           
  Lines       65422    65431    +9     
  Branches    10557    10560    +3     
=======================================
+ Hits        44134    44145   +11     
+ Misses      18717    18714    -3     
- Partials     2571     2572    +1     
Flag Coverage Δ
Linux_1 32.14% <0.00%> (-0.01%) ⬇️
Linux_2 55.58% <100.00%> (+<0.01%) ⬆️
Linux_3 44.90% <0.00%> (-0.02%) ⬇️
Linux_4 35.07% <80.00%> (+0.09%) ⬆️
Windows_1 32.16% <0.00%> (-0.01%) ⬇️
Windows_2 55.55% <100.00%> (+<0.01%) ⬆️
Windows_3 44.92% <0.00%> (-0.01%) ⬇️
Windows_4 35.07% <80.00%> (+0.09%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@huyaboo huyaboo changed the title Install vega sample data [MDS] Install Vega sample data Mar 20, 2024
@huyaboo huyaboo marked this pull request as ready for review March 20, 2024 18:09
@xinruiba xinruiba added the multiple datasource multiple datasource project label Mar 20, 2024
Copy link
Contributor

@yujin-emma yujin-emma left a comment

Choose a reason for hiding this comment

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

LGTM

}

export const updateDataSourceNameInVegaSpec = (
props: UpdateDataSourceNameInVegaSpecProps
): string => {
const { spec } = props;
const { spec, spacing } = props;
const stringifiedSpacing = !!spacing ? spacing : 2;
Copy link
Member

Choose a reason for hiding this comment

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

a shorter way to write this const stringifiedSpacing = spacing || 2;

import { SavedObject, updateDataSourceNameInVegaSpec } from '../../../../../../core/server';

describe('getSavedObjectsWithDataSource()', () => {
const getVisualizationSavedObjects = (): Array<SavedObject<any>> => {
Copy link
Member

Choose a reason for hiding this comment

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

nonblocking: you can move this large json object to a data.json file and then load it with one line

import data from './data.json'

CHANGELOG.md Outdated
@@ -59,6 +59,9 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
- [Discover] Options button to configure legacy mode and remove the top navigation option ([#6170](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/6170))
- [Multiple Datasource] Add default functionality for customer to choose default datasource ([#6058](https://github.com/opensearch-project/OpenSearch-Dashboards/issues/6058))
- [Multiple Datasource] Add import support for Vega when specifying a datasource ([#6123](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/6123))
- [Workspace] Validate if workspace exists when setup inside a workspace ([#6154](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/6154))
Copy link
Member

Choose a reason for hiding this comment

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

@huyaboo would you rebase from main, so others change won't showup in your PR

Copy link
Member Author

Choose a reason for hiding this comment

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

The CHANGELOG.md change was because my commit adds a new line at the end of the file

CHANGELOG.md Outdated
- Update caniuse to fix failed integration tests ([#2322](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/2322))
Copy link
Collaborator

Choose a reason for hiding this comment

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

Did we change this line?

Copy link
Member Author

Choose a reason for hiding this comment

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

I believe it was a newline added to the end of my CHANGELOG.md

Copy link
Member

Choose a reason for hiding this comment

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

@huyaboo let's rebase with main. Other contributor's change should not show in your PR.

}

export const updateDataSourceNameInVegaSpec = (
props: UpdateDataSourceNameInVegaSpecProps
): string => {
const { spec } = props;
const { spec, spacing } = props;
const stringifiedSpacing = spacing || 2;
Copy link
Collaborator

Choose a reason for hiding this comment

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

So the type of spacing is number, why is it called stringifiedSpacing? Also, why it is || 2 but not other number? what if spacing is 0?

Copy link
Member Author

Choose a reason for hiding this comment

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

stringifiedSpacing is how much indenting should occur when an HJSON document is stringified. It's set to 2 as that seems to be the default for most Vega visualizations. If it were 0 there would be no indenting between the lines so it would look something like this:

{
data: {
url: {
index: some_index
body: {
...
}
}
}
...
}

Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we add those explanation as comments?

const updatedVegaSpec = updateDataSourceNameInVegaSpec({
spec: vegaSpec,
newDataSourceName: dataSourceTitle,
spacing: 1,
Copy link
Collaborator

Choose a reason for hiding this comment

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

why do we hard code spacing as 1 and what does it do?

Copy link
Member Author

Choose a reason for hiding this comment

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

The reason spacing is 1 is because there is one sample data visualization (sankey visualization) that would cause a URL too long error. This setting limits the spacing so the visualization will still be rendered/accessed.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we add those explanation as comments?

BionIT
BionIT previously approved these changes Mar 27, 2024
BionIT
BionIT previously approved these changes Mar 28, 2024
@xinruiba
Copy link
Member

LGTM, thanks

xinruiba
xinruiba previously approved these changes Mar 28, 2024
CHANGELOG.md Outdated
@@ -71,7 +71,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
- [Workspace] Add create workspace page ([#6179](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/6179))
- [Multiple Datasource] Make sure customer always have a default datasource ([#6237](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/6237))
- [Workspace] Add workspace list page ([#6182](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/6182))

- [Multiple Datasource] Append `data_source_name` to the Vega spec and add datasource reference when installing sample data ([#6218](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/6218))
Copy link
Member

Choose a reason for hiding this comment

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

nit: can we add simpler text instead of adding details so that it would be easy to understand by anyone? maybe [Multiple Datasource] Add multi data source support to sample vega visualizations

@@ -6,15 +6,24 @@
import { parse, stringify } from 'hjson';
import { SavedObject, SavedObjectsClientContract } from '../types';

/**
* Given a Vega spec, the new datasource (by name), and spacing,
Copy link
Member

Choose a reason for hiding this comment

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

It's not clear from this line, what exactly this function is doing.

@bandinib-amzn
Copy link
Member

Can you update with rebase before merge?

Signed-off-by: Huy Nguyen <73027756+huyaboo@users.noreply.github.com>
Signed-off-by: Huy Nguyen <73027756+huyaboo@users.noreply.github.com>
Signed-off-by: Huy Nguyen <73027756+huyaboo@users.noreply.github.com>
Signed-off-by: Huy Nguyen <73027756+huyaboo@users.noreply.github.com>
Signed-off-by: Huy Nguyen <73027756+huyaboo@users.noreply.github.com>
Signed-off-by: Huy Nguyen <73027756+huyaboo@users.noreply.github.com>
Signed-off-by: Huy Nguyen <73027756+huyaboo@users.noreply.github.com>
@huyaboo huyaboo dismissed stale reviews from xinruiba and BionIT via c000459 March 29, 2024 00:28
Signed-off-by: Huy Nguyen <73027756+huyaboo@users.noreply.github.com>
@BionIT BionIT merged commit 8810f08 into opensearch-project:main Mar 29, 2024
68 checks passed
@opensearch-trigger-bot
Copy link
Contributor

The backport to 2.x failed:

The process '/usr/bin/git' failed with exit code 128

To backport manually, run these commands in your terminal:

# Navigate to the root of your repository
cd $(git rev-parse --show-toplevel)
# Fetch latest updates from GitHub
git fetch
# Create a new working tree
git worktree add ../.worktrees/OpenSearch-Dashboards/backport-2.x 2.x
# Navigate to the new working tree
pushd ../.worktrees/OpenSearch-Dashboards/backport-2.x
# Create a new branch
git switch --create backport/backport-6218-to-2.x
# Cherry-pick the merged commit of this pull request and resolve the conflicts
git cherry-pick -x --mainline 1 8810f085164243532bf8d87f3952c30172ff8d22
# Push it to GitHub
git push --set-upstream origin backport/backport-6218-to-2.x
# Go back to the original working tree
popd
# Delete the working tree
git worktree remove ../.worktrees/OpenSearch-Dashboards/backport-2.x

Then, create a pull request where the base branch is 2.x and the compare/head branch is backport/backport-6218-to-2.x.

@huyaboo huyaboo deleted the install-vega-sample-data branch March 29, 2024 16:34
huyaboo added a commit to huyaboo/OpenSearch-Dashboards that referenced this pull request Mar 29, 2024
* Add data_source_name to sample data install

Signed-off-by: Huy Nguyen <73027756+huyaboo@users.noreply.github.com>

* Add unit test coverage

Signed-off-by: Huy Nguyen <73027756+huyaboo@users.noreply.github.com>

* Resolve CHANGELOG.md conflicts

Signed-off-by: Huy Nguyen <73027756+huyaboo@users.noreply.github.com>

* Refactor logic

Signed-off-by: Huy Nguyen <73027756+huyaboo@users.noreply.github.com>

* Remove newline

Signed-off-by: Huy Nguyen <73027756+huyaboo@users.noreply.github.com>

* Remove newline

Signed-off-by: Huy Nguyen <73027756+huyaboo@users.noreply.github.com>

* Add comments for spacing

Signed-off-by: Huy Nguyen <73027756+huyaboo@users.noreply.github.com>

* Update jsdoc

Signed-off-by: Huy Nguyen <73027756+huyaboo@users.noreply.github.com>

---------

Signed-off-by: Huy Nguyen <73027756+huyaboo@users.noreply.github.com>
(cherry picked from commit 8810f08)
bandinib-amzn pushed a commit that referenced this pull request Apr 1, 2024
* Add data_source_name to sample data install

Signed-off-by: Huy Nguyen <73027756+huyaboo@users.noreply.github.com>

* Add unit test coverage

Signed-off-by: Huy Nguyen <73027756+huyaboo@users.noreply.github.com>

* Resolve CHANGELOG.md conflicts

Signed-off-by: Huy Nguyen <73027756+huyaboo@users.noreply.github.com>

* Refactor logic

Signed-off-by: Huy Nguyen <73027756+huyaboo@users.noreply.github.com>

* Remove newline

Signed-off-by: Huy Nguyen <73027756+huyaboo@users.noreply.github.com>

* Remove newline

Signed-off-by: Huy Nguyen <73027756+huyaboo@users.noreply.github.com>

* Add comments for spacing

Signed-off-by: Huy Nguyen <73027756+huyaboo@users.noreply.github.com>

* Update jsdoc

Signed-off-by: Huy Nguyen <73027756+huyaboo@users.noreply.github.com>

---------

Signed-off-by: Huy Nguyen <73027756+huyaboo@users.noreply.github.com>
(cherry picked from commit 8810f08)

Signed-off-by: Huy Nguyen <73027756+huyaboo@users.noreply.github.com>
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.

[RFC] Vega support with MDS
8 participants