Skip to content

Commit

Permalink
[APM] Fleet: adding support for legacy fields (#110136) (#110730)
Browse files Browse the repository at this point in the history
* supporting legacy fields

* addressing PR comments

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>

Co-authored-by: Cauê Marcondes <55978943+cauemarcondes@users.noreply.github.com>
  • Loading branch information
kibanamachine and cauemarcondes authored Sep 1, 2021
1 parent 34f32a5 commit e64892a
Showing 1 changed file with 45 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ interface GetApmPackagePolicyDefinitionOptions {
export function getApmPackagePolicyDefinition(
options: GetApmPackagePolicyDefinitionOptions
) {
const { apmServerSchema, cloudPluginSetup } = options;
return {
name: 'Elastic APM',
namespace: 'default',
Expand All @@ -27,7 +28,10 @@ export function getApmPackagePolicyDefinition(
type: 'apm',
enabled: true,
streams: [],
vars: getApmPackageInputVars(options),
vars: getApmPackageInputVars({
cloudPluginSetup,
apmServerSchema: preprocessLegacyFields({ apmServerSchema }),
}),
},
],
package: {
Expand All @@ -38,6 +42,34 @@ export function getApmPackagePolicyDefinition(
};
}

function preprocessLegacyFields({
apmServerSchema,
}: {
apmServerSchema: Record<string, any>;
}) {
const copyOfApmServerSchema = { ...apmServerSchema };
[
{
key: 'apm-server.auth.anonymous.rate_limit.event_limit',
legacyKey: 'apm-server.rum.event_rate.limit',
},
{
key: 'apm-server.auth.anonymous.rate_limit.ip_limit',
legacyKey: 'apm-server.rum.event_rate.lru_size',
},
{
key: 'apm-server.auth.anonymous.allow_service',
legacyKey: 'apm-server.rum.allow_service_names',
},
].forEach(({ key, legacyKey }) => {
if (!copyOfApmServerSchema[key]) {
copyOfApmServerSchema[key] = copyOfApmServerSchema[legacyKey];
delete copyOfApmServerSchema[legacyKey];
}
});
return copyOfApmServerSchema;
}

function getApmPackageInputVars(options: GetApmPackagePolicyDefinitionOptions) {
const { apmServerSchema } = options;
const apmServerConfigs = Object.entries(
Expand Down Expand Up @@ -90,6 +122,18 @@ export const apmConfigMapping: Record<
name: 'rum_allow_headers',
type: 'text',
},
'apm-server.rum.event_rate.limit': {
name: 'rum_event_rate_limit',
type: 'integer',
},
'apm-server.rum.allow_service_names': {
name: 'rum_allow_service_names',
type: 'text',
},
'apm-server.rum.event_rate.lru_size': {
name: 'rum_event_rate_lru_size',
type: 'integer',
},
'apm-server.rum.response_headers': {
name: 'rum_response_headers',
type: 'yaml',
Expand Down

0 comments on commit e64892a

Please sign in to comment.