Skip to content
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] Add higher-level helper to ruleRegistry plugin exports #101541

Closed
jasonrhodes opened this issue Jun 7, 2021 · 5 comments
Closed

[RAC] Add higher-level helper to ruleRegistry plugin exports #101541

jasonrhodes opened this issue Jun 7, 2021 · 5 comments
Assignees
Labels
Team:Infra Monitoring UI - DEPRECATED DEPRECATED - Label for the Infra Monitoring UI team. Use Team:obs-ux-infra_services Theme: rac label obsolete v7.15.0

Comments

@jasonrhodes
Copy link
Member

jasonrhodes commented Jun 7, 2021

Related:

In Logs and Metrics, we're just using the basic ruleRegistry flow for now. I think it's a smart idea to provide access to the lower-level primitive methods for creating index templates, etc., especially as we start to take advantage of fields, but I think we could find a middle ground for an API that is similar to what we had before but without going all the way back to wrapping the entire alerting framework's API and becoming our own framework, if we don't want to do that.

I'm thinking it would be nice to have an API like this:

// in plugin's setup method, store this somewhere
const createLifecycleRuleType = plugins.ruleRegistry.createLifecycleRuleTypeFactory({
  appName: "logs",
  mapping: {}
});

// in rule registration
return createLifecycleRuleType({
    id: METRIC_THRESHOLD_ALERT_TYPE_ID,
  name: i18n.translate('xpack.infra.metrics.alertName', {
    defaultMessage: 'Metric threshold',
  }),
  validate: {
    // ...
  },
  minimumLicenseRequired: 'basic',
  executor: async ({ services, params }) => {
    // ...
  }
});

This encapsulates the logger, the cluster client, the need for core.getStartServices, the index and component template creation, the check for isWriteEnabled, and everything about the rule data client inside of the ruleRegistry plugin until I need it. (I'd also be okay with starting out with something like const { createLifecycleRuleType } = plugins.ruleRegistry.createLifecycleRuleTypeFactory() so we can add to the return of that factory function over time ...)

This pattern currently aligns with what we're doing for our Logs/Metrics rule types and seems like it'd work for the Uptime rule type registration, also.

@botelastic botelastic bot added the needs-team Issues missing a team label label Jun 7, 2021
@jasonrhodes jasonrhodes changed the title [RAC] Prepare the ruleRegistry plugin to coordinate with alerts as data client [RAC] Simplify ruleRegistry plugin and coordinate with alerts as data client Jun 7, 2021
@jasonrhodes jasonrhodes changed the title [RAC] Simplify ruleRegistry plugin and coordinate with alerts as data client [RAC] Simplify ruleRegistry plugin Jun 7, 2021
@jasonrhodes jasonrhodes added the Theme: rac label obsolete label Jun 8, 2021
@jasonrhodes jasonrhodes changed the title [RAC] Simplify ruleRegistry plugin [RAC] Add higher-level helper to ruleRegistry plugin exports Jun 8, 2021
@dgieselaar
Copy link
Member

Agreed that a helper (for the bootstrap process) is more than useful here. I'm not sure if appName or mapping should be tied into the lifecycle rule type helper though. I think we'll fairly quickly end up writing different rule type helpers, that all want to use the same mappings/appName.

@jasonrhodes
Copy link
Member Author

Makes sense, @dgieselaar -- I am mostly trying to avoid leaking the RuleDataClient abstraction to my plugin if I don't really need to use it, i.e. receiving it only to pass it back to something from the ruleRegistry plugin. Maybe a class that retains a reference to its client would allow for this?

const ruleRegistration = new RuleRegistration({
  appName: "logs",
  mapping: {}
});

const createLogsRuleType = ruleRegistration.createRuleTypeFactory();

ruleRegistration.client.getReader().search() // etc.

@jportner jportner added the Team: SecuritySolution Security Solutions Team working on SIEM, Endpoint, Timeline, Resolver, etc. label Jun 29, 2021
@elasticmachine
Copy link
Contributor

Pinging @elastic/security-solution (Team: SecuritySolution)

@botelastic botelastic bot removed the needs-team Issues missing a team label label Jun 29, 2021
@jasonrhodes jasonrhodes self-assigned this Jul 12, 2021
@jasonrhodes jasonrhodes added v7.15.0 Team:Infra Monitoring UI - DEPRECATED DEPRECATED - Label for the Infra Monitoring UI team. Use Team:obs-ux-infra_services and removed Team: SecuritySolution Security Solutions Team working on SIEM, Endpoint, Timeline, Resolver, etc. labels Jul 12, 2021
@elasticmachine
Copy link
Contributor

Pinging @elastic/logs-metrics-ui (Team:logs-metrics-ui)

@jasonrhodes
Copy link
Member Author

Done by @banderror

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Team:Infra Monitoring UI - DEPRECATED DEPRECATED - Label for the Infra Monitoring UI team. Use Team:obs-ux-infra_services Theme: rac label obsolete v7.15.0
Projects
None yet
Development

No branches or pull requests

4 participants