Skip to content
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
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
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;
}

This file was deleted.

This file was deleted.

Loading