-
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
[APM] Fixes duplicate ML job creation for existing environments (#85023) #93098
[APM] Fixes duplicate ML job creation for existing environments (#85023) #93098
Conversation
Pinging @elastic/apm-ui (Team:apm) |
// skip creation of duplicate ML jobs | ||
const jobs = await getAnomalyDetectionJobs(setup, logger); | ||
const existingMlJobEnvs = jobs.map(({ environment }) => environment); | ||
const requestedExistingMlJobEnvs = environments.filter((env) => |
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 wish partition
was a native array method. You can get it from lodash but this is fine.
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 didn't know about _.partition
. It's neat but I had to go to the lodash docs to understand it.
The current code I can read with no manual. So while slightly longer it comes with a lower overhead (for me at least)
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.
Btw. I agree partition
would be better if it was native
@@ -38,14 +39,32 @@ export async function createAnomalyDetectionJobs( | |||
throw Boom.forbidden(ML_ERRORS.ML_NOT_AVAILABLE_IN_SPACE); | |||
} | |||
|
|||
// skip creation of duplicate ML jobs |
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: What about extracting this out?
async function getUniqueMlJobEnvs(
setup: Setup,
environments: string[],
logger: Logger
) {
// skip creation of duplicate ML jobs
const jobs = await getAnomalyDetectionJobs(setup, logger);
const existingMlJobEnvs = jobs.map(({ environment }) => environment);
const requestedExistingMlJobEnvs = environments.filter((env) =>
existingMlJobEnvs.includes(env)
);
if (requestedExistingMlJobEnvs.length) {
logger.warn(
`Skipping creation of existing ML jobs for environments: [${requestedExistingMlJobEnvs}]}`
);
}
return environments.filter((env) => !existingMlJobEnvs.includes(env));
}
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.
Good job! Let's hope this fixes it for good 🤞
💚 Build SucceededMetrics [docs]Async chunks
Page load bundle
History
To update your PR or re-run it, just comment with: |
…tic#85023) (elastic#93098) * [APM] Fixes duplicate ML job creation for existing environments (elastic#85023) * Removes commented out test code. * Adds API integration tests * clean up code for readability
…tic#85023) (elastic#93098) * [APM] Fixes duplicate ML job creation for existing environments (elastic#85023) * Removes commented out test code. * Adds API integration tests * clean up code for readability
Closes #85023.
Checks for existing ML jobs for the currently selected environments in the API before creating a duplicate jobs. This was only happening on the client-side previously.
Example: