Skip to content

Commit

Permalink
Migrate metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
sorenlouv committed Aug 1, 2019
1 parent 265cc3b commit 89b1f9e
Show file tree
Hide file tree
Showing 9 changed files with 67 additions and 56 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { MetricsChartsByAgentAPIResponse } from '../../server/lib/metrics/get_metrics_chart_data_by_agent';
import { loadMetricsChartData } from '../services/rest/apm/metrics';
import { IUrlParams } from '../context/UrlParamsContext/types';
import { useUiFilters } from '../context/UrlParamsContext';
import { useFetcher } from './useFetcher';
import { PromiseReturnType } from '../../typings/common';

const INITIAL_DATA: MetricsChartsByAgentAPIResponse = {
const INITIAL_DATA: PromiseReturnType<typeof loadMetricsChartData> = {
charts: []
};

Expand All @@ -20,9 +20,7 @@ export function useServiceMetricCharts(
) {
const { serviceName, start, end } = urlParams;
const uiFilters = useUiFilters(urlParams);
const { data = INITIAL_DATA, error, status } = useFetcher<
MetricsChartsByAgentAPIResponse
>(() => {
const { data = INITIAL_DATA, error, status } = useFetcher(() => {
if (serviceName && start && end && agentName) {
return loadMetricsChartData({
serviceName,
Expand Down
6 changes: 3 additions & 3 deletions x-pack/legacy/plugins/apm/public/services/rest/apm/metrics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { MetricsChartsByAgentAPIResponse } from '../../../../server/lib/metrics/get_metrics_chart_data_by_agent';
import { callApi } from '../callApi';
import { callApmApi } from '../callApi';
import { UIFilters } from '../../../../typings/ui-filters';
import { metricsChartDataByAgentRoute } from '../../../../server/routes/metrics/metrics_chart_data_by_agent_route';

export async function loadMetricsChartData({
serviceName,
Expand All @@ -21,7 +21,7 @@ export async function loadMetricsChartData({
end: string;
uiFilters: UIFilters;
}) {
return callApi<MetricsChartsByAgentAPIResponse>({
return callApmApi<typeof metricsChartDataByAgentRoute>({
pathname: `/api/apm/services/${serviceName}/metrics/charts`,
query: {
start,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@
import { Setup } from '../../helpers/setup_request';
import { getCPUChartData } from './shared/cpu';
import { getMemoryChartData } from './shared/memory';
import { GenericMetricsChart } from '../transform_metrics_chart';

export async function getDefaultMetricsCharts(
setup: Setup,
serviceName: string
) {
const charts = await Promise.all([
const charts: GenericMetricsChart[] = await Promise.all([
getCPUChartData(setup, serviceName),
getMemoryChartData(setup, serviceName)
]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@ import { getNonHeapMemoryChart } from './non_heap_memory';
import { getThreadCountChart } from './thread_count';
import { getCPUChartData } from '../shared/cpu';
import { getMemoryChartData } from '../shared/memory';
import { GenericMetricsChart } from '../../transform_metrics_chart';

export async function getJavaMetricsCharts(setup: Setup, serviceName: string) {
const charts = await Promise.all([
const charts: GenericMetricsChart[] = await Promise.all([
getCPUChartData(setup, serviceName),
getMemoryChartData(setup, serviceName),
getHeapMemoryChart(setup, serviceName),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,6 @@
import { Setup } from '../helpers/setup_request';
import { getJavaMetricsCharts } from './by_agent/java';
import { getDefaultMetricsCharts } from './by_agent/default';
import { GenericMetricsChart } from './transform_metrics_chart';

export interface MetricsChartsByAgentAPIResponse {
charts: GenericMetricsChart[];
}

export async function getMetricsChartDataByAgent({
setup,
Expand All @@ -20,7 +15,7 @@ export async function getMetricsChartDataByAgent({
setup: Setup;
serviceName: string;
agentName: string;
}): Promise<MetricsChartsByAgentAPIResponse> {
}) {
switch (agentName) {
case 'java': {
return getJavaMetricsCharts(setup, serviceName);
Expand Down
2 changes: 1 addition & 1 deletion x-pack/legacy/plugins/apm/server/new-platform/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { InternalCoreSetup } from 'src/core/server';
import { makeApmUsageCollector } from '../lib/apm_telemetry';
import { CoreSetupWithUsageCollector } from '../lib/apm_telemetry/make_apm_usage_collector';
import { initErrorsApi } from '../routes/errors/init';
import { initMetricsApi } from '../routes/metrics';
import { initMetricsApi } from '../routes/metrics/init';
import { initServicesApi } from '../routes/services';
import { initTracesApi } from '../routes/traces';
import { initTransactionGroupsApi } from '../routes/transaction_groups/init';
Expand Down
39 changes: 0 additions & 39 deletions x-pack/legacy/plugins/apm/server/routes/metrics.ts

This file was deleted.

14 changes: 14 additions & 0 deletions x-pack/legacy/plugins/apm/server/routes/metrics/init.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

import { InternalCoreSetup } from 'src/core/server';
import { metricsChartDataByAgentRoute } from './metrics_chart_data_by_agent_route';

export function initMetricsApi(core: InternalCoreSetup) {
const { server } = core.http;

server.route(metricsChartDataByAgentRoute);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

import Joi from 'joi';
import { withDefaultQueryParamValidators } from '../../lib/helpers/input_validation';
import {
setupRequest,
APMRequest,
DefaultQueryParams
} from '../../lib/helpers/setup_request';
import { getMetricsChartDataByAgent } from '../../lib/metrics/get_metrics_chart_data_by_agent';

interface Query extends DefaultQueryParams {
agentName: string;
}

export const metricsChartDataByAgentRoute = {
method: 'GET',
path: `/api/apm/services/{serviceName}/metrics/charts`,
options: {
validate: {
query: withDefaultQueryParamValidators({
agentName: Joi.string().required()
})
},
tags: ['access:apm']
},
handler: async (req: APMRequest<Query>) => {
const setup = await setupRequest(req);
const { serviceName } = req.params;
const { agentName } = req.query;
return await getMetricsChartDataByAgent({
setup,
serviceName,
agentName
});
}
};

0 comments on commit 89b1f9e

Please sign in to comment.