Skip to content

Commit

Permalink
- replaces full index configuration paths with references in the `xpa…
Browse files Browse the repository at this point in the history
…ck.apm.indices` namespace

- removes mergeConfig function and test
  • Loading branch information
ogupte committed Oct 12, 2021
1 parent cbb5944 commit 72c4e18
Show file tree
Hide file tree
Showing 85 changed files with 816 additions and 1,163 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,12 @@ kibana_vars=(
xpack.alerts.invalidateApiKeysTask.interval
xpack.alerts.invalidateApiKeysTask.removalDelay
xpack.apm.enabled
xpack.apm.errors
xpack.apm.metrics
xpack.apm.onboarding
xpack.apm.sourcemaps
xpack.apm.spans
xpack.apm.transactions
xpack.apm.maxServiceEnvironments
xpack.apm.searchAggregatedTransactions
xpack.apm.serviceMapEnabled
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ describe('No data screen', () => {
url: apmIndicesSaveURL,
method: 'POST',
body: {
'xpack.apm.sourcemapIndices': 'foo-*',
'xpack.apm.errorIndices': 'foo-*',
'xpack.apm.onboardingIndices': 'foo-*',
'xpack.apm.spanIndices': 'foo-*',
'xpack.apm.transactionIndices': 'foo-*',
'xpack.apm.metricsIndices': 'foo-*',
sourcemaps: 'foo-*',
errors: 'foo-*',
onboarding: 'foo-*',
spans: 'foo-*',
transactions: 'foo-*',
metrics: 'foo-*',
},
headers: {
'kbn-xsrf': true,
Expand All @@ -49,12 +49,12 @@ describe('No data screen', () => {
url: apmIndicesSaveURL,
method: 'POST',
body: {
'xpack.apm.sourcemapIndices': '',
'xpack.apm.errorIndices': '',
'xpack.apm.onboardingIndices': '',
'xpack.apm.spanIndices': '',
'xpack.apm.transactionIndices': '',
'xpack.apm.metricsIndices': '',
sourcemaps: '',
errors: '',
onboarding: '',
spans: '',
transactions: '',
metrics: '',
},
headers: { 'kbn-xsrf': true },
auth: { user: 'apm_power_user', pass: 'changeme' },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,40 +30,40 @@ import {

const APM_INDEX_LABELS = [
{
configurationName: 'xpack.apm.sourcemapIndices',
configurationName: 'sourcemaps',
label: i18n.translate(
'xpack.apm.settings.apmIndices.sourcemapIndicesLabel',
{ defaultMessage: 'Sourcemap Indices' }
),
},
{
configurationName: 'xpack.apm.errorIndices',
configurationName: 'errors',
label: i18n.translate('xpack.apm.settings.apmIndices.errorIndicesLabel', {
defaultMessage: 'Error Indices',
}),
},
{
configurationName: 'xpack.apm.onboardingIndices',
configurationName: 'onboarding',
label: i18n.translate(
'xpack.apm.settings.apmIndices.onboardingIndicesLabel',
{ defaultMessage: 'Onboarding Indices' }
),
},
{
configurationName: 'xpack.apm.spanIndices',
configurationName: 'spans',
label: i18n.translate('xpack.apm.settings.apmIndices.spanIndicesLabel', {
defaultMessage: 'Span Indices',
}),
},
{
configurationName: 'xpack.apm.transactionIndices',
configurationName: 'transactions',
label: i18n.translate(
'xpack.apm.settings.apmIndices.transactionIndicesLabel',
{ defaultMessage: 'Transaction Indices' }
),
},
{
configurationName: 'xpack.apm.metricsIndices',
configurationName: 'metrics',
label: i18n.translate('xpack.apm.settings.apmIndices.metricsIndicesLabel', {
defaultMessage: 'Metrics Indices',
}),
Expand Down Expand Up @@ -214,7 +214,10 @@ export function ApmIndices() {
{
defaultMessage:
'Overrides {configurationName}: {defaultValue}',
values: { configurationName, defaultValue },
values: {
configurationName: `xpack.apm.indices.${configurationName}`,
defaultValue,
},
}
)}
fullWidth
Expand Down
24 changes: 12 additions & 12 deletions x-pack/plugins/apm/public/utils/testHelpers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -119,12 +119,12 @@ interface MockSetup {
config: APMConfig;
uiFilters: UxUIFilters;
indices: {
'xpack.apm.sourcemapIndices': string;
'xpack.apm.errorIndices': string;
'xpack.apm.onboardingIndices': string;
'xpack.apm.spanIndices': string;
'xpack.apm.transactionIndices': string;
'xpack.apm.metricsIndices': string;
sourcemaps: string;
errors: string;
onboarding: string;
spans: string;
transactions: string;
metrics: string;
apmAgentConfigurationIndex: string;
apmCustomLinkIndex: string;
};
Expand Down Expand Up @@ -176,12 +176,12 @@ export async function inspectSearchParams(
) as APMConfig,
uiFilters: {},
indices: {
'xpack.apm.sourcemapIndices': 'myIndex',
'xpack.apm.errorIndices': 'myIndex',
'xpack.apm.onboardingIndices': 'myIndex',
'xpack.apm.spanIndices': 'myIndex',
'xpack.apm.transactionIndices': 'myIndex',
'xpack.apm.metricsIndices': 'myIndex',
sourcemaps: 'myIndex',
errors: 'myIndex',
onboarding: 'myIndex',
spans: 'myIndex',
transactions: 'myIndex',
metrics: 'myIndex',
apmAgentConfigurationIndex: 'myIndex',
apmCustomLinkIndex: 'myIndex',
},
Expand Down
12 changes: 6 additions & 6 deletions x-pack/plugins/apm/scripts/shared/read-kibana-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@ export const readKibanaConfig = () => {
};

return {
'xpack.apm.transactionIndices': 'apm-*',
'xpack.apm.metricsIndices': 'apm-*',
'xpack.apm.errorIndices': 'apm-*',
'xpack.apm.spanIndices': 'apm-*',
'xpack.apm.onboardingIndices': 'apm-*',
'xpack.apm.sourcemapIndices': 'apm-*',
'xpack.apm.indices.transactions': 'apm-*',
'xpack.apm.indices.metrics': 'apm-*',
'xpack.apm.indices.errors': 'apm-*',
'xpack.apm.indices.spans': 'apm-*',
'xpack.apm.indices.onboarding': 'apm-*',
'xpack.apm.indices.sourcemaps': 'apm-*',
'elasticsearch.hosts': 'http://localhost:9200',
...loadedKibanaConfig,
...cliEsCredentials,
Expand Down
7 changes: 6 additions & 1 deletion x-pack/plugins/apm/scripts/upload-telemetry-data/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,12 @@ async function uploadData() {
collectTelemetryParams: {
logger: console as unknown as Logger,
indices: {
...config,
transactions: config['xpack.apm.indices.transactions'],
metrics: config['xpack.apm.indices.metrics'],
errors: config['xpack.apm.indices.errors'],
spans: config['xpack.apm.indices.spans'],
onboarding: config['xpack.apm.indices.onboarding'],
sourcemaps: config['xpack.apm.indices.sourcemaps'],
apmCustomLinkIndex: '.apm-custom-links',
apmAgentConfigurationIndex: '.apm-agent-configuration',
},
Expand Down
34 changes: 0 additions & 34 deletions x-pack/plugins/apm/server/index.test.ts

This file was deleted.

69 changes: 16 additions & 53 deletions x-pack/plugins/apm/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,18 +46,18 @@ const configSchema = schema.object({
enabled: schema.boolean({ defaultValue: false }),
}),
}),
transactionIndices: schema.string({ defaultValue: 'traces-apm*,apm-*' }),
spanIndices: schema.string({ defaultValue: 'traces-apm*,apm-*' }),
errorIndices: schema.string({ defaultValue: 'logs-apm*,apm-*' }),
metricsIndices: schema.string({ defaultValue: 'metrics-apm*,apm-*' }),
sourcemapIndices: schema.string({ defaultValue: 'apm-*' }),
onboardingIndices: schema.string({ defaultValue: 'apm-*' }),
indexPattern: schema.string({ defaultValue: 'apm-*' }),
fleetMode: schema.boolean({ defaultValue: true }),
indices: schema.object({
transactions: schema.string({ defaultValue: 'traces-apm*,apm-*' }),
spans: schema.string({ defaultValue: 'traces-apm*,apm-*' }),
errors: schema.string({ defaultValue: 'logs-apm*,apm-*' }),
metrics: schema.string({ defaultValue: 'metrics-apm*,apm-*' }),
sourcemaps: schema.string({ defaultValue: 'apm-*' }),
onboarding: schema.string({ defaultValue: 'apm-*' }),
}),
});

// plugin config
export const config: PluginConfigDescriptor<APMXPackConfig> = {
export const config: PluginConfigDescriptor<APMConfig> = {
deprecations: ({
deprecate,
renameFromRoot,
Expand All @@ -67,13 +67,13 @@ export const config: PluginConfigDescriptor<APMXPackConfig> = {
deprecate('enabled', '8.0.0'),
renameFromRoot(
'apm_oss.transactionIndices',
'xpack.apm.transactionIndices'
'xpack.apm.indices.transactions'
),
renameFromRoot('apm_oss.spanIndices', 'xpack.apm.spanIndices'),
renameFromRoot('apm_oss.errorIndices', 'xpack.apm.errorIndices'),
renameFromRoot('apm_oss.metricsIndices', 'xpack.apm.metricsIndices'),
renameFromRoot('apm_oss.sourcemapIndices', 'xpack.apm.sourcemapIndices'),
renameFromRoot('apm_oss.onboardingIndices', 'xpack.apm.onboardingIndices'),
renameFromRoot('apm_oss.spanIndices', 'xpack.apm.indices.spans'),
renameFromRoot('apm_oss.errorIndices', 'xpack.apm.indices.errors'),
renameFromRoot('apm_oss.metricsIndices', 'xpack.apm.indices.metrics'),
renameFromRoot('apm_oss.sourcemapIndices', 'xpack.apm.indices.sourcemaps'),
renameFromRoot('apm_oss.onboardingIndices', 'xpack.apm.indices.onboarding'),
deprecateFromRoot('apm_oss.enabled', '8.0.0'),
unusedFromRoot('apm_oss.fleetMode'),
unusedFromRoot('apm_oss.indexPattern'),
Expand All @@ -94,44 +94,7 @@ export const config: PluginConfigDescriptor<APMXPackConfig> = {
schema: configSchema,
};

export type APMXPackConfig = TypeOf<typeof configSchema>;
export type APMConfig = ReturnType<typeof mergeConfigs>;

// plugin config and ui indices settings
export function mergeConfigs(apmConfig: APMXPackConfig) {
const mergedConfig = {
'xpack.apm.transactionIndices': apmConfig.transactionIndices,
'xpack.apm.spanIndices': apmConfig.spanIndices,
'xpack.apm.errorIndices': apmConfig.errorIndices,
'xpack.apm.metricsIndices': apmConfig.metricsIndices,
'xpack.apm.sourcemapIndices': apmConfig.sourcemapIndices,
'xpack.apm.onboardingIndices': apmConfig.onboardingIndices,
'xpack.apm.serviceMapEnabled': apmConfig.serviceMapEnabled,
'xpack.apm.serviceMapFingerprintBucketSize':
apmConfig.serviceMapFingerprintBucketSize,
'xpack.apm.serviceMapTraceIdBucketSize':
apmConfig.serviceMapTraceIdBucketSize,
'xpack.apm.serviceMapFingerprintGlobalBucketSize':
apmConfig.serviceMapFingerprintGlobalBucketSize,
'xpack.apm.serviceMapTraceIdGlobalBucketSize':
apmConfig.serviceMapTraceIdGlobalBucketSize,
'xpack.apm.serviceMapMaxTracesPerRequest':
apmConfig.serviceMapMaxTracesPerRequest,
'xpack.apm.ui.enabled': apmConfig.ui.enabled,
'xpack.apm.ui.maxTraceItems': apmConfig.ui.maxTraceItems,
'xpack.apm.ui.transactionGroupBucketSize':
apmConfig.ui.transactionGroupBucketSize,
'xpack.apm.autocreateApmIndexPattern': apmConfig.autocreateApmIndexPattern,
'xpack.apm.telemetryCollectionEnabled':
apmConfig.telemetryCollectionEnabled,
'xpack.apm.searchAggregatedTransactions':
apmConfig.searchAggregatedTransactions,
'xpack.apm.metricsInterval': apmConfig.metricsInterval,
'xpack.apm.agent.migrations.enabled': apmConfig.agent.migrations.enabled,
};

return mergedConfig;
}
export type APMConfig = TypeOf<typeof configSchema>;

export const plugin = (initContext: PluginInitializerContext) =>
new APMPlugin(initContext);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ export function registerErrorCountAlertType({
});

const searchParams = {
index: indices['xpack.apm.errorIndices'],
index: indices.errors,
size: 0,
body: {
query: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,12 +115,12 @@ export function registerTransactionDurationAlertType({
// to prevent (likely) unnecessary blocking request
// in rule execution
const searchAggregatedTransactions =
config['xpack.apm.searchAggregatedTransactions'] !==
config.searchAggregatedTransactions !==
SearchAggregatedTransactionSetting.never;

const index = searchAggregatedTransactions
? indices['xpack.apm.metricsIndices']
: indices['xpack.apm.transactionIndices'];
? indices.metrics
: indices.transactions;

const field = getTransactionDurationFieldForAggregatedTransactions(
searchAggregatedTransactions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,12 @@ export function registerTransactionErrorRateAlertType({
// to prevent (likely) unnecessary blocking request
// in rule execution
const searchAggregatedTransactions =
config['xpack.apm.searchAggregatedTransactions'] !==
config.searchAggregatedTransactions !==
SearchAggregatedTransactionSetting.never;

const index = searchAggregatedTransactions
? indices['xpack.apm.metricsIndices']
: indices['xpack.apm.transactionIndices'];
? indices.metrics
: indices.transactions;

const searchParams = {
index,
Expand Down
6 changes: 4 additions & 2 deletions x-pack/plugins/apm/server/lib/alerts/test_utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@ export const createRuleTypeMocks = () => {
let alertExecutor: (...args: any[]) => Promise<any>;

const mockedConfig$ = of({
'xpack.apm.errorIndices': 'apm-*',
'xpack.apm.transactionIndices': 'apm-*',
indices: {
errors: 'apm-*',
transactions: 'apm-*',
},
} as APMConfig);

const loggerMock = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export async function createAnomalyDetectionJobs(
`Creating ML anomaly detection jobs for environments: [${uniqueMlJobEnvs}].`
);

const indexPatternName = indices['xpack.apm.metricsIndices'];
const indexPatternName = indices.metrics;
const responses = await Promise.all(
uniqueMlJobEnvs.map((environment) =>
createAnomalyDetectionJob({ ml, environment, indexPatternName })
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ import {

describe('data telemetry collection tasks', () => {
const indices = {
'xpack.apm.errorIndices': 'apm-8.0.0-error',
'xpack.apm.metricsIndices': 'apm-8.0.0-metric',
'xpack.apm.spanIndices': 'apm-8.0.0-span',
'xpack.apm.transactionIndices': 'apm-8.0.0-transaction',
errors: 'apm-8.0.0-error',
metrics: 'apm-8.0.0-metric',
spans: 'apm-8.0.0-span',
transactions: 'apm-8.0.0-transaction',
} as ApmIndicesConfig;

describe('environments', () => {
Expand Down
Loading

0 comments on commit 72c4e18

Please sign in to comment.