Skip to content

Commit

Permalink
Merge branch 'main' into security/frequency-integration/per-action-fr…
Browse files Browse the repository at this point in the history
…equency-UI
  • Loading branch information
kibanamachine authored Apr 11, 2023
2 parents ac0a2d3 + e29265e commit 949df36
Show file tree
Hide file tree
Showing 77 changed files with 1,580 additions and 427 deletions.
8 changes: 4 additions & 4 deletions .buildkite/scripts/steps/artifacts/docker_image.sh
Original file line number Diff line number Diff line change
Expand Up @@ -76,19 +76,19 @@ buildkite-agent artifact upload "kibana-$BASE_VERSION-docker-image-aarch64.tar.g
buildkite-agent artifact upload "dependencies-$GIT_ABBREV_COMMIT.csv"
cd -

# This part is related with updating the configuration of kibana-controller,
# so that new stack instances contain the latest and greatest image of kibana,
# and the respective stack components of course.
echo "--- Trigger image tag update"
if [[ "$BUILDKITE_BRANCH" == "$KIBANA_BASE_BRANCH" ]]; then

cat << EOF | buildkite-agent pipeline upload
steps:
- trigger: k8s-gitops-update-image-tag
- trigger: serverless-gitops-update-stack-image-tag
async: true
label: ":argo: Update image tag for Kibana"
branches: main
build:
env:
MODE: sed
TARGET_FILE: kibana-controller.yaml
IMAGE_TAG: "git-$GIT_ABBREV_COMMIT"
SERVICE: kibana-controller
NAMESPACE: kibana-ci
Expand Down
27 changes: 27 additions & 0 deletions src/plugins/vis_types/timeseries/common/empty_label.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* 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 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

import { getValueOrEmpty } from './empty_label';

describe('getValueOrEmpty', () => {
test('returns the value if not empty or slash value given', () => {
expect(getValueOrEmpty('/test/blog')).toEqual('/test/blog');
});

test('returns (empty) if value is slash', () => {
expect(getValueOrEmpty('/')).toEqual('(empty)');
});

test('returns (empty) if value is empty', () => {
expect(getValueOrEmpty('')).toEqual('(empty)');
});

test('returns (empty) if value is null', () => {
expect(getValueOrEmpty(null)).toEqual('(empty)');
});
});
2 changes: 1 addition & 1 deletion src/plugins/vis_types/timeseries/common/empty_label.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export const emptyLabel = i18n.translate('visTypeTimeseries.emptyTextValue', {
});

export const getValueOrEmpty = (value: unknown) => {
if (value === '' || value === null || value === undefined) {
if (value === '' || value === '/' || value === null || value === undefined) {
return emptyLabel;
}
return `${value}`;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,35 +31,39 @@ export const ChartComponent: FC<ChartComponentProps> = React.memo(({ annotation

const timeRange = useTimeRangeUpdates();
const { dataView } = useDataSource();
const { requestParams, bucketInterval } = useChangePointDetectionContext();
const { requestParams, bucketInterval, resultQuery, resultFilters } =
useChangePointDetectionContext();

const filters = useMemo(() => {
return annotation.group
? [
{
meta: {
index: dataView.id!,
alias: null,
negate: false,
disabled: false,
type: 'phrase',
key: annotation.group.name,
params: {
query: annotation.group.value,
return [
...resultFilters,
...(annotation.group
? [
{
meta: {
index: dataView.id!,
alias: null,
negate: false,
disabled: false,
type: 'phrase',
key: annotation.group.name,
params: {
query: annotation.group.value,
},
},
},
query: {
match_phrase: {
[annotation.group.name]: annotation.group.value,
query: {
match_phrase: {
[annotation.group.name]: annotation.group.value,
},
},
$state: {
store: FilterStateStore.APP_STATE,
},
},
$state: {
store: FilterStateStore.APP_STATE,
},
},
]
: [];
}, [dataView.id, annotation.group]);
]
: []),
];
}, [dataView.id, annotation.group, resultFilters]);

// @ts-ignore incorrect types for attributes
const attributes = useMemo<TypedLensByValueInput['attributes']>(() => {
Expand Down Expand Up @@ -151,10 +155,7 @@ export const ChartComponent: FC<ChartComponentProps> = React.memo(({ annotation
: []),
],
},
query: {
query: '',
language: 'kuery',
},
query: resultQuery,
filters,
datasourceStates: {
formBased: {
Expand Down Expand Up @@ -202,13 +203,26 @@ export const ChartComponent: FC<ChartComponentProps> = React.memo(({ annotation
adHocDataViews: {},
},
};
}, [dataView.id, dataView.timeFieldName, annotation, requestParams, filters, bucketInterval]);
}, [
annotation.group?.value,
annotation.timestamp,
annotation.label,
dataView.id,
dataView.timeFieldName,
resultQuery,
filters,
bucketInterval.expression,
requestParams.fn,
requestParams.metricField,
]);

return (
<EmbeddableComponent
id={`changePointChart_${annotation.group ? annotation.group.value : annotation.label}`}
style={{ height: 350 }}
timeRange={timeRange}
query={resultQuery}
filters={filters}
attributes={attributes}
renderMode={'view'}
executionContext={{
Expand Down
1 change: 1 addition & 0 deletions x-pack/plugins/ml/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
scripts/apidoc_scripts/ML_API.mdx
scripts/apidoc_scripts/ml_kibana_api.mdx
scripts/apidoc_scripts/header.md
apidoc_config.json
5 changes: 3 additions & 2 deletions x-pack/plugins/ml/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"scripts": {
"generateHeader": "node scripts/apidoc_scripts/header_generator/index.js",
"generateApidocConfig": "node scripts/apidoc_scripts/apidoc_config/index.js",
"apiDocs": "yarn generateHeader && yarn generateApidocConfig && cd ./scripts/apidoc_scripts/ && ../../../../../node_modules/.bin/apidoc-markdown -i ../../server/routes -c ./apidoc_config.json -o ./ML_API.mdx --parse-workers apischema=./schema_worker/index.js --parse-parsers apischema=./schema_parser/index.js --parse-filters apiversion=./version_filter/index.js --header ./header.md --template ./template.md"
"generateContentPage": "node scripts/apidoc_scripts/content_page/index.js",
"apiDocs": "yarn generateContentPage && yarn generateHeader && yarn generateApidocConfig && cd ./scripts/apidoc_scripts/ && ../../../../../node_modules/.bin/apidoc-markdown -i ../../server/routes -c ./apidoc_config.json -o ./ML_API.mdx --parse-workers apischema=./schema_worker/index.js --parse-parsers apischema=./schema_parser/index.js --parse-filters apiversion=./version_filter/index.js --header ./header.md --template ./template.md"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/*
* 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 * as fs from 'fs';
import * as path from 'path';
// @ts-ignore can only be default-imported using the 'esModuleInterop' flag
import moment from 'moment';
import { kibanaPackageJson } from '@kbn/repo-info';
// eslint-disable-next-line import/no-extraneous-dependencies
import { createDoc } from 'apidoc-light';

interface Group {
anchor: string;
text: string;
}

const getContent = (groups: Group[]) => {
const groupsStr = groups
.map(({ anchor, text }) => `- <DocLink id="uiMlApi" section="${anchor}" text="${text} API" />`)
.join('\n');

return `---
id: uiMlKibanaRestApi
slug: /ml-team/docs/ui/rest-api/ml-kibana-rest-api
title: Machine Learning Kibana REST API
image: https://source.unsplash.com/400x175/?Nature
description: This page contains documentation for the ML Kibana REST API.
date: ${moment().format('YYYY-MM-DD')}
tags: ['machine learning','internal docs', 'UI']
---
_Updated for ${kibanaPackageJson.version}_
Some of the features of the Machine Learning (ML) Kibana plugin are provided via a REST API, which is ideal for creating an integration with the ML plugin.
Each API is experimental and can include breaking changes in any version of the ML plugin, or might have been entirely removed from the plugin.
- <DocLink id="uiMlApi" text="View complete API documentation" />
The following APIs are available:
${groupsStr}
`;
};

export const generateContentPage = () => {
const doc = createDoc({
src: path.resolve(__dirname, '..', '..', '..', 'server', 'routes'),
config: path.resolve(__dirname, '..', 'apidoc_config', 'apidoc.json'),
// if you don't want to generate the output files:
dryRun: true,
// if you don't want to see any log output:
silent: true,
});

const groups = [...new Set(doc.data.map((v) => v.group))].map((group) => {
return {
anchor: `-${group.toLowerCase()}`,
text: group.replace(/([a-z])([A-Z])/g, '$1 $2'),
};
});

fs.writeFileSync(path.resolve(__dirname, '..', 'ml_kibana_api.mdx'), getContent(groups));
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/*
* 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.
*/

require('../../../../../../src/setup_node_env');
require('./content_page').generateContentPage();
5 changes: 5 additions & 0 deletions x-pack/plugins/security_solution/common/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ export const DEFAULT_RULE_REFRESH_INTERVAL_VALUE = 60000 as const; // ms
export const DEFAULT_RULE_NOTIFICATION_QUERY_SIZE = 100 as const;
export const SECURITY_FEATURE_ID = 'Security' as const;
export const SECURITY_TAG_NAME = 'Security Solution' as const;
export const SECURITY_TAG_DESCRIPTION = 'Security Solution auto-generated tag' as const;
export const DEFAULT_SPACE_ID = 'default' as const;
export const DEFAULT_RELATIVE_DATE_THRESHOLD = 24 as const;

Expand Down Expand Up @@ -303,6 +304,10 @@ export const prebuiltSavedObjectsBulkCreateUrl = (templateName: string) =>
export const PREBUILT_SAVED_OBJECTS_BULK_DELETE = `${INTERNAL_RISK_SCORE_URL}/prebuilt_content/saved_objects/_bulk_delete/{template_name}`;
export const prebuiltSavedObjectsBulkDeleteUrl = (templateName: string) =>
`${INTERNAL_RISK_SCORE_URL}/prebuilt_content/saved_objects/_bulk_delete/${templateName}` as const;

export const INTERNAL_DASHBOARDS_URL = `/internal/dashboards` as const;
export const INTERNAL_TAGS_URL = `/internal/tags`;

export const RISK_SCORE_CREATE_INDEX = `${INTERNAL_RISK_SCORE_URL}/indices/create`;
export const RISK_SCORE_DELETE_INDICES = `${INTERNAL_RISK_SCORE_URL}/indices/delete`;
export const RISK_SCORE_CREATE_STORED_SCRIPT = `${INTERNAL_RISK_SCORE_URL}/stored_scripts/create`;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ import { cleanKibana } from '../../tasks/common';
import { login, visitWithoutDateRange } from '../../tasks/login';
import { DETECTIONS_RULE_MANAGEMENT_URL } from '../../urls/navigation';

describe('Rules selection', () => {
// TODO: See https://github.com/elastic/kibana/issues/154694
describe.skip('Rules selection', () => {
beforeEach(() => {
cleanKibana();
login();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ import { setRowsPerPageTo } from '../../tasks/table_pagination';

const DEFAULT_RULE_REFRESH_INTERVAL_VALUE = 60000;

describe('Alerts detection rules table auto-refresh', () => {
// TODO: See https://github.com/elastic/kibana/issues/154694
describe.skip('Alerts detection rules table auto-refresh', () => {
before(() => {
cleanKibana();
login();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/*
* 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 { MOCK_TAG_ID, DEFAULT_DASHBOARDS_RESPONSE } from '../api/__mocks__';

export const getSecurityTagIds = jest.fn().mockResolvedValue([MOCK_TAG_ID]);

export const getSecurityDashboards = jest.fn().mockResolvedValue(DEFAULT_DASHBOARDS_RESPONSE);
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* 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 { SECURITY_TAG_NAME, SECURITY_TAG_DESCRIPTION } from '../../../../../../common/constants';

export const MOCK_TAG_ID = 'securityTagId';

export const DEFAULT_TAGS_RESPONSE = [
{
id: MOCK_TAG_ID,
name: SECURITY_TAG_NAME,
description: SECURITY_TAG_DESCRIPTION,
color: '#2c7b82',
},
];

export const DEFAULT_DASHBOARDS_RESPONSE = [
{
type: 'dashboard',
id: 'c0ac2c00-c1c0-11e7-8995-936807a28b16-ecs',
namespaces: ['default'],
attributes: {
description: 'Summary of Linux kernel audit events.',
title: '[Auditbeat Auditd] Overview ECS',
version: 1,
},
references: [
{
name: 'tag-ref-ba964280-d211-11ed-890b-153ddf1a08e9',
id: 'ba964280-d211-11ed-890b-153ddf1a08e9',
type: 'tag',
},
],
coreMigrationVersion: '8.8.0',
typeMigrationVersion: '8.7.0',
updated_at: '2023-04-03T11:38:00.902Z',
created_at: '2023-04-03T11:20:50.603Z',
version: 'WzE4NzQsMV0=',
score: 0,
},
];

export const getSecuritySolutionTags = jest
.fn()
.mockImplementation(() => Promise.resolve(DEFAULT_TAGS_RESPONSE));

export const getSecuritySolutionDashboards = jest
.fn()
.mockImplementation(() => Promise.resolve(DEFAULT_DASHBOARDS_RESPONSE));
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* 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 type { HttpSetup } from '@kbn/core/public';
import type { Tag } from '@kbn/saved-objects-tagging-plugin/public';
import { INTERNAL_TAGS_URL, INTERNAL_DASHBOARDS_URL } from '../../../../../common/constants';
import type { DashboardTableItem } from '../types';

export const getSecuritySolutionTags = ({ http }: { http: HttpSetup }): Promise<Tag[] | null> =>
http.get(INTERNAL_TAGS_URL);

export const getSecuritySolutionDashboards = ({
http,
}: {
http: HttpSetup;
}): Promise<DashboardTableItem[] | null> => http.get(INTERNAL_DASHBOARDS_URL);
Loading

0 comments on commit 949df36

Please sign in to comment.