-
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
[SoMigV2] Fail fast if unknown document types are present in the source index #103341
Changes from 11 commits
927f8ec
cb5559c
fb89a59
fbb7959
d41fec4
19bcb03
c367717
270f9b4
81de68a
f566e17
1fdbf28
26c36e9
b9375f9
8011281
2095a60
774d58a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
import * as Either from 'fp-ts/lib/Either'; | ||
import * as TaskEither from 'fp-ts/lib/TaskEither'; | ||
import { estypes } from '@elastic/elasticsearch'; | ||
import type { SavedObjectsRawDocSource } from '../../serialization'; | ||
import { ElasticsearchClient } from '../../../elasticsearch'; | ||
import { | ||
catchRetryableEsClientErrors, | ||
RetryableEsClientError, | ||
} from './catch_retryable_es_client_errors'; | ||
|
||
/** @internal */ | ||
export interface CheckForUnknownDocsParams { | ||
client: ElasticsearchClient; | ||
indexName: string; | ||
unusedTypesQuery: estypes.QueryDslQueryContainer; | ||
knownTypes: string[]; | ||
} | ||
|
||
/** @internal */ | ||
export interface CheckForUnknownDocsResponseDoc { | ||
id: string; | ||
type: string; | ||
} | ||
|
||
/** @internal */ | ||
export interface CheckForUnknownDocsResponse { | ||
unknownDocs: CheckForUnknownDocsResponseDoc[]; | ||
} | ||
|
||
export const checkForUnknownDocs = ({ | ||
client, | ||
indexName, | ||
unusedTypesQuery, | ||
knownTypes, | ||
}: CheckForUnknownDocsParams): TaskEither.TaskEither< | ||
RetryableEsClientError, | ||
CheckForUnknownDocsResponse | ||
> => () => { | ||
const query = createUnknownDocQuery(unusedTypesQuery, knownTypes); | ||
|
||
return client | ||
.search<SavedObjectsRawDocSource>({ | ||
index: indexName, | ||
body: { | ||
query, | ||
}, | ||
}) | ||
.then((response) => { | ||
const { hits } = response.body.hits; | ||
return Either.right({ | ||
unknownDocs: hits.map((hit) => ({ id: hit._id, type: hit._source?.type ?? 'undefined' })), | ||
}); | ||
}) | ||
.catch(catchRetryableEsClientErrors); | ||
}; | ||
|
||
const createUnknownDocQuery = ( | ||
unusedTypesQuery: estypes.QueryDslQueryContainer, | ||
knownTypes: string[] | ||
): estypes.QueryDslQueryContainer => { | ||
return { | ||
bool: { | ||
must: unusedTypesQuery, | ||
must_not: knownTypes.map((type) => ({ | ||
term: { | ||
type, | ||
}, | ||
})), | ||
}, | ||
}; | ||
Comment on lines
+75
to
+84
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I included the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does it mean that users must remove them to continue the migration? If so, it might be considered as a breaking change even though we just fixed a bug. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, I mean the opposite actually: I'm excluding the objects matching the unusedTypesQuery, to avoid failing if any is encountered given than we don't migrate them anyway. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ok, There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yea, the whole |
||
}; |
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.
Should this file get an explicit unit test?