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

Revisit custom threshold types in public folder #170306

Conversation

maryam-saeidi
Copy link
Member

@maryam-saeidi maryam-saeidi commented Nov 1, 2023

Part of #159340
Closes #169364

Summary

This PR:

  1. Removes preFill logic
    In this PR, I removed the logic about prefilling custom threshold rule params as it was originally for other rule types (not custom equation) and to be used in the Metric threshold rule and the code related to this logic was super confusing, and I wasn't even sure if it works as expected since we haven't used this logic anywhere. I created a ticket to bring back this feature properly later, specifically for the custom equation, and integrate it in one of the apps, such as Infra. We also need to be able to preFill data view information (both adHoc and persisted data view)
  2. Renames types and file names
    • From metricThreshold to customThreshold
    • From metricExplorer to expression
  3. Removes unused types
  4. Remove logic related to aggregations other than the custom equation at the top level

Also, the fields that end with pct now have the % after the related value: (The reason message was fixed in another PR)

🧪 How to test

  • Nothing has changed related to functionality, so please make sure the custom threshold rule is working as before for
    • Creating a new rule with multiple conditions
    • Adding groups
    • Editing a rule and checking the charts are shown as before
    • Test both adHoc and persisted data view

@maryam-saeidi maryam-saeidi added the release_note:skip Skip the PR/issue when compiling release notes label Nov 1, 2023
@maryam-saeidi maryam-saeidi self-assigned this Nov 1, 2023
@apmmachine
Copy link
Contributor

🤖 GitHub comments

Expand to view the GitHub comments

Just comment with:

  • /oblt-deploy : Deploy a Kibana instance using the Observability test environments.
  • /oblt-deploy-serverless : Deploy a serverless Kibana instance using the Observability test environments.
  • run elasticsearch-ci/docs : Re-trigger the docs validation. (use unformatted text in the comment!)

@maryam-saeidi maryam-saeidi marked this pull request as ready for review November 3, 2023 09:02
@maryam-saeidi maryam-saeidi requested review from a team as code owners November 3, 2023 09:02
@fkanout fkanout self-requested a review November 8, 2023 07:37
@fkanout fkanout requested a review from a team as a code owner November 9, 2023 14:21
Copy link
Contributor

@fkanout fkanout left a comment

Choose a reason for hiding this comment

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

@maryam-saeidi, when visiting the rule details it shows an error about not enabling to get the execution history.
Screenshot 2023-11-09 at 15 25 28

Copy link
Contributor

@fkanout fkanout left a comment

Choose a reason for hiding this comment

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

On serverless, it fires alerts without the error of execution history we saw in stateful

Screenshot 2023-11-09 at 16 35 12

@@ -5,16 +5,13 @@
* 2.0.
*/

export const SNAPSHOT_CUSTOM_AGGREGATIONS = ['avg', 'max', 'min', 'rate'] as const;
export const METRIC_EXPLORER_AGGREGATIONS = [
Copy link
Contributor

Choose a reason for hiding this comment

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

To be deleted it's not used anymore.

Copy link
Member Author

Choose a reason for hiding this comment

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

@@ -22,7 +23,7 @@ export const scenario2 = {
params: {
criteria: [
{
aggType: Aggregators.CUSTOM,
aggType: CUSTOM_AGGREGATOR,
Copy link
Contributor

Choose a reason for hiding this comment

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

Same: I think we should keep referring to the custom from Aggregators to keep everything on track when an updates occurs. Can you explain the benefits of not using the value fromAggregators?
I will not repeate the same comment for the other files :D

Copy link
Member Author

Choose a reason for hiding this comment

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

I changed it to CUSTOM_AGGREGATOR because it is the only acceptable value at this level and does not belong to Aggregators anymore. There were a lot of type duplications to handle this scenario, and by splitting them, we don't need to exclude custom from Aggregators to be used in the rule.

I am considering creating a ticket to remove CUSTOM_AGGREGATOR everywhere if it does not have a backward compatibility issue.

@@ -14,7 +14,7 @@ import { InfraWaffleMapDataFormat } from './types';

export const FORMATTERS = {
number: formatNumber,
// Because the implimentation for formatting large numbers is the same as formatting
// Because the implementation for formatting large numbers is the same as formatting
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

* 2.0.
*/

import * as rt from 'io-ts';
Copy link
Contributor

Choose a reason for hiding this comment

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

👏🏻 DELETEING

*
* This utility function can be used to turn a TypeScript enum into a io-ts codec.
*/
export function fromEnum<EnumType extends string>(
Copy link
Contributor

Choose a reason for hiding this comment

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

What does this function do?

Copy link
Member Author

Choose a reason for hiding this comment

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

This is for turning a Typescript enum into an io-ts validation. I used it for the Aggregators enum.

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 already some nice utils exposed via perhaps worth reusing that or move that into packages/kbn-io-ts-utils
import { enumeration } from '@kbn/securitysolution-io-ts-types';

const { groupBy, filterQuery, metrics } = metricThresholdPrefill;

return <AlertFlyout options={{ groupBy, filterQuery, metrics }} visible setVisible={onClose} />;
return <AlertFlyout visible setVisible={onClose} />;
Copy link
Contributor

Choose a reason for hiding this comment

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

We don't need to send options={{ groupBy, filterQuery, metrics }} ?

Copy link
Member Author

Choose a reason for hiding this comment

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

This is related to preFill logic; I removed it because it did not match the new custom threshold structure and created a ticket to add this logic correctly (#170295)

@maryam-saeidi
Copy link
Member Author

@fkanout I tried the Stateful rule details page and didn't face the issue you shared. Can you please check which API fails and if there are any error logs in your server? Is it related to changes in this PR?
image

Copy link
Contributor

@shahzad31 shahzad31 left a comment

Choose a reason for hiding this comment

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

LGTM !!

Tested creating threshold rule, editing, charts, group by and rule details page. !!

@benakansara
Copy link
Contributor

@maryam-saeidi I think using a different unit for percentage metrics is confusing for user and we need to handle different scenarios when switching between percentage and non-percentage metrics. Also, how do we handle a scenario when all metrics in a condition are percentage.

Switching from average to count

Screen.Recording.2023-11-13.at.22.44.22.mov

Using both percentage metrics in a condition

Screen.Recording.2023-11-13.at.22.50.33.mov

@maryam-saeidi
Copy link
Member Author

maryam-saeidi commented Nov 13, 2023

@maryam-saeidi I think using a different unit for percentage metrics is confusing for user and we need to handle different scenarios when switching between percentage and non-percentage metrics. Also, how do we handle a scenario when all metrics in a condition are percentage.

Switching from average to count

Screen.Recording.2023-11-13.at.22.44.22.mov

Using both percentage metrics in a condition

Screen.Recording.2023-11-13.at.22.50.33.mov

@benakansara For now, I only handled the scenario that there is only one percentage metric, which is similar to what we had in the Metric threshold. It should be easy to do the same when all the metrics are percentages if we decide to do so. I'll create an issue to get @maciejforcone 's opinion on this case as well. This improvement helps to see the value of percentage fields accordingly instead of setting 0.1 as the threshold for percentage fields, but I agree that the current solution is not perfect either.

Regarding the first issue, I didn't find an ideal solution; one possible option is not to have a default value for the threshold similar to the Metric threshold. Let's discuss this with @maciejforcone as well.

Issue: #171121

@maryam-saeidi maryam-saeidi enabled auto-merge (squash) November 13, 2023 17:56
@kibana-ci
Copy link
Collaborator

💚 Build Succeeded

Metrics [docs]

Module Count

Fewer modules leads to a faster build time

id before after diff
observability 491 480 -11

Async chunks

Total size of all lazy-loaded chunks that will be downloaded as the user navigates the app

id before after diff
observability 1.1MB 1.1MB -6.9KB
triggersActionsUi 1.4MB 1.4MB +12.0B
total -6.9KB

Page load bundle

Size of the bundles that are downloaded on every page load. Target size is below 100kb

id before after diff
observability 104.1KB 100.4KB -3.7KB
Unknown metric groups

ESLint disabled line counts

id before after diff
observability 37 38 +1

Total ESLint disabled count

id before after diff
observability 42 43 +1

History

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

cc @maryam-saeidi

@maryam-saeidi maryam-saeidi merged commit 6f2ad26 into elastic:main Nov 14, 2023
@kibanamachine kibanamachine added v8.12.0 backport:skip This commit does not require backporting labels Nov 14, 2023
@maryam-saeidi maryam-saeidi deleted the 159340-revisit-custom-threshold-public-types branch November 14, 2023 09:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport:skip This commit does not require backporting release_note:skip Skip the PR/issue when compiling release notes v8.12.0
Projects
None yet
8 participants