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

Migrate es-archiver to typescript #56008

Merged
merged 12 commits into from
Feb 3, 2020

Conversation

pgayvallet
Copy link
Contributor

@pgayvallet pgayvallet commented Jan 27, 2020

Summary

Migrate es-archiver codebase to TS in prevision of potential changes because of #55860

This is a direct / straightforward conversion. The goal was mostly to be able to have proper signatures in src/es_archiver/actions and src/es_archiver/lib

@pgayvallet pgayvallet added v7.7.0 release_note:skip Skip the PR/issue when compiling release notes labels Jan 27, 2020
Copy link
Contributor Author

@pgayvallet pgayvallet left a 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 = {}) {
Copy link
Contributor Author

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.

Comment on lines -25 to +38
await deleteKibanaIndices({ client, stats });
await migrateKibanaIndex({ client, log, stats, kibanaPluginIds });
await deleteKibanaIndices({ client, stats, log });
await migrateKibanaIndex({ client, log, kibanaPluginIds });
Copy link
Contributor Author

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

Comment on lines -67 to +84
const progress = new Progress('load progress');
const progress = new Progress();
Copy link
Contributor Author

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.

Comment on lines -72 to +89
createCreateIndexStream({ client, stats, skipExisting, log, kibanaPluginIds }),
createCreateIndexStream({ client, stats, skipExisting, log }),
Copy link
Contributor Author

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.

Comment on lines 67 to +72
await createPromiseFromStreams([
createReadStream(childPath),
createReadStream(childPath) as Readable,
...createParseArchiveStreams({ gzip }),
...createFormatArchiveStreams({ gzip }),
createWriteStream(tempFile),
]);
] as [Readable, ...Writable[]]);
Copy link
Contributor Author

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.

Comment on lines 37 to +48
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);
}
Copy link
Contributor Author

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';
Copy link
Contributor Author

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);
Copy link
Contributor Author

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>;
Copy link
Contributor Author

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.

Comment on lines 22 to 24
export function concatStreamProviders(
sourceProviders: Readable[],
sourceProviders: Array<() => Readable>,
options: TransformOptions
Copy link
Contributor Author

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)

@pgayvallet pgayvallet self-assigned this Jan 27, 2020
@pgayvallet pgayvallet added the Team:Operations Team label for Operations Team label Jan 27, 2020
@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-operations (Team:Operations)

@pgayvallet pgayvallet added the Team:Core Core services & architecture: plugins, logging, config, saved objects, http, ES client, i18n, etc label Jan 27, 2020
@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-platform (Team:Platform)

@pgayvallet pgayvallet marked this pull request as ready for review January 27, 2020 16:20
@pgayvallet pgayvallet requested a review from a team as a code owner January 27, 2020 16:20
@pgayvallet pgayvallet requested a review from a team January 27, 2020 16:23
@mistic
Copy link
Member

mistic commented Jan 29, 2020

@elasticmachine merge upstream

Copy link
Member

@mistic mistic left a 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

@mshustov
Copy link
Contributor

ack: will review on Monday

if (skipDocsFromIndices.has(record.value.index)) {
return;
}

stream.push(record);
}

async function handleIndex(record) {
async function handleIndex(record: any) {
Copy link
Contributor

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>;
}

@kibanamachine
Copy link
Contributor

💚 Build Succeeded

History

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

@pgayvallet pgayvallet merged commit 38dc1cb into elastic:master Feb 3, 2020
pgayvallet added a commit to pgayvallet/kibana that referenced this pull request Feb 3, 2020
* 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]>
pgayvallet added a commit that referenced this pull request Feb 3, 2020
* 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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release_note:skip Skip the PR/issue when compiling release notes Team:Core Core services & architecture: plugins, logging, config, saved objects, http, ES client, i18n, etc Team:Operations Team label for Operations Team v7.7.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants