Skip to content

Commit

Permalink
Merge branch 'main' into ELS-168
Browse files Browse the repository at this point in the history
  • Loading branch information
kibanamachine authored Aug 21, 2023
2 parents ef9f9c7 + b5af8c8 commit d87f482
Show file tree
Hide file tree
Showing 46 changed files with 585 additions and 668 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,14 @@ import { EuiEmptyPrompt } from '@elastic/eui';
interface Props {
title: React.ReactNode;
message: React.ReactNode | string;
dataTestSubj?: string;
}

export const NotAuthorizedSection = ({ title, message }: Props) => (
<EuiEmptyPrompt iconType="securityApp" title={<h2>{title}</h2>} body={<p>{message}</p>} />
export const NotAuthorizedSection = ({ title, message, dataTestSubj }: Props) => (
<EuiEmptyPrompt
iconType="securityApp"
data-test-subj={dataTestSubj ? dataTestSubj : 'notAuthorizedSection'}
title={<h2>{title}</h2>}
body={<p>{message}</p>}
/>
);
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,7 @@ const IndexPropertiesComponent: React.FC<Props> = ({
errorCount: error ? 1 : 0,
ilmPhase,
indexId,
indexName,
isCheckAll: false,
numberOfDocuments: docsCount,
numberOfIncompatibleFields: indexIncompatible,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ export type DataQualityIndexCheckedParams = DataQualityCheckAllCompletedParams &
errorCount?: number;
ilmPhase?: string;
indexId: string;
indexName: string;
unallowedMappingFields?: string[];
unallowedValueFields?: string[];
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ export const useResultsRollup = ({ ilmPhases, patterns }: Props): UseResultsRoll
errorCount: error ? 1 : 0,
ilmPhase: getIlmPhase(ilmExplain[indexName]),
indexId,
indexName,
isCheckAll: true,
numberOfDocuments: getDocsCount({ indexName, stats: updated[pattern].stats }),
numberOfIncompatibleFields: getIndexIncompatible({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export function DiagnosticsIndices() {
return <EuiLoadingElastic size="m" />;
}

const { invalidIndices, validIndices } = diagnosticsBundle;
const { invalidIndices = [], validIndices = [] } = diagnosticsBundle;
const columns: Array<EuiBasicTableColumn<IndiciesItem>> = [
{
field: 'index',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import React from 'react';
import { EuiLink } from '@elastic/eui';
import { isEmpty } from 'lodash';
import { useApmParams } from '../../../../hooks/use_apm_params';
import { FETCH_STATUS } from '../../../../hooks/use_fetcher';
import { APIReturnType } from '../../../../services/rest/create_call_apm_api';
Expand Down Expand Up @@ -45,5 +46,5 @@ export function getIsIndicesTabOk(diagnosticsBundle?: DiagnosticsBundle) {
return true;
}

return diagnosticsBundle.invalidIndices.length === 0;
return isEmpty(diagnosticsBundle.invalidIndices);
}
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@ async function handleInvalidIndexTemplateException<T>(promise: Promise<T>) {
return [];
}

throw error;
console.error(`Suppressed unknown exception: ${error.message}`);

return [];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*/

import { ElasticsearchClient } from '@kbn/core-elasticsearch-server';
import { NOT_AVAILABLE_LABEL } from '../../../common/i18n';
import { ApmIndicesConfig } from '../settings/apm_indices/get_apm_indices';
import { getDataStreams } from './bundle/get_data_streams';
import { getNonDataStreamIndices } from './bundle/get_non_data_stream_indices';
Expand All @@ -15,7 +16,7 @@ import { getExistingApmIndexTemplates } from './bundle/get_existing_index_templa
import { getIndicesStates } from './bundle/get_indices_states';
import { getApmEvents } from './bundle/get_apm_events';
import { getApmIndexTemplates } from './helpers/get_apm_index_template_names';
import { handle403Exception } from './helpers/handle_403_exception';
import { handleExceptions } from './helpers/handle_exceptions';
import { getDiagnosticsPrivileges } from './helpers/get_diagnostic_privileges';

const DEFEAULT_START = Date.now() - 60 * 5 * 1000; // 5 minutes
Expand All @@ -39,62 +40,54 @@ export async function getDiagnosticsBundle({
apmIndices,
});

const indexTemplatesByIndexPattern = await handle403Exception(
getIndexTemplatesByIndexPattern({
esClient,
apmIndices,
}),
[]
);
const indexTemplatesByIndexPattern =
(await handleExceptions(
getIndexTemplatesByIndexPattern({
esClient,
apmIndices,
})
)) ?? [];

const existingIndexTemplates = await handle403Exception(
getExistingApmIndexTemplates({
esClient,
}),
[]
);
const existingIndexTemplates =
(await handleExceptions(
getExistingApmIndexTemplates({
esClient,
})
)) ?? [];

const dataStreams = await handle403Exception(
getDataStreams({ esClient, apmIndices }),
[]
);
const nonDataStreamIndices = await handle403Exception(
getNonDataStreamIndices({
esClient,
apmIndices,
}),
[]
);
const dataStreams =
(await handleExceptions(getDataStreams({ esClient, apmIndices }))) ?? [];

const nonDataStreamIndices =
(await handleExceptions(
getNonDataStreamIndices({
esClient,
apmIndices,
})
)) ?? [];

const { invalidIndices, validIndices, indices, ingestPipelines, fieldCaps } =
await handle403Exception(
(await handleExceptions(
getIndicesStates({
esClient,
apmIndices,
}),
{
invalidIndices: [],
validIndices: [],
indices: [],
ingestPipelines: [],
fieldCaps: {},
}
);
})
)) ?? {};

const apmEvents =
(await handleExceptions(
getApmEvents({
esClient,
apmIndices,
start,
end,
kuery,
})
)) ?? [];

const apmEvents = await handle403Exception(
getApmEvents({
esClient,
apmIndices,
start,
end,
kuery,
}),
[]
);
const elasticsearchVersion = await handle403Exception(
getElasticsearchVersion(esClient),
'N/A'
);
const elasticsearchVersion =
(await handleExceptions(getElasticsearchVersion(esClient))) ??
NOT_AVAILABLE_LABEL;

return {
created_at: new Date().toISOString(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@
*/
import { errors } from '@elastic/elasticsearch';

export async function handle403Exception<T>(
promise: Promise<T>,
defaultValue: unknown
) {
export async function handleExceptions<T>(promise: Promise<T>) {
try {
return await promise;
} catch (error) {
Expand All @@ -18,13 +15,13 @@ export async function handle403Exception<T>(
error.meta.statusCode === 403
) {
console.error(`Suppressed insufficient access error: ${error.message}}`);
return defaultValue as T;
return;
}

console.error(
`Unhandled error: ${error.message} ${JSON.stringify(error)}}`
);

throw error;
return;
}
}
10 changes: 5 additions & 5 deletions x-pack/plugins/apm/server/routes/diagnostics/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ const getDiagnosticsRoute = createApmServerRoute({
): Promise<{
esResponses: {
existingIndexTemplates: IndicesGetIndexTemplateIndexTemplateItem[];
fieldCaps: FieldCapsResponse;
indices: IndicesGetResponse;
ingestPipelines: IngestGetPipelineResponse;
fieldCaps?: FieldCapsResponse;
indices?: IndicesGetResponse;
ingestPipelines?: IngestGetPipelineResponse;
};
diagnosticsPrivileges: {
index: Record<string, SecurityHasPrivilegesPrivileges>;
Expand All @@ -77,8 +77,8 @@ const getDiagnosticsRoute = createApmServerRoute({
kibanaVersion: string;
elasticsearchVersion: string;
apmEvents: ApmEvent[];
invalidIndices: IndiciesItem[];
validIndices: IndiciesItem[];
invalidIndices?: IndiciesItem[];
validIndices?: IndiciesItem[];
dataStreams: IndicesDataStream[];
nonDataStreamIndices: string[];
indexTemplatesByIndexPattern: Array<{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,14 @@ import { i18n } from '@kbn/i18n';

interface Props {
isAutoRefreshing: boolean;
dataTestSubj?: string;
disabled?: boolean;
onClick: () => void;
}

export function AutoRefreshButton({
dataTestSubj = 'autoRefreshButton',
disabled,
isAutoRefreshing,
onClick,
}: Props) {
export function AutoRefreshButton({ disabled, isAutoRefreshing, onClick }: Props) {
return isAutoRefreshing ? (
<EuiButtonEmpty
data-test-subj={dataTestSubj}
data-test-subj="autoRefreshButton"
disabled={disabled}
iconSide="left"
iconType="pause"
Expand All @@ -35,7 +29,7 @@ export function AutoRefreshButton({
</EuiButtonEmpty>
) : (
<EuiButtonEmpty
data-test-subj={dataTestSubj}
data-test-subj="autoRefreshButton"
disabled={disabled}
iconSide="left"
iconType="play"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* 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.
*/
const AUTO_REFRESH_STORAGE_KEY = 'slo.auto_refresh';

export function useAutoRefreshStorage(): {
storeAutoRefreshState: (newValue: boolean) => void;
getAutoRefreshState: () => boolean;
} {
if (!localStorage) {
return { storeAutoRefreshState: () => {}, getAutoRefreshState: () => true };
}

return {
storeAutoRefreshState: (newValue: boolean) => {
localStorage.setItem(AUTO_REFRESH_STORAGE_KEY, JSON.stringify(newValue));
},

getAutoRefreshState: () => {
const value = localStorage.getItem(AUTO_REFRESH_STORAGE_KEY);
if (value === null) return true;

return Boolean(JSON.parse(value));
},
};
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/*
* 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.
*/

export * from './auto_refresh_button';
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,10 @@ import { HeaderTitle } from './components/header_title';
import { HeaderControl } from './components/header_control';
import { paths } from '../../../common/locators/paths';
import type { SloDetailsPathParams } from './types';
import { AutoRefreshButton } from '../slos/components/auto_refresh_button';
import { AutoRefreshButton } from '../../components/slo/auto_refresh_button';
import { FeedbackButton } from '../../components/slo/feedback_button/feedback_button';
import { useGetInstanceIdQueryParam } from './hooks/use_get_instance_id_query_param';
import { useAutoRefreshStorage } from '../../components/slo/auto_refresh_button/hooks/use_auto_refresh_storage';
import { HeaderMenu } from '../overview/components/header_menu/header_menu';

export function SloDetailsPage() {
Expand All @@ -42,7 +43,8 @@ export function SloDetailsPage() {

const { sloId } = useParams<SloDetailsPathParams>();
const sloInstanceId = useGetInstanceIdQueryParam();
const [isAutoRefreshing, setIsAutoRefreshing] = useState(true);
const { storeAutoRefreshState, getAutoRefreshState } = useAutoRefreshStorage();
const [isAutoRefreshing, setIsAutoRefreshing] = useState(getAutoRefreshState());
const { isLoading, slo } = useFetchSloDetails({
sloId,
instanceId: sloInstanceId,
Expand All @@ -65,6 +67,7 @@ export function SloDetailsPage() {

const handleToggleAutoRefresh = () => {
setIsAutoRefreshing(!isAutoRefreshing);
storeAutoRefreshState(!isAutoRefreshing);
};

return (
Expand Down
7 changes: 5 additions & 2 deletions x-pack/plugins/observability/public/pages/slos/slos.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@ import { useLicense } from '../../hooks/use_license';
import { useCapabilities } from '../../hooks/slo/use_capabilities';
import { useFetchSloList } from '../../hooks/slo/use_fetch_slo_list';
import { SloList } from './components/slo_list';
import { AutoRefreshButton } from './components/auto_refresh_button';
import { AutoRefreshButton } from '../../components/slo/auto_refresh_button';
import { HeaderTitle } from './components/header_title';
import { FeedbackButton } from '../../components/slo/feedback_button/feedback_button';
import { paths } from '../../../common/locators/paths';
import { useAutoRefreshStorage } from '../../components/slo/auto_refresh_button/hooks/use_auto_refresh_storage';
import { HeaderMenu } from '../overview/components/header_menu/header_menu';

export function SlosPage() {
Expand All @@ -34,7 +35,8 @@ export function SlosPage() {
const { isInitialLoading, isLoading, isError, sloList } = useFetchSloList();
const { total } = sloList || { total: 0 };

const [isAutoRefreshing, setIsAutoRefreshing] = useState<boolean>(true);
const { storeAutoRefreshState, getAutoRefreshState } = useAutoRefreshStorage();
const [isAutoRefreshing, setIsAutoRefreshing] = useState<boolean>(getAutoRefreshState());

useBreadcrumbs([
{
Expand All @@ -57,6 +59,7 @@ export function SlosPage() {

const handleToggleAutoRefresh = () => {
setIsAutoRefreshing(!isAutoRefreshing);
storeAutoRefreshState(!isAutoRefreshing);
};

if (isInitialLoading) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ export function getSessionIndexSettings({
number_of_replicas: 0,
auto_expand_replicas: '0-1',
priority: 1000,
refresh_interval: '1s',
hidden: true,
},
aliases: {
Expand Down
Loading

0 comments on commit d87f482

Please sign in to comment.