From 0225a8c652822d1efbd1a446b1cd8a8b145a510e Mon Sep 17 00:00:00 2001 From: cauemarcondes Date: Fri, 18 Jun 2021 11:36:19 -0400 Subject: [PATCH] adding environment credencials --- .../components/tutorial/instruction.js | 10 +- .../components/tutorial/instruction_set.js | 3 + .../components/tutorial/tutorial.js | 1 + .../tutorial/config_agent/commands/django.ts | 72 ++++ .../tutorial/config_agent/commands/dotnet.ts | 16 + .../tutorial/config_agent/commands/flask.ts | 70 ++++ .../config_agent/commands/get_commands.ts | 44 +++ .../tutorial/config_agent/commands/go.ts | 58 +++ .../tutorial/config_agent/commands/java.ts | 14 + .../tutorial/config_agent/commands/node.ts | 57 +++ .../tutorial/config_agent/commands/php.ts | 11 + .../tutorial/config_agent/commands/rack.ts | 50 +++ .../tutorial/config_agent/commands/rails.ts | 22 ++ .../tutorial/config_agent/commands/rum.ts | 60 +++ .../shared/tutorial/config_agent/index.tsx | 211 ++++++++++ .../tutorial/config_agent/rum_script.tsx | 15 + .../shared/tutorial/copy_commands.tsx | 23 ++ x-pack/plugins/apm/public/plugin.ts | 10 + .../apm/server/lib/fleet/get_agents.ts | 34 ++ x-pack/plugins/apm/server/routes/fleet.ts | 70 +++- .../instructions/apm_agent_instructions.ts | 361 +----------------- x-pack/plugins/fleet/server/plugin.ts | 1 + x-pack/plugins/fleet/server/services/index.ts | 1 + 23 files changed, 859 insertions(+), 355 deletions(-) create mode 100644 x-pack/plugins/apm/public/components/shared/tutorial/config_agent/commands/django.ts create mode 100644 x-pack/plugins/apm/public/components/shared/tutorial/config_agent/commands/dotnet.ts create mode 100644 x-pack/plugins/apm/public/components/shared/tutorial/config_agent/commands/flask.ts create mode 100644 x-pack/plugins/apm/public/components/shared/tutorial/config_agent/commands/get_commands.ts create mode 100644 x-pack/plugins/apm/public/components/shared/tutorial/config_agent/commands/go.ts create mode 100644 x-pack/plugins/apm/public/components/shared/tutorial/config_agent/commands/java.ts create mode 100644 x-pack/plugins/apm/public/components/shared/tutorial/config_agent/commands/node.ts create mode 100644 x-pack/plugins/apm/public/components/shared/tutorial/config_agent/commands/php.ts create mode 100644 x-pack/plugins/apm/public/components/shared/tutorial/config_agent/commands/rack.ts create mode 100644 x-pack/plugins/apm/public/components/shared/tutorial/config_agent/commands/rails.ts create mode 100644 x-pack/plugins/apm/public/components/shared/tutorial/config_agent/commands/rum.ts create mode 100644 x-pack/plugins/apm/public/components/shared/tutorial/config_agent/index.tsx create mode 100644 x-pack/plugins/apm/public/components/shared/tutorial/config_agent/rum_script.tsx create mode 100644 x-pack/plugins/apm/public/components/shared/tutorial/copy_commands.tsx create mode 100644 x-pack/plugins/apm/server/lib/fleet/get_agents.ts diff --git a/src/plugins/home/public/application/components/tutorial/instruction.js b/src/plugins/home/public/application/components/tutorial/instruction.js index 373f8c318a504..61aeb22107215 100644 --- a/src/plugins/home/public/application/components/tutorial/instruction.js +++ b/src/plugins/home/public/application/components/tutorial/instruction.js @@ -31,6 +31,8 @@ export function Instruction({ textPre, replaceTemplateStrings, customComponentName, + variantId, + isCloudEnabled, }) { const { tutorialService, http, uiSettings, getBasePath } = getServices(); @@ -96,18 +98,20 @@ export function Instruction({ {commandBlock} - {post} - {LazyCustomComponent && ( }> )} + {post} + ); @@ -120,4 +124,6 @@ Instruction.propTypes = { textPre: PropTypes.string, replaceTemplateStrings: PropTypes.func.isRequired, customComponentName: PropTypes.string, + variantId: PropTypes.string, + isCloudEnabled: PropTypes.bool.isRequired, }; diff --git a/src/plugins/home/public/application/components/tutorial/instruction_set.js b/src/plugins/home/public/application/components/tutorial/instruction_set.js index da368120d493c..08b55a527b3cf 100644 --- a/src/plugins/home/public/application/components/tutorial/instruction_set.js +++ b/src/plugins/home/public/application/components/tutorial/instruction_set.js @@ -187,6 +187,8 @@ class InstructionSetUi extends React.Component { textPost={instruction.textPost} replaceTemplateStrings={this.props.replaceTemplateStrings} customComponentName={instruction.customComponentName} + variantId={instructionVariant.id} + isCloudEnabled={this.props.isCloudEnabled} /> ); return { @@ -320,6 +322,7 @@ InstructionSetUi.propTypes = { paramValues: PropTypes.object.isRequired, setParameter: PropTypes.func, replaceTemplateStrings: PropTypes.func.isRequired, + isCloudEnabled: PropTypes.bool.isRequired, }; export const InstructionSet = injectI18n(InstructionSetUi); diff --git a/src/plugins/home/public/application/components/tutorial/tutorial.js b/src/plugins/home/public/application/components/tutorial/tutorial.js index 92bbb92fa0850..52daa53d4585c 100644 --- a/src/plugins/home/public/application/components/tutorial/tutorial.js +++ b/src/plugins/home/public/application/components/tutorial/tutorial.js @@ -301,6 +301,7 @@ class TutorialUi extends React.Component { setParameter={this.setParameter} replaceTemplateStrings={this.props.replaceTemplateStrings} key={index} + isCloudEnabled={this.props.isCloudEnabled} /> ); }); diff --git a/x-pack/plugins/apm/public/components/shared/tutorial/config_agent/commands/django.ts b/x-pack/plugins/apm/public/components/shared/tutorial/config_agent/commands/django.ts new file mode 100644 index 0000000000000..686fcd0276549 --- /dev/null +++ b/x-pack/plugins/apm/public/components/shared/tutorial/config_agent/commands/django.ts @@ -0,0 +1,72 @@ +/* + * 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; you may not use this file except in compliance with the Elastic License + * 2.0. + */ + +import { i18n } from '@kbn/i18n'; + +export const django = `# ${i18n.translate( + 'xpack.apm.tutorial.djangoClient.configure.commands.addAgentComment', + { + defaultMessage: 'Add the agent to the installed apps', + } +)} +INSTALLED_APPS = ( +'elasticapm.contrib.django', +# ... +) + +ELASTIC_APM = {curlyOpen} +# ${i18n.translate( + 'xpack.apm.tutorial.djangoClient.configure.commands.setRequiredServiceNameComment', + { + defaultMessage: 'Set the required service name. Allowed characters:', + } +)} +# ${i18n.translate( + 'xpack.apm.tutorial.djangoClient.configure.commands.allowedCharactersComment', + { + defaultMessage: 'a-z, A-Z, 0-9, -, _, and space', + } +)} +'SERVICE_NAME': '', + +# ${i18n.translate( + 'xpack.apm.tutorial.djangoClient.configure.commands.useIfApmServerRequiresTokenComment', + { + defaultMessage: 'Use if APM Server requires a secret token', + } +)} +'SECRET_TOKEN': '{{secretToken}}', + +# ${i18n.translate( + 'xpack.apm.tutorial.djangoClient.configure.commands.setCustomApmServerUrlComment', + { + defaultMessage: + 'Set the custom APM Server URL (default: {defaultApmServerUrl})', + values: { defaultApmServerUrl: 'http://localhost:8200' }, + } +)} +'SERVER_URL': '{{apmServerUrl}}', + +# ${i18n.translate( + 'xpack.apm.tutorial.djangoClient.configure.commands.setServiceEnvironmentComment', + { + defaultMessage: 'Set the service environment', + } +)} +'ENVIRONMENT': 'production', +{curlyClose} + +# ${i18n.translate( + 'xpack.apm.tutorial.djangoClient.configure.commands.addTracingMiddlewareComment', + { + defaultMessage: 'To send performance metrics, add our tracing middleware:', + } +)} +MIDDLEWARE = ( +'elasticapm.contrib.django.middleware.TracingMiddleware', +#... +)`; diff --git a/x-pack/plugins/apm/public/components/shared/tutorial/config_agent/commands/dotnet.ts b/x-pack/plugins/apm/public/components/shared/tutorial/config_agent/commands/dotnet.ts new file mode 100644 index 0000000000000..d11234e0b546c --- /dev/null +++ b/x-pack/plugins/apm/public/components/shared/tutorial/config_agent/commands/dotnet.ts @@ -0,0 +1,16 @@ +/* + * 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; you may not use this file except in compliance with the Elastic License + * 2.0. + */ +// TODO: ${'http://localhost:8200'}' fallback server_url + +export const dotnet = `{ +"ElasticApm": { +"SecretToken": "{{secretToken}}", +"ServerUrls": "{{apmServerUrl}}", //Set custom APM Server URL (default: http://localhost:8200) +"ServiceName": "MyApp", //allowed characters: a-z, A-Z, 0-9, -, _, and space. Default is the entry assembly of the application +"Environment": "production", // Set the service environment +} +}`; diff --git a/x-pack/plugins/apm/public/components/shared/tutorial/config_agent/commands/flask.ts b/x-pack/plugins/apm/public/components/shared/tutorial/config_agent/commands/flask.ts new file mode 100644 index 0000000000000..d97b5e7172328 --- /dev/null +++ b/x-pack/plugins/apm/public/components/shared/tutorial/config_agent/commands/flask.ts @@ -0,0 +1,70 @@ +/* + * 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; you may not use this file except in compliance with the Elastic License + * 2.0. + */ + +import { i18n } from '@kbn/i18n'; + +export const flask = `# ${i18n.translate( + 'xpack.apm.tutorial.flaskClient.configure.commands.initializeUsingEnvironmentVariablesComment', + { + defaultMessage: 'initialize using environment variables', + } +)} +from elasticapm.contrib.flask import ElasticAPM +app = Flask(__name__) +apm = ElasticAPM(app) + +# ${i18n.translate( + 'xpack.apm.tutorial.flaskClient.configure.commands.configureElasticApmComment', + { + defaultMessage: + "or configure to use ELASTIC_APM in your application's settings", + } +)} +from elasticapm.contrib.flask import ElasticAPM +app.config['ELASTIC_APM'] = {curlyOpen} +# ${i18n.translate( + 'xpack.apm.tutorial.flaskClient.configure.commands.setRequiredServiceNameComment', + { + defaultMessage: 'Set the required service name. Allowed characters:', + } +)} +# ${i18n.translate( + 'xpack.apm.tutorial.flaskClient.configure.commands.allowedCharactersComment', + { + defaultMessage: 'a-z, A-Z, 0-9, -, _, and space', + } +)} +'SERVICE_NAME': '', + +# ${i18n.translate( + 'xpack.apm.tutorial.flaskClient.configure.commands.useIfApmServerRequiresTokenComment', + { + defaultMessage: 'Use if APM Server requires a secret token', + } +)} +'SECRET_TOKEN': '{{secretToken}}', + +# ${i18n.translate( + 'xpack.apm.tutorial.flaskClient.configure.commands.setCustomApmServerUrlComment', + { + defaultMessage: + 'Set the custom APM Server URL (default: {defaultApmServerUrl})', + values: { defaultApmServerUrl: 'http://localhost:8200' }, + } +)} +'SERVER_URL': '{{apmServerUrl}}', + +# ${i18n.translate( + 'xpack.apm.tutorial.flaskClient.configure.commands.setServiceEnvironmentComment', + { + defaultMessage: 'Set the service environment', + } +)} +'ENVIRONMENT': 'production', +{curlyClose} + +apm = ElasticAPM(app)`; diff --git a/x-pack/plugins/apm/public/components/shared/tutorial/config_agent/commands/get_commands.ts b/x-pack/plugins/apm/public/components/shared/tutorial/config_agent/commands/get_commands.ts new file mode 100644 index 0000000000000..5fa869b019f24 --- /dev/null +++ b/x-pack/plugins/apm/public/components/shared/tutorial/config_agent/commands/get_commands.ts @@ -0,0 +1,44 @@ +/* + * 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; you may not use this file except in compliance with the Elastic License + * 2.0. + */ +import Mustache from 'mustache'; +import { java } from './java'; +import { node } from './node'; +import { django } from './django'; +import { flask } from './flask'; +import { rails } from './rails'; +import { rack } from './rack'; +import { go } from './go'; +import { dotnet } from './dotnet'; +import { php } from './php'; +import { rum, rumScript } from './rum'; + +const commands: Record = { + java, + node, + django, + flask, + rails, + rack, + go, + dotnet, + php, + js: rum, + js_script: rumScript, +}; + +export function getCommands({ + variantId, + environmentDetails, +}: { + variantId: string; + environmentDetails: { + apmServerUrl?: string; + secretToken?: string; + }; +}) { + return Mustache.render(commands[variantId], environmentDetails); +} diff --git a/x-pack/plugins/apm/public/components/shared/tutorial/config_agent/commands/go.ts b/x-pack/plugins/apm/public/components/shared/tutorial/config_agent/commands/go.ts new file mode 100644 index 0000000000000..a1878dc382764 --- /dev/null +++ b/x-pack/plugins/apm/public/components/shared/tutorial/config_agent/commands/go.ts @@ -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; you may not use this file except in compliance with the Elastic License + * 2.0. + */ + +import { i18n } from '@kbn/i18n'; + +export const go = `# ${i18n.translate( + 'xpack.apm.tutorial.goClient.configure.commands.initializeUsingEnvironmentVariablesComment', + { + defaultMessage: 'Initialize using environment variables:', + } +)} + +# ${i18n.translate( + 'xpack.apm.tutorial.goClient.configure.commands.setServiceNameComment', + { + defaultMessage: + 'Set the service name. Allowed characters: # a-z, A-Z, 0-9, -, _, and space.', + } +)} +# ${i18n.translate( + 'xpack.apm.tutorial.goClient.configure.commands.usedExecutableNameComment', + { + defaultMessage: + 'If ELASTIC_APM_SERVICE_NAME is not specified, the executable name will be used.', + } +)} +export ELASTIC_APM_SERVICE_NAME= + +# ${i18n.translate( + 'xpack.apm.tutorial.goClient.configure.commands.setCustomApmServerUrlComment', + { + defaultMessage: + 'Set custom APM Server URL (default: {defaultApmServerUrl})', + values: { defaultApmServerUrl: 'http://localhost:8200' }, + } +)} +export ELASTIC_APM_SERVER_URL={{apmServerUrl}} + +# ${i18n.translate( + 'xpack.apm.tutorial.goClient.configure.commands.useIfApmRequiresTokenComment', + { + defaultMessage: 'Use if APM Server requires a secret token', + } +)} +export ELASTIC_APM_SECRET_TOKEN={{secretToken}} + +# ${i18n.translate( + 'xpack.apm.tutorial.goClient.configure.commands.setServiceEnvironment', + { + defaultMessage: 'Set the service environment', + } +)} +export ELASTIC_APM_ENVIRONMENT= +`; diff --git a/x-pack/plugins/apm/public/components/shared/tutorial/config_agent/commands/java.ts b/x-pack/plugins/apm/public/components/shared/tutorial/config_agent/commands/java.ts new file mode 100644 index 0000000000000..2d8c38d73966c --- /dev/null +++ b/x-pack/plugins/apm/public/components/shared/tutorial/config_agent/commands/java.ts @@ -0,0 +1,14 @@ +/* + * 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; you may not use this file except in compliance with the Elastic License + * 2.0. + */ + +export const java = `java -javaagent:/path/to/elastic-apm-agent-.jar \\ +-Delastic.apm.service_name=my-application \\ +-Delastic.apm.server_urls= {{apmServerUrl}} \\ +-Delastic.apm.secret_token= {{secretToken}} \\ +-Delastic.apm.environment=production \\ +-Delastic.apm.application_packages=org.example \\ +-jar my-application.jar`; diff --git a/x-pack/plugins/apm/public/components/shared/tutorial/config_agent/commands/node.ts b/x-pack/plugins/apm/public/components/shared/tutorial/config_agent/commands/node.ts new file mode 100644 index 0000000000000..553d861cfb0c3 --- /dev/null +++ b/x-pack/plugins/apm/public/components/shared/tutorial/config_agent/commands/node.ts @@ -0,0 +1,57 @@ +/* + * 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; you may not use this file except in compliance with the Elastic License + * 2.0. + */ +import { i18n } from '@kbn/i18n'; + +export const node = `// ${i18n.translate( + 'xpack.apm.tutorial.nodeClient.configure.commands.addThisToTheFileTopComment', + { + defaultMessage: + 'Add this to the VERY top of the first file loaded in your app', + } +)} +var apm = require('elastic-apm-node').start({ + +// ${i18n.translate( + 'xpack.apm.tutorial.nodeClient.configure.commands.setRequiredServiceNameComment', + { + defaultMessage: 'Override the service name from package.json', + } +)} +// ${i18n.translate( + 'xpack.apm.tutorial.nodeClient.configure.commands.allowedCharactersComment', + { + defaultMessage: 'Allowed characters: a-z, A-Z, 0-9, -, _, and space', + } +)} +serviceName: '', + +// ${i18n.translate( + 'xpack.apm.tutorial.nodeClient.configure.commands.useIfApmRequiresTokenComment', + { + defaultMessage: 'Use if APM Server requires a secret token', + } +)} +secretToken: '{{secretToken}}', + +// ${i18n.translate( + 'xpack.apm.tutorial.nodeClient.configure.commands.setCustomApmServerUrlComment', + { + defaultMessage: + 'Set the custom APM Server URL (default: {defaultApmServerUrl})', + values: { defaultApmServerUrl: 'http://localhost:8200' }, + } +)} +serverUrl: '{{apmServerUrl}}', + +// ${i18n.translate( + 'xpack.apm.tutorial.nodeClient.configure.commands.setCustomServiceEnvironmentComment', + { + defaultMessage: 'Set the service environment', + } +)} +environment: 'production' +})`; diff --git a/x-pack/plugins/apm/public/components/shared/tutorial/config_agent/commands/php.ts b/x-pack/plugins/apm/public/components/shared/tutorial/config_agent/commands/php.ts new file mode 100644 index 0000000000000..443f3def8bb53 --- /dev/null +++ b/x-pack/plugins/apm/public/components/shared/tutorial/config_agent/commands/php.ts @@ -0,0 +1,11 @@ +/* + * 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; you may not use this file except in compliance with the Elastic License + * 2.0. + */ + +export const php = `elastic_apm.server_url="{{apmServerUrl}}" +elastic.apm.secret_token="{{secretToken}}" +elastic_apm.service_name="My service" +`; diff --git a/x-pack/plugins/apm/public/components/shared/tutorial/config_agent/commands/rack.ts b/x-pack/plugins/apm/public/components/shared/tutorial/config_agent/commands/rack.ts new file mode 100644 index 0000000000000..55043042e1e36 --- /dev/null +++ b/x-pack/plugins/apm/public/components/shared/tutorial/config_agent/commands/rack.ts @@ -0,0 +1,50 @@ +/* + * 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; you may not use this file except in compliance with the Elastic License + * 2.0. + */ + +import { i18n } from '@kbn/i18n'; + +export const rack = `# config/elastic_apm.yml: + +# ${i18n.translate( + 'xpack.apm.tutorial.rackClient.createConfig.commands.setServiceNameComment', + { + defaultMessage: + 'Set the service name - allowed characters: a-z, A-Z, 0-9, -, _ and space', + } +)} +# ${i18n.translate( + 'xpack.apm.tutorial.rackClient.createConfig.commands.defaultsToTheNameOfRackAppClassComment', + { + defaultMessage: "Defaults to the name of your Rack app's class.", + } +)} +service_name: 'my-service' + +# ${i18n.translate( + 'xpack.apm.tutorial.rackClient.createConfig.commands.useIfApmServerRequiresTokenComment', + { + defaultMessage: 'Use if APM Server requires a token', + } +)} +secret_token: '{{secretToken}}' + +# ${i18n.translate( + 'xpack.apm.tutorial.rackClient.createConfig.commands.setCustomApmServerComment', + { + defaultMessage: 'Set custom APM Server URL (default: {defaultServerUrl})', + values: { defaultServerUrl: 'http://localhost:8200' }, + } +)} +server_url: {{apmServerUrl}}, + +# ${i18n.translate( + 'xpack.apm.tutorial.rackClient.createConfig.commands.setServiceEnvironment', + { + defaultMessage: 'Set the service environment', + } +)} +environment: 'production'`; diff --git a/x-pack/plugins/apm/public/components/shared/tutorial/config_agent/commands/rails.ts b/x-pack/plugins/apm/public/components/shared/tutorial/config_agent/commands/rails.ts new file mode 100644 index 0000000000000..e0663709e1020 --- /dev/null +++ b/x-pack/plugins/apm/public/components/shared/tutorial/config_agent/commands/rails.ts @@ -0,0 +1,22 @@ +/* + * 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; you may not use this file except in compliance with the Elastic License + * 2.0. + */ + +// TODO: ${'http://localhost:8200'}' fallback server_url +export const rails = `# config/elastic_apm.yml: + +# Set the service name - allowed characters: a-z, A-Z, 0-9, -, _ and space +# Defaults to the name of your Rails app +service_name: 'my-service' + +# Use if APM Server requires a secret token +secret_token: '{{secretToken}}' + +# Set the custom APM Server URL (default: http://localhost:8200) +server_url: '{{apmServerUrl}}' + +# Set the service environment +environment: 'production'`; diff --git a/x-pack/plugins/apm/public/components/shared/tutorial/config_agent/commands/rum.ts b/x-pack/plugins/apm/public/components/shared/tutorial/config_agent/commands/rum.ts new file mode 100644 index 0000000000000..91a8283c8ae63 --- /dev/null +++ b/x-pack/plugins/apm/public/components/shared/tutorial/config_agent/commands/rum.ts @@ -0,0 +1,60 @@ +/* + * 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; you may not use this file except in compliance with the Elastic License + * 2.0. + */ + +import { i18n } from '@kbn/i18n'; + +// TODO: doesn't have token +export const rum = `import { init as initApm } from '@elastic/apm-rum' +var apm = initApm({ + + // ${i18n.translate( + 'xpack.apm.tutorial.jsClient.installDependency.commands.setRequiredServiceNameComment', + { + defaultMessage: + 'Set required service name (allowed characters: a-z, A-Z, 0-9, -, _, and space)', + } + )} + serviceName: 'your-app-name', + + // ${i18n.translate( + 'xpack.apm.tutorial.jsClient.installDependency.commands.setCustomApmServerUrlComment', + { + defaultMessage: + 'Set custom APM Server URL (default: {defaultApmServerUrl})', + values: { defaultApmServerUrl: 'http://localhost:8200' }, + } + )} + serverUrl: '{{apmServerUrl}}', + + // ${i18n.translate( + 'xpack.apm.tutorial.jsClient.installDependency.commands.setServiceVersionComment', + { + defaultMessage: + 'Set the service version (required for source map feature)', + } + )} + serviceVersion: '', + + // ${i18n.translate( + 'xpack.apm.tutorial.jsClient.installDependency.commands.setServiceEnvironmentComment', + { + defaultMessage: 'Set the service environment', + } + )} + environment: 'production' +})`; + +// TODO: doesn't have token/url +export const rumScript = `\ + + +`; diff --git a/x-pack/plugins/apm/public/components/shared/tutorial/config_agent/index.tsx b/x-pack/plugins/apm/public/components/shared/tutorial/config_agent/index.tsx new file mode 100644 index 0000000000000..b6e882a7a48ef --- /dev/null +++ b/x-pack/plugins/apm/public/components/shared/tutorial/config_agent/index.tsx @@ -0,0 +1,211 @@ +/* + * 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; you may not use this file except in compliance with the Elastic License + * 2.0. + */ +import { + EuiButton, + EuiButtonEmpty, + EuiCodeBlock, + EuiFlexGroup, + EuiFlexItem, + EuiLoadingSpinner, + EuiPopover, + EuiPopoverFooter, + EuiPopoverTitle, + EuiSelectable, + EuiSpacer, +} from '@elastic/eui'; +import { HttpStart } from 'kibana/public'; +import React, { useEffect, useState } from 'react'; +import styled from 'styled-components'; +import { APIReturnType } from '../../../../services/rest/createCallApmApi'; +import { CopyCommands } from '../copy_commands'; +import { getCommands } from './commands/get_commands'; + +interface Props { + variantId: string; + http: HttpStart; + basePath: string; + isCloudEnabled: boolean; +} + +const CentralizedContainer = styled.div` + display: flex; + justify-content: center; + align-items: center; +`; + +const onPremStandaloneOption = { + key: 'onPrem_standalone', + label: 'Default Standalone configuration', + apmServerUrl: 'http://localhost:8200', + secretKey: '', + checked: 'on', +}; + +type APIResponseType = APIReturnType<'GET /api/apm/fleet/agents'>; +const INITIAL_STATE: APIResponseType = { + agentsCredentials: [], + cloudAgentPolicyCredential: undefined, + cloudCredentials: undefined, +}; + +type SelectValuesType = 'onPrem_standalone' | 'cloud_standalone' | string; + +interface Credential { + key: string; + label: string; + apmServerUrl?: string; + secretToken?: string; + checked?: 'on'; +} + +function TutorialAgentSecretTokenSelector({ + variantId, + http, + basePath, + isCloudEnabled, +}: Props) { + const [isPopoverOpen, setIsPopoverOpen] = useState(false); + const [data, setData] = useState(INITIAL_STATE); + const [isLoading, setIsLoading] = useState(true); + const [options, setOptions] = useState([]); + const [option, setOption] = useState(); + + useEffect(() => { + const checkedOption = options.find(({ checked }) => checked === 'on'); + setOption(checkedOption); + }, [options]); + + useEffect(() => { + async function fetchData() { + setIsLoading(true); + try { + const response = await http.get('/api/apm/fleet/agents'); + setData(response as APIResponseType); + } catch (e) { + console.error('Error while fetching fleet agents.', e); + } + setIsLoading(false); + } + fetchData(); + }, [http]); + + useEffect(() => { + const newOptions = []; + if (isCloudEnabled) { + // has Elastic Cloud managed policy + if (data.cloudAgentPolicyCredential) { + const { + id, + name, + apmServerUrl, + secretToken, + } = data.cloudAgentPolicyCredential; + newOptions.push({ + key: id, + label: name, + apmServerUrl, + secretToken, + checked: 'on', + }); + } else { + // adds standalone cloud + newOptions.push({ + key: 'cloud_standalone', + label: 'Default Standalone configuration', + apmServerUrl: data.cloudCredentials?.apmServerUrl, + secretToken: data.cloudCredentials?.secretToken, + checked: 'on', + }); + } + } else { + // when onPrem + newOptions.push(onPremStandaloneOption); + } + + newOptions.push( + ...data.agentsCredentials?.map( + ({ id, name, apmServerUrl, secretToken }) => ({ + key: id, + label: name, + apmServerUrl, + secretToken, + }) + ) + ); + setOptions(newOptions); + }, [data, isCloudEnabled]); + + if (isLoading) { + return ( + + + + ); + } + + const command = getCommands({ + variantId, + environmentDetails: { + apmServerUrl: option?.apmServerUrl, + secretToken: option?.secretToken, + }, + }); + + function toggleIsPopoverOpen() { + setIsPopoverOpen((state) => !state); + } + + return ( + <> + + + + {option?.label} + + } + isOpen={isPopoverOpen} + closePopover={toggleIsPopoverOpen} + > + setOptions(newOptions)} + singleSelection + > + {(list, search) => ( +
+ {search} + {list} + + + Manage this list + + +
+ )} +
+
+
+ + + +
+ + {command} + + ); +} + +// eslint-disable-next-line import/no-default-export +export default TutorialAgentSecretTokenSelector; diff --git a/x-pack/plugins/apm/public/components/shared/tutorial/config_agent/rum_script.tsx b/x-pack/plugins/apm/public/components/shared/tutorial/config_agent/rum_script.tsx new file mode 100644 index 0000000000000..ac9ca53bdee6c --- /dev/null +++ b/x-pack/plugins/apm/public/components/shared/tutorial/config_agent/rum_script.tsx @@ -0,0 +1,15 @@ +/* + * 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; you may not use this file except in compliance with the Elastic License + * 2.0. + */ +import React from 'react'; +import TutorialAgentSecretTokenSelector from './'; + +function TutorialConfigAgentRumScript() { + return ; +} + +// eslint-disable-next-line import/no-default-export +export default TutorialConfigAgentRumScript; diff --git a/x-pack/plugins/apm/public/components/shared/tutorial/copy_commands.tsx b/x-pack/plugins/apm/public/components/shared/tutorial/copy_commands.tsx new file mode 100644 index 0000000000000..9e02efef05919 --- /dev/null +++ b/x-pack/plugins/apm/public/components/shared/tutorial/copy_commands.tsx @@ -0,0 +1,23 @@ +/* + * 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; you may not use this file except in compliance with the Elastic License + * 2.0. + */ +import { EuiButton, EuiCopy } from '@elastic/eui'; +import React from 'react'; + +interface Props { + commands: string; +} +export function CopyCommands({ commands }: Props) { + return ( + + {(copy) => ( + + Copy snippet + + )} + + ); +} diff --git a/x-pack/plugins/apm/public/plugin.ts b/x-pack/plugins/apm/public/plugin.ts index f8c8ffb855080..868be2d5281c2 100644 --- a/x-pack/plugins/apm/public/plugin.ts +++ b/x-pack/plugins/apm/public/plugin.ts @@ -175,6 +175,16 @@ export class ApmPlugin implements Plugin { () => import('./components/shared/tutorial_fleet_instructions') ); + pluginSetupDeps.home?.tutorials.registerCustomComponent( + 'TutorialConfigAgent', + () => import('./components/shared/tutorial/config_agent') + ); + + pluginSetupDeps.home?.tutorials.registerCustomComponent( + 'TutorialConfigAgentRumScript', + () => import('./components/shared/tutorial/config_agent/rum_script') + ); + plugins.observability.dashboard.register({ appName: 'apm', hasData: async () => { diff --git a/x-pack/plugins/apm/server/lib/fleet/get_agents.ts b/x-pack/plugins/apm/server/lib/fleet/get_agents.ts new file mode 100644 index 0000000000000..5ee44bb3ad174 --- /dev/null +++ b/x-pack/plugins/apm/server/lib/fleet/get_agents.ts @@ -0,0 +1,34 @@ +/* + * 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; you may not use this file except in compliance with the Elastic License + * 2.0. + */ + +import { + CoreSetup, + CoreStart, + SavedObjectsClientContract, +} from 'kibana/server'; +import { APMPluginStartDependencies } from '../../types'; +import { getInternalSavedObjectsClient } from '../helpers/get_internal_saved_objects_client'; + +export async function getFleetAgents({ + policyIds, + core, + fleetPluginStart, +}: { + policyIds: string[]; + core: { setup: CoreSetup; start: () => Promise }; + fleetPluginStart: NonNullable; +}) { + // @ts-ignore + const savedObjectsClient: SavedObjectsClientContract = await getInternalSavedObjectsClient( + core.setup + ); + + return await fleetPluginStart.agentPolicyService.getByIds( + savedObjectsClient, + policyIds + ); +} diff --git a/x-pack/plugins/apm/server/routes/fleet.ts b/x-pack/plugins/apm/server/routes/fleet.ts index e2a394414308a..3e2d63a5e70e4 100644 --- a/x-pack/plugins/apm/server/routes/fleet.ts +++ b/x-pack/plugins/apm/server/routes/fleet.ts @@ -5,10 +5,15 @@ * 2.0. */ +import { keyBy } from 'lodash'; +import { AgentPolicy, PackagePolicy } from '../../../fleet/common'; +import { getFleetAgents } from '../lib/fleet/get_agents'; import { getApmPackgePolicies } from '../lib/fleet/get_apm_package_policies'; import { createApmServerRoute } from './create_apm_server_route'; import { createApmServerRouteRepository } from './create_apm_server_route_repository'; +const POLICY_ELASTIC_AGENT_ON_CLOUD = 'policy-elastic-agent-on-cloud'; + const hasFleetDataRoute = createApmServerRoute({ endpoint: 'GET /api/apm/fleet/has_data', options: { tags: [] }, @@ -22,6 +27,65 @@ const hasFleetDataRoute = createApmServerRoute({ }, }); -export const ApmFleetRouteRepository = createApmServerRouteRepository().add( - hasFleetDataRoute -); +function getAgentPolicyCredentials( + agent: AgentPolicy, + policiesGroupedById: Record +) { + const packagePolicy = policiesGroupedById[agent.id]; + const apmServerCompiledInputs = + packagePolicy.inputs[0].compiled_input['apm-server']; + return { + id: agent.id, + name: agent.name, + apmServerUrl: apmServerCompiledInputs?.host, + secretToken: apmServerCompiledInputs?.secret_token, + }; +} + +const fleetAgentsRoute = createApmServerRoute({ + endpoint: 'GET /api/apm/fleet/agents', + options: { tags: [] }, + handler: async ({ core, plugins }) => { + const cloudSetup = plugins.cloud?.setup; + const cloudCredentials = cloudSetup + ? { + apmServerUrl: cloudSetup?.apm.url, + secretToken: cloudSetup?.apm.secretToken, + } + : undefined; + + const fleetPluginStart = await plugins.fleet.start(); + // fetches package policies that contains APM integrations + const packagePolicies = await getApmPackgePolicies({ + core, + fleetPluginStart, + }); + + const policiesGroupedById = keyBy(packagePolicies.items, 'policy_id'); + + // fetches all agents with the found package policies + const agents = await getFleetAgents({ + policyIds: Object.keys(policiesGroupedById), + core, + fleetPluginStart, + }); + + const cloudAgentPolicy = agents.find( + ({ name }) => name === POLICY_ELASTIC_AGENT_ON_CLOUD + ); + + return { + cloudAgentPolicyCredential: cloudAgentPolicy + ? getAgentPolicyCredentials(cloudAgentPolicy, policiesGroupedById) + : undefined, + cloudCredentials, + agentsCredentials: agents.map((agent) => { + return getAgentPolicyCredentials(agent, policiesGroupedById); + }), + }; + }, +}); + +export const ApmFleetRouteRepository = createApmServerRouteRepository() + .add(hasFleetDataRoute) + .add(fleetAgentsRoute); diff --git a/x-pack/plugins/apm/server/tutorial/instructions/apm_agent_instructions.ts b/x-pack/plugins/apm/server/tutorial/instructions/apm_agent_instructions.ts index ba11a996f00df..e2bf09dae5bed 100644 --- a/x-pack/plugins/apm/server/tutorial/instructions/apm_agent_instructions.ts +++ b/x-pack/plugins/apm/server/tutorial/instructions/apm_agent_instructions.ts @@ -31,55 +31,7 @@ export const createNodeAgentInstructions = ( APM services are created programmatically based on the `serviceName`. \ This agent supports a variety of frameworks but can also be used with your custom stack.', }), - commands: `// ${i18n.translate( - 'xpack.apm.tutorial.nodeClient.configure.commands.addThisToTheFileTopComment', - { - defaultMessage: - 'Add this to the VERY top of the first file loaded in your app', - } - )} -var apm = require('elastic-apm-node').start({curlyOpen} - - // ${i18n.translate( - 'xpack.apm.tutorial.nodeClient.configure.commands.setRequiredServiceNameComment', - { - defaultMessage: 'Override the service name from package.json', - } - )} - // ${i18n.translate( - 'xpack.apm.tutorial.nodeClient.configure.commands.allowedCharactersComment', - { - defaultMessage: 'Allowed characters: a-z, A-Z, 0-9, -, _, and space', - } - )} - serviceName: '', - - // ${i18n.translate( - 'xpack.apm.tutorial.nodeClient.configure.commands.useIfApmRequiresTokenComment', - { - defaultMessage: 'Use if APM Server requires a secret token', - } - )} - secretToken: '${secretToken}', - - // ${i18n.translate( - 'xpack.apm.tutorial.nodeClient.configure.commands.setCustomApmServerUrlComment', - { - defaultMessage: - 'Set the custom APM Server URL (default: {defaultApmServerUrl})', - values: { defaultApmServerUrl: 'http://localhost:8200' }, - } - )} - serverUrl: '${apmServerUrl}', - - // ${i18n.translate( - 'xpack.apm.tutorial.nodeClient.configure.commands.setCustomServiceEnvironmentComment', - { - defaultMessage: 'Set the service environment', - } - )} - environment: 'production' -{curlyClose})`.split('\n'), + customComponentName: 'TutorialConfigAgent', textPost: i18n.translate( 'xpack.apm.tutorial.nodeClient.configure.textPost', { @@ -122,70 +74,7 @@ export const createDjangoAgentInstructions = ( APM services are created programmatically based on the `SERVICE_NAME`.', } ), - commands: `# ${i18n.translate( - 'xpack.apm.tutorial.djangoClient.configure.commands.addAgentComment', - { - defaultMessage: 'Add the agent to the installed apps', - } - )} -INSTALLED_APPS = ( - 'elasticapm.contrib.django', - # ... -) - -ELASTIC_APM = {curlyOpen} - # ${i18n.translate( - 'xpack.apm.tutorial.djangoClient.configure.commands.setRequiredServiceNameComment', - { - defaultMessage: 'Set the required service name. Allowed characters:', - } - )} - # ${i18n.translate( - 'xpack.apm.tutorial.djangoClient.configure.commands.allowedCharactersComment', - { - defaultMessage: 'a-z, A-Z, 0-9, -, _, and space', - } - )} - 'SERVICE_NAME': '', - - # ${i18n.translate( - 'xpack.apm.tutorial.djangoClient.configure.commands.useIfApmServerRequiresTokenComment', - { - defaultMessage: 'Use if APM Server requires a secret token', - } - )} - 'SECRET_TOKEN': '${secretToken}', - - # ${i18n.translate( - 'xpack.apm.tutorial.djangoClient.configure.commands.setCustomApmServerUrlComment', - { - defaultMessage: - 'Set the custom APM Server URL (default: {defaultApmServerUrl})', - values: { defaultApmServerUrl: 'http://localhost:8200' }, - } - )} - 'SERVER_URL': '${apmServerUrl}', - - # ${i18n.translate( - 'xpack.apm.tutorial.djangoClient.configure.commands.setServiceEnvironmentComment', - { - defaultMessage: 'Set the service environment', - } - )} - 'ENVIRONMENT': 'production', -{curlyClose} - -# ${i18n.translate( - 'xpack.apm.tutorial.djangoClient.configure.commands.addTracingMiddlewareComment', - { - defaultMessage: - 'To send performance metrics, add our tracing middleware:', - } - )} -MIDDLEWARE = ( - 'elasticapm.contrib.django.middleware.TracingMiddleware', - #... -)`.split('\n'), + customComponentName: 'TutorialConfigAgent', textPost: i18n.translate( 'xpack.apm.tutorial.djangoClient.configure.textPost', { @@ -225,67 +114,7 @@ export const createFlaskAgentInstructions = ( APM services are created programmatically based on the `SERVICE_NAME`.', } ), - commands: `# ${i18n.translate( - 'xpack.apm.tutorial.flaskClient.configure.commands.initializeUsingEnvironmentVariablesComment', - { - defaultMessage: 'initialize using environment variables', - } - )} -from elasticapm.contrib.flask import ElasticAPM -app = Flask(__name__) -apm = ElasticAPM(app) - -# ${i18n.translate( - 'xpack.apm.tutorial.flaskClient.configure.commands.configureElasticApmComment', - { - defaultMessage: - "or configure to use ELASTIC_APM in your application's settings", - } - )} -from elasticapm.contrib.flask import ElasticAPM -app.config['ELASTIC_APM'] = {curlyOpen} - # ${i18n.translate( - 'xpack.apm.tutorial.flaskClient.configure.commands.setRequiredServiceNameComment', - { - defaultMessage: 'Set the required service name. Allowed characters:', - } - )} - # ${i18n.translate( - 'xpack.apm.tutorial.flaskClient.configure.commands.allowedCharactersComment', - { - defaultMessage: 'a-z, A-Z, 0-9, -, _, and space', - } - )} - 'SERVICE_NAME': '', - - # ${i18n.translate( - 'xpack.apm.tutorial.flaskClient.configure.commands.useIfApmServerRequiresTokenComment', - { - defaultMessage: 'Use if APM Server requires a secret token', - } - )} - 'SECRET_TOKEN': '${secretToken}', - - # ${i18n.translate( - 'xpack.apm.tutorial.flaskClient.configure.commands.setCustomApmServerUrlComment', - { - defaultMessage: - 'Set the custom APM Server URL (default: {defaultApmServerUrl})', - values: { defaultApmServerUrl: 'http://localhost:8200' }, - } - )} - 'SERVER_URL': '${apmServerUrl}', - - # ${i18n.translate( - 'xpack.apm.tutorial.flaskClient.configure.commands.setServiceEnvironmentComment', - { - defaultMessage: 'Set the service environment', - } - )} - 'ENVIRONMENT': 'production', -{curlyClose} - -apm = ElasticAPM(app)`.split('\n'), + customComponentName: 'TutorialConfigAgent', textPost: i18n.translate( 'xpack.apm.tutorial.flaskClient.configure.textPost', { @@ -325,20 +154,7 @@ export const createRailsAgentInstructions = ( values: { configFile: '`config/elastic_apm.yml`' }, } ), - commands: `# config/elastic_apm.yml: - -# Set the service name - allowed characters: a-z, A-Z, 0-9, -, _ and space -# Defaults to the name of your Rails app -service_name: 'my-service' - -# Use if APM Server requires a secret token -secret_token: '${secretToken}' - -# Set the custom APM Server URL (default: http://localhost:8200) -server_url: '${apmServerUrl || 'http://localhost:8200'}' - -# Set the service environment -environment: 'production'`.split('\n'), + customComponentName: 'TutorialConfigAgent', textPost: i18n.translate( 'xpack.apm.tutorial.railsClient.configure.textPost', { @@ -413,48 +229,7 @@ export const createRackAgentInstructions = ( values: { configFile: '`config/elastic_apm.yml`' }, } ), - commands: `# config/elastic_apm.yml: - -# ${i18n.translate( - 'xpack.apm.tutorial.rackClient.createConfig.commands.setServiceNameComment', - { - defaultMessage: - 'Set the service name - allowed characters: a-z, A-Z, 0-9, -, _ and space', - } - )} -# ${i18n.translate( - 'xpack.apm.tutorial.rackClient.createConfig.commands.defaultsToTheNameOfRackAppClassComment', - { - defaultMessage: "Defaults to the name of your Rack app's class.", - } - )} -service_name: 'my-service' - -# ${i18n.translate( - 'xpack.apm.tutorial.rackClient.createConfig.commands.useIfApmServerRequiresTokenComment', - { - defaultMessage: 'Use if APM Server requires a token', - } - )} -secret_token: '${secretToken}' - -# ${i18n.translate( - 'xpack.apm.tutorial.rackClient.createConfig.commands.setCustomApmServerComment', - { - defaultMessage: - 'Set custom APM Server URL (default: {defaultServerUrl})', - values: { defaultServerUrl: 'http://localhost:8200' }, - } - )} -server_url: '${apmServerUrl || 'http://localhost:8200'}', - -# ${i18n.translate( - 'xpack.apm.tutorial.rackClient.createConfig.commands.setServiceEnvironment', - { - defaultMessage: 'Set the service environment', - } - )} -environment: 'production'`.split('\n'), + customComponentName: 'TutorialConfigAgent', textPost: i18n.translate( 'xpack.apm.tutorial.rackClient.createConfig.textPost', { @@ -506,45 +281,7 @@ for details on how to enable RUM support.', The Agent can then be initialized and configured in your application like this:', } ), - commands: `import {curlyOpen} init as initApm {curlyClose} from '@elastic/apm-rum' -var apm = initApm({curlyOpen} - - // ${i18n.translate( - 'xpack.apm.tutorial.jsClient.installDependency.commands.setRequiredServiceNameComment', - { - defaultMessage: - 'Set required service name (allowed characters: a-z, A-Z, 0-9, -, _, and space)', - } - )} - serviceName: 'your-app-name', - - // ${i18n.translate( - 'xpack.apm.tutorial.jsClient.installDependency.commands.setCustomApmServerUrlComment', - { - defaultMessage: - 'Set custom APM Server URL (default: {defaultApmServerUrl})', - values: { defaultApmServerUrl: 'http://localhost:8200' }, - } - )} - serverUrl: '${apmServerUrl}', - - // ${i18n.translate( - 'xpack.apm.tutorial.jsClient.installDependency.commands.setServiceVersionComment', - { - defaultMessage: - 'Set the service version (required for source map feature)', - } - )} - serviceVersion: '', - - // ${i18n.translate( - 'xpack.apm.tutorial.jsClient.installDependency.commands.setServiceEnvironmentComment', - { - defaultMessage: 'Set the service environment', - } - )} - environment: 'production' -{curlyClose})`.split('\n'), + customComponentName: 'TutorialConfigAgent', textPost: i18n.translate( 'xpack.apm.tutorial.jsClient.installDependency.textPost', { @@ -575,15 +312,7 @@ and host the file on your Server/CDN before deploying to production.", 'https://unpkg.com/@elastic/apm-rum/dist/bundles/elastic-apm-rum.umd.min.js', }, }), - commands: `\ - - -`.split('\n'), + customComponentName: 'TutorialConfigAgentRumScript', }, ]; @@ -610,55 +339,7 @@ export const createGoAgentInstructions = ( APM services are created programmatically based on the executable \ file name, or the `ELASTIC_APM_SERVICE_NAME` environment variable.', }), - commands: `# ${i18n.translate( - 'xpack.apm.tutorial.goClient.configure.commands.initializeUsingEnvironmentVariablesComment', - { - defaultMessage: 'Initialize using environment variables:', - } - )} - -# ${i18n.translate( - 'xpack.apm.tutorial.goClient.configure.commands.setServiceNameComment', - { - defaultMessage: - 'Set the service name. Allowed characters: # a-z, A-Z, 0-9, -, _, and space.', - } - )} -# ${i18n.translate( - 'xpack.apm.tutorial.goClient.configure.commands.usedExecutableNameComment', - { - defaultMessage: - 'If ELASTIC_APM_SERVICE_NAME is not specified, the executable name will be used.', - } - )} -export ELASTIC_APM_SERVICE_NAME= - -# ${i18n.translate( - 'xpack.apm.tutorial.goClient.configure.commands.setCustomApmServerUrlComment', - { - defaultMessage: - 'Set custom APM Server URL (default: {defaultApmServerUrl})', - values: { defaultApmServerUrl: 'http://localhost:8200' }, - } - )} -export ELASTIC_APM_SERVER_URL=${apmServerUrl} - -# ${i18n.translate( - 'xpack.apm.tutorial.goClient.configure.commands.useIfApmRequiresTokenComment', - { - defaultMessage: 'Use if APM Server requires a secret token', - } - )} -export ELASTIC_APM_SECRET_TOKEN=${secretToken} - -# ${i18n.translate( - 'xpack.apm.tutorial.goClient.configure.commands.setServiceEnvironment', - { - defaultMessage: 'Set the service environment', - } - )} -export ELASTIC_APM_ENVIRONMENT= -`.split('\n'), + customComponentName: 'TutorialConfigAgent', textPost: i18n.translate('xpack.apm.tutorial.goClient.configure.textPost', { defaultMessage: 'See the [documentation]({documentationLink}) for advanced configuration.', @@ -743,13 +424,7 @@ Do **not** add the agent as a dependency to your application.', values: { customApmServerUrl: 'http://localhost:8200' }, } ), - commands: `java -javaagent:/path/to/elastic-apm-agent-.jar \\ - -Delastic.apm.service_name=my-application \\ - -Delastic.apm.server_urls=${apmServerUrl || 'http://localhost:8200'} \\ - -Delastic.apm.secret_token=${secretToken} \\ - -Delastic.apm.environment=production \\ - -Delastic.apm.application_packages=org.example \\ - -jar my-application.jar`.split('\n'), + customComponentName: 'TutorialConfigAgent', textPost: i18n.translate( 'xpack.apm.tutorial.javaClient.startApplication.textPost', { @@ -837,16 +512,7 @@ export const createDotNetAgentInstructions = ( defaultMessage: 'Sample appsettings.json file:', } ), - commands: `{curlyOpen} - "ElasticApm": {curlyOpen} - "SecretToken": "${secretToken}", - "ServerUrls": "${ - apmServerUrl || 'http://localhost:8200' - }", //Set custom APM Server URL (default: http://localhost:8200) - "ServiceName": "MyApp", //allowed characters: a-z, A-Z, 0-9, -, _, and space. Default is the entry assembly of the application - "Environment": "production", // Set the service environment - {curlyClose} -{curlyClose}`.split('\n'), + customComponentName: 'TutorialConfigAgent', textPost: i18n.translate( 'xpack.apm.tutorial.dotNetClient.configureAgent.textPost', { @@ -913,12 +579,7 @@ export const createPhpAgentInstructions = ( 'APM is automatically started when your app boots. Configure the agent either via `php.ini` file:', } ), - commands: `elastic_apm.server_url="${ - apmServerUrl || 'http://localhost:8200' - }" -elastic.apm.secret_token="${secretToken}" -elastic_apm.service_name="My service" -`.split('\n'), + customComponentName: 'TutorialConfigAgent', textPost: i18n.translate( 'xpack.apm.tutorial.phpClient.configure.textPost', { diff --git a/x-pack/plugins/fleet/server/plugin.ts b/x-pack/plugins/fleet/server/plugin.ts index f933965effebf..1f8f54261c721 100644 --- a/x-pack/plugins/fleet/server/plugin.ts +++ b/x-pack/plugins/fleet/server/plugin.ts @@ -328,6 +328,7 @@ export class FleetPlugin list: agentPolicyService.list, getDefaultAgentPolicyId: agentPolicyService.getDefaultAgentPolicyId, getFullAgentPolicy: agentPolicyService.getFullAgentPolicy, + getByIds: agentPolicyService.getByIDs, }, packagePolicyService, registerExternalCallback: (type: ExternalCallback[0], callback: ExternalCallback[1]) => { diff --git a/x-pack/plugins/fleet/server/services/index.ts b/x-pack/plugins/fleet/server/services/index.ts index ebddb695d695b..f82415987e5ac 100644 --- a/x-pack/plugins/fleet/server/services/index.ts +++ b/x-pack/plugins/fleet/server/services/index.ts @@ -69,6 +69,7 @@ export interface AgentPolicyServiceInterface { list: typeof agentPolicyService['list']; getDefaultAgentPolicyId: typeof agentPolicyService['getDefaultAgentPolicyId']; getFullAgentPolicy: typeof agentPolicyService['getFullAgentPolicy']; + getByIds: typeof agentPolicyService['getByIDs']; } // Saved object services