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

[migration]clean up __from and __to in dashboard json_metadata #6378

Merged

Conversation

graceguo-supercat
Copy link

@graceguo-supercat graceguo-supercat commented Nov 13, 2018

In dashboard Superset allows user save default values for filter slice, and saved in json_metadata. So that when the dashboard is loaded, it will be pre-populated with values for the filters. Superset also allows user set charts that immune from filters. For example:

{"filter_immune_slices": [], "timed_refresh_immune_slices": [], "filter_immune_slice_fields": {"255": ["__from", "__to"]}, "expanded_slices": {}, "default_filters": "{\"254\": {\"__from\": \"1 months ago\", \"dim_country\": [\"all\"]}}"}

after recently introduced time_range, __from and __to in json_metadata didn't correctly merge with time_range. It introduces extra __from/__to parameter into Filter control, and cause chart show no data. In airbnb we have about 500 dashboards set __from and __to in json_metadata.

screen shot 2018-11-15 at 10 42 32 am

Fix: I wrote this migration script to update __from/__to to __time_range for json_metadata.

@betodealmeida @mistercrunch @john-bodley @timifasubaa @michellethomas

@codecov-io
Copy link

codecov-io commented Nov 13, 2018

Codecov Report

Merging #6378 into master will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##           master    #6378   +/-   ##
=======================================
  Coverage   77.31%   77.31%           
=======================================
  Files          67       67           
  Lines        9581     9581           
=======================================
  Hits         7408     7408           
  Misses       2173     2173

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update c17de39...5219596. Read the comment docs.

@graceguo-supercat graceguo-supercat force-pushed the gg-MigrateDashboardMetadata branch 2 times, most recently from b020596 to 476b2ce Compare November 13, 2018 20:05
@mistercrunch mistercrunch added the risk:db-migration PRs that require a DB migration label Nov 14, 2018

if has_update:
dashboard.json_metadata = json.dumps(json_metadata)
session.merge(dashboard)
Copy link
Member

Choose a reason for hiding this comment

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

We don't need to do a merge and having a single commit at the end is more efficient.

for key in keys:
val = filters[key]
val['__time_range'] = '{} : {}'.format(
val.pop('__from', '') or '',
Copy link
Member

Choose a reason for hiding this comment

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

I don't think we need the or.

@graceguo-supercat
Copy link
Author

code is updated per comment. also tested in dev environment...much faster!!

val.pop('__from', ''),
val.pop('__to', ''),
)
json_metadata.update(
Copy link
Member

Choose a reason for hiding this comment

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

Nit. json_metadata['default_filters'] = json.dumps(filters).

Copy link
Author

Choose a reason for hiding this comment

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

fixed.

if '__to' in val:
val.remove('__to')
val.append('__time_range')
json_metadata.update(
Copy link
Member

Choose a reason for hiding this comment

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

Nit. json_metadata['filter_immune_slice_fields'] = filter_immune_slice_fields .

Copy link
Author

Choose a reason for hiding this comment

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

fixed

if len(keys):
for key in keys:
val = filters[key]
val['__time_range'] = '{} : {}'.format(
Copy link
Member

Choose a reason for hiding this comment

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

Is there any concern that __time_range could already exist? If so should it trump the __from and __to?

Copy link
Author

Choose a reason for hiding this comment

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

yes, i think should check if __time_range exist. if it is exist, just abandon __from and __to parameter, so that not override existed __time_range.

@graceguo-supercat graceguo-supercat merged commit c42bcf8 into apache:master Nov 16, 2018
@graceguo-supercat graceguo-supercat deleted the gg-MigrateDashboardMetadata branch November 16, 2018 19:03
graceguo-supercat pushed a commit to graceguo-supercat/superset that referenced this pull request Nov 16, 2018
michellethomas pushed a commit to michellethomas/panoramix that referenced this pull request Nov 20, 2018
betodealmeida pushed a commit to lyft/incubator-superset that referenced this pull request Dec 18, 2018
betodealmeida pushed a commit to lyft/incubator-superset that referenced this pull request Dec 18, 2018
betodealmeida pushed a commit to lyft/incubator-superset that referenced this pull request Dec 19, 2018
bipinsoniguavus pushed a commit to ThalesGroup/incubator-superset that referenced this pull request Dec 26, 2018
betodealmeida pushed a commit to lyft/incubator-superset that referenced this pull request Dec 26, 2018
betodealmeida pushed a commit to lyft/incubator-superset that referenced this pull request Dec 28, 2018
betodealmeida pushed a commit to lyft/incubator-superset that referenced this pull request Jan 4, 2019
betodealmeida pushed a commit to lyft/incubator-superset that referenced this pull request Jan 9, 2019
xtinec pushed a commit to lyft/incubator-superset that referenced this pull request Jan 9, 2019
betodealmeida pushed a commit to lyft/incubator-superset that referenced this pull request Jan 11, 2019
youngyjd pushed a commit to lyft/incubator-superset that referenced this pull request Jan 11, 2019
youngyjd pushed a commit to lyft/incubator-superset that referenced this pull request Jan 11, 2019
betodealmeida pushed a commit to lyft/incubator-superset that referenced this pull request Jan 12, 2019
betodealmeida pushed a commit to lyft/incubator-superset that referenced this pull request Jan 14, 2019
betodealmeida pushed a commit to lyft/incubator-superset that referenced this pull request Jan 14, 2019
youngyjd pushed a commit to lyft/incubator-superset that referenced this pull request Jan 14, 2019
betodealmeida pushed a commit to lyft/incubator-superset that referenced this pull request Jan 14, 2019
betodealmeida pushed a commit to lyft/incubator-superset that referenced this pull request Jan 17, 2019
betodealmeida pushed a commit to lyft/incubator-superset that referenced this pull request Jan 24, 2019
betodealmeida pushed a commit to lyft/incubator-superset that referenced this pull request Jan 30, 2019
betodealmeida pushed a commit to lyft/incubator-superset that referenced this pull request Jan 30, 2019
@mistercrunch mistercrunch added 🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels 🚢 0.34.0 labels Feb 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels risk:db-migration PRs that require a DB migration v0.29 🚢 0.34.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants