-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
[ML] Data Frame Analytics: support custom urls in jobs #154287
[ML] Data Frame Analytics: support custom urls in jobs #154287
Conversation
Pinging @elastic/ml-ui (:ml) |
x-pack/plugins/ml/public/application/components/custom_urls/custom_url_editor/utils.ts
Outdated
Show resolved
Hide resolved
x-pack/plugins/ml/public/application/components/custom_urls/custom_url_editor/utils.ts
Outdated
Show resolved
Hide resolved
...ics/pages/analytics_exploration/components/expandable_section/expandable_section_results.tsx
Outdated
Show resolved
Hide resolved
@@ -10,6 +10,7 @@ import { runtimeMappingsSchema } from './runtime_mappings_schema'; | |||
|
|||
export const dataAnalyticsJobConfigSchema = schema.object({ | |||
description: schema.maybe(schema.string()), | |||
_meta: schema.maybe(schema.any()), |
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.
_meta: schema.maybe(schema.any()), | |
_meta: schema.maybe(schema.object()), |
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 one I left as any
because schema.object
requires the properties to be defined and _meta
can take whatever properties we want to add. So this could be problematic as it's volatile and for _meta
properties that get added automatically on job creation, etc.
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.
Since this is passed on to the corresponding ES API endpoint, does this one have any documentation about the expected structure of the _meta
field we could align with?
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.
So in the [PR](https://github.com/elastic/elasticsearch/pull/94529)
adding it in it's described as
The _meta field stores an arbitrary key-value map. Keys are strings. Values are arbitrary objects (possibly also maps).
I don't believe schema let's you specify a key type without knowing what the key is. Happy to add it in if I'm wrong about that.
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.
The TS spec now defines it as an optional record like _meta: undefined | Record<string, any>;
(in other places _meta: undefined | Record<string, unknown>;
) but this one just as an optional any
, maybe it can be updated to also be like the Record
?
@walterra - yep, did some digging and there is an option with an 'unknown' - added in in 7ee455c
x-pack/plugins/ml/server/routes/schemas/data_analytics_schema.ts
Outdated
Show resolved
Hide resolved
x-pack/plugins/ml/server/routes/schemas/data_analytics_schema.ts
Outdated
Show resolved
Hide resolved
This has been updated and is ready for another look when you get a chance 🙏 cc @peteharverson, @darnautov, @walterra |
x-pack/plugins/ml/public/application/components/custom_urls/custom_urls.tsx
Show resolved
Hide resolved
@elasticmachine merge upstream |
x-pack/plugins/ml/public/application/components/custom_urls/custom_urls.tsx
Show resolved
Hide resolved
onChange={onQueryEntitiesChange} | ||
isClearable={true} | ||
data-test-subj="mlJobCustomUrlQueryEntitiesInput" | ||
entityOptions.length > 0 ? ( |
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.
Is there a need to switch to this ternary version? Should be fine to keep the &&
variant.
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 based on something @darnautov brought up before about unexpected things happening because of the nature of &&
and I thought we all agreed it was better to explicitly return null
. Not married to either - happy to stick with whatever we decide is best practice. Just want to be consistent.
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.
Removed in 3d93dc5
|
||
export function isAnomalyDetectionJob(arg: unknown): arg is Job { | ||
return ( | ||
isPopulatedObject(arg) && typeof arg.job_id === 'string' && arg.analysis_config !== undefined |
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: You could move part of the check to isPopulatedObject
here like this:
isPopulatedObject(arg, ['job_id', 'analysis_config']) && typeof arg.job_id === 'string'
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.
Updated in 7ee455c
|
||
export function isKibanaUrlConfigWithTimeRange(arg: unknown): arg is KibanaUrlConfigWithTimeRange { | ||
return ( | ||
isPopulatedObject(arg) && |
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: You could move part of the check to isPopulatedObject here like this:
isPopulatedObject(arg, ['url_name', 'url_value', 'time_range']) && typeof arg.time_range === 'string'
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.
Updated in 7ee455c
|
||
export function isDataFrameAnalyticsConfigs(arg: unknown): arg is DataFrameAnalyticsConfig { | ||
return ( | ||
isPopulatedObject(arg) && |
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: You could move part of the check to isPopulatedObject here like this:
isPopulatedObject(arg, ['dest', 'analysis', 'id']) && typeof arg.id === 'string'
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.
Updated in 7ee455c
@@ -61,33 +61,6 @@ exports[`CustomUrlList renders a list of custom URLs 1`] = ` | |||
/> | |||
</EuiFormRow> | |||
</EuiFlexItem> | |||
<EuiFlexItem |
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'd expect these snapshots not to change what do you think? Maybe it's worth updating the configs in the tests so they render the same.
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.
Yep - it wasn't recognizing the job as an anomaly detection job so was removing the time range selector. I just added in the properties so it would be recognized and updated the result 👍 in 7ee455c
@@ -10,6 +10,7 @@ import { runtimeMappingsSchema } from './runtime_mappings_schema'; | |||
|
|||
export const dataAnalyticsJobConfigSchema = schema.object({ | |||
description: schema.maybe(schema.string()), | |||
_meta: schema.maybe(schema.any()), |
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.
The TS spec now defines it as an optional record like _meta: undefined | Record<string, any>;
(in other places _meta: undefined | Record<string, unknown>;
) but this one just as an optional any
, maybe it can be updated to also be like the Record
?
@walterra - yep, did some digging and there is an option with an 'unknown' - added in in 7ee455c
@elasticmachine merge upstream |
Updated with all suggestions 🙏 cc @walterra, @peteharverson |
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.
Latest changes LGTM
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.
Tested latest changes and looks good.
Would it be possible to add some functional test coverage for this, as we have for anomaly detection jobs?
@@ -87,6 +87,7 @@ export interface State { | |||
maxNumThreads: undefined | number; | |||
maxOptimizationRoundsPerHyperparameter: undefined | number; | |||
maxTrees: undefined | number; | |||
_meta: undefined | Record<string, any>; |
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.
_meta: undefined | Record<string, any>; | |
_meta: undefined | Record<string, unknown>; |
@@ -56,16 +57,26 @@ export interface ClassificationAnalysis { | |||
} | |||
|
|||
export type AnalysisConfig = estypes.MlDataframeAnalysisContainer; | |||
interface DataFrameAnalyticsMeta { | |||
custom_urls: any[]; |
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.
we have a type for custom_urls
@@ -56,16 +57,26 @@ export interface ClassificationAnalysis { | |||
} | |||
|
|||
export type AnalysisConfig = estypes.MlDataframeAnalysisContainer; | |||
interface DataFrameAnalyticsMeta { | |||
custom_urls: any[]; | |||
[key: string]: any; |
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.
[key: string]: any; | |
[key: string]: unknown; |
defaultMessage="Interval" | ||
/> | ||
} | ||
className="url-time-range" |
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 css class doesn't exist anymore
className="url-time-range" |
@@ -179,22 +255,22 @@ async function buildDashboardUrlFromSettings(settings) { | |||
}); | |||
|
|||
// Temp workaround | |||
const state = location.state; | |||
const state: any = location?.state; |
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.
do we have a better type definition for the state
?
@@ -328,7 +401,7 @@ export async function getTestUrl(job, customUrl) { | |||
// attempt load the non-combined job and datafeed so they can be used in the datafeed preview | |||
const [{ jobs }, { datafeeds }] = await Promise.all([ | |||
ml.getJobs({ jobId: job.job_id }), | |||
ml.getDatafeeds({ datafeedId: job.datafeed_config.datafeed_id }), | |||
ml.getDatafeeds({ datafeedId: job.datafeed_config?.datafeed_id ?? '' }), |
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 sorry, ❓ shall we pass undefined
instead of empty string here?
@@ -54,12 +58,20 @@ export const EditActionFlyout: FC<Required<EditAction>> = ({ closeFlyout, item } | |||
); | |||
const [mmlValidationError, setMmlValidationError] = useState<string | undefined>(); | |||
const [maxNumThreads, setMaxNumThreads] = useState<number | undefined>(config.max_num_threads); | |||
const [activeTabId, setActiveTabId] = useState<string>('job-details'); | |||
const [customUrls, setCustomUrls] = useState<UrlConfig[]>([]); | |||
const [analyticsJob, setAnalyticsJob] = useState<any>(); |
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.
could you please set an appropriate type for the list of DFA jobs 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.
Makes sense to add functional tests once the other items for custom URLs for DFA jobs are in. I added it as an item to #152009.
LGTM.
💚 Build Succeeded
Metrics [docs]Module Count
Async chunks
Unknown metric groupsESLint disabled line counts
References to deprecated APIs
Total ESLint disabled count
History
To update your PR or re-run it, just comment with: |
Summary
Related meta issue: #150375
This PR:
customUrls.mp4
Checklist
Delete any items that are not applicable to this PR.