-
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
Migrate es-archiver to typescript #56008
Conversation
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.
Some (a lot of) comments and context
export async function readConfigFile(log: ToolingLog, path: string, settingOverrides: any) { | ||
export async function readConfigFile(log: ToolingLog, path: string, settingOverrides: any = {}) { |
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.
Some calls where ignoring the last parameter. Added a default.
await deleteKibanaIndices({ client, stats }); | ||
await migrateKibanaIndex({ client, log, stats, kibanaPluginIds }); | ||
await deleteKibanaIndices({ client, stats, log }); | ||
await migrateKibanaIndex({ client, log, kibanaPluginIds }); |
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.
Fixed calls with incorrect (additional or missing) parameters
const progress = new Progress('load progress'); | ||
const progress = new Progress(); |
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.
Progress
actually only have a no-args constructor.
createCreateIndexStream({ client, stats, skipExisting, log, kibanaPluginIds }), | ||
createCreateIndexStream({ client, stats, skipExisting, log }), |
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.
Incorrect call parameters, kibanaPluginIds
is not used or declared in createCreateIndexStream
.
await createPromiseFromStreams([ | ||
createReadStream(childPath), | ||
createReadStream(childPath) as Readable, | ||
...createParseArchiveStreams({ gzip }), | ||
...createFormatArchiveStreams({ gzip }), | ||
createWriteStream(tempFile), | ||
]); | ||
] as [Readable, ...Writable[]]); |
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 are a lot of these in the PR, will only comment once). Typescript is not able to understand the [Readable, ...Writable[]]
signature due to the fact that most transformers are Duplex
( both Readable and Writable). I had to help him.
const getIndicesToDelete = async () => { | ||
const aliasInfo = await client.indices.getAlias({ name: index, ignore: [404] }); | ||
return aliasInfo.status === 404 ? index : Object.keys(aliasInfo); | ||
return aliasInfo.status === 404 ? [index] : Object.keys(aliasInfo); | ||
}; | ||
|
||
try { | ||
const indicesToDelete = await getIndicesToDelete(); | ||
await client.indices.delete({ index: indicesToDelete }); | ||
stats.deletedIndex(indicesToDelete); | ||
for (let i = 0; i < indicesToDelete.length; i++) { | ||
const indexToDelete = indicesToDelete[i]; | ||
stats.deletedIndex(indexToDelete); | ||
} |
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.
In case of aliases, we were calling stats.deletedIndex
with the list of indices, which resulted on incorrect behavior (the call expects a string). Fixed it with a loop.
import path from 'path'; | ||
import Path from 'path'; |
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.
TS error path is already defined in the upper scope
for a lot of (path:string) => something handlers. renaming to Path
was the easiest solution.
callback(null, record); | ||
callback(undefined, record); |
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.
signature expects undefined
instead of null
@@ -37,6 +37,8 @@ export interface IndexStats { | |||
}; | |||
} | |||
|
|||
export type Stats = ReturnType<typeof createStats>; |
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 is a very strange pattern using inline class definition to access the parent context in this file... Had to use ReturnType
to extract a proper TS type.
export function concatStreamProviders( | ||
sourceProviders: Readable[], | ||
sourceProviders: Array<() => Readable>, | ||
options: TransformOptions |
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.
Wrong signature definition (as the other changes in this file)
Pinging @elastic/kibana-operations (Team:Operations) |
Pinging @elastic/kibana-platform (Team:Platform) |
@elasticmachine merge upstream |
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.
for the intent of this PR to be a simple TS transition, it LGTM
ack: will review on Monday |
if (skipDocsFromIndices.has(record.value.index)) { | ||
return; | ||
} | ||
|
||
stream.push(record); | ||
} | ||
|
||
async function handleIndex(record) { | ||
async function handleIndex(record: any) { |
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.
optional: it seems we can define a type for record (probably not full)
interface Record {
index: string;
type: string;
settings: Record<string, any>;
// can be imported from SO?
mappings: Record<string, any>;
aliases: Record<string, any>;
}
💚 Build SucceededHistory
To update your PR or re-run it, just comment with: |
* migrate lib/archives and lib/docs * migrate lib/indices * migrate end of /lib * migrate /actions * migrate es_archiver * migrate cli * migrate tests * use proper log stub * add Record typing Co-authored-by: Elastic Machine <[email protected]>
* Migrate es-archiver to typescript (#56008) * migrate lib/archives and lib/docs * migrate lib/indices * migrate end of /lib * migrate /actions * migrate es_archiver * migrate cli * migrate tests * use proper log stub * add Record typing Co-authored-by: Elastic Machine <[email protected]> * fix typings Co-authored-by: Elastic Machine <[email protected]>
Summary
Migrate
es-archiver
codebase to TS in prevision of potential changes because of #55860This is a direct / straightforward conversion. The goal was mostly to be able to have proper signatures in
src/es_archiver/actions
andsrc/es_archiver/lib