Skip to content

Commit

Permalink
[Alerting] replace index threshold graph usage of watcher apis
Browse files Browse the repository at this point in the history
  • Loading branch information
pmuellr committed Mar 5, 2020
1 parent ba5784a commit 9e3843a
Show file tree
Hide file tree
Showing 16 changed files with 101 additions and 790 deletions.
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 { TimeBuckets } from './time_buckets';
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
2 changes: 1 addition & 1 deletion x-pack/plugins/triggers_actions_ui/kibana.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
"version": "kibana",
"server": false,
"ui": true,
"requiredPlugins": ["management", "charts", "data"]
"requiredPlugins": ["management", "charts", "data", "alerting", "alertingBuiltins"]
}
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 @@ -476,6 +478,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;
}

This file was deleted.

This file was deleted.

Loading

0 comments on commit 9e3843a

Please sign in to comment.