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 24 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
b6a0594
[ML] Adding file upload tools to package
jgowdyelastic May 20, 2025
ec04ec6
[CI] Auto-commit changed files from 'node scripts/notice'
kibanamachine May 20, 2025
ae3567a
adding server side changes
jgowdyelastic May 21, 2025
846c0a8
fixing lite flyout
jgowdyelastic May 21, 2025
5fe99db
plugin refactor
jgowdyelastic May 21, 2025
7bf51bf
[CI] Auto-commit changed files from 'node scripts/generate codeowners'
kibanamachine May 21, 2025
5b233c2
[CI] Auto-commit changed files from 'node scripts/yarn_deduplicate'
kibanamachine May 22, 2025
4f25fb1
Merge branch 'main' into file-upload-tools
jgowdyelastic May 22, 2025
1dcc1d8
[CI] Auto-commit changed files from 'node scripts/lint_packages --fix'
kibanamachine May 22, 2025
a18777f
Merge branch 'main' into file-upload-tools
jgowdyelastic May 22, 2025
f8313e6
fixing js
jgowdyelastic May 22, 2025
ac3ab26
Merge branch 'main' into file-upload-tools
jgowdyelastic May 26, 2025
75e5905
Merge branch 'main' into file-upload-tools
jgowdyelastic May 27, 2025
7bdf8e7
removing commented code
jgowdyelastic May 27, 2025
6f2a46a
Merge branch 'main' into file-upload-tools
jgowdyelastic May 29, 2025
caa9006
Merge branch 'file-upload-tools' of github.com:jgowdyelastic/kibana i…
jgowdyelastic May 29, 2025
240229c
Merge branch 'main' into file-upload-tools
jgowdyelastic May 30, 2025
31f70e8
Merge branch 'main' into file-upload-tools
jgowdyelastic Jun 2, 2025
27397be
Merge branch 'file-upload-tools' of github.com:jgowdyelastic/kibana i…
jgowdyelastic Jun 2, 2025
66ec860
Merge branch 'main' into file-upload-tools
jgowdyelastic Jun 3, 2025
16d6633
[CI] Auto-commit changed files from 'node scripts/capture_oas_snapsho…
kibanamachine Jun 3, 2025
a009a48
[CI] Auto-commit changed files from 'make api-docs'
kibanamachine Jun 3, 2025
d3af9a0
Merge branch 'file-upload-tools' of github.com:jgowdyelastic/kibana i…
jgowdyelastic Jun 3, 2025
bbabf59
changes based on review
jgowdyelastic Jun 4, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -820,6 +820,7 @@ x-pack/platform/packages/shared/ai-infra/inference-common @elastic/appex-ai-infr
x-pack/platform/packages/shared/ai-infra/inference-langchain @elastic/appex-ai-infra
x-pack/platform/packages/shared/ai-infra/product-doc-common @elastic/appex-ai-infra
x-pack/platform/packages/shared/alerting-rule-utils @elastic/obs-ux-management-team
x-pack/platform/packages/shared/file-upload @elastic/ml-ui
x-pack/platform/packages/shared/file-upload-common @elastic/ml-ui
x-pack/platform/packages/shared/index-lifecycle-management/index_lifecycle_management_common_shared @elastic/kibana-management
x-pack/platform/packages/shared/index-management/index_management_shared_types @elastic/kibana-management
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -548,6 +548,7 @@
"@kbn/field-types": "link:src/platform/packages/shared/kbn-field-types",
"@kbn/field-utils": "link:src/platform/packages/shared/kbn-field-utils",
"@kbn/fields-metadata-plugin": "link:x-pack/platform/plugins/shared/fields_metadata",
"@kbn/file-upload": "link:x-pack/platform/packages/shared/file-upload",
"@kbn/file-upload-common": "link:x-pack/platform/packages/shared/file-upload-common",
"@kbn/file-upload-plugin": "link:x-pack/platform/plugins/private/file_upload",
"@kbn/files-example-plugin": "link:examples/files_example",
Expand Down
2 changes: 2 additions & 0 deletions tsconfig.base.json
Original file line number Diff line number Diff line change
Expand Up @@ -970,6 +970,8 @@
"@kbn/field-utils/*": ["src/platform/packages/shared/kbn-field-utils/*"],
"@kbn/fields-metadata-plugin": ["x-pack/platform/plugins/shared/fields_metadata"],
"@kbn/fields-metadata-plugin/*": ["x-pack/platform/plugins/shared/fields_metadata/*"],
"@kbn/file-upload": ["x-pack/platform/packages/shared/file-upload"],
"@kbn/file-upload/*": ["x-pack/platform/packages/shared/file-upload/*"],
"@kbn/file-upload-common": ["x-pack/platform/packages/shared/file-upload-common"],
"@kbn/file-upload-common/*": ["x-pack/platform/packages/shared/file-upload-common/*"],
"@kbn/file-upload-plugin": ["x-pack/platform/plugins/private/file_upload"],
Expand Down
11 changes: 10 additions & 1 deletion x-pack/platform/packages/shared/file-upload-common/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,13 @@
*/

export type { FileUploadResults, OpenFileUploadLiteContext } from './src/types';
export { OPEN_FILE_UPLOAD_LITE_ACTION, OPEN_FILE_UPLOAD_LITE_TRIGGER } from './src/constants';
export {
OPEN_FILE_UPLOAD_LITE_ACTION,
OPEN_FILE_UPLOAD_LITE_TRIGGER,
FILE_FORMATS,
FILE_SIZE_DISPLAY_FORMAT,
MB,
NO_TIME_FORMAT,
TIKA_PREVIEW_CHARS,
INDEX_META_DATA_CREATED_BY,
} from './src/constants';
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,23 @@
export const OPEN_FILE_UPLOAD_LITE_ACTION = 'openFileUploadLiteTrigger';

export const OPEN_FILE_UPLOAD_LITE_TRIGGER = 'OPEN_FILE_UPLOAD_LITE_TRIGGER';

export const FILE_FORMATS = {
DELIMITED: 'delimited',
NDJSON: 'ndjson',
SEMI_STRUCTURED_TEXT: 'semi_structured_text',
TIKA: 'tika',
};

export const UI_SETTING_MAX_FILE_SIZE = 'fileUpload:maxFileSize';
export const MAX_FILE_SIZE = '100MB';
export const MAX_FILE_SIZE_BYTES = 524288000; // 500MB
export const ABSOLUTE_MAX_FILE_SIZE_BYTES = 1073741274; // 1GB
export const FILE_SIZE_DISPLAY_FORMAT = '0,0.[0] b';
export const MAX_TIKA_FILE_SIZE_BYTES = 62914560; // 60MB

export const NO_TIME_FORMAT = 'null';
export const MB = Math.pow(2, 20);

export const TIKA_PREVIEW_CHARS = 100000;
export const INDEX_META_DATA_CREATED_BY = 'file-data-visualizer';
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,15 @@ export interface FileUploadResults {
dataView?: { id: string; title: string };
inferenceId?: string;
files: Array<{ fileName: string; docCount: number; fileFormat: string; documentType: string }>;
timeFieldName?: string;
}

export interface OpenFileUploadLiteContext {
onUploadComplete?: (results: FileUploadResults | null) => void;
indexSettings?: IndicesIndexSettings;
autoAddInference?: string;
autoCreateDataView?: boolean;
existingIndex?: string;
initialIndexName?: string;
flyoutContent?: FlyoutContent;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@
"exclude": [
"target/**/*"
],
"kbn_references": []
"kbn_references": [
]
}
3 changes: 3 additions & 0 deletions x-pack/platform/packages/shared/file-upload/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# @kbn/file-upload

Functions from performing file upload
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
/*
* 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; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import type {
InferenceInferenceEndpointInfo,
InferenceInferenceResponse,
} from '@elastic/elasticsearch/lib/api/types';
import type { HttpSetup } from '@kbn/core/public';

const POLL_INTERVAL = 5; // seconds

export class AutoDeploy {
private inferError: Error | null = null;
private inferFinished: boolean = false;
constructor(private readonly http: HttpSetup, private readonly inferenceId: string) {}

public async deploy() {
this.inferError = null;
if (await this.isDeployed()) {
return;
}

this.infer()
.then(() => {
this.inferFinished = true;
})
.catch((e) => {
Comment on lines +27 to +31
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?

Copy link
Member Author

Choose a reason for hiding this comment

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

This was old code that has been moved.
It was written using then/catch as we don't want to wait for the response from infer we just call it and then poll to see when the model is deployed.

// ignore timeout errors
// The deployment may take a long time
// we'll know when it's ready from polling the inference endpoints
// looking for num_allocations
const status = e.response?.status;
if (status === 408 || status === 504 || status === 502 || status === 500) {
return;
}
this.inferError = e;
});
await this.pollIsDeployed();
}

private async infer() {
return this.http.fetch<InferenceInferenceResponse>(
`/internal/data_visualizer/inference/${this.inferenceId}`,
{
method: 'POST',
version: '1',
body: JSON.stringify({ input: '' }),
}
);
}

private async isDeployed() {
const inferenceEndpoints = await this.http.fetch<InferenceInferenceEndpointInfo[]>(
'/internal/data_visualizer/inference_endpoints',
{
method: 'GET',
version: '1',
}
);

// if the call to inference has already finished, we know the model is deployed
if (this.inferFinished) {
return true;
}

// otherwise, we need to check the allocation count
return inferenceEndpoints.some((endpoint) => {
return (
endpoint.inference_id === this.inferenceId && endpoint.service_settings.num_allocations > 0
);
});
}

private async pollIsDeployed() {
while (true) {
if (this.inferError !== null) {
throw this.inferError;
}
const isDeployed = await this.isDeployed();
if (isDeployed) {
// break out of the loop once we have a successful deployment
return;
}
await new Promise((resolve) => setTimeout(resolve, POLL_INTERVAL * 1000));
}
}
}
Loading