Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into lens/reference-ui
Browse files Browse the repository at this point in the history
  • Loading branch information
wylieconlon committed Dec 21, 2020
2 parents 0850115 + f349d0a commit 7ac5dde
Show file tree
Hide file tree
Showing 16 changed files with 60 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export const stubIndexPattern: IIndexPattern = {
fields: stubFields,
title: 'logstash-*',
timeFieldName: '@timestamp',
getTimeField: () => ({ name: '@timestamp', type: 'date' }),
};

export const stubIndexPatternWithFields: IIndexPattern = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ export const getDateHistogramBucketAgg = ({
type: 'field',
filterFieldTypes: KBN_FIELD_TYPES.DATE,
default(agg: IBucketDateHistogramAggConfig) {
return agg.getIndexPattern().timeFieldName;
return agg.getIndexPattern().getTimeField?.()?.name;
},
onChange(agg: IBucketDateHistogramAggConfig) {
if (isAutoInterval(get(agg, 'params.interval')) && !agg.fieldIsTimeField()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ export function DimensionEditor(props: DimensionEditorProps) {
updateLayer={setStateWrapper}
columnId={columnId}
currentColumn={state.layers[layerId].columns[columnId]}
dateRange={props.dateRange}
dateRange={dateRange}
indexPattern={currentIndexPattern}
{...services}
/>
Expand Down
1 change: 1 addition & 0 deletions x-pack/plugins/ml/common/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ export { SearchResponse7 } from './types/es_client';
export { ANOMALY_SEVERITY, ANOMALY_THRESHOLD, SEVERITY_COLORS } from './constants/anomalies';
export { getSeverityColor, getSeverityType } from './util/anomaly_utils';
export { composeValidators, patternValidator } from './util/validators';
export { extractErrorMessage } from './util/errors';
14 changes: 3 additions & 11 deletions x-pack/plugins/ml/common/types/modules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*/
import { SavedObjectAttributes } from 'kibana/public';
import { Datafeed, Job } from './anomaly_detection_jobs';
import { ErrorType } from '../util/errors';

export interface ModuleJob {
id: string;
Expand Down Expand Up @@ -63,22 +64,13 @@ export interface KibanaObjectResponse extends ResultItem {
error?: any;
}

export interface SetupError {
body: string;
msg: string;
path: string;
query: {};
response: string;
statusCode: number;
}

export interface DatafeedResponse extends ResultItem {
started: boolean;
error?: SetupError;
error?: ErrorType;
}

export interface JobResponse extends ResultItem {
error?: SetupError;
error?: ErrorType;
}

export interface DataRecognizerConfigResponse {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,26 +160,6 @@ export class CategorizationJobCreator extends JobCreator {
return this._categorizationAnalyzer;
}

public cloneFromExistingJob(job: Job, datafeed: Datafeed) {
this._overrideConfigs(job, datafeed);
this.createdBy = CREATED_BY_LABEL.CATEGORIZATION;
const detectors = getRichDetectors(job, datafeed, this.additionalFields, false);

const dtr = detectors[0];
if (detectors.length && dtr.agg !== null && dtr.field !== null) {
this._detectorType =
dtr.agg.id === ML_JOB_AGGREGATION.COUNT
? ML_JOB_AGGREGATION.COUNT
: ML_JOB_AGGREGATION.RARE;

const bs = job.analysis_config.bucket_span;
this.setDetectorType(this._detectorType);
// set the bucketspan back to the original value
// as setDetectorType applies a default
this.bucketSpan = bs;
}
}

public get categorizationPerPartitionField() {
return this._partitionFieldName;
}
Expand All @@ -204,4 +184,43 @@ export class CategorizationJobCreator extends JobCreator {
}
}
}

// override the setter and getter for the per-partition toggle
// so we can remove the partition field in the wizard when
// per-partition categorization is disabled.
public get perPartitionCategorization() {
return this._job_config.analysis_config.per_partition_categorization?.enabled === true;
}

public set perPartitionCategorization(enabled: boolean) {
this._initPerPartitionCategorization();
this._job_config.analysis_config.per_partition_categorization!.enabled = enabled;
if (enabled === false) {
this.categorizationPerPartitionField = null;
}
}

public cloneFromExistingJob(job: Job, datafeed: Datafeed) {
this._overrideConfigs(job, datafeed);
this.createdBy = CREATED_BY_LABEL.CATEGORIZATION;
const detectors = getRichDetectors(job, datafeed, this.additionalFields, false);

const dtr = detectors[0];
if (dtr !== undefined && dtr.agg !== null && dtr.field !== null) {
const detectorType =
dtr.agg.id === ML_JOB_AGGREGATION.COUNT
? ML_JOB_AGGREGATION.COUNT
: ML_JOB_AGGREGATION.RARE;

const bs = job.analysis_config.bucket_span;
this.setDetectorType(detectorType);
if (dtr.partitionField !== null) {
this.categorizationPerPartitionField = dtr.partitionField.id;
}

// set the bucketspan back to the original value
// as setDetectorType applies a default
this.bucketSpan = bs;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -631,7 +631,7 @@ export class JobCreator {
return JSON.stringify(this._datafeed_config, null, 2);
}

private _initPerPartitionCategorization() {
protected _initPerPartitionCategorization() {
if (this._job_config.analysis_config.per_partition_categorization === undefined) {
this._job_config.analysis_config.per_partition_categorization = {};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { ModuleJobUI } from '../page';
import { SETUP_RESULTS_WIDTH } from './module_jobs';
import { tabColor } from '../../../../../../common/util/group_color_utils';
import { JobOverride } from '../../../../../../common/types/modules';
import { extractErrorMessage } from '../../../../../../common/util/errors';

interface JobItemProps {
job: ModuleJobUI;
Expand Down Expand Up @@ -94,13 +95,13 @@ export const JobItem: FC<JobItemProps> = memo(

{setupResult && setupResult.error && (
<EuiText size="xs" color="danger">
{setupResult.error.msg}
{extractErrorMessage(setupResult.error)}
</EuiText>
)}

{datafeedResult && datafeedResult.error && (
<EuiText size="xs" color="danger">
{datafeedResult.error.msg}
{extractErrorMessage(datafeedResult.error)}
</EuiText>
)}
</EuiFlexItem>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
} from '@elastic/eui';
import { i18n } from '@kbn/i18n';
import { KibanaObjectUi } from '../page';
import { extractErrorMessage } from '../../../../../../common/util/errors';

export interface KibanaObjectItemProps {
objectType: string;
Expand Down Expand Up @@ -57,7 +58,7 @@ export const KibanaObjects: FC<KibanaObjectItemProps> = memo(
</EuiText>
{success === false && error !== undefined && (
<EuiText size="xs" color="danger">
{error.message}
{extractErrorMessage(error)}
</EuiText>
)}
</EuiFlexItem>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ export async function fetchESUsage(
{
timestamp: {
order: 'desc',
unmapped_type: 'long',
},
},
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export async function fetchLicenseType(
{
timestamp: {
order: 'desc',
unmapped_type: 'long',
},
},
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ describe('fetchLegacyAlerts', () => {
],
body: {
size,
sort: [{ timestamp: { order: 'desc' } }],
sort: [{ timestamp: { order: 'desc', unmapped_type: 'long' } }],
query: {
bool: {
minimum_should_match: 1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export async function fetchLegacyAlerts(
{
timestamp: {
order: 'desc',
unmapped_type: 'long',
},
},
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ export async function fetchMissingMonitoringData(
{
timestamp: {
order: 'desc',
unmapped_type: 'long',
},
},
],
Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/monitoring/server/lib/beats/get_beats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ export async function getBeats(req: LegacyRequest, beatsIndexPattern: string, cl
inner_hits: {
name: 'earliest',
size: 1,
sort: [{ 'beats_stats.timestamp': 'asc' }],
sort: [{ 'beats_stats.timestamp': { order: 'asc', unmapped_type: 'long' } }],
},
},
sort: [
Expand Down
3 changes: 2 additions & 1 deletion x-pack/plugins/uptime/public/state/api/ml_anomaly.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
JobExistResult,
MlCapabilitiesResponse,
} from '../../../../../plugins/ml/public';
import { extractErrorMessage } from '../../../../../plugins/ml/common';
import {
CreateMLJobSuccess,
DeleteJobResults,
Expand Down Expand Up @@ -62,7 +63,7 @@ export const createMLJob = async ({
};
} else {
const { error } = jobResponse;
throw new Error(error?.msg);
throw new Error(extractErrorMessage(error));
}
} else {
return null;
Expand Down

0 comments on commit 7ac5dde

Please sign in to comment.