Skip to content

Commit

Permalink
Merge branch 'main' into fix/121063
Browse files Browse the repository at this point in the history
  • Loading branch information
kibanamachine authored Jan 3, 2022
2 parents 0b2ec90 + 87f753d commit dac9de7
Show file tree
Hide file tree
Showing 25 changed files with 634 additions and 23,436 deletions.
2 changes: 1 addition & 1 deletion NOTICE.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Kibana source code with Kibana X-Pack source code
Copyright 2012-2021 Elasticsearch B.V.
Copyright 2012-2022 Elasticsearch B.V.

---
Pretty handling of logarithmic axes.
Expand Down
14 changes: 10 additions & 4 deletions src/plugins/kibana_react/common/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,13 @@
* Side Public License, v 1.
*/

// TODO: https://github.com/elastic/kibana/issues/109898
/* eslint-disable @kbn/eslint/no_export_all */

export * from './eui_styled_components';
export type { EuiTheme } from './eui_styled_components';
export {
EuiThemeProviderDecorator,
css,
euiStyled,
EuiThemeProvider,
createGlobalStyle,
keyframes,
withTheme,
} from './eui_styled_components';
82 changes: 67 additions & 15 deletions src/plugins/kibana_react/public/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,80 @@
* Side Public License, v 1.
*/

// TODO: https://github.com/elastic/kibana/issues/109898
/* eslint-disable @kbn/eslint/no_export_all */

export * from './code_editor';
export * from './url_template_editor';
export * from './exit_full_screen_button';
export * from './context';
export * from './overview_page';
export * from './overlays';
export * from './ui_settings';
export * from './table_list_view';
export * from './toolbar_button';
export * from './react_router_navigate';
export * from './page_template';
export type { CodeEditorProps } from './code_editor';
export {
CssLang,
MarkdownLang,
YamlLang,
HandlebarsLang,
HJsonLang,
CodeEditor,
CodeEditorField,
} from './code_editor';

export type { UrlTemplateEditorVariable, UrlTemplateEditorProps } from './url_template_editor';
export { UrlTemplateEditor } from './url_template_editor';

export type { ExitFullScreenButtonProps } from './exit_full_screen_button';
export { ExitFullScreenButton } from './exit_full_screen_button';

export type { KibanaReactContext, KibanaReactContextValue, KibanaServices } from './context';
export {
context,
createKibanaReactContext,
KibanaContextProvider,
useKibana,
withKibana,
} from './context';

export { overviewPageActions, OverviewPageFooter } from './overview_page';

export type { KibanaReactOverlays } from './overlays';
export { createReactOverlays } from './overlays';

export { useUiSetting, useUiSetting$ } from './ui_settings';

export type { TableListViewProps, TableListViewState } from './table_list_view';
export { TableListView } from './table_list_view';

export type { ToolbarButtonProps } from './toolbar_button';
export { POSITIONS, WEIGHTS, TOOLBAR_BUTTON_SIZES, ToolbarButton } from './toolbar_button';

export { reactRouterNavigate, reactRouterOnClickHandler } from './react_router_navigate';

export type {
KibanaPageTemplateProps,
NoDataPageActions,
NoDataPageActionsProps,
NoDataPageProps,
ElasticAgentCardProps,
} from './page_template';
export {
KibanaPageTemplate,
KibanaPageTemplateSolutionNavAvatar,
NO_DATA_PAGE_MAX_WIDTH,
NO_DATA_PAGE_TEMPLATE_PROPS,
NO_DATA_RECOMMENDED,
NoDataPage,
ElasticAgentCard,
NoDataCard,
} from './page_template';

export type { Value } from './validated_range';
export { ValidatedDualRange } from './validated_range';
export * from './notifications';

export type { ToastInput, KibanaReactNotifications } from './notifications';
export { createNotifications } from './notifications';

export { Markdown, MarkdownSimple } from './markdown';

export { reactToUiComponent, uiToReactComponent } from './adapters';

export { toMountPoint, MountPointPortal } from './util';
export type { ToMountPointOptions } from './util';

export { RedirectAppLinks } from './app_links';

export { wrapWithTheme, KibanaThemeProvider } from './theme';

/** dummy plugin, we just want kibanaReact to have its own bundle */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export type TestSubjects =
| 'deleteTemplatesConfirmation'
| 'documentationLink'
| 'emptyPrompt'
| 'forcemergeIndexMenuButton'
| 'filterList.filterItem'
| 'ilmPolicyLink'
| 'includeStatsSwitch'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export interface IndicesTestBed extends TestBed<TestSubjects> {
clickDataStreamAt: (index: number) => void;
clickManageContextMenuButton: () => void;
clickContextMenuOption: (optionDataTestSubject: string) => void;
clickModalConfirm: () => void;
};
findDataStreamDetailPanel: () => ReactWrapper;
findDataStreamDetailPanelTitle: () => string;
Expand Down Expand Up @@ -97,6 +98,15 @@ export const setup = async (overridingDependencies: any = {}): Promise<IndicesTe
component.update();
};

const clickModalConfirm = async () => {
const { find, component } = testBed;

await act(async () => {
find('confirmModalConfirmButton').simulate('click');
});
component.update();
};

const findDataStreamDetailPanel = () => {
const { find } = testBed;
return find('dataStreamDetailPanel');
Expand All @@ -116,6 +126,7 @@ export const setup = async (overridingDependencies: any = {}): Promise<IndicesTe
clickDataStreamAt,
clickManageContextMenuButton,
clickContextMenuOption,
clickModalConfirm,
},
findDataStreamDetailPanel,
findDataStreamDetailPanelTitle,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ describe('<IndexManagementHome />', () => {

test("should be able to clear an index's cache", async () => {
const { actions } = testBed;
actions.clickManageContextMenuButton();
await actions.clickManageContextMenuButton();

await actions.clickManageContextMenuButton();
await actions.clickContextMenuOption('clearCacheIndexMenuButton');
Expand Down Expand Up @@ -291,6 +291,26 @@ describe('<IndexManagementHome />', () => {
// The unfreeze action should not be present anymore
expect(exists('unfreezeIndexMenuButton')).toBe(false);
});

test('should be able to force merge an index', async () => {
const { actions, exists } = testBed;

httpRequestsMockHelpers.setReloadIndicesResponse([{ ...indexMockA, isFrozen: false }]);

// Open context menu
await actions.clickManageContextMenuButton();
// Check that the force merge action exists for the current index and merge it
expect(exists('forcemergeIndexMenuButton')).toBe(true);
await actions.clickContextMenuOption('forcemergeIndexMenuButton');

await actions.clickModalConfirm();

const requestsCount = server.requests.length;
expect(server.requests[requestsCount - 2].url).toBe(`${API_BASE_PATH}/indices/forcemerge`);
// After the index is force merged, we immediately do a reload. So we need to expect to see
// a reload server call also.
expect(server.requests[requestsCount - 1].url).toBe(`${API_BASE_PATH}/indices/reload`);
});
});

describe('Edit index settings', () => {
Expand Down
16 changes: 10 additions & 6 deletions x-pack/plugins/monitoring/common/types/es.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export interface ElasticsearchSourceKibanaStats {
};
transport_address?: string;
host?: string;
version?: string;
};
os?: {
memory?: {
Expand Down Expand Up @@ -416,7 +417,9 @@ export interface ElasticsearchMetricbeatNode {
export interface ElasticsearchMetricbeatSource {
'@timestamp'?: string;
service?: {
id?: string;
address?: string;
version?: string;
};
elasticsearch?: {
node?: ElasticsearchLegacySource['source_node'] & ElasticsearchMetricbeatNode;
Expand Down Expand Up @@ -534,15 +537,16 @@ export interface ElasticsearchMetricbeatSource {
};
};
kibana?: {
kibana?: {
transport_address?: string;
stats?: {
name?: string;
host?: string;
uuid?: string;
index?: string;
status?: string;
};
stats?: {
transport_address?: string;
concurrent_connections?: number;
snapshot?: boolean;
host?: {
name?: string;
};
process?: {
uptime?: {
ms?: number;
Expand Down
35 changes: 35 additions & 0 deletions x-pack/plugins/monitoring/server/lib/kibana/build_kibana_info.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* 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 { ElasticsearchResponseHit } from '../../../common/types/es';

export interface KibanaInfo {
transport_address?: string;
name?: string;
index?: string;
host?: string;
uuid?: string;
status?: string;
snapshot?: boolean;
version?: string;
}

export const buildKibanaInfo = (hit: ElasticsearchResponseHit): KibanaInfo => {
const source = hit._source;
if (source.kibana_stats) return source.kibana_stats.kibana as KibanaInfo;

return {
name: source.kibana?.stats?.name,
host: source.kibana?.stats?.host?.name,
status: source.kibana?.stats?.status,
transport_address: source.kibana?.stats?.transport_address,
uuid: source.service?.id,
snapshot: source.kibana?.stats?.snapshot,
index: source.kibana?.stats?.index,
version: source.service?.version,
};
};
17 changes: 10 additions & 7 deletions x-pack/plugins/monitoring/server/lib/kibana/get_kibana_info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,18 @@ import { checkParam, MissingRequiredError } from '../error_missing_required';
import { calculateAvailability } from '../calculate_availability';
import { LegacyRequest } from '../../types';
import { ElasticsearchResponse } from '../../../common/types/es';
import { buildKibanaInfo } from './build_kibana_info';

export function handleResponse(resp: ElasticsearchResponse) {
const legacySource = resp.hits?.hits[0]?._source.kibana_stats;
const mbSource = resp.hits?.hits[0]?._source.kibana?.stats;
const kibana = resp.hits?.hits[0]?._source.kibana?.kibana ?? legacySource?.kibana;
const availabilityTimestamp =
resp.hits?.hits[0]?._source['@timestamp'] ?? legacySource?.timestamp;
const hit = resp.hits?.hits[0];
const legacySource = hit?._source.kibana_stats;
const mbSource = hit?._source.kibana?.stats;
const availabilityTimestamp = hit?._source['@timestamp'] ?? legacySource?.timestamp;
if (!availabilityTimestamp) {
throw new MissingRequiredError('timestamp');
}
return merge(kibana, {

return merge(buildKibanaInfo(hit!), {
availability: calculateAvailability(availabilityTimestamp),
os_memory_free: mbSource?.os?.memory?.free_in_bytes ?? legacySource?.os?.memory?.free_in_bytes,
uptime: mbSource?.process?.uptime?.ms ?? legacySource?.process?.uptime_in_millis,
Expand All @@ -42,13 +43,15 @@ export function getKibanaInfo(
ignore_unavailable: true,
filter_path: [
'hits.hits._source.kibana_stats.kibana',
'hits.hits._source.kibana.kibana',
'hits.hits._source.kibana.stats',
'hits.hits._source.kibana_stats.os.memory.free_in_bytes',
'hits.hits._source.kibana.stats.os.memory.free_in_bytes',
'hits.hits._source.kibana_stats.process.uptime_in_millis',
'hits.hits._source.kibana.stats.process.uptime.ms',
'hits.hits._source.kibana_stats.timestamp',
'hits.hits._source.@timestamp',
'hits.hits._source.service.id',
'hits.hits._source.service.version',
],
body: {
query: {
Expand Down
25 changes: 10 additions & 15 deletions x-pack/plugins/monitoring/server/lib/kibana/get_kibanas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ import { calculateAvailability } from '../calculate_availability';
// @ts-ignore
import { KibanaMetric } from '../metrics';
import { LegacyRequest } from '../../types';
import { ElasticsearchResponse } from '../../../common/types/es';
import { ElasticsearchResponse, ElasticsearchResponseHit } from '../../../common/types/es';
import { KibanaInfo, buildKibanaInfo } from './build_kibana_info';

interface Kibana {
process?: {
Expand All @@ -36,13 +37,7 @@ interface Kibana {
total?: number;
};
concurrent_connections?: number;
kibana?: {
transport_address?: string;
name?: string;
host?: string;
uuid?: string;
status?: string;
};
kibana?: KibanaInfo;
availability: boolean;
}

Expand Down Expand Up @@ -98,15 +93,15 @@ export async function getKibanas(
'kibana_stats.requests.total',
'kibana.stats.request.total',
'kibana_stats.kibana.transport_address',
'kibana.kibana.transport_address',
'kibana.stats.transport_address',
'kibana_stats.kibana.name',
'kibana.kibana.name',
'kibana.stats.name',
'kibana_stats.kibana.host',
'kibana.kibana.host',
'kibana.stats.host.name',
'kibana_stats.kibana.uuid',
'kibana.kibana.uuid',
'service.id',
'kibana_stats.kibana.status',
'kibana.kibana.status',
'kibana.stats.status',
'kibana_stats.concurrent_connections',
'kibana.stats.concurrent_connections',
],
Expand All @@ -117,12 +112,12 @@ export async function getKibanas(
const response: ElasticsearchResponse = await callWithRequest(req, 'search', params);
const instances = response.hits?.hits ?? [];

return instances.map((hit) => {
return instances.map((hit: ElasticsearchResponseHit) => {
const legacyStats = hit._source.kibana_stats;
const mbStats = hit._source.kibana?.stats;

const kibana: Kibana = {
kibana: hit._source.kibana?.kibana ?? legacyStats?.kibana,
kibana: buildKibanaInfo(hit),
concurrent_connections:
mbStats?.concurrent_connections ?? legacyStats?.concurrent_connections,
process: {
Expand Down
Loading

0 comments on commit dac9de7

Please sign in to comment.