Skip to content

Commit

Permalink
adding fleet information on APM tutorial
Browse files Browse the repository at this point in the history
  • Loading branch information
cauemarcondes committed Jun 1, 2021
1 parent 2a00cc7 commit 0f0f458
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 15 deletions.
10 changes: 6 additions & 4 deletions src/plugins/home/public/application/application.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import React from 'react';
import { render, unmountComponentAtNode } from 'react-dom';
import { i18n } from '@kbn/i18n';
import { ScopedHistory, CoreStart } from 'kibana/public';
import { KibanaContextProvider } from '../../../kibana_react/public';
import { KibanaContextProvider, RedirectAppLinks } from '../../../kibana_react/public';
// @ts-ignore
import { HomeApp } from './components/home_app';
import { getServices } from './kibana_services';
Expand Down Expand Up @@ -44,9 +44,11 @@ export const renderApp = async (
});

render(
<KibanaContextProvider services={{ ...coreStart }}>
<HomeApp directories={directories} solutions={solutions} />
</KibanaContextProvider>,
<RedirectAppLinks application={coreStart.application}>
<KibanaContextProvider services={{ ...coreStart }}>
<HomeApp directories={directories} solutions={solutions} />
</KibanaContextProvider>
</RedirectAppLinks>,
element
);

Expand Down
21 changes: 16 additions & 5 deletions src/plugins/home/public/application/components/apm_fleet/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
EuiCard,
EuiFlexGroup,
EuiFlexItem,
EuiImage,
EuiLoadingSpinner,
EuiPanel,
} from '@elastic/eui';
Expand All @@ -29,7 +30,8 @@ interface APIResponse {
}

export function APMFleet() {
const { getBasePath } = getServices();
const { http, getBasePath, uiSettings } = getServices();
const isDarkTheme = uiSettings.get('theme:darkMode');
const basePath = getBasePath();
const [data, setData] = useState<APIResponse | undefined>();
const [isLoading, setIsLoading] = useState(false);
Expand All @@ -38,16 +40,16 @@ export function APMFleet() {
async function fetchData() {
setIsLoading(true);
try {
const response = await fetch(`${basePath}/api/apm/fleet/hasData`);
setData((await response.json()) as APIResponse);
const response = await http.get('/api/apm/fleet/has_data');
setData(response as APIResponse);
} catch (e) {
// eslint-disable-next-line no-console
console.error('Error while fetching fleet details.', e);
}
setIsLoading(false);
}
fetchData();
}, [basePath]);
}, [http]);

if (isLoading) {
return (
Expand Down Expand Up @@ -94,7 +96,16 @@ export function APMFleet() {
}
/>
</EuiFlexItem>
<EuiFlexItem grow={3} style={{ background: 'red' }} />
<EuiFlexItem grow={3}>
<EuiImage
src={`${basePath}/plugins/apm/assets/${
isDarkTheme
? 'illustration_integrations_darkmode.svg'
: 'illustration_integrations_lightmode.svg'
}`}
alt="Illustration"
/>
</EuiFlexItem>
</EuiFlexGroup>
</EuiPanel>
);
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion x-pack/plugins/apm/server/routes/fleet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { createApmServerRoute } from './create_apm_server_route';
import { createApmServerRouteRepository } from './create_apm_server_route_repository';

const hasFleetDataRoute = createApmServerRoute({
endpoint: 'GET /api/apm/fleet/hasData',
endpoint: 'GET /api/apm/fleet/has_data',
options: { tags: [] },
handler: async (resources) => {
const { core } = resources.context;
Expand Down
11 changes: 7 additions & 4 deletions x-pack/plugins/apm/server/tutorial/envs/elastic_cloud.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@ export function createElasticCloudInstructions(
const instructionSets = [];

instructionSets.push(
getApmServerInstructionSet({ cloudSetup, hasApmServerUrl: !!apmServerUrl })
getApmServerInstructionSet({
cloudSetup,
isApmServerEnabled: !!apmServerUrl,
})
);

instructionSets.push(getApmAgentInstructionSet(cloudSetup));
Expand All @@ -45,10 +48,10 @@ export function createElasticCloudInstructions(

function getApmServerInstructionSet({
cloudSetup,
hasApmServerUrl,
isApmServerEnabled,
}: {
cloudSetup?: CloudSetup;
hasApmServerUrl: boolean;
isApmServerEnabled: boolean;
}): InstructionSetSchema {
const instructionVariants: InstructionSetSchema['instructionVariants'] = [
{
Expand All @@ -57,7 +60,7 @@ function getApmServerInstructionSet({
},
];

if (!hasApmServerUrl) {
if (!isApmServerEnabled) {
instructionVariants.push({
id: INSTRUCTION_VARIANT.ESC,
instructions: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -913,7 +913,10 @@ export const createPhpAgentInstructions = (
'APM is automatically started when your app boots. Configure the agent either via `php.ini` file:',
}
),
commands: `elastic_apm.server_url=http://localhost:8200
commands: `elastic_apm.server_url="${
apmServerUrl || 'http://localhost:8200'
}"
elastic.apm.secret_token="${secretToken}"
elastic_apm.service_name="My service"
`.split('\n'),
textPost: i18n.translate(
Expand Down

0 comments on commit 0f0f458

Please sign in to comment.