Skip to content
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] Do not match time series counter fields with aggs in wizards #153021

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 3 additions & 1 deletion x-pack/plugins/ml/common/util/fields_utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@ export function combineFieldsAndAggs(
default:
// all other aggs take numerical fields
numericalFields.forEach((f) => {
mix(f, a);
if (f.aggregatable) {
mix(f, a);
}
});
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import type * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
import type { IScopedClusterClient } from '@kbn/core/server';
import { ES_FIELD_TYPES } from '@kbn/field-types';
import type { DataViewsService } from '@kbn/data-views-plugin/common';
import type { Field, FieldId, NewJobCaps, RollupFields } from '../../../../common/types/fields';
import type { Field, NewJobCaps, RollupFields } from '../../../../common/types/fields';
import { combineFieldsAndAggs } from '../../../../common/util/fields_utils';
import { rollupServiceProvider } from './rollup';
import { aggregations, mlOnlyAggregations } from '../../../../common/constants/aggregation_types';
Expand Down Expand Up @@ -62,7 +62,7 @@ class FieldsService {
this._dataViewsService = dataViewsService;
}

private async loadFieldCaps(): Promise<any> {
private async loadFieldCaps() {
return await this._mlClusterClient.asCurrentUser.fieldCaps(
{
index: this._indexPattern,
Expand All @@ -77,7 +77,7 @@ class FieldsService {
const fieldCaps = await this.loadFieldCaps();
const fields: Field[] = [];
if (fieldCaps && fieldCaps.fields) {
Object.keys(fieldCaps.fields).forEach((k: FieldId) => {
Object.keys(fieldCaps.fields).forEach((k) => {
const fc = fieldCaps.fields[k];
const firstKey = Object.keys(fc)[0];
if (firstKey !== undefined) {
Expand All @@ -90,8 +90,8 @@ class FieldsService {
fields.push({
id: k,
name: k,
type: field.type,
aggregatable: field.aggregatable,
type: field.type as ES_FIELD_TYPES,
aggregatable: this.isFieldAggregatable(field),
aggs: [],
});
}
Expand All @@ -101,6 +101,13 @@ class FieldsService {
return fields.sort((a, b) => a.id.localeCompare(b.id));
}

// check to see whether the field is aggregatable
// If it is a counter field from a time series data stream, we cannot currently
// support any aggregations and so it cannot be used as a field_name in a detector.
private isFieldAggregatable(field: estypes.FieldCapsFieldCapability) {
return field.time_series_metric !== 'counter' ?? field.aggregatable;
}

// public function to load fields from _field_caps and create a list
// of aggregations and fields that can be used for an ML job
// if the index is a rollup, the fields and aggs will be filtered
Expand Down