Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[APM] Migrate server routes to NP #49455

Merged
merged 5 commits into from
Nov 21, 2019
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/legacy/core_plugins/apm_oss/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ export default function apmOss(kibana) {
spanIndices: Joi.string().default('apm-*'),
metricsIndices: Joi.string().default('apm-*'),
onboardingIndices: Joi.string().default('apm-*'),
apmAgentConfigurationIndex: Joi.string().default('.apm-agent-configuration'),
dgieselaar marked this conversation as resolved.
Show resolved Hide resolved
}).default();
},

Expand Down
11 changes: 11 additions & 0 deletions src/plugins/apm_oss/kibana.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"id": "apm_oss",
"version": "8.0.0",
"server": true,
"kibanaVersion": "kibana",
"configPath": [
"apm_oss"
],
"ui": false,
"requiredPlugins": []
}
41 changes: 41 additions & 0 deletions src/plugins/apm_oss/server/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
import { schema, TypeOf } from '@kbn/config-schema';
import { PluginInitializerContext } from '../../../core/server';
import { APMOSSPlugin } from './plugin';

export const config = {
schema: schema.object({
transactionIndices: schema.string({ defaultValue: 'apm-*' }),
spanIndices: schema.string({ defaultValue: 'apm-*' }),
errorIndices: schema.string({ defaultValue: 'apm-*' }),
metricsIndices: schema.string({ defaultValue: 'apm-*' }),
sourcemapIndices: schema.string({ defaultValue: 'apm-*' }),
onboardingIndices: schema.string({ defaultValue: 'apm-*' }),
indexPattern: schema.string({ defaultValue: 'apm-*' }),
}),
};

export function plugin(initializerContext: PluginInitializerContext) {
return new APMOSSPlugin(initializerContext);
}

export type APMOSSConfig = TypeOf<typeof config.schema>;

export { APMOSSPlugin as Plugin };
38 changes: 38 additions & 0 deletions src/plugins/apm_oss/server/plugin.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
import { Plugin, CoreSetup, PluginInitializerContext } from 'src/core/server';
import { Observable } from 'rxjs';
import { APMOSSConfig } from './';

export class APMOSSPlugin implements Plugin<{ config$: Observable<APMOSSConfig> }> {
constructor(private readonly initContext: PluginInitializerContext) {
this.initContext = initContext;
}

public setup(core: CoreSetup) {
const config$ = this.initContext.config.create<APMOSSConfig>();

return {
config$,
};
}

start() {}
stop() {}
}
8 changes: 6 additions & 2 deletions x-pack/legacy/plugins/apm/common/projections/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { Setup } from '../../server/lib/helpers/setup_request';
import {
Setup,
SetupTimeRange,
SetupUIFilters
} from '../../server/lib/helpers/setup_request';
import {
PROCESSOR_EVENT,
SERVICE_NAME,
Expand All @@ -16,7 +20,7 @@ export function getErrorGroupsProjection({
setup,
serviceName
}: {
setup: Setup;
setup: Setup & SetupTimeRange & SetupUIFilters;
serviceName: string;
}) {
const { start, end, uiFiltersES, indices } = setup;
Expand Down
8 changes: 6 additions & 2 deletions x-pack/legacy/plugins/apm/common/projections/metrics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { Setup } from '../../server/lib/helpers/setup_request';
import {
Setup,
SetupTimeRange,
SetupUIFilters
} from '../../server/lib/helpers/setup_request';
import {
SERVICE_NAME,
PROCESSOR_EVENT,
Expand All @@ -30,7 +34,7 @@ export function getMetricsProjection({
serviceName,
serviceNodeName
}: {
setup: Setup;
setup: Setup & SetupTimeRange & SetupUIFilters;
serviceName: string;
serviceNodeName?: string;
}) {
Expand Down
8 changes: 6 additions & 2 deletions x-pack/legacy/plugins/apm/common/projections/service_nodes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { Setup } from '../../server/lib/helpers/setup_request';
import {
Setup,
SetupTimeRange,
SetupUIFilters
} from '../../server/lib/helpers/setup_request';
import { SERVICE_NODE_NAME } from '../elasticsearch_fieldnames';
import { mergeProjection } from './util/merge_projection';
import { getMetricsProjection } from './metrics';
Expand All @@ -14,7 +18,7 @@ export function getServiceNodesProjection({
serviceName,
serviceNodeName
}: {
setup: Setup;
setup: Setup & SetupTimeRange & SetupUIFilters;
serviceName: string;
serviceNodeName?: string;
}) {
Expand Down
12 changes: 10 additions & 2 deletions x-pack/legacy/plugins/apm/common/projections/services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,19 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { Setup } from '../../server/lib/helpers/setup_request';
import {
Setup,
SetupUIFilters,
SetupTimeRange
} from '../../server/lib/helpers/setup_request';
import { SERVICE_NAME, PROCESSOR_EVENT } from '../elasticsearch_fieldnames';
import { rangeFilter } from '../../server/lib/helpers/range_filter';

export function getServicesProjection({ setup }: { setup: Setup }) {
export function getServicesProjection({
setup
}: {
setup: Setup & SetupTimeRange & SetupUIFilters;
}) {
const { start, end, uiFiltersES, indices } = setup;

return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@
* you may not use this file except in compliance with the Elastic License.
*/
import { omit } from 'lodash';
import { Setup } from '../../server/lib/helpers/setup_request';
import {
Setup,
SetupTimeRange,
SetupUIFilters
} from '../../server/lib/helpers/setup_request';
import { TRANSACTION_NAME, PARENT_ID } from '../elasticsearch_fieldnames';
import { Options } from '../../server/lib/transaction_groups/fetcher';
import { getTransactionsProjection } from './transactions';
Expand All @@ -14,7 +18,7 @@ export function getTransactionGroupsProjection({
setup,
options
}: {
setup: Setup;
setup: Setup & SetupTimeRange & SetupUIFilters;
options: Options;
}) {
const transactionsProjection = getTransactionsProjection({
Expand Down
8 changes: 6 additions & 2 deletions x-pack/legacy/plugins/apm/common/projections/transactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { Setup } from '../../server/lib/helpers/setup_request';
import {
Setup,
SetupTimeRange,
SetupUIFilters
} from '../../server/lib/helpers/setup_request';
import {
SERVICE_NAME,
TRANSACTION_TYPE,
Expand All @@ -19,7 +23,7 @@ export function getTransactionsProjection({
transactionName,
transactionType
}: {
setup: Setup;
setup: Setup & SetupTimeRange & SetupUIFilters;
serviceName?: string;
transactionName?: string;
transactionType?: string;
Expand Down
20 changes: 6 additions & 14 deletions x-pack/legacy/plugins/apm/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
import { i18n } from '@kbn/i18n';
import { Server } from 'hapi';
import { resolve } from 'path';
import { PluginInitializerContext } from '../../../../src/core/server';
import { APMPluginContract } from '../../../plugins/apm/server/plugin';
import { LegacyPluginInitializer } from '../../../../src/legacy/types';
import mappings from './mappings.json';
import { plugin } from './server/new-platform';
import { makeApmUsageCollector } from './server/lib/apm_telemetry';

export const apm: LegacyPluginInitializer = kibana => {
return new kibana.Plugin({
Expand Down Expand Up @@ -68,10 +68,6 @@ export const apm: LegacyPluginInitializer = kibana => {
// enable plugin
enabled: Joi.boolean().default(true),

// buckets
minimumBucketSize: Joi.number().default(15),
bucketTargetCount: Joi.number().default(15),

// index patterns
autocreateApmIndexPattern: Joi.boolean().default(true),

Expand Down Expand Up @@ -112,15 +108,11 @@ export const apm: LegacyPluginInitializer = kibana => {
}
}
});
makeApmUsageCollector(server);
const apmPlugin = server.newPlatform.setup.plugins
.apm as APMPluginContract;

const initializerContext = {} as PluginInitializerContext;
const legacySetup = {
server
};
plugin(initializerContext).setup(
server.newPlatform.setup.core,
legacySetup
);
apmPlugin.registerLegacyAPI({ server });
}
});
};
3 changes: 0 additions & 3 deletions x-pack/legacy/plugins/apm/mappings.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,6 @@
},
"apm_oss.metricsIndices": {
"type": "keyword"
},
"apm_oss.apmAgentConfigurationIndex": {
dgieselaar marked this conversation as resolved.
Show resolved Hide resolved
"type": "keyword"
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,6 @@ const APM_INDEX_LABELS = [
label: i18n.translate('xpack.apm.settings.apmIndices.metricsIndicesLabel', {
defaultMessage: 'Metrics Indices'
})
},
{
configurationName: 'apm_oss.apmAgentConfigurationIndex',
label: i18n.translate(
'xpack.apm.settings.apmIndices.apmAgentConfigurationIndexLabel',
{ defaultMessage: 'Agent Configuration Index' }
)
}
];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ describe('callApi', () => {
it('should not add debug param for non-APM endpoints', async () => {
await callApi(http, { pathname: `/api/kibana` });

expect(http.get).toHaveBeenCalledWith('/api/kibana', {});
expect(http.get).toHaveBeenCalledWith('/api/kibana', { query: {} });
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,10 @@ describe('callApmApi', () => {
expect.objectContaining({
pathname: '/api/apm',
method: 'POST',
body: JSON.stringify({
body: {
foo: 'bar',
bar: 'foo'
})
}
})
);
});
Expand Down
16 changes: 12 additions & 4 deletions x-pack/legacy/plugins/apm/public/services/rest/callApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,23 @@ function fetchOptionsWithDebug(fetchOptions: FetchOptions) {
sessionStorage.getItem('apm_debug') === 'true' &&
startsWith(fetchOptions.pathname, '/api/apm');

if (!debugEnabled) {
return fetchOptions;
}
const isGet = !fetchOptions.method || fetchOptions.method === 'GET';

// Need an empty body to pass route validation
const body = isGet
? {}
: {
body: JSON.stringify(
fetchOptions.body || ({} as HttpFetchOptions['body'])
)
};

return {
...fetchOptions,
...body,
query: {
...fetchOptions.query,
_debug: true
...(debugEnabled ? { _debug: true } : {})
}
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,6 @@ export const createCallApmApi = (http: HttpServiceBase) =>
const { pathname, params = {}, ...opts } = options;

const path = (params.path || {}) as Record<string, any>;
const body = params.body
? { body: JSON.stringify(params.body) }
: undefined;
const query = params.query ? { query: params.query } : undefined;

const formattedPathname = Object.keys(path).reduce((acc, paramName) => {
return acc.replace(`{${paramName}}`, path[paramName]);
Expand All @@ -34,7 +30,7 @@ export const createCallApmApi = (http: HttpServiceBase) =>
return callApi(http, {
...opts,
pathname: formattedPathname,
...body,
...query
body: params.body,
query: params.query
});
}) as APMClient;
Loading