Skip to content

Commit

Permalink
Merge branch 'master' into alerting/ui-form-server-errors
Browse files Browse the repository at this point in the history
  • Loading branch information
elasticmachine authored Mar 6, 2020
2 parents 06019dd + 708d92a commit 44bc013
Show file tree
Hide file tree
Showing 37 changed files with 209 additions and 815 deletions.
7 changes: 4 additions & 3 deletions .github/workflows/pr-project-assigner.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ jobs:
with:
issue-mappings: |
[
{ "label": "Team:AppArch", "projectName": "kibana-app-arch", "columnId": 6173897 },
{ "label": "Feature:Lens", "projectName": "Lens", "columnId": 6219362 },
{ "label": "Team:Canvas", "projectName": "canvas", "columnId": 6187580 }
]
ghToken: ${{ secrets.PROJECT_ASSIGNER_TOKEN }}

# { "label": "Team:AppArch", "projectName": "kibana-app-arch", "columnId": 6173897 },
# { "label": "Feature:Lens", "projectName": "Lens", "columnId": 6219362 },
# { "label": "Team:Canvas", "projectName": "canvas", "columnId": 6187580 }
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/
jest.mock('ui/new_platform');
import { savedMap } from './saved_map';
import { getQueryFilters } from '../../../server/lib/build_embeddable_filters';
import { getQueryFilters } from '../../../public/lib/build_embeddable_filters';

const filterContext = {
and: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import { ExpressionFunctionDefinition } from 'src/plugins/expressions/common';
import { TimeRange } from 'src/plugins/data/public';
import { EmbeddableInput } from 'src/legacy/core_plugins/embeddable_api/public/np_ready/public';
import { getQueryFilters } from '../../../server/lib/build_embeddable_filters';
import { getQueryFilters } from '../../../public/lib/build_embeddable_filters';
import { Filter, MapCenter, TimeRange as TimeRangeArg } from '../../../types';
import {
EmbeddableTypes,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/
jest.mock('ui/new_platform');
import { savedSearch } from './saved_search';
import { buildEmbeddableFilters } from '../../../server/lib/build_embeddable_filters';
import { buildEmbeddableFilters } from '../../../public/lib/build_embeddable_filters';

const filterContext = {
and: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
EmbeddableExpression,
} from '../../expression_types';

import { buildEmbeddableFilters } from '../../../server/lib/build_embeddable_filters';
import { buildEmbeddableFilters } from '../../../public/lib/build_embeddable_filters';
import { Filter } from '../../../types';
import { getFunctionHelp } from '../../../i18n';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/
jest.mock('ui/new_platform');
import { savedVisualization } from './saved_visualization';
import { buildEmbeddableFilters } from '../../../server/lib/build_embeddable_filters';
import { buildEmbeddableFilters } from '../../../public/lib/build_embeddable_filters';

const filterContext = {
and: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
EmbeddableExpressionType,
EmbeddableExpression,
} from '../../expression_types';
import { buildEmbeddableFilters } from '../../../server/lib/build_embeddable_filters';
import { buildEmbeddableFilters } from '../../../public/lib/build_embeddable_filters';
import { Filter } from '../../../types';
import { getFunctionHelp } from '../../../i18n';

Expand Down
2 changes: 1 addition & 1 deletion x-pack/legacy/plugins/canvas/public/application.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export const renderApp = (
canvasStore: Store
) => {
ReactDOM.render(
<KibanaContextProvider services={{ ...coreStart, ...plugins }}>
<KibanaContextProvider services={{ ...plugins, ...coreStart }}>
<I18nProvider>
<Provider store={canvasStore}>
<App />
Expand Down
21 changes: 21 additions & 0 deletions x-pack/legacy/plugins/canvas/public/lib/build_bool_array.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

import { getESFilter } from './get_es_filter';

const compact = arr => (Array.isArray(arr) ? arr.filter(val => Boolean(val)) : []);

export function buildBoolArray(canvasQueryFilterArray) {
return compact(
canvasQueryFilterArray.map(clause => {
try {
return getESFilter(clause);
} catch (e) {
return;
}
})
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,11 @@
import { Filter } from '../../types';
// @ts-ignore Untyped Local
import { buildBoolArray } from './build_bool_array';

// TODO: We should be importing from `data/server` below instead of `data/common`, but
// need to keep `data/common` since the contents of this file are currently imported
// by the browser. This file should probably be refactored so that the pieces required
// on the client live in a `public` directory instead. See kibana/issues/52343
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
import {
TimeRange,
esFilters,
Filter as DataFilter,
} from '../../../../../../src/plugins/data/server';
} from '../../../../../../src/plugins/data/public';

export interface EmbeddableFilterInput {
filters: DataFilter[];
Expand Down
38 changes: 38 additions & 0 deletions x-pack/legacy/plugins/canvas/public/lib/filters.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

/*
TODO: This could be pluggable
*/

export function time(filter) {
if (!filter.column) {
throw new Error('column is required for Elasticsearch range filters');
}
return {
range: {
[filter.column]: { gte: filter.from, lte: filter.to },
},
};
}

export function luceneQueryString(filter) {
return {
query_string: {
query: filter.query || '*',
},
};
}

export function exactly(filter) {
return {
term: {
[filter.column]: {
value: filter.value,
},
},
};
}
26 changes: 26 additions & 0 deletions x-pack/legacy/plugins/canvas/public/lib/get_es_filter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

/*
boolArray is the array of bool filter clauses to push filters into. Usually this would be
the value of must, should or must_not.
filter is the abstracted canvas filter.
*/

/*eslint import/namespace: ['error', { allowComputed: true }]*/
import * as filters from './filters';

export function getESFilter(filter) {
if (!filters[filter.type]) {
throw new Error(`Unknown filter type: ${filter.type}`);
}

try {
return filters[filter.type](filter);
} catch (e) {
throw new Error(`Could not create elasticsearch filter from ${filter.type}`);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ export function getColumns(
defaultMessage: 'actions',
}),
render: item => {
if (showLinksMenuForItem(item) === true) {
if (showLinksMenuForItem(item, showViewSeriesLink) === true) {
return (
<LinksMenu
anomaly={item}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ const EuiFlyoutContainer = styled.div<{ headerHeight: number }>`
.timeline-flyout-body {
overflow-y: hidden;
padding: 0;
.euiFlyoutBody__overflow {
.euiFlyoutBody__overflowContent {
padding: 0;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const MINUTES_REGEX = /^[1-9][0-9]*m$/;
const HOURS_REGEX = /^[1-9][0-9]*h$/;
const DAYS_REGEX = /^[1-9][0-9]*d$/;

// parse an interval string '{digit*}{s|m|h|d}' into milliseconds
export function parseDuration(duration: string): number {
const parsed = parseInt(duration, 10);
if (isSeconds(duration)) {
Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/alerting/server/lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
* you may not use this file except in compliance with the Elastic License.
*/

export { parseDuration, validateDurationSchema } from './parse_duration';
export { parseDuration, validateDurationSchema } from '../../common/parse_duration';
export { LicenseState } from './license_state';
export { validateAlertTypeParams } from './validate_alert_type_params';
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,13 @@
* you may not use this file except in compliance with the Elastic License.
*/

export const TimeBuckets: any;
export interface TimeSeriesResult {
results: TimeSeriesResultRow[];
}

export interface TimeSeriesResultRow {
group: string;
metrics: MetricResult[];
}

export type MetricResult = [string, number]; // [iso date, value]
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,11 @@ import {
getDateStartAfterDateEndErrorMessage,
} from './date_range_info';

// The result is an object with a key for every field value aggregated
// via the `aggField` property. If `aggField` is not specified, the
// object will have a single key of `all documents`. The value associated
// with each key is an array of 2-tuples of `[ ISO-date, calculated-value ]`

export interface TimeSeriesResult {
results: TimeSeriesResultRow[];
}
export interface TimeSeriesResultRow {
group: string;
metrics: MetricResult[];
}
export type MetricResult = [string, number]; // [iso date, value]
export {
TimeSeriesResult,
TimeSeriesResultRow,
MetricResult,
} from '../../../../common/alert_types/index_threshold';

// The parameters here are very similar to the alert parameters.
// Missing are `comparator` and `threshold`, which aren't needed to generate
Expand Down
4 changes: 2 additions & 2 deletions x-pack/plugins/endpoint/common/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ export enum Direction {

export class EndpointAppConstants {
static BASE_API_URL = '/api/endpoint';
static ALERT_INDEX_NAME = 'my-index';
static ENDPOINT_INDEX_NAME = 'endpoint-agent*';
static EVENT_INDEX_NAME = 'endpoint-events-*';
static ALERT_INDEX_NAME = 'events-endpoint-1';
static EVENT_INDEX_NAME = 'events-endpoint-*';
static DEFAULT_TOTAL_HITS = 10000;
/**
* Legacy events are stored in indices with endgame-* prefix
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import { ResolverEvent, LegacyEndpointEvent } from '../../../../common/types';

function isLegacyData(data: ResolverEvent): data is LegacyEndpointEvent {
return data.agent.type === 'endgame';
return data.agent?.type === 'endgame';
}

export function extractEventID(event: ResolverEvent) {
Expand Down
1 change: 1 addition & 0 deletions x-pack/plugins/triggers_actions_ui/kibana.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
"version": "kibana",
"server": false,
"ui": true,
"optionalPlugins": ["alerting", "alertingBuiltins"],
"requiredPlugins": ["management", "charts", "data"]
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ const expressionFieldsWithValidation = [

interface IndexThresholdProps {
alertParams: IndexThresholdAlertParams;
alertInterval: string;
setAlertParams: (property: string, value: any) => void;
setAlertProperty: (key: string, value: any) => void;
errors: { [key: string]: string[] };
Expand All @@ -71,6 +72,7 @@ interface IndexThresholdProps {

export const IndexThresholdAlertTypeExpression: React.FunctionComponent<IndexThresholdProps> = ({
alertParams,
alertInterval,
setAlertParams,
setAlertProperty,
errors,
Expand Down Expand Up @@ -477,6 +479,7 @@ export const IndexThresholdAlertTypeExpression: React.FunctionComponent<IndexThr
<Fragment>
<ThresholdVisualization
alertParams={alertParams}
alertInterval={alertInterval}
aggregationTypes={builtInAggregationTypes}
comparators={builtInComparators}
alertsContext={alertsContext}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
* you may not use this file except in compliance with the Elastic License.
*/
import { HttpSetup } from 'kibana/public';
import { TimeSeriesResult } from '../types';
export { TimeSeriesResult } from '../types';

const WATCHER_API_ROOT = '/api/watcher';

Expand Down Expand Up @@ -60,20 +62,35 @@ export const loadIndexPatterns = async () => {
return savedObjects;
};

const TimeSeriesQueryRoute = '/api/alerting_builtins/index_threshold/_time_series_query';

interface GetThresholdAlertVisualizationDataParams {
model: any;
visualizeOptions: any;
http: HttpSetup;
}

export async function getThresholdAlertVisualizationData({
model,
visualizeOptions,
http,
}: {
model: any;
visualizeOptions: any;
http: HttpSetup;
}): Promise<Record<string, any>> {
const { visualizeData } = await http.post(`${WATCHER_API_ROOT}/watch/visualize`, {
body: JSON.stringify({
watch: model,
options: visualizeOptions,
}),
}: GetThresholdAlertVisualizationDataParams): Promise<TimeSeriesResult> {
const timeSeriesQueryParams = {
index: model.index,
timeField: model.timeField,
aggType: model.aggType,
aggField: model.aggField,
groupBy: model.groupBy,
termField: model.termField,
termSize: model.termSize,
timeWindowSize: model.timeWindowSize,
timeWindowUnit: model.timeWindowUnit,
dateStart: new Date(visualizeOptions.rangeFrom).toISOString(),
dateEnd: new Date(visualizeOptions.rangeTo).toISOString(),
interval: visualizeOptions.interval,
};

return await http.post<TimeSeriesResult>(TimeSeriesQueryRoute, {
body: JSON.stringify(timeSeriesQueryParams),
});
return visualizeData;
}
Loading

0 comments on commit 44bc013

Please sign in to comment.