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

[Alerting] Moves the Index & Geo Threshold UIs into the Stack Alerts Public Plugin #82951

Merged
merged 20 commits into from
Nov 12, 2020

Conversation

gmmorris
Copy link
Contributor

@gmmorris gmmorris commented Nov 9, 2020

Summary

closes #80958

This PR includes the following refactors:

  1. Moves the Index Pattern Api from Stack Alerts to the Server plugin of Trigger Actions UI. This fixes a potential bug where a user could disable the Stack Alerts plugin and inadvertently break the UI of the _ES Index _ action type.
  2. Extracts the UI components for Index Threshold and Geo Threshold from the Trigger Actions UI plugin and moves them into Stack Alerts.

Checklist

Delete any items that are not applicable to this PR.

For maintainers

* master: (39 commits)
  Fix ilm navigation (elastic#81664)
  [Lens] Distinct icons for XY and pie chart value labels toolbar (elastic#82927)
  [data.search.aggs] Throw an error when trying to create an agg type that doesn't exist. (elastic#81509)
  Index patterns api - load field list on server (elastic#82629)
  New events resolver (elastic#82170)
  [App Search] Misc naming tech debt (elastic#82770)
  load empty_kibana in test to have clean starting point (elastic#82772)
  Remove data <--> expressions circular dependencies. (elastic#82685)
  Update 8.0 breaking change template to gather information on how to programmatically detect it. (elastic#82905)
  Add alerting as codeowners to related documentation folder (elastic#82777)
  Add captions to user and space grid pages (elastic#82713)
  add alternate path for x-pack/Cloud test for Lens (elastic#82634)
  Uses asCurrentUser in getClusterUuid (elastic#82908)
  [Alerting][Connectors] Add new executor subaction to get 3rd party case fields (elastic#82519)
  Fix test import objects (elastic#82767)
  [ML] Add option for anomaly charts for metric detector should plot min, mean or max as appropriate (elastic#81662)
  Update alert type selection layout to rows instead of grid (elastic#73665)
  Prevent Kerberos and PKI providers from initiating a new session for unauthenticated XHR/API requests. (elastic#82817)
  Update grunt and related packages (elastic#79327)
  Allow the repository to search across all namespaces (elastic#82863)
  ...
Comment on lines +1 to +45
/*
* 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 { HttpSetup } from 'kibana/public';
import { TimeSeriesResult } from '../../../../triggers_actions_ui/common';
import { IndexThresholdAlertParams } from './types';

const INDEX_THRESHOLD_DATA_API_ROOT = '/api/triggers_actions_ui/data';

export interface GetThresholdAlertVisualizationDataParams {
model: IndexThresholdAlertParams;
visualizeOptions: {
rangeFrom: string;
rangeTo: string;
interval: string;
};
http: HttpSetup;
}

export async function getThresholdAlertVisualizationData({
model,
visualizeOptions,
http,
}: 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>(`${INDEX_THRESHOLD_DATA_API_ROOT}/_time_series_query`, {
body: JSON.stringify(timeSeriesQueryParams),
});
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extracted from the original index_threshold_api.ts which lived in triggers_actions_ui, so this ins't new code, it's just been split into two files - one lives in stack_alerts and the other stays in triggers_actions_ui (which is now renamed data_apis).

Comment on lines +74 to +79

export function runTests(schema: ObjectType, defaultTypeParams: Record<string, unknown>): void {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
let params: any;

const CoreDefaultParams: Writable<Partial<CoreQueryParams>> = {
Copy link
Contributor Author

@gmmorris gmmorris Nov 10, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This helper test function has been duplicated between the two plugins.
This is because both plugins have components using the same Api and the same schema.

I couldn't think of a clean way of sharing this test code in both plugins, so chose to duplicate instead, but it's worth noting as the schema itself is shared it means these tests are linked through the schema, so changing the schema will be caught by both components that rely on it - which is probably a good thing.

@gmmorris gmmorris changed the title extracted index-threshold apis into triggers actions ui [Alerting] Moves the Index & Geo Threshold UIs into the Stack Alerts Public Plugin Nov 10, 2020
@gmmorris gmmorris marked this pull request as ready for review November 10, 2020 11:34
@gmmorris gmmorris requested review from a team as code owners November 10, 2020 11:34
@gmmorris gmmorris added Feature:Alerting release_note:skip Skip the PR/issue when compiling release notes Team:ResponseOps Label for the ResponseOps team (formerly the Cases and Alerting teams) v7.11.0 v8.0.0 labels Nov 10, 2020
@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-alerting-services (Team:Alerting Services)

Copy link
Contributor

@ymao1 ymao1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! I tried creating an Index Threshold & Geo Alert and everything worked as expected.

@gmmorris
Copy link
Contributor Author

@elasticmachine merge upstream

kibanamachine and others added 3 commits November 10, 2020 11:47
…na into alerts/stack-alerts-public

* 'alerts/stack-alerts-public' of github.com:gmmorris/kibana:
  [Security Solution] Fix DNS Network table query (elastic#82778)
  [Workplace Search] Consolidate groups routes (elastic#83015)
  Adds cloud links to user menu (elastic#82803)
  [Security Solution][Detections] - follow up cleanup on auto refresh rules (elastic#83023)
  [App Search] Added the log retention panel to the Settings page (elastic#82982)
  [Maps] show icon when layer is filtered by time and allow layers to ignore global time range (elastic#83006)
  [DOCS] Consolidates drilldown pages (elastic#82081)
  [Maps] add on-prem EMS config (elastic#82525)
  migrate i18n mixin to KP (elastic#81799)
  [bundle optimization] fix imports of react-use lib (elastic#82847)
  [Discover] Add metric on adding filter (elastic#82961)
  [Lens] Performance refactoring for indexpattern fast lookup and Operation support matrix computation (elastic#82829)
  skip flaky suite (elastic#82804)
  Fix SO query for searching across spaces (elastic#83025)
  renaming built-in alerts to Stack Alerts (elastic#82873)
  [TSVB] Disable using top_hits in pipeline aggregations (elastic#82278)
  [Visualizations] Remove kui usage (elastic#82810)
  [Visualizations] Make the icon buttons labels more descriptive (elastic#82585)
  [Lens] Do not reset formatting when switching between custom ranges and auto histogram (elastic#82694)
:
@gmmorris gmmorris requested a review from a team as a code owner November 10, 2020 17:58
Copy link
Contributor

@spalger spalger left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Operations: new plugin, new limit, LGTM

Copy link
Member

@pmuellr pmuellr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, nice clean up, super nice to see such a minimal set of changes to the FT (as you would expect for a PR like this). Only one real meaningful comment, about whether we need the schema.maybe() on enableGeoTrackingThresholdAlert.

@@ -8,6 +8,7 @@ import { schema, TypeOf } from '@kbn/config-schema';

export const configSchema = schema.object({
enabled: schema.boolean({ defaultValue: true }),
enableGeoTrackingThresholdAlert: schema.maybe(schema.boolean({ defaultValue: false })),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think using defaultValue: false means you don't need a schema.maybe() wrapper. Or else I'm not sure what this could mean. When would the defaultValue be applied?

This is always a bit of a confusing aspect to me with config-schema, and other type builders like this. :-) I'd prefer we use the "fewer possibilities" of what the value can be, when we can, and removing the schema.maybe() means that property should always have a boolean value vs boolean | undefined, which seems like will be easier for us anyway.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a fair point - I copied it as is from the original plugin.
Think you're right... I'll sort that out.

@@ -3,7 +3,7 @@
"server": true,
"version": "8.0.0",
"kibanaVersion": "kibana",
"requiredPlugins": ["alerts", "features"],
"requiredPlugins": ["alerts", "features", "triggersActionsUi", "kibanaReact"],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't have a case where someone would want to disable triggersActionsUi but have the stack alerts still usable, right? Probably anyway? :-)

I could imagine a situation where we might someday want to build a UI-free version of Kibana to be able to run the alerts/actions without the UI, but that's super-long term, and no need to account for that yet, I don't think.

Just wanted to make sure we didn't have any other use cases like that ...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the time being we'll have to live with it as a dependency for actions or alerts 🤷
In the future, sure, we might want to offer alerting without UI, but for now I think this is ok.

@@ -123,227 +120,6 @@ server log [17:32:10.060] [warning][actions][actions][plugins] \
[now-iso]: https://github.com/pmuellr/now-iso


## http endpoints
## Data Apis via the TriggersActionsUi plugin and its http endpoints
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ahhh ... now I see, the index action UIs are also using these APIs I guess. Confused me for a bit as to why the APIs moved there. I think this makes sense for now, but does seem a little weird - I guess it feels like maybe we need YAAP (yet another alerting plugin) where these back-end APIs might live, to separate it out a bit from the mainly UI plugin (I guess I kinda alluded to that in a previous comment re: the new plugin dependencies). A change to make later, if we ever need to ...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TBH I think these APIs belong in the data plugin... hence the name ;)
For now it makes sense in the Triggers Actions UI as it's a plugin we can expect to always be enabled if actions or alerts are in use

@@ -152,7 +155,7 @@ export function getAlertType(service: Service): AlertType<Params, {}, {}, Action
interval: undefined,
};
// console.log(`index_threshold: query: ${JSON.stringify(queryParams, null, 4)}`);
const result = await service.indexThreshold.timeSeriesQuery({
const result = await (await data).timeSeriesQuery({
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

await await (hehe)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I hate it 😆

…ts-public

* upstream/master: (57 commits)
  Remove unused asciidoc file (elastic#83228)
  [Lens] Remove background from lens embeddable (elastic#83061)
  [Discover] Unskip flaky tests based on discover fixture index pattern (elastic#82991)
  Removing unnecessary trailing slash in CODEOWNERS
  Trying to fix CODEOWNERS again, where was a non-existent team prior (elastic#83236)
  Trying to fix CODEOWERS, missing a starting slash (elastic#83233)
  skip flaky suite (elastic#83231)
  Add enzyme rerender test helper (elastic#83208)
  Move Elasticsearch type definitions out of APM (elastic#83081)
  [ts/checkTsProjects] produce a more useful error message (elastic#83209)
  [kbnClient] retry updating config if necessary (elastic#83205)
  I accidentally removed this line in a recent PR (elastic#83201)
  Don't make the caller do work the function can do (elastic#83180)
  [App Search] Update EngineRouter & EngineNav to use EngineLogic (elastic#83138)
  [Workplace Search] Add routes for Sources (elastic#83125)
  Update logstash pipeline management to use system index APIs (elastic#80405)
  [ML] Replace EuiBasicTable with EuiInMemoryTable (elastic#83057)
  [Metrics UI] Add basic interaction and shell for node details overlay (elastic#82013)
  [App Search] Added the log retention confirmation modal to the Settings page (elastic#83009)
  [docs] Fix create map title in import geospatial page (elastic#83172)
  ...
* master:
  [Advanced Settings] Introducing telemetry (elastic#82860)
  [alerts] add executionStatus to event log doc for action execute (elastic#82401)
  Add additional sources routes (elastic#83227)
  [ML] Persisted URL state for the "Anomaly detection jobs" page (elastic#83149)
  [Logs UI] Add pagination to the log stream shared component (elastic#81193)
  [Index Management] Add an index template link to data stream details (elastic#82592)
  Add maps_oss folder to code_owners (elastic#83204)
  fix truncation issue (elastic#83000)
  [Ingest Manger] Move asset getters out of registry (elastic#83214)
@kibanamachine
Copy link
Contributor

💚 Build Succeeded

Metrics [docs]

Module Count

Fewer modules leads to a faster build time

id before after diff
stackAlerts - 31 +31
triggersActionsUi 297 275 -22
total +9

Async chunks

Total size of all lazy-loaded chunks that will be downloaded as the user navigates the app

id before after diff
stackAlerts - 79.6KB +79.6KB
triggersActionsUi 1.5MB 1.4MB -95.3KB
total -15.7KB

Distributable file count

id before after diff
default 42775 42782 +7

Page load bundle

Size of the bundles that are downloaded on every page load. Target size is below 100kb

id before after diff
stackAlerts - 14.3KB +14.3KB
triggersActionsUi 133.1KB 140.0KB +6.9KB
total +21.2KB
Unknown metric groups

async chunk count

id before after diff
stackAlerts - 2 +2
triggersActionsUi 33 31 -2
total -0

History

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

@gmmorris gmmorris merged commit ab72206 into elastic:master Nov 12, 2020
gmmorris added a commit to gmmorris/kibana that referenced this pull request Nov 12, 2020
* master:
  [ML] Update apidoc config with the Trained models endpoints  (elastic#83274)
  [Fleet] IngestManager Plugin interface for registering UI extensions (elastic#82783)
  [Alerting] Moves the Index & Geo Threshold UIs into the Stack Alerts Public Plugin (elastic#82951)
gmmorris added a commit to gmmorris/kibana that referenced this pull request Nov 12, 2020
…Public Plugin (elastic#82951)

This PR includes the following refactors:
1. Moves the Index Pattern Api from _Stack Alerts_ to the _Server_ plugin of _Trigger Actions UI_. This fixes a potential bug where a user could disable the _Stack Alerts_ plugin and inadvertently break the UI of the _ES Index _ action type.
2. Extracts the UI components for _Index Threshold_ and _Geo Threshold_ from the _Trigger Actions UI_ plugin and moves them into _Stack Alerts_.
# Conflicts:
#	packages/kbn-optimizer/limits.yml
gmmorris added a commit that referenced this pull request Nov 12, 2020
…Public Plugin (#82951) (#83316)

This PR includes the following refactors:
1. Moves the Index Pattern Api from _Stack Alerts_ to the _Server_ plugin of _Trigger Actions UI_. This fixes a potential bug where a user could disable the _Stack Alerts_ plugin and inadvertently break the UI of the _ES Index _ action type.
2. Extracts the UI components for _Index Threshold_ and _Geo Threshold_ from the _Trigger Actions UI_ plugin and moves them into _Stack Alerts_.
# Conflicts:
#	packages/kbn-optimizer/limits.yml
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature:Alerting release_note:skip Skip the PR/issue when compiling release notes Team:ResponseOps Label for the ResponseOps team (formerly the Cases and Alerting teams) v7.11.0 v8.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Stack Alerts UI Public components don't reside next to their Server components
7 participants