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

UI-9566 - Ensure a best effort migration of the KPI titles even when some titles could not be successfully migrated. #129

Merged
merged 23 commits into from
Sep 25, 2024

Conversation

NZepeda
Copy link
Contributor

@NZepeda NZepeda commented Jul 29, 2024

Summary

Issue

As the ticket states, when migrating KPIs containing custom titles, if the migration of one of the titles throws an error, none of the custom titles are migrated.

On this specific ticket, the issue was that when the KPI contained a title with an empty tupleKey as seen below, the process would error out resulting in none of the titles (even the valid ones) being migrated.

"": {
   title: "Title with empty tupleKey"
}

Solution

This PR aims to improve on that by ensuring that even if there is an error, the successfully migrated titles are persisted and the KPI widget is marked as Partially migrated.

Corresponding ticket: https://activeviam.atlassian.net/browse/UI-9566

Reviewing

Ensure the new and updated tests make sense

Comment on lines 34 to 36
"": {
title: "Empty measure title",
},
Copy link
Contributor Author

Choose a reason for hiding this comment

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

For this fix, I went with dropping titles that have an empty tuple key and ensuring the rest of the titles are still migrated. However, I'm not 100% sure how one can even land in this state. It doesn't seem like it's valid so I dropped it, but if it is better to ensure this kind of custom title is supported, I can adapt the change to ensure it's also migrated.

…hub.com:activeviam/atoti-ui-migration into task/nze/UI-9566-support-migrating-empty-titles
@NZepeda NZepeda assigned Nouzbe and NZepeda and unassigned Nouzbe Jul 30, 2024
…is an error while migrating one of the titles the succesfully migrated titles should still be persisted.
Comment on lines +46 to +63
if (memberUniqueName) {
const compoundIdentifier =
parse<MdxUnknownCompoundIdentifier>(memberUniqueName);
const specificCompoundIdentifier = getSpecificCompoundIdentifier(
compoundIdentifier,
{ cube },
);
tuple[hierarchyUniqueName] = specificCompoundIdentifier.path;
if (specificCompoundIdentifier.type === "measure") {
tuple[`[Measures].[Measures]`] = [
specificCompoundIdentifier.measureName,
];
} else if (specificCompoundIdentifier.type === "member") {
const hierarchyUniqueName = quote(
specificCompoundIdentifier.dimensionName,
specificCompoundIdentifier.hierarchyName,
);
tuple[hierarchyUniqueName] = specificCompoundIdentifier.path;
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Looks like a big change but all I did was wrap this logic block in an if statement.

Comment on lines +116 to +147
try {
const memberUniqueNames: string[] = [];

ordinalFields.forEach((field) => {
if (field.type === "hierarchy") {
const hierarchyUniqueName = quote(
field.dimensionName,
field.hierarchyName,
);
const namePath = tuple[hierarchyUniqueName];
if (namePath) {
memberUniqueNames.push(
`${hierarchyUniqueName}.${quote(...namePath)}`,
ordinalFields.forEach((field) => {
if (field.type === "hierarchy") {
const hierarchyUniqueName = quote(
field.dimensionName,
field.hierarchyName,
);
const namePath = tuple[hierarchyUniqueName];
if (namePath) {
memberUniqueNames.push(
`${hierarchyUniqueName}.${quote(...namePath)}`,
);
}
}
});

if (measuresPositionInTuple > -1) {
const measureName = tuple[quote("Measures", "Measures")][0];
memberUniqueNames.splice(
measuresPositionInTuple,
0,
quote("Measures", measureName),
);
}
});

if (measuresPositionInTuple > -1) {
const measureName = tuple[quote("Measures", "Measures")][0];
memberUniqueNames.splice(
measuresPositionInTuple,
0,
quote("Measures", measureName),
);
}

const tupleKey = memberUniqueNames.join(",");
migratedTitles[tupleKey] = title;
const tupleKey = memberUniqueNames.join(",");
migratedTitles[tupleKey] = title;
} catch (error) {
errors.push(error as Error);
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Again, looks like a big change but I just wrapped this logic block in a try-catch.

Comment on lines +150 to +155
if (errors.length > 0) {
throw new Error(
`One or more errors occurred while migrating the titles for the kpi named ${legacyKpiState.name}: ` +
errors.map((e) => e.message).join(", "),
);
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This function "swallows" any error until all legacyTitles have been attempted to be migrated. This throws at the end to ensure that the kpi widget that is being migrated is marked as partially migrated.

@NZepeda NZepeda changed the title UI-9566 - Ensure kpis with titles corresponding to empty measures have the titles migrated. UI-9566 - Ensure a best effort migration of the KPI titles even when some titles could not be successfully migrated. Jul 31, 2024
…hub.com:activeviam/atoti-ui-migration into task/nze/UI-9566-support-migrating-empty-titles
@NZepeda NZepeda assigned Nouzbe and unassigned NZepeda Jul 31, 2024
Copy link
Collaborator

@Nouzbe Nouzbe left a comment

Choose a reason for hiding this comment

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

Could you please merge #128 into main, rebase this branch and take the following comment into consideration before reassigning?

* The shortened version of the content of the /ui folder on a Content Server, useful for unit tests.
* Contains a KPI widget containing a custom title with an empty `tupleKey` for its location.
*/
export const smallLegacyUIFolderWithInvalidKpiTitle = {
Copy link
Collaborator

Choose a reason for hiding this comment

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

It would be nice to factorize the common part between this and the test resource introduced in #128, in order to avoid adding redundant content to this repo.

For instance, we could have a emptyLegacyUIFolder test resource and a addLegacyBookmarkToUIFolder test resource function that takes a map of id to legacy bookmark as argument and returns the "small legacy UI folder with ..." object, without mutating emptyLegacyFolder.

@Nouzbe Nouzbe assigned NZepeda and unassigned Nouzbe Sep 12, 2024
@NZepeda
Copy link
Contributor Author

NZepeda commented Sep 18, 2024

It would be great to use our new addLegacyBookmarkToUIFolder in order to generate our existing:

  • smallLegacyUIFolder
  • smallLegacyUIFolderWithInvalidDashboard
  • smallLegacyUIFolderWithInvalidFilter

It would still be nice to have them as their own test resources, but this way we would cut down some duplicate content and lower the entropy of this repo.

This is done via one of the latest commits 🫡

@NZepeda
Copy link
Contributor Author

NZepeda commented Sep 18, 2024

@Nouzbe Your latest suggestions have been addressed in the latest commits 👍

@NZepeda NZepeda assigned Nouzbe and unassigned NZepeda Sep 18, 2024
Copy link
Collaborator

@Nouzbe Nouzbe left a comment

Choose a reason for hiding this comment

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

The KPI titles change looks good. The test resources refactor looks good too. There's just a couple instances where we've lost some content in our snapshots (I assume because we've lost them in some test resources). See comments below.

Otherwise, good to go!

},
"settings": {
"entry": {
"content": "{"theme":"dark-activeviam","search.maxResults":10,"userFilters.areEnabled":true,"drillthrough.defaultSelectedColumns":{"EquityDerivativesCube":["delta","gamma","pnlVega","Desk","Currency","Date","HostName"],"EquityDerivativesCubeDist":["BumpedMtmDown","ProductQtyMultiplier","vega","rho","productId","pnlVega","pnlDelta","pnl","gamma","delta","TradeId","ProductBaseMtm"]}}",
Copy link
Collaborator

Choose a reason for hiding this comment

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

Oops, it looks like we're losing the settings conversion part of this test snapshot. It's probably because some settings that were part of a legacy UI folder test resource were lost in the process. Can you please make sure that we don't lose this?

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've added a new commit to avoid losing this information. However, it means re-adding the settings to the emptyLegacyUIFolder since we are now generating test resources such as smallLegacyUIFolder via the emptyLegacyUIFolder and addLegacyBookmarkToUIFolder.

@@ -2247,12 +2247,8 @@ exports[`migrate_43_to_50 returns a valid ActiveUI5 /ui folder on a small input
"content": "{"name":"hidden grand totals"}",
"isDirectory": true,
"lastEditor": "admin",
"owners": [
"admin",
Copy link
Collaborator

Choose a reason for hiding this comment

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

Here too, it would be nice to not lose this, in order to ensure that the migration script does not erase bookmark permissions.

});
if (migratedTitles && Object.keys(migratedTitles).length > 0) {
migratedWidgetState.titles = migratedTitles;
}
}
} catch (error) {
// Migrating the KPI titles is a best effort.
// If there is an error while migrating one of the titles, the successfully migrated titles are still persisted.
if (migratedTitles && Object.keys(migratedTitles).length > 0) {
migratedWidgetState.titles = migratedTitles;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Got it now, thank you 👍

@Nouzbe Nouzbe assigned NZepeda and unassigned Nouzbe Sep 25, 2024
@@ -2397,6 +2404,86 @@ exports[`migrate_43_to_50 returns a valid ActiveUI5 /ui folder on a small input
},
},
"users": {
"children": {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This change results from re-adding the settings to the emptyLegacyUIFolder. With the changes in this commit, this file remains unchanged in this PR.

@NZepeda NZepeda assigned Nouzbe and unassigned NZepeda Sep 25, 2024
@NZepeda
Copy link
Contributor Author

NZepeda commented Sep 25, 2024

@Nouzbe With the latest commit, I've ensured that we are not losing any data in the migrate_43_to_50 test snapshot. However, that meant re-adding the previously removed settings to the emptyLegacyUIFolder. This is required since test resources such as the smallLegacyUIFolder are being generated via the emptyLegacyUIFolder test resource and the addLegacyBookmarkToFolder function.

Copy link
Collaborator

@Nouzbe Nouzbe left a comment

Choose a reason for hiding this comment

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

A different approach could be to have a addLegacySettings function, which adds given settings to a legacy UI folder. This way, smallLegacyUIFolder could be generated from an actually empty emptyLegacyUIFolder using this function.

If you like this way better, I'll leave it up to you if you prefer to do it in this PR or separately.

This is good to go, thank you for bearing with me 👍

@Nouzbe Nouzbe assigned NZepeda and unassigned Nouzbe Sep 25, 2024
@NZepeda
Copy link
Contributor Author

NZepeda commented Sep 25, 2024

A different approach could be to have a addLegacySettings function, which adds given settings to a legacy UI folder. This way, smallLegacyUIFolder could be generated from an actually empty emptyLegacyUIFolder using this function.

If you like this way better, I'll leave it up to you if you prefer to do it in this PR or separately.

This is good to go, thank you for bearing with me 👍

I'll address this in a separate PR 👍

@NZepeda NZepeda merged commit 5c4f836 into main Sep 25, 2024
2 checks passed
@NZepeda NZepeda deleted the task/nze/UI-9566-support-migrating-empty-titles branch September 25, 2024 17:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants