Skip to content

Commit

Permalink
refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
cauemarcondes committed Jun 18, 2021
1 parent 0225a8c commit 798503a
Show file tree
Hide file tree
Showing 15 changed files with 570 additions and 163 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ ELASTIC_APM = {curlyOpen}
defaultMessage: 'Use if APM Server requires a secret token',
}
)}
'SECRET_TOKEN': '{{secretToken}}',
'SECRET_TOKEN': '{{{secretToken}}}',
# ${i18n.translate(
'xpack.apm.tutorial.djangoClient.configure.commands.setCustomApmServerUrlComment',
Expand All @@ -49,7 +49,7 @@ ELASTIC_APM = {curlyOpen}
values: { defaultApmServerUrl: 'http://localhost:8200' },
}
)}
'SERVER_URL': '{{apmServerUrl}}',
'SERVER_URL': '{{{apmServerUrl}}}',
# ${i18n.translate(
'xpack.apm.tutorial.djangoClient.configure.commands.setServiceEnvironmentComment',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@

export const dotnet = `{
"ElasticApm": {
"SecretToken": "{{secretToken}}",
"ServerUrls": "{{apmServerUrl}}", //Set custom APM Server URL (default: http://localhost:8200)
"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
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ app.config['ELASTIC_APM'] = {curlyOpen}
defaultMessage: 'Use if APM Server requires a secret token',
}
)}
'SECRET_TOKEN': '{{secretToken}}',
'SECRET_TOKEN': '{{{secretToken}}}',
# ${i18n.translate(
'xpack.apm.tutorial.flaskClient.configure.commands.setCustomApmServerUrlComment',
Expand All @@ -56,7 +56,7 @@ app.config['ELASTIC_APM'] = {curlyOpen}
values: { defaultApmServerUrl: 'http://localhost:8200' },
}
)}
'SERVER_URL': '{{apmServerUrl}}',
'SERVER_URL': '{{{apmServerUrl}}}',
# ${i18n.translate(
'xpack.apm.tutorial.flaskClient.configure.commands.setServiceEnvironmentComment',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,15 @@ export ELASTIC_APM_SERVICE_NAME=
values: { defaultApmServerUrl: 'http://localhost:8200' },
}
)}
export ELASTIC_APM_SERVER_URL={{apmServerUrl}}
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}}
export ELASTIC_APM_SECRET_TOKEN={{{secretToken}}}
# ${i18n.translate(
'xpack.apm.tutorial.goClient.configure.commands.setServiceEnvironment',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@

export const java = `java -javaagent:/path/to/elastic-apm-agent-<version>.jar \\
-Delastic.apm.service_name=my-application \\
-Delastic.apm.server_urls= {{apmServerUrl}} \\
-Delastic.apm.secret_token= {{secretToken}} \\
-Delastic.apm.server_urls= {{{apmServerUrl}}} \\
-Delastic.apm.secret_token= {{{{secretToken}}}} \\
-Delastic.apm.environment=production \\
-Delastic.apm.application_packages=org.example \\
-jar my-application.jar`;
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ serviceName: '',
defaultMessage: 'Use if APM Server requires a secret token',
}
)}
secretToken: '{{secretToken}}',
secretToken: '{{{secretToken}}}',
// ${i18n.translate(
'xpack.apm.tutorial.nodeClient.configure.commands.setCustomApmServerUrlComment',
Expand All @@ -45,7 +45,7 @@ secretToken: '{{secretToken}}',
values: { defaultApmServerUrl: 'http://localhost:8200' },
}
)}
serverUrl: '{{apmServerUrl}}',
serverUrl: '{{{apmServerUrl}}}',
// ${i18n.translate(
'xpack.apm.tutorial.nodeClient.configure.commands.setCustomServiceEnvironmentComment',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* 2.0.
*/

export const php = `elastic_apm.server_url="{{apmServerUrl}}"
elastic.apm.secret_token="{{secretToken}}"
export const php = `elastic_apm.server_url="{{{apmServerUrl}}}"
elastic.apm.secret_token="{{{secretToken}}}"
elastic_apm.service_name="My service"
`;
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ service_name: 'my-service'
defaultMessage: 'Use if APM Server requires a token',
}
)}
secret_token: '{{secretToken}}'
secret_token: '{{{secretToken}}}'
# ${i18n.translate(
'xpack.apm.tutorial.rackClient.createConfig.commands.setCustomApmServerComment',
Expand All @@ -39,7 +39,7 @@ secret_token: '{{secretToken}}'
values: { defaultServerUrl: 'http://localhost:8200' },
}
)}
server_url: {{apmServerUrl}},
server_url: {{{apmServerUrl}}},
# ${i18n.translate(
'xpack.apm.tutorial.rackClient.createConfig.commands.setServiceEnvironment',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ export const rails = `# config/elastic_apm.yml:
service_name: 'my-service'
# Use if APM Server requires a secret token
secret_token: '{{secretToken}}'
secret_token: '{{{secretToken}}}'
# Set the custom APM Server URL (default: http://localhost:8200)
server_url: '{{apmServerUrl}}'
server_url: '{{{apmServerUrl}}}'
# Set the service environment
environment: 'production'`;
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ var apm = initApm({
values: { defaultApmServerUrl: 'http://localhost:8200' },
}
)}
serverUrl: '{{apmServerUrl}}',
serverUrl: '{{{apmServerUrl}}}',
// ${i18n.translate(
'xpack.apm.tutorial.jsClient.installDependency.commands.setServiceVersionComment',
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
/*
* 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 {
EuiButtonEmpty,
EuiFlexGroup,
EuiFlexItem,
EuiPopover,
EuiPopoverFooter,
EuiPopoverTitle,
EuiSelectable,
} from '@elastic/eui';
import { i18n } from '@kbn/i18n';
import React, { useEffect, useState } from 'react';
import styled from 'styled-components';
import { px } from '../../../../style/variables';

export interface EnvironmentConfigurationOption {
key: string;
label: string;
apmServerUrl?: string;
secretToken?: string;
checked?: 'on';
}

const StyledEuiButtomEmpty = styled(EuiButtonEmpty)`
.euiButtonContent {
display: flex;
justify-content: space-between;
}
`;

interface Props {
options: EnvironmentConfigurationOption[];
selectedOption?: EnvironmentConfigurationOption;
onChange: (selectedOption?: EnvironmentConfigurationOption) => void;
fleetLink: {
label: string;
href: string;
};
}

function findCheckedOption(options: EnvironmentConfigurationOption[]) {
return options.find(({ checked }) => checked === 'on');
}

export function EnvironmentConfigurationSelector({
options,
selectedOption,
onChange,
fleetLink,
}: Props) {
const [isPopoverOpen, setIsPopoverOpen] = useState(false);
const [availableOptions, setAvailableOptions] = useState<
EnvironmentConfigurationOption[]
>(options);

useEffect(() => {
const checkedOption = findCheckedOption(availableOptions);
onChange(checkedOption);
}, [availableOptions, onChange]);

function toggleIsPopoverOpen() {
setIsPopoverOpen((state) => !state);
}

return (
<EuiPopover
button={
<StyledEuiButtomEmpty
color="text"
style={{ width: px(300) }}
iconType="arrowDown"
iconSide="right"
onClick={toggleIsPopoverOpen}
>
{selectedOption?.label}
</StyledEuiButtomEmpty>
}
isOpen={isPopoverOpen}
closePopover={toggleIsPopoverOpen}
>
<div style={{ width: px(400) }}>
<EuiSelectable
searchable
searchProps={{
placeholder: i18n.translate(
'xpack.apm.tutorial.config_agent.searc',
{ defaultMessage: 'Search' }
),
compressed: true,
}}
options={availableOptions}
onChange={(newOptions) => {
const nextSelectedOption = findCheckedOption(newOptions);
// When there is no checked option don't update the options so we always have at least one option selected
if (nextSelectedOption) {
setAvailableOptions(newOptions);
}
}}
singleSelection
>
{(list, search) => {
return (
<>
<EuiPopoverTitle paddingSize="s">{search}</EuiPopoverTitle>
{list}
<EuiPopoverFooter paddingSize="none">
<EuiFlexGroup gutterSize="none">
<EuiFlexItem>
<EuiButtonEmpty
iconType="gear"
size="s"
href={fleetLink.href}
>
{fleetLink.label}
</EuiButtonEmpty>
</EuiFlexItem>
</EuiFlexGroup>
</EuiPopoverFooter>
</>
);
}}
</EuiSelectable>
</div>
</EuiPopover>
);
}
Loading

0 comments on commit 798503a

Please sign in to comment.