Skip to content

Commit

Permalink
Merge branch 'main' into feature-preconfigure-es-fleet-server-hosts
Browse files Browse the repository at this point in the history
  • Loading branch information
kibanamachine authored Jul 7, 2022
2 parents 48ad54b + 876f9d5 commit 5fa5b4b
Show file tree
Hide file tree
Showing 136 changed files with 2,044 additions and 5,740 deletions.
5 changes: 5 additions & 0 deletions packages/elastic-apm-synthtrace/src/lib/apm/instance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ export class Instance extends Entity<ApmFields> {
});
}

containerId(containerId: string) {
this.fields['container.id'] = containerId;
return this;
}

podId(podId: string) {
this.fields['kubernetes.pod.uid'] = podId;
return this;
Expand Down
1 change: 0 additions & 1 deletion packages/elastic-apm-synthtrace/src/lib/apm/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ export class Service extends Entity<ApmFields> {
...this.fields,
['service.node.name']: instanceName,
'host.name': instanceName,
'container.id': instanceName,
});
}
}
Expand Down
58 changes: 58 additions & 0 deletions packages/elastic-apm-synthtrace/src/scenarios/aws_lambda.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

import { apm, timerange } from '..';
import { ApmFields } from '../lib/apm/apm_fields';
import { Scenario } from '../scripts/scenario';
import { getLogger } from '../scripts/utils/get_common_services';
import { RunOptions } from '../scripts/utils/parse_run_cli_flags';

const scenario: Scenario<ApmFields> = async (runOptions: RunOptions) => {
const logger = getLogger(runOptions);

return {
generate: ({ from, to }) => {
const range = timerange(from, to);
const timestamps = range.interval('1s').rate(3);

const instance = apm.service('lambda-python', 'production', 'python').instance('instance');

const traceEventsSetups = [
{ functionName: 'lambda-python-1', coldStart: true },
{ functionName: 'lambda-python-2', coldStart: false },
];

const traceEvents = ({ functionName, coldStart }: typeof traceEventsSetups[0]) => {
return timestamps.generator((timestamp) =>
instance
.transaction('GET /order/{id}')
.defaults({
'service.runtime.name': 'AWS_Lambda_python3.8',
'cloud.provider': 'aws',
'cloud.service.name': 'lambda',
'cloud.region': 'us-east-1',
'faas.id': `arn:aws:lambda:us-west-2:123456789012:function:${functionName}`,
'faas.coldstart': coldStart,
'faas.trigger.type': 'other',
})
.timestamp(timestamp)
.duration(1000)
.success()
);
};

return traceEventsSetups
.map((traceEventsSetup) =>
logger.perf('generating_apm_events', () => traceEvents(traceEventsSetup))
)
.reduce((p, c) => p.merge(c));
},
};
};

export default scenario;
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ describe('simple trace', () => {

beforeEach(() => {
const javaService = apm.service('opbeans-java', 'production', 'java');
const javaInstance = javaService.instance('instance-1');
const javaInstance = javaService.instance('instance-1').containerId('instance-1');

const range = timerange(
new Date('2021-01-01T00:00:00.000Z'),
Expand Down
23 changes: 20 additions & 3 deletions src/plugins/dashboard/public/application/dashboard_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@
*/

import { History } from 'history';
import React, { useEffect, useMemo, useState } from 'react';
import React, { useEffect, useMemo, useRef, useState } from 'react';

import { useKibana, useExecutionContext } from '@kbn/kibana-react-plugin/public';

import { useDashboardSelector } from './state';
import { useDashboardAppState } from './hooks';
import {
dashboardFeatureCatalog,
getDashboardBreadcrumb,
getDashboardTitle,
leaveConfirmStrings,
Expand Down Expand Up @@ -49,6 +50,7 @@ export function DashboardApp({
} = useKibana<DashboardAppServices>().services;

const [showNoDataPage, setShowNoDataPage] = useState<boolean>(false);
const dashboardTitleRef = useRef<HTMLHeadingElement>(null);

const kbnUrlStateStorage = useMemo(
() =>
Expand Down Expand Up @@ -76,6 +78,15 @@ export function DashboardApp({
isEmbeddedExternally: Boolean(embedSettings),
});

// focus on the top header when title or view mode is changed
useEffect(() => {
dashboardTitleRef.current?.focus();
}, [dashboardState.title, dashboardState.viewMode]);

const dashboardTitle = useMemo(() => {
return getDashboardTitle(dashboardState.title, dashboardState.viewMode, !savedDashboardId);
}, [dashboardState.title, dashboardState.viewMode, savedDashboardId]);

// Build app leave handler whenever hasUnsavedChanges changes
useEffect(() => {
onAppLeave((actions) => {
Expand Down Expand Up @@ -108,10 +119,10 @@ export function DashboardApp({
},
},
{
text: getDashboardTitle(dashboardState.title, dashboardState.viewMode, !savedDashboardId),
text: dashboardTitle,
},
]);
}, [chrome, dashboardState.title, dashboardState.viewMode, redirectTo, savedDashboardId]);
}, [chrome, dashboardState.title, redirectTo, savedDashboardId, dashboardTitle]);

// clear search session when leaving dashboard route
useEffect(() => {
Expand All @@ -131,6 +142,12 @@ export function DashboardApp({

return (
<>
<h1
id="dashboardTitle"
className="euiScreenReaderOnly"
ref={dashboardTitleRef}
tabIndex={-1}
>{`${dashboardFeatureCatalog.getTitle()} - ${dashboardTitle}`}</h1>
{showNoDataPage && (
<DashboardAppNoDataPage onDataViewCreated={() => setShowNoDataPage(false)} />
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ export const getSavedObjects = (): SavedObject[] => [
uiStateJSON: '{}',
version: 1,
visState:
'{"title":"[eCommerce] Markdown","type":"markdown","params":{"fontSize":12,"openLinksInNewTab":false,"markdown":"### Sample eCommerce Data\\nThis dashboard contains sample data for you to play with. You can view it, search it, and interact with the visualizations. For more information about Kibana, check our [docs](https://www.elastic.co/guide/en/kibana/current/index.html)."},"aggs":[]}',
'{"title":"[eCommerce] Markdown","type":"markdown","params":{"fontSize":12,"openLinksInNewTab":false,"markdown":"## Sample eCommerce Data\\nThis dashboard contains sample data for you to play with. You can view it, search it, and interact with the visualizations. For more information about Kibana, check our [docs](https://www.elastic.co/guide/en/kibana/current/index.html)."},"aggs":[]}',
},
coreMigrationVersion: '8.0.0',
id: 'c00d1f90-f5ea-11eb-a78e-83aac3c38a60',
Expand Down

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,9 @@ describe('service logs', () => {
expect(
getInfrastructureKQLFilter(
{
serviceInfrastructure: {
containerIds: [],
hostNames: [],
},
containerIds: [],
hostNames: [],
podNames: [],
},
serviceName
)
Expand All @@ -28,10 +27,9 @@ describe('service logs', () => {
expect(
getInfrastructureKQLFilter(
{
serviceInfrastructure: {
containerIds: ['foo', 'bar'],
hostNames: ['baz', `quz`],
},
containerIds: ['foo', 'bar'],
hostNames: ['baz', `quz`],
podNames: [],
},
serviceName
)
Expand All @@ -44,10 +42,9 @@ describe('service logs', () => {
expect(
getInfrastructureKQLFilter(
{
serviceInfrastructure: {
containerIds: [],
hostNames: ['baz', `quz`],
},
containerIds: [],
hostNames: ['baz', `quz`],
podNames: [],
},
serviceName
)
Expand Down
13 changes: 5 additions & 8 deletions x-pack/plugins/apm/public/components/app/service_logs/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export function ServiceLogs() {
(callApmApi) => {
if (start && end) {
return callApmApi(
'GET /internal/apm/services/{serviceName}/infrastructure_attributes_for_logs',
'GET /internal/apm/services/{serviceName}/infrastructure_attributes',
{
params: {
path: { serviceName },
Expand All @@ -55,10 +55,7 @@ export function ServiceLogs() {
);

const noInfrastructureData = useMemo(() => {
return (
isEmpty(data?.serviceInfrastructure?.containerIds) &&
isEmpty(data?.serviceInfrastructure?.hostNames)
);
return isEmpty(data?.containerIds) && isEmpty(data?.hostNames);
}, [data]);

if (status === FETCH_STATUS.LOADING) {
Expand Down Expand Up @@ -98,12 +95,12 @@ export function ServiceLogs() {

export const getInfrastructureKQLFilter = (
data:
| APIReturnType<'GET /internal/apm/services/{serviceName}/infrastructure_attributes_for_logs'>
| APIReturnType<'GET /internal/apm/services/{serviceName}/infrastructure_attributes'>
| undefined,
serviceName: string
) => {
const containerIds = data?.serviceInfrastructure?.containerIds ?? [];
const hostNames = data?.serviceInfrastructure?.hostNames ?? [];
const containerIds = data?.containerIds ?? [];
const hostNames = data?.hostNames ?? [];

const infraAttributes = containerIds.length
? containerIds.map((id) => `${CONTAINER_ID}: "${id}"`)
Expand Down

This file was deleted.

39 changes: 0 additions & 39 deletions x-pack/plugins/apm/server/routes/services/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ import { getServiceTransactionTypes } from './get_service_transaction_types';
import { getThroughput } from './get_throughput';
import { getServiceProfilingStatistics } from './profiling/get_service_profiling_statistics';
import { getServiceProfilingTimeline } from './profiling/get_service_profiling_timeline';
import { getServiceInfrastructure } from './get_service_infrastructure';
import { withApmSpan } from '../../utils/with_apm_span';
import { createApmServerRoute } from '../apm_routes/create_apm_server_route';
import {
Expand Down Expand Up @@ -1130,43 +1129,6 @@ const serviceProfilingStatisticsRoute = createApmServerRoute({
},
});

// TODO: remove this endpoint in favour of
const serviceInfrastructureRoute = createApmServerRoute({
endpoint:
'GET /internal/apm/services/{serviceName}/infrastructure_attributes_for_logs',
params: t.type({
path: t.type({
serviceName: t.string,
}),
query: t.intersection([kueryRt, rangeRt, environmentRt]),
}),
options: { tags: ['access:apm'] },
handler: async (
resources
): Promise<{
serviceInfrastructure: { containerIds: string[]; hostNames: string[] };
}> => {
const setup = await setupRequest(resources);

const { params } = resources;

const {
path: { serviceName },
query: { environment, kuery, start, end },
} = params;

const serviceInfrastructure = await getServiceInfrastructure({
setup,
serviceName,
environment,
kuery,
start,
end,
});
return { serviceInfrastructure };
},
});

const serviceAnomalyChartsRoute = createApmServerRoute({
endpoint: 'GET /internal/apm/services/{serviceName}/anomaly_charts',
params: t.type({
Expand Down Expand Up @@ -1298,7 +1260,6 @@ export const serviceRouteRepository = {
...serviceDependenciesBreakdownRoute,
...serviceProfilingTimelineRoute,
...serviceProfilingStatisticsRoute,
...serviceInfrastructureRoute,
...serviceAnomalyChartsRoute,
...sortedAndFilteredServicesRoute,
};

This file was deleted.

Loading

0 comments on commit 5fa5b4b

Please sign in to comment.