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

[RAC] Rule registry plugin #95903

Merged
merged 42 commits into from
Apr 9, 2021
Merged
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
456bc37
Rule registry
dgieselaar Mar 15, 2021
5952259
Merge branch 'master' of github.com:elastic/kibana into rule-registry
dgieselaar Mar 24, 2021
b01fb63
Index alert events
dgieselaar Mar 26, 2021
023fc6b
Merge branch 'master' of github.com:elastic/kibana into rule-registry
dgieselaar Mar 26, 2021
649eaa4
Merge branch 'master' of github.com:elastic/kibana into rule-registry
dgieselaar Mar 26, 2021
d7e194c
Scoped rule registry client
dgieselaar Mar 30, 2021
b8ae24f
Merge branch 'master' of github.com:elastic/kibana into rule-registry
dgieselaar Mar 30, 2021
1433e7c
Clean up APM rule type tests
dgieselaar Mar 31, 2021
bfe5767
Merge branch 'master' of github.com:elastic/kibana into rule-registry
dgieselaar Mar 31, 2021
1d656ad
create scoped client for request
dgieselaar Mar 31, 2021
c942603
Remove parent reference
dgieselaar Mar 31, 2021
5166848
Add README
dgieselaar Mar 31, 2021
008f837
Merge branch 'master' of github.com:elastic/kibana into rule-registry
dgieselaar Apr 1, 2021
a85cacb
Namespace alert fields
dgieselaar Apr 1, 2021
f64a930
Update allowed user defined alert fields
dgieselaar Apr 1, 2021
3fe959e
Review feedback
dgieselaar Apr 1, 2021
e21813d
Namespace > name
dgieselaar Apr 1, 2021
6762c6a
Add rule registry plugin to docs
dgieselaar Apr 1, 2021
8344826
configurable writes
dgieselaar Apr 1, 2021
bd77029
Update producer field
dgieselaar Apr 1, 2021
2b243f9
Revert changes to index template error
dgieselaar Apr 1, 2021
94da2ca
Merge branch 'master' of github.com:elastic/kibana into rule-registry
dgieselaar Apr 2, 2021
7720830
Merge branch 'master' into rule-registry
kibanamachine Apr 4, 2021
473dfba
Merge branch 'master' of github.com:elastic/kibana into rule-registry
dgieselaar Apr 7, 2021
71ec07c
Merge branch 'rule-registry' of github.com:dgieselaar/kibana into rul…
dgieselaar Apr 7, 2021
260ea64
Merge branch 'master' of github.com:elastic/kibana into rule-registry
dgieselaar Apr 7, 2021
7df11b9
Merge branch 'master' of github.com:elastic/kibana into rule-registry
dgieselaar Apr 7, 2021
18c0644
Add rule registry project to apm tsconfig
dgieselaar Apr 7, 2021
d23e693
Merge branch 'master' of github.com:elastic/kibana into rule-registry
dgieselaar Apr 7, 2021
b7044e7
Merge branch 'master' of github.com:elastic/kibana into rule-registry
dgieselaar Apr 8, 2021
7ebaff6
Add simple integration tests for rule registry
dgieselaar Apr 8, 2021
1e9f240
Merge branch 'master' of github.com:elastic/kibana into rule-registry
dgieselaar Apr 8, 2021
74d3edd
Revert change to getEsNames
dgieselaar Apr 8, 2021
8137e1a
Merge branch 'master' of github.com:elastic/kibana into rule-registry
dgieselaar Apr 8, 2021
45b5fff
Add rules integration tests to config
dgieselaar Apr 8, 2021
4f43921
Export APMRuleRegistry type again
dgieselaar Apr 8, 2021
d41d709
Merge branch 'master' of github.com:elastic/kibana into rule-registry
dgieselaar Apr 8, 2021
585e83a
Lowercase index alias name
dgieselaar Apr 8, 2021
36d4786
Removed unused import
dgieselaar Apr 8, 2021
31f97de
Include alert types in SO client
dgieselaar Apr 8, 2021
d3848c9
Merge branch 'master' of github.com:elastic/kibana into rule-registry
dgieselaar Apr 9, 2021
11679ef
Use wildcard to prevent version mismatch in index target
dgieselaar Apr 9, 2021
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
4 changes: 4 additions & 0 deletions docs/developer/plugin-list.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,10 @@ Elastic.
|Welcome to the Kibana rollup plugin! This plugin provides Kibana support for Elasticsearch's rollup feature. Please refer to the Elasticsearch documentation to understand rollup indices and how to create rollup jobs.


|{kib-repo}blob/{branch}/x-pack/plugins/rule_registry/README.md[ruleRegistry]
|The rule registry plugin aims to make it easy for rule type producers to have their rules produce the data that they need to build rich experiences on top of a unified experience, without the risk of mapping conflicts.


|{kib-repo}blob/{branch}/x-pack/plugins/runtime_fields/README.md[runtimeFields]
|Welcome to the home of the runtime field editor and everything related to runtime fields!

Expand Down
10 changes: 10 additions & 0 deletions typings/elasticsearch/search.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,16 @@ export type AggregateOf<
missing: {
doc_count: number;
} & SubAggregateOf<TAggregationContainer, TDocument>;
multi_terms: {
doc_count_error_upper_bound: number;
sum_other_doc_count: number;
buckets: Array<
{
doc_count: number;
key: string[];
} & SubAggregateOf<TAggregationContainer, TDocument>
>;
};
nested: {
doc_count: number;
} & SubAggregateOf<TAggregationContainer, TDocument>;
Expand Down
18 changes: 18 additions & 0 deletions x-pack/plugins/apm/common/environment_filter_values.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,13 @@ const environmentLabels: Record<string, string> = {
};

export const ENVIRONMENT_ALL = {
esFieldValue: undefined,
Copy link
Member

Choose a reason for hiding this comment

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

@dgieselaar This (esFieldValue) is being passed to the DOM elements causing the following error:

image

value: ENVIRONMENT_ALL_VALUE,
text: environmentLabels[ENVIRONMENT_ALL_VALUE],
};

export const ENVIRONMENT_NOT_DEFINED = {
esFieldValue: undefined,
value: ENVIRONMENT_NOT_DEFINED_VALUE,
text: environmentLabels[ENVIRONMENT_NOT_DEFINED_VALUE],
};
Expand All @@ -35,6 +37,22 @@ export function getEnvironmentLabel(environment: string) {
return environmentLabels[environment] || environment;
}

export function parseEnvironmentUrlParam(environment: string) {
if (environment === ENVIRONMENT_ALL_VALUE) {
return ENVIRONMENT_ALL;
}

if (environment === ENVIRONMENT_NOT_DEFINED_VALUE) {
return ENVIRONMENT_NOT_DEFINED;
}

return {
esFieldValue: environment,
value: environment,
text: environment,
};
}
Comment on lines +40 to +54
Copy link
Member

Choose a reason for hiding this comment

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

Afaict this should be:

export function getEsFieldValue(environment: string) {
    if (environment === ENVIRONMENT_ALL_VALUE) {
      return ENVIRONMENT_ALL;
    }
  
    if (environment === ENVIRONMENT_NOT_DEFINED_VALUE) {
      return ENVIRONMENT_NOT_DEFINED;
    }
  
    return environment
}

Then you can call it the specific places where needed (currently just for alerts)


// returns the environment url param that should be used
// based on the requested environment. If the requested
// environment is different from the URL parameter, we'll
Expand Down
4 changes: 2 additions & 2 deletions x-pack/plugins/apm/kibana.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
"licensing",
"triggersActionsUi",
"embeddable",
"infra"
"infra",
"observability"
],
"optionalPlugins": [
"spaces",
Expand All @@ -18,7 +19,6 @@
"taskManager",
"actions",
"alerting",
"observability",
"security",
"ml",
"home",
Expand Down
1 change: 1 addition & 0 deletions x-pack/plugins/apm/scripts/optimize-tsconfig/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"include": [
"./x-pack/plugins/apm/**/*",
"./x-pack/plugins/observability/**/*",
"./x-pack/plugins/rule_registry/**/*",
"./typings/**/*"
],
"exclude": [
Expand Down
12 changes: 6 additions & 6 deletions x-pack/plugins/apm/server/lib/alerts/action_variables.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,28 +13,28 @@ export const apmActionVariables = {
'xpack.apm.alerts.action_variables.serviceName',
{ defaultMessage: 'The service the alert is created for' }
),
name: 'serviceName',
name: 'serviceName' as const,
},
transactionType: {
description: i18n.translate(
'xpack.apm.alerts.action_variables.transactionType',
{ defaultMessage: 'The transaction type the alert is created for' }
),
name: 'transactionType',
name: 'transactionType' as const,
},
environment: {
description: i18n.translate(
'xpack.apm.alerts.action_variables.environment',
{ defaultMessage: 'The transaction type the alert is created for' }
),
name: 'environment',
name: 'environment' as const,
},
threshold: {
description: i18n.translate('xpack.apm.alerts.action_variables.threshold', {
defaultMessage:
'Any trigger value above this value will cause the alert to fire',
}),
name: 'threshold',
name: 'threshold' as const,
},
triggerValue: {
description: i18n.translate(
Expand All @@ -44,7 +44,7 @@ export const apmActionVariables = {
'The value that breached the threshold and triggered the alert',
}
),
name: 'triggerValue',
name: 'triggerValue' as const,
},
interval: {
description: i18n.translate(
Expand All @@ -54,6 +54,6 @@ export const apmActionVariables = {
'The length and unit of the time period where the alert conditions were met',
}
),
name: 'interval',
name: 'interval' as const,
},
};
28 changes: 12 additions & 16 deletions x-pack/plugins/apm/server/lib/alerts/alerting_es_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,24 @@
* 2.0.
*/

import { ApiResponse } from '@elastic/elasticsearch';
import { ThresholdMetActionGroupId } from '../../../common/alert_types';
import {
ESSearchRequest,
ESSearchResponse,
} from '../../../../../../typings/elasticsearch';
import {
AlertInstanceContext,
AlertInstanceState,
AlertServices,
} from '../../../../alerting/server';
import { AlertServices } from '../../../../alerting/server';

export function alertingEsClient<TParams extends ESSearchRequest>(
services: AlertServices<
AlertInstanceState,
AlertInstanceContext,
ThresholdMetActionGroupId
>,
export async function alertingEsClient<TParams extends ESSearchRequest>(
scopedClusterClient: AlertServices<
never,
never,
never
>['scopedClusterClient'],
params: TParams
): Promise<ApiResponse<ESSearchResponse<unknown, TParams>>> {
return (services.scopedClusterClient.asCurrentUser.search({
): Promise<ESSearchResponse<unknown, TParams>> {
const response = await scopedClusterClient.asCurrentUser.search({
...params,
ignore_unavailable: true,
}) as unknown) as Promise<ApiResponse<ESSearchResponse<unknown, TParams>>>;
});

return (response.body as unknown) as ESSearchResponse<unknown, TParams>;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import { createLifecycleRuleTypeFactory } from '../../../../rule_registry/server';
import { APMRuleRegistry } from '../../plugin';

export const createAPMLifecycleRuleType = createLifecycleRuleTypeFactory<APMRuleRegistry>();
33 changes: 10 additions & 23 deletions x-pack/plugins/apm/server/lib/alerts/register_apm_alerts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,38 +6,25 @@
*/

import { Observable } from 'rxjs';
import { AlertingPlugin } from '../../../../alerting/server';
import { ActionsPlugin } from '../../../../actions/server';
import { Logger } from 'kibana/server';
import { registerTransactionDurationAlertType } from './register_transaction_duration_alert_type';
import { registerTransactionDurationAnomalyAlertType } from './register_transaction_duration_anomaly_alert_type';
import { registerErrorCountAlertType } from './register_error_count_alert_type';
import { APMConfig } from '../..';
import { MlPluginSetup } from '../../../../ml/server';
import { registerTransactionErrorRateAlertType } from './register_transaction_error_rate_alert_type';
import { APMRuleRegistry } from '../../plugin';

interface Params {
alerting: AlertingPlugin['setup'];
actions: ActionsPlugin['setup'];
export interface RegisterRuleDependencies {
registry: APMRuleRegistry;
ml?: MlPluginSetup;
config$: Observable<APMConfig>;
logger: Logger;
}

export function registerApmAlerts(params: Params) {
registerTransactionDurationAlertType({
alerting: params.alerting,
config$: params.config$,
});
registerTransactionDurationAnomalyAlertType({
alerting: params.alerting,
ml: params.ml,
config$: params.config$,
});
registerErrorCountAlertType({
alerting: params.alerting,
config$: params.config$,
});
registerTransactionErrorRateAlertType({
alerting: params.alerting,
config$: params.config$,
});
export function registerApmAlerts(dependencies: RegisterRuleDependencies) {
registerTransactionDurationAlertType(dependencies);
registerTransactionDurationAnomalyAlertType(dependencies);
registerErrorCountAlertType(dependencies);
registerTransactionErrorRateAlertType(dependencies);
}
Loading