-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
Don't save the current timezone in visualizations #34795
Conversation
Pinging @elastic/kibana-app |
@@ -146,6 +175,7 @@ export const migrations = { | |||
throw new Error(`Failure attempting to migrate saved object '${doc.attributes.title}' - ${e}`); | |||
} | |||
}, | |||
'7.0.1': removeDateHistogramTimeZones, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@tylersmalley I already talked to Chris, but we wanted to clarify with you that our thoughts were correct:
In the backport to 6.7, I'll remove this 7.0.1 migration and just leave the 6.7
migration in. But since we already released 7.0, and potentially have now people on that version that should get the same fix, we need both 6.7.2
and 7.0.1
to do the migrations. Also just adding a 7.0.1
wouldn't be good, since if we backport this to 6.7 a user who runs the 7.0.1
migration on 6.7
would then, after upgrading to 7.0.1
+, not get all the 7.0.0
migrations.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There should only be one - one of these needs to be removed. It doesn't necessarily have to follow the versioning of Kibana. On startup, it will see if there are any newer versions for the visualization type, we will run those migrations to get up to that version.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think there needs to be 2, because some clients will have run the 7.0.0 migrations already, but some will not have (those running 6.x). And we want to fix both people without forcing the 6.x people to upgrade to 7.x. Does that make sense, @tylersmalley
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We talked about that offline and it makes sense now to everyone. I updated the code to have a better explanation why we need it twice.
💔 Build Failed |
@timroes I will test it tomorrow! Cheers. |
💚 Build Succeeded |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewed code; still need to test. Overall LGTM, just a couple nits. Will try to get this tested tomorrow.
@@ -57,6 +57,34 @@ function migrateIndexPattern(doc) { | |||
doc.attributes.kibanaSavedObjectMeta.searchSourceJSON = JSON.stringify(searchSource); | |||
} | |||
|
|||
function removeDateHistogramTimeZones(doc) { | |||
const newDoc = cloneDeep(doc); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: Not a huge thing, but you don't necessarily need to clone every doc that comes in since you are only going to be updating attributes.visState
on date histograms. You could return early if the doc is not identified as needing to be changed, and only clone / reassign the visState
on docs that you know you need to touch.
|
||
if (get(agg, 'params.customBucket.type', null) === 'date_histogram' && agg.params.customBucket.params) { | ||
delete agg.params.customBucket.params.time_zone; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: lodash omit
could save you from some conditionals here, e.g.
if (agg.type === 'date_histogram' || get(agg, 'params.customBucket.type') === 'date_histogram') {
agg.params = omit(agg.params, ['time_zone', 'customBucket.params.time_zone']);
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would you prefer that? I find it actually harder to read, then the more explicit version :-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think either is fine. Go with what you think is most obvious.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I marked it as a nit for a reason 😉 Totally up to your preference here, I only suggested it because omit
will automatically skip things that are undefined.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(And FWIW I had no issues groking the code as it is currently written)
// If we would store this changing the time zone in Kibana would not affect any already saved visualizations | ||
// anymore, which is not the desired behavior. So always returning undefined here, makes sure we're never | ||
// saving that parameter and just keep it "transient". | ||
return undefined; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense, glad you explained this to minimize "WTF moments" in the future.
💔 Build Failed |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
💚 Build Succeeded |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! Finally got the chance to test this (Chrome OSX)... I created a new vis with a date_histogram agg, saved it, manually updated the migrationVersion
to something older, restarted the Kibana server, and verified the migration ran and correctly removed the time_zone
param.
Co-Authored-By: timroes <[email protected]>
💚 Build Succeeded |
LGTM. Tested it on chrome OSX. No time_zone in date histogram in saved objects. |
* Don't save the current timezone in visualizations * Add additional test * Add test and switch migration number * Don't clone object according to review feedback * Better documentation * Update src/legacy/core_plugins/kibana/migrations.js Co-Authored-By: timroes <[email protected]>
* Don't save the current timezone in visualizations * Add additional test * Add test and switch migration number * Don't clone object according to review feedback * Better documentation * Update src/legacy/core_plugins/kibana/migrations.js Co-Authored-By: timroes <[email protected]>
* Don't save the current timezone in visualizations * Add additional test * Add test and switch migration number * Don't clone object according to review feedback * Better documentation * Update src/legacy/core_plugins/kibana/migrations.js Co-Authored-By: timroes <[email protected]>
* Don't save the current timezone in visualizations * Add additional test * Add test and switch migration number * Don't clone object according to review feedback * Better documentation * Update src/legacy/core_plugins/kibana/migrations.js Co-Authored-By: timroes <[email protected]>
) * Don't save the current timezone in visualizations (#34795) * Don't save the current timezone in visualizations * Add additional test * Add test and switch migration number * Don't clone object according to review feedback * Better documentation * Update src/legacy/core_plugins/kibana/migrations.js Co-Authored-By: timroes <[email protected]> * Fix migrationVersion in tests
) * Don't save the current timezone in visualizations (#34795) * Don't save the current timezone in visualizations * Add additional test * Add test and switch migration number * Don't clone object according to review feedback * Better documentation * Update src/legacy/core_plugins/kibana/migrations.js Co-Authored-By: timroes <[email protected]> * Fix migrationVersion in integration tests * Fix tests * Fix migrationVersion in tests * Fix more tests
Summary
Fixes #34784
Since the introduction of rollups we technically had the possibility to specify a
time_zone
for adate_histogram
in the AggConfig. This was needed so the rollup plugin can overwrite the timezone by the one from the rollup job. Unfortunately that means the time_zone was also serialized and saved in the saved object when saving the visualization, meaning every visualization you created since 6.5 with a date histogram in it basically stored the time zone of the user creating it for the date_histogram.This means if a user in a different time zone or if you change your Kibana's time_zone, you'll still see that saved visualization in the time zone it was saved in. That's a very bad behavior since it basically breaks collaboration over multiple time zones and changing your Kibana's time zone.
This PR fixes that behavior by making sure the
time_zone
parameter won't be saved in the saved object anymore, but only lives transient "in memory".It also migrates all saved visualizations to remove the stored
time_zone
from it, since there is no legit state where you want to store it with the visualization.@LeeDr and/or @bhavyarm since this fix is going back to 6.7 and we're migrating all saved object I would appreciate if one of you could give this a QA test too, before merging.
Steps to reproduce
params.time_zone
in the date_histogram invisState.aggs
which shouldn't be there.If possible also test migrating of old documents. If you save an visualization before that fix, it will have that
params.time_zone
in it (and render in that time zone no matter what you configured in Kibana). If you apply that fix, your saved object should be fixed and thetime_zone
should be removed from alldate_histogram
aggregations.Checklist
Use
strikethroughsto remove checklist items you don't feel are applicable to this PR.[ ] This was checked for cross-browser compatibility, including a check against IE11[ ] Any text added follows EUI's writing guidelines, uses sentence case text and includes i18n support[ ] Documentation was added for features that require explanation or tutorials[ ] This was checked for keyboard-only and screenreader accessibilityFor maintainers
[ ] This was checked for breaking API changes and was labeled appropriately