Skip to content

Commit

Permalink
[APM] Make route tags required (#83801)
Browse files Browse the repository at this point in the history
  • Loading branch information
sorenlouv authored Nov 19, 2020
1 parent f793d9b commit 3d0770f
Show file tree
Hide file tree
Showing 20 changed files with 59 additions and 10 deletions.
2 changes: 2 additions & 0 deletions x-pack/plugins/apm/server/routes/correlations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export const correlationsForSlowTransactionsRoute = createRoute({
rangeRt,
]),
}),
options: { tags: ['access:apm'] },
handler: async ({ context, request }) => {
const setup = await setupRequest(context, request);
const {
Expand Down Expand Up @@ -71,6 +72,7 @@ export const correlationsForRangesRoute = createRoute({
rangeRt,
]),
}),
options: { tags: ['access:apm'] },
handler: async ({ context, request }) => {
const setup = await setupRequest(context, request);

Expand Down
3 changes: 3 additions & 0 deletions x-pack/plugins/apm/server/routes/create_api/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,15 @@ describe('createApi', () => {
createApi()
.add(() => ({
endpoint: 'GET /foo',
options: { tags: ['access:apm'] },
handler: async () => null,
}))
.add(() => ({
endpoint: 'POST /bar',
params: t.type({
body: t.string,
}),
options: { tags: ['access:apm'] },
handler: async () => null,
}))
.add(() => ({
Expand Down Expand Up @@ -125,6 +127,7 @@ describe('createApi', () => {
.add(() => ({
endpoint: 'GET /foo',
params,
options: { tags: ['access:apm'] },
handler: handlerMock,
}))
.init(mock, context);
Expand Down
7 changes: 1 addition & 6 deletions x-pack/plugins/apm/server/routes/create_api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,7 @@ export function createApi() {
? routeOrFactoryFn(core)
: routeOrFactoryFn;

const {
params,
endpoint,
options = { tags: ['access:apm'] },
handler,
} = route;
const { params, endpoint, options, handler } = route;

const [method, path] = endpoint.split(' ');

Expand Down
3 changes: 3 additions & 0 deletions x-pack/plugins/apm/server/routes/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export const errorsRoute = createRoute({
rangeRt,
]),
}),
options: { tags: ['access:apm'] },
handler: async ({ context, request }) => {
const setup = await setupRequest(context, request);
const { params } = context;
Expand All @@ -51,6 +52,7 @@ export const errorGroupsRoute = createRoute({
}),
query: t.intersection([uiFiltersRt, rangeRt]),
}),
options: { tags: ['access:apm'] },
handler: async ({ context, request }) => {
const setup = await setupRequest(context, request);
const { serviceName, groupId } = context.params.path;
Expand All @@ -72,6 +74,7 @@ export const errorDistributionRoute = createRoute({
rangeRt,
]),
}),
options: { tags: ['access:apm'] },
handler: async ({ context, request }) => {
const setup = await setupRequest(context, request);
const { params } = context;
Expand Down
3 changes: 3 additions & 0 deletions x-pack/plugins/apm/server/routes/index_pattern.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { UIProcessorEvent } from '../../common/processor_event';

export const staticIndexPatternRoute = createRoute((core) => ({
endpoint: 'POST /api/apm/index_pattern/static',
options: { tags: ['access:apm'] },
handler: async ({ context, request }) => {
const setup = await setupRequest(context, request);
const savedObjectsClient = await getInternalSavedObjectsClient(core);
Expand All @@ -37,6 +38,7 @@ export const dynamicIndexPatternRoute = createRoute({
]),
}),
}),
options: { tags: ['access:apm'] },
handler: async ({ context }) => {
const indices = await getApmIndices({
config: context.config,
Expand All @@ -59,6 +61,7 @@ export const dynamicIndexPatternRoute = createRoute({

export const apmIndexPatternTitleRoute = createRoute({
endpoint: 'GET /api/apm/index_pattern/title',
options: { tags: ['access:apm'] },
handler: async ({ context }) => {
return getApmIndexPatternTitle(context);
},
Expand Down
1 change: 1 addition & 0 deletions x-pack/plugins/apm/server/routes/metrics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export const metricsChartsRoute = createRoute({
rangeRt,
]),
}),
options: { tags: ['access:apm'] },
handler: async ({ context, request }) => {
const setup = await setupRequest(context, request);
const { params } = context;
Expand Down
2 changes: 2 additions & 0 deletions x-pack/plugins/apm/server/routes/observability_overview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { getSearchAggregatedTransactions } from '../lib/helpers/aggregated_trans

export const observabilityOverviewHasDataRoute = createRoute({
endpoint: 'GET /api/apm/observability_overview/has_data',
options: { tags: ['access:apm'] },
handler: async ({ context, request }) => {
const setup = await setupRequest(context, request);
return await hasData({ setup });
Expand All @@ -25,6 +26,7 @@ export const observabilityOverviewRoute = createRoute({
params: t.type({
query: t.intersection([rangeRt, t.type({ bucketSize: t.string })]),
}),
options: { tags: ['access:apm'] },
handler: async ({ context, request }) => {
const setup = await setupRequest(context, request);
const { bucketSize } = context.params.query;
Expand Down
11 changes: 11 additions & 0 deletions x-pack/plugins/apm/server/routes/rum_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export const rumClientMetricsRoute = createRoute({
params: t.type({
query: uxQueryRt,
}),
options: { tags: ['access:apm'] },
handler: async ({ context, request }) => {
const setup = await setupRequest(context, request);

Expand All @@ -56,6 +57,7 @@ export const rumPageLoadDistributionRoute = createRoute({
params: t.type({
query: t.intersection([uxQueryRt, percentileRangeRt]),
}),
options: { tags: ['access:apm'] },
handler: async ({ context, request }) => {
const setup = await setupRequest(context, request);

Expand All @@ -81,6 +83,7 @@ export const rumPageLoadDistBreakdownRoute = createRoute({
t.type({ breakdown: t.string }),
]),
}),
options: { tags: ['access:apm'] },
handler: async ({ context, request }) => {
const setup = await setupRequest(context, request);

Expand All @@ -103,6 +106,7 @@ export const rumPageViewsTrendRoute = createRoute({
params: t.type({
query: t.intersection([uxQueryRt, t.partial({ breakdowns: t.string })]),
}),
options: { tags: ['access:apm'] },
handler: async ({ context, request }) => {
const setup = await setupRequest(context, request);

Expand All @@ -123,6 +127,7 @@ export const rumServicesRoute = createRoute({
params: t.type({
query: t.intersection([uiFiltersRt, rangeRt]),
}),
options: { tags: ['access:apm'] },
handler: async ({ context, request }) => {
const setup = await setupRequest(context, request);

Expand All @@ -135,6 +140,7 @@ export const rumVisitorsBreakdownRoute = createRoute({
params: t.type({
query: uxQueryRt,
}),
options: { tags: ['access:apm'] },
handler: async ({ context, request }) => {
const setup = await setupRequest(context, request);

Expand All @@ -154,6 +160,7 @@ export const rumWebCoreVitals = createRoute({
params: t.type({
query: uxQueryRt,
}),
options: { tags: ['access:apm'] },
handler: async ({ context, request }) => {
const setup = await setupRequest(context, request);

Expand All @@ -174,6 +181,7 @@ export const rumLongTaskMetrics = createRoute({
params: t.type({
query: uxQueryRt,
}),
options: { tags: ['access:apm'] },
handler: async ({ context, request }) => {
const setup = await setupRequest(context, request);

Expand All @@ -194,6 +202,7 @@ export const rumUrlSearch = createRoute({
params: t.type({
query: uxQueryRt,
}),
options: { tags: ['access:apm'] },
handler: async ({ context, request }) => {
const setup = await setupRequest(context, request);

Expand All @@ -215,6 +224,7 @@ export const rumJSErrors = createRoute({
t.partial({ urlQuery: t.string }),
]),
}),
options: { tags: ['access:apm'] },
handler: async ({ context, request }) => {
const setup = await setupRequest(context, request);

Expand All @@ -236,6 +246,7 @@ export const rumHasDataRoute = createRoute({
params: t.type({
query: t.intersection([uiFiltersRt, rangeRt]),
}),
options: { tags: ['access:apm'] },
handler: async ({ context, request }) => {
const setup = await setupRequest(context, request);
return await hasRumData({ setup });
Expand Down
2 changes: 2 additions & 0 deletions x-pack/plugins/apm/server/routes/service_map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export const serviceMapRoute = createRoute({
rangeRt,
]),
}),
options: { tags: ['access:apm'] },
handler: async ({ context, request }) => {
if (!context.config['xpack.apm.serviceMapEnabled']) {
throw Boom.notFound();
Expand Down Expand Up @@ -69,6 +70,7 @@ export const serviceMapServiceNodeRoute = createRoute({
}),
query: t.intersection([rangeRt, uiFiltersRt]),
}),
options: { tags: ['access:apm'] },
handler: async ({ context, request }) => {
if (!context.config['xpack.apm.serviceMapEnabled']) {
throw Boom.notFound();
Expand Down
1 change: 1 addition & 0 deletions x-pack/plugins/apm/server/routes/service_nodes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export const serviceNodesRoute = createRoute({
}),
query: t.intersection([rangeRt, uiFiltersRt]),
}),
options: { tags: ['access:apm'] },
handler: async ({ context, request }) => {
const setup = await setupRequest(context, request);
const { params } = context;
Expand Down
6 changes: 6 additions & 0 deletions x-pack/plugins/apm/server/routes/services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export const servicesRoute = createRoute({
params: t.type({
query: t.intersection([uiFiltersRt, rangeRt]),
}),
options: { tags: ['access:apm'] },
handler: async ({ context, request }) => {
const setup = await setupRequest(context, request);

Expand All @@ -50,6 +51,7 @@ export const serviceAgentNameRoute = createRoute({
}),
query: rangeRt,
}),
options: { tags: ['access:apm'] },
handler: async ({ context, request }) => {
const setup = await setupRequest(context, request);
const { serviceName } = context.params.path;
Expand All @@ -73,6 +75,7 @@ export const serviceTransactionTypesRoute = createRoute({
}),
query: rangeRt,
}),
options: { tags: ['access:apm'] },
handler: async ({ context, request }) => {
const setup = await setupRequest(context, request);
const { serviceName } = context.params.path;
Expand All @@ -96,6 +99,7 @@ export const serviceNodeMetadataRoute = createRoute({
}),
query: t.intersection([uiFiltersRt, rangeRt]),
}),
options: { tags: ['access:apm'] },
handler: async ({ context, request }) => {
const setup = await setupRequest(context, request);
const { serviceName, serviceNodeName } = context.params.path;
Expand All @@ -116,6 +120,7 @@ export const serviceAnnotationsRoute = createRoute({
}),
]),
}),
options: { tags: ['access:apm'] },
handler: async ({ context, request }) => {
const setup = await setupRequest(context, request);
const { serviceName } = context.params.path;
Expand Down Expand Up @@ -220,6 +225,7 @@ export const serviceErrorGroupsRoute = createRoute({
}),
]),
}),
options: { tags: ['access:apm'] },
handler: async ({ context, request }) => {
const setup = await setupRequest(context, request);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import { getSearchAggregatedTransactions } from '../../lib/helpers/aggregated_tr
// get list of configurations
export const agentConfigurationRoute = createRoute({
endpoint: 'GET /api/apm/settings/agent-configuration',
options: { tags: ['access:apm'] },
handler: async ({ context, request }) => {
const setup = await setupRequest(context, request);
return await listConfigurations({ setup });
Expand All @@ -39,6 +40,7 @@ export const getSingleAgentConfigurationRoute = createRoute({
params: t.partial({
query: serviceRt,
}),
options: { tags: ['access:apm'] },
handler: async ({ context, request }) => {
const setup = await setupRequest(context, request);
const { name, environment } = context.params.query;
Expand Down Expand Up @@ -148,6 +150,7 @@ export const agentConfigurationSearchRoute = createRoute({
params: t.type({
body: searchParamsRt,
}),
options: { tags: ['access:apm'] },
handler: async ({ context, request }) => {
const {
service,
Expand Down Expand Up @@ -194,6 +197,7 @@ export const agentConfigurationSearchRoute = createRoute({
// get list of services
export const listAgentConfigurationServicesRoute = createRoute({
endpoint: 'GET /api/apm/settings/agent-configuration/services',
options: { tags: ['access:apm'] },
handler: async ({ context, request }) => {
const setup = await setupRequest(context, request);
const searchAggregatedTransactions = await getSearchAggregatedTransactions(
Expand All @@ -212,6 +216,7 @@ export const listAgentConfigurationEnvironmentsRoute = createRoute({
params: t.partial({
query: t.partial({ serviceName: t.string }),
}),
options: { tags: ['access:apm'] },
handler: async ({ context, request }) => {
const setup = await setupRequest(context, request);
const { serviceName } = context.params.query;
Expand All @@ -233,6 +238,7 @@ export const agentConfigurationAgentNameRoute = createRoute({
params: t.type({
query: t.type({ serviceName: t.string }),
}),
options: { tags: ['access:apm'] },
handler: async ({ context, request }) => {
const setup = await setupRequest(context, request);
const { serviceName } = context.params.query;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ export const createAnomalyDetectionJobsRoute = createRoute({
// get all available environments to create anomaly detection jobs for
export const anomalyDetectionEnvironmentsRoute = createRoute({
endpoint: 'GET /api/apm/settings/anomaly-detection/environments',
options: { tags: ['access:apm'] },
handler: async ({ context, request }) => {
const setup = await setupRequest(context, request);

Expand Down
2 changes: 2 additions & 0 deletions x-pack/plugins/apm/server/routes/settings/apm_indices.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { saveApmIndices } from '../../lib/settings/apm_indices/save_apm_indices'
// get list of apm indices and values
export const apmIndexSettingsRoute = createRoute({
endpoint: 'GET /api/apm/settings/apm-index-settings',
options: { tags: ['access:apm'] },
handler: async ({ context }) => {
return await getApmIndexSettings({ context });
},
Expand All @@ -23,6 +24,7 @@ export const apmIndexSettingsRoute = createRoute({
// get apm indices configuration object
export const apmIndicesRoute = createRoute({
endpoint: 'GET /api/apm/settings/apm-indices',
options: { tags: ['access:apm'] },
handler: async ({ context }) => {
return await getApmIndices({
savedObjectsClient: context.core.savedObjects.client,
Expand Down
6 changes: 3 additions & 3 deletions x-pack/plugins/apm/server/routes/settings/custom_link.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ function isActiveGoldLicense(license: ILicense) {

export const customLinkTransactionRoute = createRoute({
endpoint: 'GET /api/apm/settings/custom_links/transaction',
options: { tags: ['access:apm'] },
params: t.partial({
query: filterOptionsRt,
}),
Expand All @@ -42,6 +43,7 @@ export const customLinkTransactionRoute = createRoute({

export const listCustomLinksRoute = createRoute({
endpoint: 'GET /api/apm/settings/custom_links',
options: { tags: ['access:apm'] },
params: t.partial({
query: filterOptionsRt,
}),
Expand All @@ -62,9 +64,7 @@ export const createCustomLinkRoute = createRoute({
params: t.type({
body: payloadRt,
}),
options: {
tags: ['access:apm', 'access:apm_write'],
},
options: { tags: ['access:apm'] },
handler: async ({ context, request }) => {
if (!isActiveGoldLicense(context.licensing.license)) {
throw Boom.forbidden(INVALID_LICENSE);
Expand Down
Loading

0 comments on commit 3d0770f

Please sign in to comment.