Skip to content

Commit 00177a6

Browse files
Merge branch '7.x' into backport/7.x/pr-87045
2 parents 3c48ee7 + 8a50f81 commit 00177a6

File tree

6 files changed

+27
-27
lines changed

6 files changed

+27
-27
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@
113113
"@hapi/good-squeeze": "6.0.0",
114114
"@hapi/h2o2": "^9.0.2",
115115
"@hapi/hapi": "^20.0.3",
116-
"@hapi/hoek": "^9.1.0",
116+
"@hapi/hoek": "^9.1.1",
117117
"@hapi/inert": "^6.0.3",
118118
"@hapi/podium": "^4.1.1",
119119
"@hapi/statehood": "^7.0.3",

src/core/server/http/http_server.ts

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
* specific language governing permissions and limitations
1717
* under the License.
1818
*/
19-
import { Server, ServerRoute } from '@hapi/hapi';
19+
import { Server } from '@hapi/hapi';
2020
import HapiStaticFiles from '@hapi/inert';
2121
import url from 'url';
2222
import uuid from 'uuid';
@@ -167,21 +167,28 @@ export class HttpServer {
167167
for (const router of this.registeredRouters) {
168168
for (const route of router.getRoutes()) {
169169
this.log.debug(`registering route handler for [${route.path}]`);
170+
// Hapi does not allow payload validation to be specified for 'head' or 'get' requests
171+
const validate = isSafeMethod(route.method) ? undefined : { payload: true };
170172
const { authRequired, tags, body = {}, timeout } = route.options;
171173
const { accepts: allow, maxBytes, output, parse } = body;
172174

173175
const kibanaRouteOptions: KibanaRouteOptions = {
174176
xsrfRequired: route.options.xsrfRequired ?? !isSafeMethod(route.method),
175177
};
176178

177-
const routeOpts: ServerRoute = {
179+
this.server.route({
178180
handler: route.handler,
179181
method: route.method,
180182
path: route.path,
181183
options: {
182184
auth: this.getAuthOption(authRequired),
183185
app: kibanaRouteOptions,
184186
tags: tags ? Array.from(tags) : undefined,
187+
// TODO: This 'validate' section can be removed once the legacy platform is completely removed.
188+
// We are telling Hapi that NP routes can accept any payload, so that it can bypass the default
189+
// validation applied in ./http_tools#getServerOptions
190+
// (All NP routes are already required to specify their own validation in order to access the payload)
191+
validate,
185192
// @ts-expect-error Types are outdated and doesn't allow `payload.multipart` to be `true`
186193
payload: [allow, maxBytes, output, parse, timeout?.payload].some((x) => x !== undefined)
187194
? {
@@ -197,22 +204,7 @@ export class HttpServer {
197204
socket: timeout?.idleSocket ?? this.config!.socketTimeout,
198205
},
199206
},
200-
};
201-
202-
// Hapi does not allow payload validation to be specified for 'head' or 'get' requests
203-
if (!isSafeMethod(route.method)) {
204-
// TODO: This 'validate' section can be removed once the legacy platform is completely removed.
205-
// We are telling Hapi that NP routes can accept any payload, so that it can bypass the default
206-
// validation applied in ./http_tools#getServerOptions
207-
// (All NP routes are already required to specify their own validation in order to access the payload)
208-
// TODO: Move the setting of the validate option back up to being set at `routeOpts` creation-time once
209-
// https://github.com/hapijs/hoek/pull/365 is merged and released in @hapi/hoek v9.1.1. At that point I
210-
// imagine the ts-error below will go away as well.
211-
// @ts-expect-error "Property 'validate' does not exist on type 'RouteOptions'" <-- ehh?!? yes it does!
212-
routeOpts.options!.validate = { payload: true };
213-
}
214-
215-
this.server.route(routeOpts);
207+
});
216208
}
217209
}
218210

x-pack/plugins/apm/public/components/app/service_details/service_icons/index.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ export function ServiceIcons({ serviceName }: Props) {
8282
(callApmApi) => {
8383
if (selectedIconPopover && serviceName && start && end) {
8484
return callApmApi({
85+
isCachable: true,
8586
endpoint: 'GET /api/apm/services/{serviceName}/metadata/details',
8687
params: {
8788
path: { serviceName },

x-pack/plugins/apm/server/lib/service_map/fetch_service_paths_from_trace_ids.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,27 @@
33
* or more contributor license agreements. Licensed under the Elastic License;
44
* you may not use this file except in compliance with the Elastic License.
55
*/
6+
import { rangeFilter } from '../../../common/utils/range_filter';
67
import { ProcessorEvent } from '../../../common/processor_event';
78
import { TRACE_ID } from '../../../common/elasticsearch_fieldnames';
89
import {
910
ConnectionNode,
1011
ExternalConnectionNode,
1112
ServiceConnectionNode,
1213
} from '../../../common/service_map';
13-
import { Setup } from '../helpers/setup_request';
14+
import { Setup, SetupTimeRange } from '../helpers/setup_request';
1415

1516
export async function fetchServicePathsFromTraceIds(
16-
setup: Setup,
17+
setup: Setup & SetupTimeRange,
1718
traceIds: string[]
1819
) {
1920
const { apmEventClient } = setup;
2021

22+
// make sure there's a range so ES can skip shards
23+
const dayInMs = 24 * 60 * 60 * 1000;
24+
const start = setup.start - dayInMs;
25+
const end = setup.end + dayInMs;
26+
2127
const serviceMapParams = {
2228
apm: {
2329
events: [ProcessorEvent.span, ProcessorEvent.transaction],
@@ -32,6 +38,7 @@ export async function fetchServicePathsFromTraceIds(
3238
[TRACE_ID]: traceIds,
3339
},
3440
},
41+
{ range: rangeFilter(start, end) },
3542
],
3643
},
3744
},

x-pack/plugins/apm/server/lib/service_map/get_service_map_from_trace_ids.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {
1010
SERVICE_NAME,
1111
} from '../../../common/elasticsearch_fieldnames';
1212
import { Connection, ConnectionNode } from '../../../common/service_map';
13-
import { Setup } from '../helpers/setup_request';
13+
import { Setup, SetupTimeRange } from '../helpers/setup_request';
1414
import { fetchServicePathsFromTraceIds } from './fetch_service_paths_from_trace_ids';
1515

1616
export function getConnections({
@@ -79,7 +79,7 @@ export async function getServiceMapFromTraceIds({
7979
serviceName,
8080
environment,
8181
}: {
82-
setup: Setup;
82+
setup: Setup & SetupTimeRange;
8383
traceIds: string[];
8484
serviceName?: string;
8585
environment?: string;

yarn.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1970,10 +1970,10 @@
19701970
"@hapi/hoek" "9.x.x"
19711971
"@hapi/validate" "1.x.x"
19721972

1973-
"@hapi/hoek@9.x.x", "@hapi/hoek@^9.0.0", "@hapi/hoek@^9.0.4", "@hapi/hoek@^9.1.0":
1974-
version "9.1.0"
1975-
resolved "https://registry.yarnpkg.com/@hapi/hoek/-/hoek-9.1.0.tgz#6c9eafc78c1529248f8f4d92b0799a712b6052c6"
1976-
integrity sha512-i9YbZPN3QgfighY/1X1Pu118VUz2Fmmhd6b2n0/O8YVgGGfw0FbUYoA97k7FkpGJ+pLCFEDLUmAPPV4D1kpeFw==
1973+
"@hapi/hoek@9.x.x", "@hapi/hoek@^9.0.0", "@hapi/hoek@^9.0.4", "@hapi/hoek@^9.1.1":
1974+
version "9.1.1"
1975+
resolved "https://registry.yarnpkg.com/@hapi/hoek/-/hoek-9.1.1.tgz#9daf5745156fd84b8e9889a2dc721f0c58e894aa"
1976+
integrity sha512-CAEbWH7OIur6jEOzaai83jq3FmKmv4PmX1JYfs9IrYcGEVI/lyL1EXJGCj7eFVJ0bg5QR8LMxBlEtA+xKiLpFw==
19771977

19781978
"@hapi/inert@^6.0.3":
19791979
version "6.0.3"

0 commit comments

Comments
 (0)