-
Notifications
You must be signed in to change notification settings - Fork 8.4k
[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
jgowdyelastic
wants to merge
24
commits into
elastic:main
Choose a base branch
from
jgowdyelastic:file-upload-tools
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+1,792
−809
Open
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 ec04ec6
[CI] Auto-commit changed files from 'node scripts/notice'
kibanamachine ae3567a
adding server side changes
jgowdyelastic 846c0a8
fixing lite flyout
jgowdyelastic 5fe99db
plugin refactor
jgowdyelastic 7bf51bf
[CI] Auto-commit changed files from 'node scripts/generate codeowners'
kibanamachine 5b233c2
[CI] Auto-commit changed files from 'node scripts/yarn_deduplicate'
kibanamachine 4f25fb1
Merge branch 'main' into file-upload-tools
jgowdyelastic 1dcc1d8
[CI] Auto-commit changed files from 'node scripts/lint_packages --fix'
kibanamachine a18777f
Merge branch 'main' into file-upload-tools
jgowdyelastic f8313e6
fixing js
jgowdyelastic ac3ab26
Merge branch 'main' into file-upload-tools
jgowdyelastic 75e5905
Merge branch 'main' into file-upload-tools
jgowdyelastic 7bdf8e7
removing commented code
jgowdyelastic 6f2a46a
Merge branch 'main' into file-upload-tools
jgowdyelastic caa9006
Merge branch 'file-upload-tools' of github.com:jgowdyelastic/kibana i…
jgowdyelastic 240229c
Merge branch 'main' into file-upload-tools
jgowdyelastic 31f70e8
Merge branch 'main' into file-upload-tools
jgowdyelastic 27397be
Merge branch 'file-upload-tools' of github.com:jgowdyelastic/kibana i…
jgowdyelastic 66ec860
Merge branch 'main' into file-upload-tools
jgowdyelastic 16d6633
[CI] Auto-commit changed files from 'node scripts/capture_oas_snapsho…
kibanamachine a009a48
[CI] Auto-commit changed files from 'make api-docs'
kibanamachine d3af9a0
Merge branch 'file-upload-tools' of github.com:jgowdyelastic/kibana i…
jgowdyelastic bbabf59
changes based on review
jgowdyelastic File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,5 +13,6 @@ | |
"exclude": [ | ||
"target/**/*" | ||
], | ||
"kbn_references": [] | ||
"kbn_references": [ | ||
] | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# @kbn/file-upload | ||
|
||
Functions from performing file upload |
91 changes: 91 additions & 0 deletions
91
x-pack/platform/packages/shared/file-upload/file_upload_manager/auto_deploy.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) => { | ||
// 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)); | ||
} | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
nit: as it is an async function, shall we stick to the
await
syntax?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.
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.