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

[ResponseOps] Move custom threshold rule params to the package #208686

Merged

Conversation

guskovaue
Copy link
Contributor

@guskovaue guskovaue commented Jan 29, 2025

Fixes: #195191

Move log threshold rule type params to the new package.

P.S.: I've moved function validateKQLStringFilter and test for it in my previous PR: #205507

@guskovaue guskovaue self-assigned this Jan 29, 2025
@guskovaue guskovaue added Feature:Alerting release_note:skip Skip the PR/issue when compiling release notes Team:ResponseOps Label for the ResponseOps team (formerly the Cases and Alerting teams) labels Jan 29, 2025
@guskovaue
Copy link
Contributor Author

/ci

@guskovaue guskovaue changed the title initial commit [ResponseOps] Move custom threshold rule params to the package Jan 29, 2025
@guskovaue guskovaue added v9.0.0 backport:prev-minor Backport to (9.0) the previous minor version (i.e. one version back from main) v8.18.0 labels Jan 29, 2025
@guskovaue guskovaue marked this pull request as ready for review January 29, 2025 13:24
@guskovaue guskovaue requested review from a team as code owners January 29, 2025 13:24
@elasticmachine
Copy link
Contributor

Pinging @elastic/response-ops (Team:ResponseOps)

@elastic elastic deleted a comment from elasticmachine Jan 29, 2025
@botelastic botelastic bot added the Team:obs-ux-management Observability Management User Experience Team label Jan 29, 2025
@elasticmachine
Copy link
Contributor

Pinging @elastic/obs-ux-management-team (Team:obs-ux-management)

const comparators = Object.values({ ...COMPARATORS, ...LEGACY_COMPARATORS });

const allowedAggregators = Object.values(Aggregators);
allowedAggregators.splice(Object.values(Aggregators).indexOf(Aggregators.COUNT), 1);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is really strange for me to have this logic here. If we never use the element COUNT of Aggregators why not just do:

enum Aggregators { // or call it AllowedAggregators instead
  // COUNT = 'count',
  AVERAGE = 'avg',
  SUM = 'sum',
  MIN = 'min',
  MAX = 'max',
  CARDINALITY = 'cardinality',
  RATE = 'rate',
  P95 = 'p95',
  P99 = 'p99',
  LAST_VALUE = 'last_value',
}

Right now we are defining an enum that is not used anywhere else and then in the only place we need it we always remove an element. Feels wrong.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree. Made changes according comments here: 0652609

….com:guskovaue/kibana into MX-195191-move-custom-threshold-rule-package
import { dataViewSpecSchema } from '../common';
import { oneOfLiterals, validateKQLStringFilter, LEGACY_COMPARATORS } from '../common/utils';

const allowedAggregators = [
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see this part has changed:

  const allowedAggregators = Object.values(Aggregators);
  allowedAggregators.splice(Object.values(Aggregators).indexOf(Aggregators.COUNT), 1);

Do we still have the Aggregators types somewhere? I am trying to remember why we had two list and excluded one from the allowed list.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, it seems we have this type still in common (Aggregator), and we use it in a lot of places.

I like the idea of having this aggregator shared everywhere (i.e., moving the common aggregator type here), but then this will increase the scope of this PR. (There is no issue in using this package both in FE and server-side, right?)

@cnasikas thoughts?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We decided not to change the way solutions use the types and the schemas due to a lack of domain knowledge. Also, some of the schemas are made with io-ts and we need the schemas to be in kbn-config. When the task is finished, we plan to inform you that you can use the package for types/schemas. It is up to the solutions to make the changes and use the types/schemas from the package if they want.

Copy link
Member

@maryam-saeidi maryam-saeidi Jan 31, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here is an idea that minimizes the number of changes, let me know what you think:

  1. Moving Aggregators enum to this package.
  2. Use it as before here:
    const allowedAggregators = Object.values(Aggregators);
    allowedAggregators.splice(Object.values(Aggregators).indexOf(Aggregators.COUNT), 1);
    
  3. Instead of aggType: schema.literal('count'),, use
    aggType: schema.literal(Aggregators.COUNT)
    
    to only rely on the enum.
  4. Import Aggregators from here in the observability > common, so we don't need to change anything else.

Would that work?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(There is no issue using this package on both the FE and server sides, right?)

I thought there was an issue using this in the FE since rule_params uses the config-schema which relies on some library(hapi?) which is not usable on the front end. Maybe @cnasikas can confirm?

If so we could move this to a different rule_params_constants package and then import it like you say.

As for the allowedAggregators values + splice logic, I don't have a better alternative :(

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I checked again, and I don't see a usage other than related to the custom threshold rule. The AI assistant usage is also related to creating a custom threshold rule.

Is there another package related to rule types from which we can expose the Aggregators enum and use it in both places?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we have a centralized package where we expose the Aggregators enum and the rules params package uses it, we can accidentally introduce breaking changes if someone modifies the enum because the Rules APIs use it. Collocating it in the rule params avoids this issue. Also, who will own the centralized package Aggregators enum?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the confusion comes from considering this enum separate from being a rule param. For us, there is no difference between this enum and the Aggregators that we use in the rule, and defining it as an enum helps us to keep the value in sync in all the usages.

Who will own the centralized package Aggregators enum?

This would be the same as this current package for exposing rule parameters, we just separate it to use it on FE as well due to the bundle limitation.

It would be good to have this improvement if we have a package that we can expose this enum, but I don't see it as a blocker, so I'll approve this PR.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks Maryam! I get your points. Let's talk about it offline.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I created an issue for a rule_params_constants package. #209547

Copy link
Contributor

@js-jankisalvi js-jankisalvi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

@cnasikas
Copy link
Member

cnasikas commented Feb 4, 2025

@elasticmachine merge upstream

@elasticmachine
Copy link
Contributor

💚 Build Succeeded

Metrics [docs]

✅ unchanged

History

cc @guskovaue

@guskovaue guskovaue merged commit 07557b6 into elastic:main Feb 4, 2025
13 checks passed
@kibanamachine
Copy link
Contributor

Starting backport for target branches: 9.0

https://github.com/elastic/kibana/actions/runs/13143813102

kibanamachine pushed a commit to kibanamachine/kibana that referenced this pull request Feb 4, 2025
…ic#208686)

Fixes: elastic#195191

Move log threshold rule type params to the new package.

P.S.: I've moved function `validateKQLStringFilter` and test for it in
my previous PR: elastic#205507

---------

Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
(cherry picked from commit 07557b6)
@kibanamachine
Copy link
Contributor

💚 All backports created successfully

Status Branch Result
9.0

Note: Successful backport PRs will be merged automatically after passing CI.

Questions ?

Please refer to the Backport tool documentation

kibanamachine added a commit that referenced this pull request Feb 4, 2025
…208686) (#209658)

# Backport

This will backport the following commits from `main` to `9.0`:
- [[ResponseOps] Move custom threshold rule params to the package
(#208686)](#208686)

<!--- Backport version: 9.4.3 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT
[{"author":{"name":"Julia","email":"iuliia.guskova@elastic.co"},"sourceCommit":{"committedDate":"2025-02-04T20:01:05Z","message":"[ResponseOps]
Move custom threshold rule params to the package (#208686)\n\nFixes:
https://github.com/elastic/kibana/issues/195191\r\n\r\nMove log
threshold rule type params to the new package.\r\n\r\nP.S.: I've moved
function `validateKQLStringFilter` and test for it in\r\nmy previous PR:
https://github.com/elastic/kibana/pull/205507\r\n\r\n---------\r\n\r\nCo-authored-by:
kibanamachine
<42973632+kibanamachine@users.noreply.github.com>\r\nCo-authored-by:
Elastic Machine
<elasticmachine@users.noreply.github.com>","sha":"07557b686c79c2af9dd3b2789c66efc1f6ca840d","branchLabelMapping":{"^v9.1.0$":"main","^v8.19.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["Feature:Alerting","release_note:skip","Team:ResponseOps","v9.0.0","backport:prev-minor","Team:obs-ux-management","v9.1.0"],"title":"[ResponseOps]
Move custom threshold rule params to the
package","number":208686,"url":"https://github.com/elastic/kibana/pull/208686","mergeCommit":{"message":"[ResponseOps]
Move custom threshold rule params to the package (#208686)\n\nFixes:
https://github.com/elastic/kibana/issues/195191\r\n\r\nMove log
threshold rule type params to the new package.\r\n\r\nP.S.: I've moved
function `validateKQLStringFilter` and test for it in\r\nmy previous PR:
https://github.com/elastic/kibana/pull/205507\r\n\r\n---------\r\n\r\nCo-authored-by:
kibanamachine
<42973632+kibanamachine@users.noreply.github.com>\r\nCo-authored-by:
Elastic Machine
<elasticmachine@users.noreply.github.com>","sha":"07557b686c79c2af9dd3b2789c66efc1f6ca840d"}},"sourceBranch":"main","suggestedTargetBranches":["9.0"],"targetPullRequestStates":[{"branch":"9.0","label":"v9.0.0","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"main","label":"v9.1.0","branchLabelMappingKey":"^v9.1.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/208686","number":208686,"mergeCommit":{"message":"[ResponseOps]
Move custom threshold rule params to the package (#208686)\n\nFixes:
https://github.com/elastic/kibana/issues/195191\r\n\r\nMove log
threshold rule type params to the new package.\r\n\r\nP.S.: I've moved
function `validateKQLStringFilter` and test for it in\r\nmy previous PR:
https://github.com/elastic/kibana/pull/205507\r\n\r\n---------\r\n\r\nCo-authored-by:
kibanamachine
<42973632+kibanamachine@users.noreply.github.com>\r\nCo-authored-by:
Elastic Machine
<elasticmachine@users.noreply.github.com>","sha":"07557b686c79c2af9dd3b2789c66efc1f6ca840d"}}]}]
BACKPORT-->

Co-authored-by: Julia <iuliia.guskova@elastic.co>
drewdaemon pushed a commit to drewdaemon/kibana that referenced this pull request Feb 6, 2025
…ic#208686)

Fixes: elastic#195191

Move log threshold rule type params to the new package.

P.S.: I've moved function `validateKQLStringFilter` and test for it in
my previous PR: elastic#205507

---------

Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport:prev-minor Backport to (9.0) the previous minor version (i.e. one version back from main) Feature:Alerting release_note:skip Skip the PR/issue when compiling release notes Team:obs-ux-management Observability Management User Experience Team Team:ResponseOps Label for the ResponseOps team (formerly the Cases and Alerting teams) v9.0.0 v9.1.0
Projects
None yet
7 participants