Skip to content

Commit

Permalink
Fix policy upgrade from APM 0.3.0 to 0.4.0
Browse files Browse the repository at this point in the history
Add debug log + logic to skip over any package variables that have been
removed from the base policy object. Issue was initially surfaced
testing upgrade from APM integration v0.3.0 to v0.4.0.

Ref elastic#109907
  • Loading branch information
kpollich committed Aug 30, 2021
1 parent f7db559 commit 72b35b1
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
25 changes: 21 additions & 4 deletions x-pack/plugins/fleet/common/services/validate_package_policy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export const validatePackagePolicy = (
const packageVars = Object.entries(packagePolicy.vars || {});
if (packageVars.length) {
validationResults.vars = packageVars.reduce((results, [name, varEntry]) => {
results[name] = validatePackagePolicyConfig(varEntry, packageVarsByName[name]);
results[name] = validatePackagePolicyConfig(varEntry, packageVarsByName[name], name);
return results;
}, {} as ValidationEntry);
}
Expand Down Expand Up @@ -138,7 +138,8 @@ export const validatePackagePolicy = (
results[name] = input.enabled
? validatePackagePolicyConfig(
configEntry,
inputVarDefsByPolicyTemplateAndType[inputKey][name]
inputVarDefsByPolicyTemplateAndType[inputKey][name],
name
)
: null;
return results;
Expand All @@ -161,7 +162,7 @@ export const validatePackagePolicy = (
(results, [name, configEntry]) => {
results[name] =
streamVarDefs && streamVarDefs[name] && input.enabled && stream.enabled
? validatePackagePolicyConfig(configEntry, streamVarDefs[name])
? validatePackagePolicyConfig(configEntry, streamVarDefs[name], name)
: null;
return results;
},
Expand All @@ -183,12 +184,14 @@ export const validatePackagePolicy = (
if (Object.entries(validationResults.inputs!).length === 0) {
validationResults.inputs = null;
}

return validationResults;
};

export const validatePackagePolicyConfig = (
configEntry: PackagePolicyConfigRecordEntry,
varDef: RegistryVarsEntry
varDef: RegistryVarsEntry,
varName: string
): string[] | null => {
const errors = [];
const { value } = configEntry;
Expand All @@ -198,6 +201,20 @@ export const validatePackagePolicyConfig = (
parsedValue = value.trim();
}

if (varDef === undefined) {
// eslint-disable-next-line no-console
console.debug(
i18n.translate('xpack.fleet.packagePolicyValidation.noVarDefErrorMessage', {
defaultMessage: 'No variable definition for {name} found ',
values: {
name: varName,
},
})
);

return null;
}

if (varDef.required) {
if (parsedValue === undefined || (typeof parsedValue === 'string' && !parsedValue)) {
errors.push(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -658,7 +658,7 @@ const UpgradeStatusCallout: React.FunctionComponent<{
</EuiPortal>
)}

{isReadyForUpgrade ? (
{isReadyForUpgrade && currentPackagePolicy ? (
<EuiCallOut
title={i18n.translate('xpack.fleet.upgradePackagePolicy.statusCallOut.successTitle', {
defaultMessage: 'Ready to upgrade',
Expand Down

0 comments on commit 72b35b1

Please sign in to comment.