Skip to content

[ML] Adding file upload tools to package #221034

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

Open
wants to merge 15 commits into
base: main
Choose a base branch
from

Conversation

jgowdyelastic
Copy link
Member

@jgowdyelastic jgowdyelastic commented May 20, 2025

Moves the core file upload classes to a package called @kbn/file-upload
Moves a lot of shared and duplicated constants to the package @kbn/file-upload-common

Adds a new context called FileUploadContext and related hook useFileUploadContext to manage all aspects of the file upload process.
Updates the file upload lite flyout used by the Search solution to use this new context.

@jgowdyelastic jgowdyelastic requested review from a team as code owners May 20, 2025 16:45
@jgowdyelastic jgowdyelastic marked this pull request as draft May 21, 2025 07:18
@jgowdyelastic
Copy link
Member Author

/ci

@jgowdyelastic
Copy link
Member Author

/ci

@jgowdyelastic
Copy link
Member Author

/ci

@jgowdyelastic jgowdyelastic self-assigned this May 28, 2025
@jgowdyelastic jgowdyelastic marked this pull request as ready for review May 28, 2025 12:27
@jgowdyelastic jgowdyelastic added :ml release_note:skip Skip the PR/issue when compiling release notes Feature:File and Index Data Viz ML file and index data visualizer Feature:File Upload labels May 28, 2025
@jgowdyelastic jgowdyelastic added backport:version Backport to applied version labels v9.1.0 v8.19.0 labels May 28, 2025
@elasticmachine
Copy link
Contributor

Pinging @elastic/ml-ui (:ml)

Copy link
Contributor

@peteharverson peteharverson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested and LGTM. Didn't find any regressions either in the dedicated page, or in the flyout version used in Search.

Comment on lines +27 to +31
this.infer()
.then(() => {
this.inferFinished = true;
})
.catch((e) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: as it is an async function, shall we stick to the await syntax?

private settings;
private mappings: MappingTypeMapping | null = null;
private pipelines: Array<IngestPipeline | undefined> = [];
public readonly settings$ = new BehaviorSubject<Config<IndicesIndexSettings>>({
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
public readonly settings$ = new BehaviorSubject<Config<IndicesIndexSettings>>({
private readonly settings$ = new BehaviorSubject<Config<IndicesIndexSettings>>({

valid: false,
count: 0,
});
public readonly existingIndexName$ = new BehaviorSubject<string | null>(null);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
public readonly existingIndexName$ = new BehaviorSubject<string | null>(null);
private readonly existingIndexName$ = new BehaviorSubject<string | null>(null);

valid: false,
count: 0,
});
public readonly mappings$ = new BehaviorSubject<Config<MappingTypeMapping>>({
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
public readonly mappings$ = new BehaviorSubject<Config<MappingTypeMapping>>({
private readonly mappings$ = new BehaviorSubject<Config<MappingTypeMapping>>({

count: 0,
});
public readonly existingIndexName$ = new BehaviorSubject<string | null>(null);

private inferenceId: string | null = null;
private importer: IImporter | null = null;
private timeFieldName: string | undefined | null = null;
private commonFileFormat: string | null = null;

public readonly uploadStatus$ = new BehaviorSubject<UploadStatus>({
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
public readonly uploadStatus$ = new BehaviorSubject<UploadStatus>({
private readonly uploadStatus$ = new BehaviorSubject<UploadStatus>({

}

http.get<Index[]>('/api/index_management/indices').then((indx) => {
setIndices(indx.filter((i) => i.hidden === false && i.isFrozen === false));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. I believe we should only fetch once on mount. We should not re-fetch all indices on fileUploaderManger reference change.
  2. We need to check the component is still mounted before setting the state


useEffect(() => {
dataViews.getTitles().then((titles) => {
setExistingDataViewNames(titles);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

need to check if it's mounted

Comment on lines +104 to +105
uploadStatus.overallImportStatus === STATUS.COMPLETED ||
uploadStatus.overallImportStatus === STATUS.FAILED;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I find it confusing that completed and failed considered as in progress. Is it correct?

Comment on lines +111 to +115
fileUploadManager.import(index, dv).then((res) => {
if (onUploadComplete && res) {
onUploadComplete(res);
}
setImportResults(res);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • can by async...await
  • is it missing error handling?
  • need to check the component is till mounted

async function updateMappings(index: string, mappings: MappingTypeMapping) {
const resp = await asCurrentUser.indices.getMapping({ index });
const existingMappings = resp[index]?.mappings;
if (JSON.stringify(existingMappings.properties) !== JSON.stringify(mappings.properties)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Key order matters with JSON.stringify, so I assume a deep equality check is safer

@elasticmachine
Copy link
Contributor

💛 Build succeeded, but was flaky

Failed CI Steps

Metrics [docs]

Module Count

Fewer modules leads to a faster build time

id before after diff
dataVisualizer 757 761 +4

Public APIs missing comments

Total count of every public API that lacks a comment. Target amount is 0. Run node scripts/build_api_docs --plugin [yourplugin] --stats comments for more detailed information.

id before after diff
@kbn/file-upload - 74 +74
@kbn/file-upload-common 16 28 +12
total +86

Async chunks

Total size of all lazy-loaded chunks that will be downloaded as the user navigates the app

id before after diff
dataVisualizer 670.8KB 680.8KB +10.0KB
enterpriseSearch 1.2MB 1.2MB +16.0B
fileUpload 644.6KB 644.6KB -1.0B
searchPlayground 207.4KB 207.4KB +15.0B
total +10.1KB

Public APIs missing exports

Total count of every type that is part of your API that should be exported but is not. This will cause broken links in the API documentation system. Target amount is 0. Run node scripts/build_api_docs --plugin [yourplugin] --stats exports for more detailed information.

id before after diff
@kbn/file-upload - 3 +3
fileUpload 8 9 +1
total +4

Page load bundle

Size of the bundles that are downloaded on every page load. Target size is below 100kb

id before after diff
dataVisualizer 26.7KB 26.4KB -326.0B
enterpriseSearch 39.3KB 39.3KB +1.0B
fileUpload 15.0KB 15.0KB -20.0B
total -345.0B
Unknown metric groups

API count

id before after diff
@kbn/file-upload - 74 +74
@kbn/file-upload-common 16 28 +12
total +86

async chunk count

id before after diff
dataVisualizer 20 19 -1

History

cc @jgowdyelastic

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport:version Backport to applied version labels Feature:File and Index Data Viz ML file and index data visualizer Feature:File Upload :ml release_note:skip Skip the PR/issue when compiling release notes v8.19.0 v9.1.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants