Skip to content

Commit

Permalink
Merge branch 'master' into feat/input_control_renderer
Browse files Browse the repository at this point in the history
  • Loading branch information
kibanamachine committed Nov 30, 2020
2 parents 8d8af00 + bdf7b88 commit 90caae9
Show file tree
Hide file tree
Showing 46 changed files with 683 additions and 306 deletions.
3 changes: 2 additions & 1 deletion test/api_integration/apis/saved_objects/migrations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ function getLogMock() {
export default ({ getService }: FtrProviderContext) => {
const esClient = getService('es');

describe('Kibana index migration', () => {
// FLAKY: https://github.com/elastic/kibana/issues/84445
describe.skip('Kibana index migration', () => {
before(() => esClient.indices.delete({ index: '.migrate-*' }));

it('Migrates an existing index that has never been migrated before', async () => {
Expand Down
66 changes: 1 addition & 65 deletions x-pack/plugins/alerts/public/alert_api.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import { AlertType } from '../common';
import { httpServiceMock } from '../../../../src/core/public/mocks';
import { loadAlert, loadAlertState, loadAlertType, loadAlertTypes } from './alert_api';
import { loadAlert, loadAlertType, loadAlertTypes } from './alert_api';
import uuid from 'uuid';

const http = httpServiceMock.createStartContract();
Expand Down Expand Up @@ -114,67 +114,3 @@ describe('loadAlert', () => {
expect(http.get).toHaveBeenCalledWith(`/api/alerts/alert/${alertId}`);
});
});

describe('loadAlertState', () => {
test('should call get API with base parameters', async () => {
const alertId = uuid.v4();
const resolvedValue = {
alertTypeState: {
some: 'value',
},
alertInstances: {
first_instance: {},
second_instance: {},
},
};
http.get.mockResolvedValueOnce(resolvedValue);

expect(await loadAlertState({ http, alertId })).toEqual(resolvedValue);
expect(http.get).toHaveBeenCalledWith(`/api/alerts/alert/${alertId}/state`);
});

test('should parse AlertInstances', async () => {
const alertId = uuid.v4();
const resolvedValue = {
alertTypeState: {
some: 'value',
},
alertInstances: {
first_instance: {
state: {},
meta: {
lastScheduledActions: {
group: 'first_group',
date: '2020-02-09T23:15:41.941Z',
},
},
},
},
};
http.get.mockResolvedValueOnce(resolvedValue);

expect(await loadAlertState({ http, alertId })).toEqual({
...resolvedValue,
alertInstances: {
first_instance: {
state: {},
meta: {
lastScheduledActions: {
group: 'first_group',
date: new Date('2020-02-09T23:15:41.941Z'),
},
},
},
},
});
expect(http.get).toHaveBeenCalledWith(`/api/alerts/alert/${alertId}/state`);
});

test('should handle empty response from api', async () => {
const alertId = uuid.v4();
http.get.mockResolvedValueOnce('');

expect(await loadAlertState({ http, alertId })).toEqual({});
expect(http.get).toHaveBeenCalledWith(`/api/alerts/alert/${alertId}/state`);
});
});
41 changes: 7 additions & 34 deletions x-pack/plugins/alerts/public/alert_api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,9 @@
*/

import { HttpSetup } from 'kibana/public';
import * as t from 'io-ts';
import { pipe } from 'fp-ts/lib/pipeable';
import { fold } from 'fp-ts/lib/Either';
import { findFirst } from 'fp-ts/lib/Array';
import { isNone } from 'fp-ts/lib/Option';

import { i18n } from '@kbn/i18n';
import { BASE_ALERT_API_PATH, alertStateSchema } from '../common';
import { Alert, AlertType, AlertTaskState } from '../common';
import { BASE_ALERT_API_PATH } from '../common';
import type { Alert, AlertType } from '../common';

export async function loadAlertTypes({ http }: { http: HttpSetup }): Promise<AlertType[]> {
return await http.get(`${BASE_ALERT_API_PATH}/list_alert_types`);
Expand All @@ -26,10 +20,10 @@ export async function loadAlertType({
http: HttpSetup;
id: AlertType['id'];
}): Promise<AlertType> {
const maybeAlertType = findFirst<AlertType>((type) => type.id === id)(
await http.get(`${BASE_ALERT_API_PATH}/list_alert_types`)
);
if (isNone(maybeAlertType)) {
const maybeAlertType = ((await http.get(
`${BASE_ALERT_API_PATH}/list_alert_types`
)) as AlertType[]).find((type) => type.id === id);
if (!maybeAlertType) {
throw new Error(
i18n.translate('xpack.alerts.loadAlertType.missingAlertTypeError', {
defaultMessage: 'Alert type "{id}" is not registered.',
Expand All @@ -39,7 +33,7 @@ export async function loadAlertType({
})
);
}
return maybeAlertType.value;
return maybeAlertType;
}

export async function loadAlert({
Expand All @@ -51,24 +45,3 @@ export async function loadAlert({
}): Promise<Alert> {
return await http.get(`${BASE_ALERT_API_PATH}/alert/${alertId}`);
}

type EmptyHttpResponse = '';
export async function loadAlertState({
http,
alertId,
}: {
http: HttpSetup;
alertId: string;
}): Promise<AlertTaskState> {
return await http
.get(`${BASE_ALERT_API_PATH}/alert/${alertId}/state`)
.then((state: AlertTaskState | EmptyHttpResponse) => (state ? state : {}))
.then((state: AlertTaskState) => {
return pipe(
alertStateSchema.decode(state),
fold((e: t.Errors) => {
throw new Error(`Alert "${alertId}" has invalid state`);
}, t.identity)
);
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,11 @@ export function ServiceNodeMetrics({ match }: ServiceNodeMetricsProps) {
const { urlParams, uiFilters } = useUrlParams();
const { serviceName, serviceNodeName } = match.params;
const { agentName } = useAgentName();
const { data } = useServiceMetricCharts(urlParams, agentName);
const { data } = useServiceMetricCharts(
urlParams,
agentName,
serviceNodeName
);
const { start, end } = urlParams;

const { data: { host, containerId } = INITIAL_DATA, status } = useFetcher(
Expand Down Expand Up @@ -177,25 +181,6 @@ export function ServiceNodeMetrics({ match }: ServiceNodeMetricsProps) {
</EuiFlexItem>
</MetadataFlexGroup>
)}
{agentName && (
<ChartPointerEventContextProvider>
<EuiFlexGrid columns={2} gutterSize="s">
{data.charts.map((chart) => (
<EuiFlexItem key={chart.key}>
<EuiPanel>
<MetricsChart
start={start}
end={end}
chart={chart}
fetchStatus={status}
/>
</EuiPanel>
</EuiFlexItem>
))}
</EuiFlexGrid>
<EuiSpacer size="xxl" />
</ChartPointerEventContextProvider>
)}
<SearchBar />
<EuiPage>
{agentName && (
Expand Down
6 changes: 4 additions & 2 deletions x-pack/plugins/apm/public/hooks/useServiceMetricCharts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ const INITIAL_DATA: MetricsChartsByAgentAPIResponse = {

export function useServiceMetricCharts(
urlParams: IUrlParams,
agentName?: string
agentName?: string,
serviceNodeName?: string
) {
const { serviceName } = useParams<{ serviceName?: string }>();
const { start, end } = urlParams;
Expand All @@ -30,6 +31,7 @@ export function useServiceMetricCharts(
params: {
path: { serviceName },
query: {
serviceNodeName,
start,
end,
agentName,
Expand All @@ -39,7 +41,7 @@ export function useServiceMetricCharts(
});
}
},
[serviceName, start, end, agentName, uiFilters]
[serviceName, start, end, agentName, serviceNodeName, uiFilters]
);

return {
Expand Down
4 changes: 2 additions & 2 deletions x-pack/plugins/apm/server/lib/metrics/by_agent/default.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ export async function getDefaultMetricsCharts(
serviceName: string
) {
const charts = await Promise.all([
getCPUChartData(setup, serviceName),
getMemoryChartData(setup, serviceName),
getCPUChartData({ setup, serviceName }),
getMemoryChartData({ setup, serviceName }),
]);

return { charts };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,22 @@ const chartBase: ChartBase = {
series,
};

const getGcRateChart = (
setup: Setup & SetupTimeRange,
serviceName: string,
serviceNodeName?: string
) => {
function getGcRateChart({
setup,
serviceName,
serviceNodeName,
}: {
setup: Setup & SetupTimeRange;
serviceName: string;
serviceNodeName?: string;
}) {
return fetchAndTransformGcMetrics({
setup,
serviceName,
serviceNodeName,
chartBase,
fieldName: METRIC_JAVA_GC_COUNT,
});
};
}

export { getGcRateChart };
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,22 @@ const chartBase: ChartBase = {
series,
};

const getGcTimeChart = (
setup: Setup & SetupTimeRange,
serviceName: string,
serviceNodeName?: string
) => {
function getGcTimeChart({
setup,
serviceName,
serviceNodeName,
}: {
setup: Setup & SetupTimeRange;
serviceName: string;
serviceNodeName?: string;
}) {
return fetchAndTransformGcMetrics({
setup,
serviceName,
serviceNodeName,
chartBase,
fieldName: METRIC_JAVA_GC_TIME,
});
};
}

export { getGcTimeChart };
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,15 @@ const chartBase: ChartBase = {
series,
};

export async function getHeapMemoryChart(
setup: Setup & SetupTimeRange,
serviceName: string,
serviceNodeName?: string
) {
export async function getHeapMemoryChart({
setup,
serviceName,
serviceNodeName,
}: {
setup: Setup & SetupTimeRange;
serviceName: string;
serviceNodeName?: string;
}) {
return fetchAndTransformMetrics({
setup,
serviceName,
Expand Down
28 changes: 16 additions & 12 deletions x-pack/plugins/apm/server/lib/metrics/by_agent/java/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,23 @@ import { getMemoryChartData } from '../shared/memory';
import { getGcRateChart } from './gc/get_gc_rate_chart';
import { getGcTimeChart } from './gc/get_gc_time_chart';

export async function getJavaMetricsCharts(
setup: Setup & SetupTimeRange,
serviceName: string,
serviceNodeName?: string
) {
export async function getJavaMetricsCharts({
setup,
serviceName,
serviceNodeName,
}: {
setup: Setup & SetupTimeRange;
serviceName: string;
serviceNodeName?: string;
}) {
const charts = await Promise.all([
getCPUChartData(setup, serviceName, serviceNodeName),
getMemoryChartData(setup, serviceName, serviceNodeName),
getHeapMemoryChart(setup, serviceName, serviceNodeName),
getNonHeapMemoryChart(setup, serviceName, serviceNodeName),
getThreadCountChart(setup, serviceName, serviceNodeName),
getGcRateChart(setup, serviceName, serviceNodeName),
getGcTimeChart(setup, serviceName, serviceNodeName),
getCPUChartData({ setup, serviceName, serviceNodeName }),
getMemoryChartData({ setup, serviceName, serviceNodeName }),
getHeapMemoryChart({ setup, serviceName, serviceNodeName }),
getNonHeapMemoryChart({ setup, serviceName, serviceNodeName }),
getThreadCountChart({ setup, serviceName, serviceNodeName }),
getGcRateChart({ setup, serviceName, serviceNodeName }),
getGcTimeChart({ setup, serviceName, serviceNodeName }),
]);

return { charts };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,15 @@ const chartBase: ChartBase = {
series,
};

export async function getNonHeapMemoryChart(
setup: Setup & SetupTimeRange,
serviceName: string,
serviceNodeName?: string
) {
export async function getNonHeapMemoryChart({
setup,
serviceName,
serviceNodeName,
}: {
setup: Setup & SetupTimeRange;
serviceName: string;
serviceNodeName?: string;
}) {
return fetchAndTransformMetrics({
setup,
serviceName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,15 @@ const chartBase: ChartBase = {
series,
};

export async function getThreadCountChart(
setup: Setup & SetupTimeRange,
serviceName: string,
serviceNodeName?: string
) {
export async function getThreadCountChart({
setup,
serviceName,
serviceNodeName,
}: {
setup: Setup & SetupTimeRange;
serviceName: string;
serviceNodeName?: string;
}) {
return fetchAndTransformMetrics({
setup,
serviceName,
Expand Down
Loading

0 comments on commit 90caae9

Please sign in to comment.