Skip to content

Commit

Permalink
Merge branch 'master' of github.com:elastic/kibana into ilm/snapshot-…
Browse files Browse the repository at this point in the history
…fields

* 'master' of github.com:elastic/kibana:
  [ILM] Fix delete phase serialization bug (elastic#84870)
  chore(NA): removes auto install of pre-commit hook (elastic#83566)
  chore(NA): upgrade node-sass into last v4.14.1 to stop shipping old node-gyp (elastic#84935)
  [Alerting] Enables AlertTypes to define the custom recovery action groups (elastic#84408)
  [ML] Functional tests - add missing test data cleanup (elastic#84998)
  Migrate privilege/role/user-related operations to a new Elasticsearch client. (elastic#84641)

# Conflicts:
#	x-pack/plugins/index_lifecycle_management/public/application/sections/edit_policy/form/deserializer_and_serializer.test.ts
#	x-pack/plugins/index_lifecycle_management/public/application/sections/edit_policy/form/serializer/serializer.ts
  • Loading branch information
jloleysens committed Dec 4, 2020
2 parents f6e1474 + 9d6d783 commit d03bfdb
Show file tree
Hide file tree
Showing 97 changed files with 893 additions and 587 deletions.
14 changes: 14 additions & 0 deletions docs/developer/getting-started/index.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,20 @@ View all available options by running `yarn start --help`

Read about more advanced options for <<running-kibana-advanced>>.

[discrete]
=== Install pre-commit hook (optional)

In case you want to run a couple of checks like linting or check the file casing of the files to commit, we provide
a way to install a pre-commit hook. To configure it you just need to run the following:

[source,bash]
----
node scripts/register_git_hook
----

After the script completes the pre-commit hook will be created within the file `.git/hooks/pre-commit`.
If you choose to not install it, don't worry, we still run a quick ci check to provide feedback earliest as we can about the same checks.

[discrete]
=== Code away!

Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
"kbn:watch": "node scripts/kibana --dev --logging.json=false",
"build:types": "rm -rf ./target/types && tsc --p tsconfig.types.json",
"docs:acceptApiChanges": "node --max-old-space-size=6144 scripts/check_published_api_changes.js --accept",
"kbn:bootstrap": "node scripts/build_ts_refs && node scripts/register_git_hook",
"kbn:bootstrap": "node scripts/build_ts_refs",
"spec_to_console": "node scripts/spec_to_console",
"backport-skip-ci": "backport --prDescription \"[skip-ci]\"",
"storybook": "node scripts/storybook",
Expand Down Expand Up @@ -746,7 +746,7 @@
"murmurhash3js": "3.0.1",
"mutation-observer": "^1.0.3",
"ncp": "^2.0.0",
"node-sass": "^4.13.1",
"node-sass": "^4.14.1",
"null-loader": "^3.0.0",
"nyc": "^15.0.1",
"oboe": "^2.1.4",
Expand Down
8 changes: 4 additions & 4 deletions src/dev/precommit_hook/get_files_for_commit.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ import { File } from '../file';
* Get the files that are staged for commit (excluding deleted files)
* as `File` objects that are aware of their commit status.
*
* @param {String} repoPath
* @param {String} gitRef
* @return {Promise<Array<File>>}
*/
export async function getFilesForCommit() {
export async function getFilesForCommit(gitRef) {
const simpleGit = new SimpleGit(REPO_ROOT);

const output = await fcb((cb) => simpleGit.diff(['--name-status', '--cached'], cb));
const gitRefForDiff = gitRef ? gitRef : '--cached';
const output = await fcb((cb) => simpleGit.diff(['--name-status', gitRefForDiff], cb));

return (
output
Expand Down
23 changes: 20 additions & 3 deletions src/dev/run_precommit_hook.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,30 @@
* under the License.
*/

import { run, combineErrors } from '@kbn/dev-utils';
import { run, combineErrors, createFlagError } from '@kbn/dev-utils';
import * as Eslint from './eslint';
import * as Sasslint from './sasslint';
import { getFilesForCommit, checkFileCasing } from './precommit_hook';

run(
async ({ log, flags }) => {
const files = await getFilesForCommit();
const files = await getFilesForCommit(flags.ref);
const errors = [];

const maxFilesCount = flags['max-files']
? Number.parseInt(String(flags['max-files']), 10)
: undefined;
if (maxFilesCount !== undefined && (!Number.isFinite(maxFilesCount) || maxFilesCount < 1)) {
throw createFlagError('expected --max-files to be a number greater than 0');
}

if (maxFilesCount && files.length > maxFilesCount) {
log.warning(
`--max-files is set to ${maxFilesCount} and ${files.length} were discovered. The current script execution will be skipped.`
);
return;
}

try {
await checkFileCasing(log, files);
} catch (error) {
Expand All @@ -52,15 +66,18 @@ run(
},
{
description: `
Run checks on files that are staged for commit
Run checks on files that are staged for commit by default
`,
flags: {
boolean: ['fix'],
string: ['max-files', 'ref'],
default: {
fix: false,
},
help: `
--fix Execute eslint in --fix mode
--max-files Max files number to check against. If exceeded the script will skip the execution
--ref Run checks against any git ref files (example HEAD or <commit_sha>) instead of running against staged ones
`,
},
}
Expand Down
11 changes: 11 additions & 0 deletions test/scripts/checks/commit/commit.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/usr/bin/env bash

source src/dev/ci_setup/setup_env.sh

# Runs pre-commit hook script for the files touched in the last commit.
# That way we can ensure a set of quick commit checks earlier as we removed
# the pre-commit hook installation by default.
# If files are more than 200 we will skip it and just use
# the further ci steps that already check linting and file casing for the entire repo.
checks-reporter-with-killswitch "Quick commit checks" \
"$(dirname "${0}")/commit_check_runner.sh"
13 changes: 13 additions & 0 deletions test/scripts/checks/commit/commit_check_runner.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/usr/bin/env bash

run_quick_commit_checks() {
echo "!!!!!!!! ATTENTION !!!!!!!!
That check is intended to provide earlier CI feedback after we remove the automatic install for the local pre-commit hook.
If you want, you can still manually install the pre-commit hook locally by running 'node scripts/register_git_hook locally'
!!!!!!!!!!!!!!!!!!!!!!!!!!!
"

node scripts/precommit_hook.js --ref HEAD~1..HEAD --max-files 200 --verbose
}

run_quick_commit_checks
1 change: 1 addition & 0 deletions vars/tasks.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ def call(List<Closure> closures) {

def check() {
tasks([
kibanaPipeline.scriptTask('Quick Commit Checks', 'test/scripts/checks/commit/commit.sh'),
kibanaPipeline.scriptTask('Check Telemetry Schema', 'test/scripts/checks/telemetry.sh'),
kibanaPipeline.scriptTask('Check TypeScript Projects', 'test/scripts/checks/ts_projects.sh'),
kibanaPipeline.scriptTask('Check Jest Configs', 'test/scripts/checks/jest_configs.sh'),
Expand Down
4 changes: 4 additions & 0 deletions x-pack/examples/alerting_example/server/alert_types/astros.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ export const alertType: AlertType = {
name: 'People In Space Right Now',
actionGroups: [{ id: 'default', name: 'default' }],
defaultActionGroupId: 'default',
recoveryActionGroup: {
id: 'hasLandedBackOnEarth',
name: 'Has landed back on Earth',
},
async executor({ services, params }) {
const { outerSpaceCapacity, craft: craftToTriggerBy, op } = params;

Expand Down
1 change: 1 addition & 0 deletions x-pack/plugins/alerts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ The following table describes the properties of the `options` object.
|name|A user-friendly name for the alert type. These will be displayed in dropdowns when choosing alert types.|string|
|actionGroups|An explicit list of groups the alert type may schedule actions for, each specifying the ActionGroup's unique ID and human readable name. Alert `actions` validation will use this configuartion to ensure groups are valid. We highly encourage using `kbn-i18n` to translate the names of actionGroup when registering the AlertType. |Array<{id:string, name:string}>|
|defaultActionGroupId|Default ID value for the group of the alert type.|string|
|recoveryActionGroup|An action group to use when an alert instance goes from an active state, to an inactive one. This action group should not be specified under the `actionGroups` property. If no recoveryActionGroup is specified, the default `recovered` action group will be used. |{id:string, name:string}|
|actionVariables|An explicit list of action variables the alert type makes available via context and state in action parameter templates, and a short human readable description. Alert UI will use this to display prompts for the users for these variables, in action parameter editors. We highly encourage using `kbn-i18n` to translate the descriptions. |{ context: Array<{name:string, description:string}, state: Array<{name:string, description:string}>|
|validate.params|When developing an alert type, you can choose to accept a series of parameters. You may also have the parameters validated before they are passed to the `executor` function or created as an alert saved object. In order to do this, provide a `@kbn/config-schema` schema that we will use to validate the `params` attribute.|@kbn/config-schema|
|executor|This is where the code of the alert type lives. This is a function to be called when executing an alert on an interval basis. For full details, see executor section below.|Function|
Expand Down
1 change: 1 addition & 0 deletions x-pack/plugins/alerts/common/alert_type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export interface AlertType {
id: string;
name: string;
actionGroups: ActionGroup[];
recoveryActionGroup: ActionGroup;
actionVariables: string[];
defaultActionGroupId: ActionGroup['id'];
producer: string;
Expand Down
6 changes: 3 additions & 3 deletions x-pack/plugins/alerts/common/builtin_action_groups.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
import { i18n } from '@kbn/i18n';
import { ActionGroup } from './alert_type';

export const RecoveredActionGroup: ActionGroup = {
export const RecoveredActionGroup: Readonly<ActionGroup> = {
id: 'recovered',
name: i18n.translate('xpack.alerts.builtinActionGroups.recovered', {
defaultMessage: 'Recovered',
}),
};

export function getBuiltinActionGroups(): ActionGroup[] {
return [RecoveredActionGroup];
export function getBuiltinActionGroups(customRecoveryGroup?: ActionGroup): ActionGroup[] {
return [customRecoveryGroup ?? Object.freeze(RecoveredActionGroup)];
}
6 changes: 5 additions & 1 deletion x-pack/plugins/alerts/public/alert_api.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { AlertType } from '../common';
import { AlertType, RecoveredActionGroup } from '../common';
import { httpServiceMock } from '../../../../src/core/public/mocks';
import { loadAlert, loadAlertType, loadAlertTypes } from './alert_api';
import uuid from 'uuid';
Expand All @@ -22,6 +22,7 @@ describe('loadAlertTypes', () => {
actionVariables: ['var1'],
actionGroups: [{ id: 'default', name: 'Default' }],
defaultActionGroupId: 'default',
recoveryActionGroup: RecoveredActionGroup,
producer: 'alerts',
},
];
Expand All @@ -45,6 +46,7 @@ describe('loadAlertType', () => {
actionVariables: ['var1'],
actionGroups: [{ id: 'default', name: 'Default' }],
defaultActionGroupId: 'default',
recoveryActionGroup: RecoveredActionGroup,
producer: 'alerts',
};
http.get.mockResolvedValueOnce([alertType]);
Expand All @@ -65,6 +67,7 @@ describe('loadAlertType', () => {
actionVariables: [],
actionGroups: [{ id: 'default', name: 'Default' }],
defaultActionGroupId: 'default',
recoveryActionGroup: RecoveredActionGroup,
producer: 'alerts',
};
http.get.mockResolvedValueOnce([alertType]);
Expand All @@ -80,6 +83,7 @@ describe('loadAlertType', () => {
actionVariables: [],
actionGroups: [{ id: 'default', name: 'Default' }],
defaultActionGroupId: 'default',
recoveryActionGroup: RecoveredActionGroup,
producer: 'alerts',
},
]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/

import { AlertNavigationRegistry } from './alert_navigation_registry';
import { AlertType, SanitizedAlert } from '../../common';
import { AlertType, RecoveredActionGroup, SanitizedAlert } from '../../common';
import uuid from 'uuid';

beforeEach(() => jest.resetAllMocks());
Expand All @@ -14,6 +14,7 @@ const mockAlertType = (id: string): AlertType => ({
id,
name: id,
actionGroups: [],
recoveryActionGroup: RecoveredActionGroup,
actionVariables: [],
defaultActionGroupId: 'default',
producer: 'alerts',
Expand Down
73 changes: 73 additions & 0 deletions x-pack/plugins/alerts/server/alert_type_registry.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,71 @@ describe('register()', () => {
);
});

test('allows an AlertType to specify a custom recovery group', () => {
const alertType = {
id: 'test',
name: 'Test',
actionGroups: [
{
id: 'default',
name: 'Default',
},
],
defaultActionGroupId: 'default',
recoveryActionGroup: {
id: 'backToAwesome',
name: 'Back To Awesome',
},
executor: jest.fn(),
producer: 'alerts',
};
const registry = new AlertTypeRegistry(alertTypeRegistryParams);
registry.register(alertType);
expect(registry.get('test').actionGroups).toMatchInlineSnapshot(`
Array [
Object {
"id": "default",
"name": "Default",
},
Object {
"id": "backToAwesome",
"name": "Back To Awesome",
},
]
`);
});

test('throws if the custom recovery group is contained in the AlertType action groups', () => {
const alertType = {
id: 'test',
name: 'Test',
actionGroups: [
{
id: 'default',
name: 'Default',
},
{
id: 'backToAwesome',
name: 'Back To Awesome',
},
],
recoveryActionGroup: {
id: 'backToAwesome',
name: 'Back To Awesome',
},
defaultActionGroupId: 'default',
executor: jest.fn(),
producer: 'alerts',
};
const registry = new AlertTypeRegistry(alertTypeRegistryParams);

expect(() => registry.register(alertType)).toThrowError(
new Error(
`Alert type [id="${alertType.id}"] cannot be registered. Action group [backToAwesome] cannot be used as both a recovery and an active action group.`
)
);
});

test('registers the executor with the task manager', () => {
const alertType = {
id: 'test',
Expand Down Expand Up @@ -243,6 +308,10 @@ describe('get()', () => {
"id": "test",
"name": "Test",
"producer": "alerts",
"recoveryActionGroup": Object {
"id": "recovered",
"name": "Recovered",
},
}
`);
});
Expand Down Expand Up @@ -300,6 +369,10 @@ describe('list()', () => {
"id": "test",
"name": "Test",
"producer": "alerts",
"recoveryActionGroup": Object {
"id": "recovered",
"name": "Recovered",
},
},
}
`);
Expand Down
Loading

0 comments on commit d03bfdb

Please sign in to comment.