-
Notifications
You must be signed in to change notification settings - Fork 8.2k
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
[Logs UI] Access ML via the programmatic plugin API #68905
[Logs UI] Access ML via the programmatic plugin API #68905
Conversation
eaedd20
to
a2db6fa
Compare
@@ -94,25 +94,6 @@ export default ({ getService }: FtrProviderContext) => { | |||
expect(logEntryRateBuckets.data.bucketDuration).to.be(15 * 60 * 1000); | |||
expect(logEntryRateBuckets.data.histogramBuckets).to.be.empty(); | |||
}); | |||
|
|||
it('should return a NotFound error when the results index does not exist', async () => { |
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 test case doesn't apply anymore, because we're not accessing the results via the alias name anymore. The access is handled internally by the programmatic ML api so we can't determine existence of the results index.
import { CoreSetup } from '../../../../../../src/core/server'; | ||
import { InfraServerPluginDeps } from '../adapters/framework/adapter_types'; | ||
|
||
export function compose(core: CoreSetup, config: InfraConfig, plugins: InfraServerPluginDeps) { |
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 hasn't been used for a while by now.
Pinging @elastic/logs-metrics-ui (Team:logs-metrics-ui) |
@elasticmachine merge upstream |
@@ -151,6 +149,25 @@ export class InfraServerPlugin { | |||
initInfraServer(this.libs); | |||
registerAlertTypes(plugins.alerts, this.libs); | |||
|
|||
core.http.registerRouteHandlerContext( |
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 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.
LGTM 👍
Thanks for taking the time to refactor so many things here; classes to plain functions, the added request context, route body validations etc 👌
|
||
export function assertHasInfraPlugins<Context extends { infra?: InfraRequestHandlerContext }>( | ||
context: Context | ||
): asserts context is Context & { infra: Context['infra'] } { |
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.
Thanks for introducing me to Assertion Signatures 😄
@@ -26,12 +32,10 @@ export const createTimeRangeFilters = (startTime: number, endTime: number) => [ | |||
}, | |||
]; | |||
|
|||
export const createResultTypeFilters = (resultType: 'model_plot' | 'record') => [ | |||
export const createResultTypeFilters = (resultTypes: Array<'model_plot' | '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.
Just curious: what's the difference/advantage here?
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.
I wanted to also use this helper in some places where we're filtering for more than one result type. Therefore the helper had to be extended to allow for that.
framework.registerRoute( | ||
{ | ||
method: 'post', | ||
path: LOG_ANALYSIS_GET_LOG_ENTRY_CATEGORIES_PATH, | ||
validate: { | ||
// short-circuit forced @kbn/config-schema validation so we can do io-ts validation | ||
body: anyObject, | ||
body: createValidationFunction(getLogEntryCategoriesRequestPayloadRT), |
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.
How do we call this function without having to provide the generic values it specifies (<DecodedValue, EncodedValue, InputValue>
)?
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.
I'm not sure I understand. The generic arguments are inferred from the codec passed as the function argument.
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.
Ah ok, I'll take this question out of this PR :)
}, | ||
}, | ||
async (requestContext, request, response) => { | ||
framework.router.handleLegacyErrors(async (requestContext, request, response) => { |
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.
What does this handleLegacyErrors function do and where is it documented? I assume it lets us use the Boom stuff inside our handler?
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.
I don't know of any documentation - I read the http
service source. Inside of our handlers we use some platform services, which throw Boom
exceptions. I found this helper improves the representation of these errors in the response. Without it we would have to capture and convert them ourselves to avoid masquerading them as generic code 500 errors.
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 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.
Thanks!
@elasticmachine merge upstream |
💚 Build SucceededBuild metricspage load asset sizebeta
History
To update your PR or re-run it, just comment with: |
* master: (45 commits) [QA] Unskip functional tests (elastic#69760) [SIEM][Detection Engine] - Update DE to work with new exceptions schema (elastic#69715) Fixes elastic#69639: Ignore url.url fields above 2048 characters (elastic#69863) PR: Provide limit warnings to user when API limits are reached. (elastic#69590) [Maps] Remove broken button (elastic#69853) Makes usage collection methods available on start (elastic#69836) [SIEM][CASE] Improve Jira's labelling (elastic#69892) [Logs UI] Access ML via the programmatic plugin API (elastic#68905) [ML] DF Analytics: Creation wizard part 3 (elastic#69456) Update Resolver generator script documentation (elastic#69912) [ML] Changes View results button text on new job page (elastic#69809) Add master branch to backport config (elastic#69893) [Ingest Manager] Kibana, not EPR, controls removable packages (elastic#69761) unskips 'Events columns' test (elastic#69684) [ML] Changes the ML overview empty analytics panel text (elastic#69801) [DOCS] Emphasizes where File Data Visualizer is located. (elastic#69812) add the `exactRoute` property to app registration (elastic#69772) Bump backport to 5.4.6 (elastic#69880) [Logs UI] ML log integration splash screen (elastic#69288) Clean up TSVB type client code to conform to the schema (elastic#68519) ...
* master: (90 commits) [Encrypted Saved Objects] Adds support for migrations in ESO (elastic#69513) [SIEM] Replace WithSource with useWithSource hook (elastic#68722) [Endpoint]EMT-451: add ability to filter endpoint metadata based on presence of unenrolled events (elastic#69708) rename old siem kibana config to securitySolution (elastic#69874) Remove unused Resolver code (elastic#69914) [Observability] Fixing dynamic return type based on the appName (elastic#69894) [SECURITY SOLUTION][INGEST] Task/endpoint list tests (elastic#69419) Fixes special clicks and 3rd party icon sizes in nav (elastic#69767) [APM] Catch annotations index permission error and log warning (elastic#69881) [Endpoint][Ingest Manager] minor code cleanup (elastic#69844) [Logs UI] Logs ui context menu (elastic#69915) Index pattern serialize and de-serialize (elastic#68844) [QA] Unskip functional tests (elastic#69760) [SIEM][Detection Engine] - Update DE to work with new exceptions schema (elastic#69715) Fixes elastic#69639: Ignore url.url fields above 2048 characters (elastic#69863) PR: Provide limit warnings to user when API limits are reached. (elastic#69590) [Maps] Remove broken button (elastic#69853) Makes usage collection methods available on start (elastic#69836) [SIEM][CASE] Improve Jira's labelling (elastic#69892) [Logs UI] Access ML via the programmatic plugin API (elastic#68905) ...
Summary
This modifies the routes related to log rate and category analysis to use the new programmatic APIs provided by the
ml
plugin to access the results index and job info. Because that access is facilitated via the request context, the log analysis lib was converted from classes to plain functions.At the same time the routes have been updated to use the most recent validation and error handling patterns.
closes #67861
Reviewing and testing
💡 The conversion of class methods to functions caused a large amount of indentation changes. Ignore white-space during code review to preserve sanity.
The behavior of everything related to the log rate and categories tabs should be unchanged from the user's perspective, so double-checking their functionality would be prudent.
Task breakdown
spaceId
available via the request context