Skip to content

Commit

Permalink
Rebase on top of Dario's changes
Browse files Browse the repository at this point in the history
  • Loading branch information
banderror committed May 25, 2021
1 parent e0f9579 commit f9ee1cf
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 22 deletions.
19 changes: 9 additions & 10 deletions x-pack/plugins/apm/server/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,19 +130,20 @@ export class APMPlugin

registerFeaturesUsage({ licensingPlugin: plugins.licensing });

const { ruleDataService } = plugins.ruleRegistry;
const getCoreStart = () =>
core.getStartServices().then(([coreStart]) => coreStart);

const ready = once(async () => {
const componentTemplateName = plugins.ruleRegistry.getFullAssetName(
const componentTemplateName = ruleDataService.getFullAssetName(
'apm-mappings'
);

if (!plugins.ruleRegistry.isWriteEnabled()) {
if (!ruleDataService.isWriteEnabled()) {
return;
}

await plugins.ruleRegistry.createOrUpdateComponentTemplate({
await ruleDataService.createOrUpdateComponentTemplate({
name: componentTemplateName,
body: {
template: {
Expand All @@ -167,16 +168,14 @@ export class APMPlugin
},
});

await plugins.ruleRegistry.createOrUpdateIndexTemplate({
name: plugins.ruleRegistry.getFullAssetName('apm-index-template'),
await ruleDataService.createOrUpdateIndexTemplate({
name: ruleDataService.getFullAssetName('apm-index-template'),
body: {
index_patterns: [
plugins.ruleRegistry.getFullAssetName('observability-apm*'),
ruleDataService.getFullAssetName('observability-apm*'),
],
composed_of: [
plugins.ruleRegistry.getFullAssetName(
TECHNICAL_COMPONENT_TEMPLATE_NAME
),
ruleDataService.getFullAssetName(TECHNICAL_COMPONENT_TEMPLATE_NAME),
componentTemplateName,
],
},
Expand All @@ -188,7 +187,7 @@ export class APMPlugin
});

const ruleDataClient = new RuleDataClient({
alias: plugins.ruleRegistry.getFullAssetName('observability-apm'),
alias: ruleDataService.getFullAssetName('observability-apm'),
getClusterClient: async () => {
const coreStart = await getCoreStart();
return coreStart.elasticsearch.client.asInternalUser;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,13 @@
*/

import { EventSchema, Event } from './schema_types';
import { FieldMap, runtimeTypeFromFieldMap, mergeFieldMaps } from '../../../common/field_map';
import {
FieldMap,
BaseRuleFieldMap,
baseRuleFieldMap,
runtimeTypeFromFieldMap,
mergeFieldMaps,
} from '../../../common';
TechnicalRuleFieldMaps,
technicalRuleFieldMap,
} from '../../../common/assets/field_maps/technical_rule_field_map';

const baseSchema = createSchema(baseRuleFieldMap);
const baseSchema = createSchema(technicalRuleFieldMap);

export abstract class Schema {
public static create<TMap extends FieldMap>(fields: TMap): EventSchema<TMap> {
Expand All @@ -29,13 +27,13 @@ export abstract class Schema {
return createSchema(combinedFields);
}

public static getBase(): EventSchema<BaseRuleFieldMap> {
public static getBase(): EventSchema<TechnicalRuleFieldMaps> {
return baseSchema;
}

public static extendBase<TMap extends FieldMap>(
fields: TMap
): EventSchema<BaseRuleFieldMap & TMap> {
): EventSchema<TechnicalRuleFieldMaps & TMap> {
const extensionSchema = createSchema(fields);
return this.combine(baseSchema, extensionSchema);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* 2.0.
*/

import { FieldMap, FieldMapType, TypeOfFieldMap } from '../../../common';
import { FieldMap, FieldMapType, TypeOfFieldMap } from '../../../common/field_map';

export interface EventSchema<TMap extends FieldMap> {
objectFields: TMap;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

import { set } from '@elastic/safer-lodash-set';
import { FieldMap } from '../../../../common';
import { FieldMap } from '../../../../common/field_map';
import { IndexMappings } from '../../elasticsearch';

export function mappingFromFieldMap(fieldMap: FieldMap): IndexMappings {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ const testImplementation = async (service: IEventLogService, logger: Logger) =>
// Log some rule execution events.

const baseTemplate = executionLog.getLoggerTemplate({
'kibana.rac.producer': 'security',
'kibana.rac.alert.producer': 'security',
});

const ruleTemplate = baseTemplate.getLoggerTemplate({
Expand Down

0 comments on commit f9ee1cf

Please sign in to comment.