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] Add pagination and sorting to the alerts search strategy #126813

Conversation

chrisronline
Copy link
Contributor

Resolves #126722

This PR adds the ability to sort and paginate the recently introduced search strategy.

Testing

I've been testing this by using Filebeat) and configure it to start ingesting the Elasticsearch server log:

cbr-mbp:filebeat chris$ ./filebeat modules list
Enabled:
elasticsearch

Disabled:
cbr-mbp:filebeat chris$ cat modules.d/elasticsearch.yml 
# Module: elasticsearch
# Docs: https://www.elastic.co/guide/en/beats/filebeat/master/filebeat-module-elasticsearch.html

- module: elasticsearch
  # Server log
  server:
    enabled: true

    # Set custom paths for the log files. If left empty,
    # Filebeat will choose the paths depending on your OS.
    var.paths:
      - /Users/chris/dev/repos/kibana/.es/8*/logs/elasticsearch_server.log
      - /Users/chris/dev/repos/kibana/.es/source/logs/elasticsearch_server.log

Start Filebeat and visit the Logs UI to ensure the data is coming in.

Then, go to the rules for security solutions:

Screen Shot 2022-03-03 at 11 29 16 AM

and create a custom rule that looks like:

Screen Shot 2022-03-03 at 11 29 53 AM

Let the rule run for a few seconds and verify alerts are showing up:

Screen Shot 2022-03-03 at 11 30 42 AM

Then, use curl or some tool to send a POST request to Kibana like:

POST https://localhost:5601/internal/bsearch

{
	"batch": [
		{
			"request": {
				"featureIds": [
					"siem"
				],
				"pagination": {
					"pageIndex": 0,
					"pageSize": 2
				},
				"sort": [
					{
						"id": "kibana.alert.rule.created_at",
						"direction": "asc"
					}
				]
			},
			"options": {
				"strategy": "ruleRegistryAlertsSearchStrategy"
			}
		}
	]
}

Using this setup, you should be able to verify the functionality is working as intended.

@chrisronline chrisronline added review release_note:skip Skip the PR/issue when compiling release notes Team:ResponseOps Label for the ResponseOps team (formerly the Cases and Alerting teams) v8.2.0 labels Mar 3, 2022
@chrisronline chrisronline requested a review from a team as a code owner March 3, 2022 16:34
@elasticmachine
Copy link
Contributor

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

pageSize: number;
}

export interface RuleRegistrySearchRequestSort {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should just use the estypes.Sort type from import type * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey';

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done!

},
};
})
: {};
Copy link
Contributor

Choose a reason for hiding this comment

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

super small nitpick: should we try to be consistent with the types? (array)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure

Copy link
Contributor

@JiaweiWu JiaweiWu left a comment

Choose a reason for hiding this comment

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

LGTM!

Copy link
Contributor

@Zacqary Zacqary left a comment

Choose a reason for hiding this comment

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

LGTM just a question about the tests.

Not sure if it makes sense to also test for paginating from index 0? Probably fine without it, but it might make the API clearer to indicate in the test files that it can start at 0.

@kibana-ci
Copy link
Collaborator

💚 Build Succeeded

Metrics [docs]

Public APIs missing exports

Total count of every type that is part of your API that should be exported but is not. This will cause broken links in the API documentation system. Target amount is 0. Run node scripts/build_api_docs --plugin [yourplugin] --stats exports for more detailed information.

id before after diff
kibana 301 302 +1
ruleRegistry 7 8 +1
total +2

History

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

cc @chrisronline

@chrisronline chrisronline merged commit 4b6f754 into elastic:main Mar 9, 2022
@chrisronline chrisronline deleted the rops/alert_search_strategy_pagination_sorting branch March 9, 2022 22:50
jloleysens added a commit to jloleysens/kibana that referenced this pull request Mar 10, 2022
…move-pdf-generation-to-screenshotting

* 'main' of github.com:elastic/kibana: (62 commits)
  [Lens] Drop partial buckets option (elastic#127153)
  chore(NA): remove unused translation xpack.ml.management.jobsSpacesList.objectNoun from fr-FR (elastic#127457)
  Add data to user details page (elastic#127019)
  [Fleet] Make upload and registry package info consistent (elastic#126915)
  [Reporting] Capture browser errors (elastic#127135)
  Initial readme commit with some stub articles (elastic#127420)
  skip flaky suite (elastic#121482)
  skip flaky suite (elastic#127416)
  Tests to ensure Kibana is handling multi-space import of saved objects correctly (elastic#127229)
  [Aggs] remove toAngularJson (elastic#127267)
  [i18n] Integrate 8.2.0 Translations (elastic#127309)
  [Security Solution] [Endpoint] Creates generic policy tab artifact component to be used for all of our artifacts (elastic#126685)
  [Kibana React] Fix Page Template `solutionNav` propagation (elastic#127140)
  [Cases] Export getRelatedCases API from cases client (elastic#127065)
  [Cloud Posture]add support for sorting benchmark page (elastic#126983)
  [User experience] Fix filters for the app (elastic#127295)
  [Fleet] Fix timeserie dimension mapping (elastic#127328)
  [data view mgmt] fix data view name wrap (elastic#127319)
  [kbn/optimizer] extract string diffing logic (elastic#127394)
  [ResponseOps] Add pagination and sorting to the alerts search strategy (elastic#126813)
  ...

# Conflicts:
#	x-pack/plugins/screenshotting/common/errors.ts
#	x-pack/plugins/screenshotting/common/index.ts
#	x-pack/plugins/screenshotting/server/screenshots/observable.ts
@kibanamachine
Copy link
Contributor

Friendly reminder: Looks like this PR hasn’t been backported yet.
To create backports run node scripts/backport --pr 126813 or prevent reminders by adding the backport:skip label.

@kibanamachine kibanamachine added the backport missing Added to PRs automatically when the are determined to be missing a backport. label Mar 11, 2022
@kibanamachine
Copy link
Contributor

Friendly reminder: Looks like this PR hasn’t been backported yet.
To create backports run node scripts/backport --pr 126813 or prevent reminders by adding the backport:skip label.

2 similar comments
@kibanamachine
Copy link
Contributor

Friendly reminder: Looks like this PR hasn’t been backported yet.
To create backports run node scripts/backport --pr 126813 or prevent reminders by adding the backport:skip label.

@kibanamachine
Copy link
Contributor

Friendly reminder: Looks like this PR hasn’t been backported yet.
To create backports run node scripts/backport --pr 126813 or prevent reminders by adding the backport:skip label.

@kibanamachine
Copy link
Contributor

Friendly reminder: Looks like this PR hasn’t been backported yet.
To create backports run node scripts/backport --pr 126813 or prevent reminders by adding the backport:skip label.

8 similar comments
@kibanamachine
Copy link
Contributor

Friendly reminder: Looks like this PR hasn’t been backported yet.
To create backports run node scripts/backport --pr 126813 or prevent reminders by adding the backport:skip label.

@kibanamachine
Copy link
Contributor

Friendly reminder: Looks like this PR hasn’t been backported yet.
To create backports run node scripts/backport --pr 126813 or prevent reminders by adding the backport:skip label.

@kibanamachine
Copy link
Contributor

Friendly reminder: Looks like this PR hasn’t been backported yet.
To create backports run node scripts/backport --pr 126813 or prevent reminders by adding the backport:skip label.

@kibanamachine
Copy link
Contributor

Friendly reminder: Looks like this PR hasn’t been backported yet.
To create backports run node scripts/backport --pr 126813 or prevent reminders by adding the backport:skip label.

@kibanamachine
Copy link
Contributor

Friendly reminder: Looks like this PR hasn’t been backported yet.
To create backports run node scripts/backport --pr 126813 or prevent reminders by adding the backport:skip label.

@kibanamachine
Copy link
Contributor

Friendly reminder: Looks like this PR hasn’t been backported yet.
To create backports run node scripts/backport --pr 126813 or prevent reminders by adding the backport:skip label.

@kibanamachine
Copy link
Contributor

Friendly reminder: Looks like this PR hasn’t been backported yet.
To create backports run node scripts/backport --pr 126813 or prevent reminders by adding the backport:skip label.

@kibanamachine
Copy link
Contributor

Friendly reminder: Looks like this PR hasn’t been backported yet.
To create backports run node scripts/backport --pr 126813 or prevent reminders by adding the backport:skip label.

@spalger spalger added the backport:skip This commit does not require backporting label Mar 30, 2022
@kibanamachine kibanamachine removed the backport missing Added to PRs automatically when the are determined to be missing a backport. label Mar 30, 2022
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 review Team:ResponseOps Label for the ResponseOps team (formerly the Cases and Alerting teams) v8.2.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[ResponseOps] Improve rules search strategy to support sorting/pagination
8 participants