-
Notifications
You must be signed in to change notification settings - Fork 8.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[RAC][Rule Registry] Improve RuleDataService API and index bootstrapping implementation #108115
Changes from all commits
ce85666
bac3d92
7f53c4c
e83207a
591dd18
a061a4e
461db8d
6ccccbb
dccd175
4ecf2e3
926cada
826276b
077ca24
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,10 +5,8 @@ | |
* 2.0. | ||
*/ | ||
|
||
import { once } from 'lodash'; | ||
import { CoreSetup, Logger } from 'src/core/server'; | ||
import { TECHNICAL_COMPONENT_TEMPLATE_NAME } from '../../../../rule_registry/common/assets'; | ||
import { RuleRegistryPluginSetupContract } from '../../../../rule_registry/server'; | ||
import { Dataset, RuleRegistryPluginSetupContract } from '../../../../rule_registry/server'; | ||
import type { InfraFeatureId } from '../../../common/constants'; | ||
import { RuleRegistrationContext, RulesServiceStartDeps } from './types'; | ||
|
||
|
@@ -25,51 +23,20 @@ export const createRuleDataClient = ({ | |
logger: Logger; | ||
ruleDataService: RuleRegistryPluginSetupContract['ruleDataService']; | ||
}) => { | ||
const initializeRuleDataTemplates = once(async () => { | ||
const componentTemplateName = ruleDataService.getFullAssetName( | ||
`${registrationContext}-mappings` | ||
); | ||
|
||
const indexNamePattern = ruleDataService.getFullAssetName(`${registrationContext}*`); | ||
|
||
if (!ruleDataService.isWriteEnabled()) { | ||
return; | ||
} | ||
|
||
await ruleDataService.createOrUpdateComponentTemplate({ | ||
name: componentTemplateName, | ||
body: { | ||
template: { | ||
settings: { | ||
number_of_shards: 1, | ||
}, | ||
mappings: {}, | ||
}, | ||
}, | ||
}); | ||
|
||
await ruleDataService.createOrUpdateIndexTemplate({ | ||
name: ruleDataService.getFullAssetName(registrationContext), | ||
body: { | ||
index_patterns: [indexNamePattern], | ||
composed_of: [ | ||
ruleDataService.getFullAssetName(TECHNICAL_COMPONENT_TEMPLATE_NAME), | ||
componentTemplateName, | ||
], | ||
return ruleDataService.initializeIndex({ | ||
feature: ownerFeatureId, | ||
registrationContext, | ||
dataset: Dataset.alerts, | ||
componentTemplateRefs: [], | ||
componentTemplates: [ | ||
{ | ||
name: 'mappings', | ||
version: 0, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Proper versioning according to the recent discussions will be implemented in a follow-up PR. |
||
mappings: {}, | ||
}, | ||
}); | ||
|
||
await ruleDataService.updateIndexMappingsMatchingPattern(indexNamePattern); | ||
}); | ||
|
||
// initialize eagerly | ||
const initializeRuleDataTemplatesPromise = initializeRuleDataTemplates().catch((err) => { | ||
logger.error(err); | ||
], | ||
indexTemplate: { | ||
version: 0, | ||
}, | ||
}); | ||
|
||
return ruleDataService.getRuleDataClient( | ||
ownerFeatureId, | ||
ruleDataService.getFullAssetName(registrationContext), | ||
() => initializeRuleDataTemplatesPromise | ||
); | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,7 +18,7 @@ import { | |
ScopedAnnotationsClientFactory, | ||
AnnotationsAPI, | ||
} from './lib/annotations/bootstrap_annotations'; | ||
import type { RuleRegistryPluginSetupContract } from '../../rule_registry/server'; | ||
import { Dataset, RuleRegistryPluginSetupContract } from '../../rule_registry/server'; | ||
import { PluginSetupContract as FeaturesSetup } from '../../features/server'; | ||
import { uiSettings } from './ui_settings'; | ||
import { registerRoutes } from './routes/register_routes'; | ||
|
@@ -100,11 +100,17 @@ export class ObservabilityPlugin implements Plugin<ObservabilityPluginSetup> { | |
|
||
const start = () => core.getStartServices().then(([coreStart]) => coreStart); | ||
|
||
const ruleDataClient = plugins.ruleRegistry.ruleDataService.getRuleDataClient( | ||
'observability', | ||
plugins.ruleRegistry.ruleDataService.getFullAssetName(), | ||
() => Promise.resolve() | ||
); | ||
const { ruleDataService } = plugins.ruleRegistry; | ||
const ruleDataClient = ruleDataService.initializeIndex({ | ||
feature: 'observability', | ||
registrationContext: 'observability', | ||
dataset: Dataset.alerts, | ||
componentTemplateRefs: [], | ||
componentTemplates: [], | ||
indexTemplate: { | ||
version: 0, | ||
}, | ||
}); | ||
Comment on lines
+103
to
+113
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This replaces the previous implementation: const ruleDataClient = plugins.ruleRegistry.ruleDataService.getRuleDataClient(
'observability',
plugins.ruleRegistry.ruleDataService.getFullAssetName(),
() => Promise.resolve()
); Seems like it's a stub. Should I keep it? Why it's needed? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
It will see if it should bootstrap any resources for
And then it will update mappings of all concrete indices matching Is this There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It seems for this use case it would be useful to expose some kind of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was also thinking about that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I created a ticket for that: #111173 |
||
|
||
registerRoutes({ | ||
core: { | ||
|
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
does this also create the index?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like it doesn't, in that case maybe another name is in order? Something like
installResources
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dgieselaar yes, it starts index bootstrapping right away inside the call in the background
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
installIndexResources
orbootstrapIndex
sounds good to me, more descriptive names. I can rename it in a follow-up PR 👍There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
first one sgtm 👍