Skip to content

Conversation

kderusso
Copy link
Member

@kderusso kderusso commented Oct 4, 2024

Adds a tester call to the query ruleset API.

Example call:

POST _query_rules/my-ruleset/_test
{
  "match_criteria": {
    "foo": "bar"
  }
}

Example response:

{
  "total_matched_rules": 1,
  "matched_rules": [
    { 
      "ruleset_id": "my-ruleset", 
      "rule_id": "my-rule" 
    }
  ]
}

@kderusso kderusso added auto-backport Automatically create backport pull requests when merged v8.16.0 labels Oct 4, 2024
@kderusso kderusso force-pushed the kderusso/query-rules-tester-api branch 2 times, most recently from c73a6bf to 3613634 Compare October 8, 2024 18:17
@kderusso kderusso force-pushed the kderusso/query-rules-tester-api branch from 3613634 to df6dfa8 Compare October 8, 2024 18:30
@kderusso kderusso marked this pull request as ready for review October 8, 2024 18:31
@kderusso kderusso requested review from a team and ioanatia October 8, 2024 18:31
@elasticsearchmachine elasticsearchmachine added the needs:triage Requires assignment of a team area label label Oct 8, 2024
@kderusso kderusso added :SearchOrg/Relevance Label for the Search (solution/org) Relevance team >enhancement and removed needs:triage Requires assignment of a team area label labels Oct 8, 2024
@elasticsearchmachine
Copy link
Collaborator

Pinging @elastic/search-eng (Team:SearchOrg)

@elasticsearchmachine
Copy link
Collaborator

Pinging @elastic/search-relevance (Team:Search - Relevance)

@elasticsearchmachine
Copy link
Collaborator

Hi @kderusso, I've created a changelog YAML for you.

Copy link
Contributor

@Samiul-TheSoccerFan Samiul-TheSoccerFan left a comment

Choose a reason for hiding this comment

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

LGTM

@Override
protected void doExecute(Task task, TestQueryRulesetAction.Request request, ActionListener<TestQueryRulesetAction.Response> listener) {
GetQueryRulesetAction.Request getQueryRulesetRequest = new GetQueryRulesetAction.Request(request.rulesetId());
originSettingClient.execute(GetQueryRulesetAction.INSTANCE, getQueryRulesetRequest, new ActionListener<>() {
Copy link
Contributor

Choose a reason for hiding this comment

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

If we ever want to open this API to not require the manage_search_query_rules privilege like we discussed, if changing this similarly to #105667 to use executeAsyncWithOrigin would be the solution

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks, I will look into that!

Copy link
Member Author

Choose a reason for hiding this comment

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

Believe it or not, that doesn't work either!

I updated the call to use executeAsyncWithOrigin and I still get yaml tests failing with the following error:

- type: "security_exception"
        reason: "action [indices:data/read/xpack/query_rules/test] is unauthorized for\
          \ user [entsearch-admin] with effective roles [admin] on restricted indices\
          \ [.query-rules], this action is granted by the index privileges [read,all]"

I am stumped why this doesn't work, as it definitely does when we use the rule query. I'm inclined to punt and figure it out later before we GA the call, just to get something out there. That would require us keeping the manage query rules privilege for now. What are your thoughts?


- do:
catch: forbidden
headers: { Authorization: "Basic ZW50c2VhcmNoLXVzZXI6ZW50c2VhcmNoLXVzZXItcGFzc3dvcmQ=" } # user
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this checking that we are requiring the manage_search_query_rules privilege?

Copy link
Member Author

Choose a reason for hiding this comment

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

Correct, that's the permission we're using right now.

include::put-query-rule.asciidoc[]
include::get-query-rule.asciidoc[]
include::delete-query-rule.asciidoc[]
include::test-query-ruleset.asciidoc[]
Copy link
Contributor

Choose a reason for hiding this comment

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

are there other docs/guides where we want to refer to this API as a way to test/troubleshoot a query rules set? (can be done as a follow up)

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'd like to do that as a followup. This is being launched in preview right now, because there may be evolving requirements. I think when it gets closer to beta or GA is when it would be most helpful to promote this more, WDYT?

private final int totalMatchedRules;
private final List<MatchedRule> matchedRules;

private static final ParseField TOTAL_MATCHED_RULES_FIELD = new ParseField("total_matched_rules");
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do we need a total_matched_rules in the response? could we just return the matched_rules? just trying to understand

Copy link
Member Author

Choose a reason for hiding this comment

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

We could just return the matched rules. I was thinking it could be convenient in the event there were 1000 rules returned, or we want to provide pagination in the future.

Copy link
Contributor

Choose a reason for hiding this comment

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

++ for keeping total_matched_rules

Copy link
Contributor

@Mikep86 Mikep86 left a comment

Choose a reason for hiding this comment

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

Looks good overall, great job 🙌 ! I only have minor comments.

private final int totalMatchedRules;
private final List<MatchedRule> matchedRules;

private static final ParseField TOTAL_MATCHED_RULES_FIELD = new ParseField("total_matched_rules");
Copy link
Contributor

Choose a reason for hiding this comment

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

++ for keeping total_matched_rules

@kderusso kderusso requested a review from a team as a code owner October 11, 2024 19:57
@kderusso kderusso requested a review from ioanatia October 14, 2024 12:27
Copy link
Contributor

@Mikep86 Mikep86 left a comment

Choose a reason for hiding this comment

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

LGTM, thanks for the changes!

@kderusso kderusso merged commit 69b4a9f into elastic:main Oct 14, 2024
16 checks passed
@kderusso kderusso deleted the kderusso/query-rules-tester-api branch October 14, 2024 16:55
@elasticsearchmachine
Copy link
Collaborator

💚 Backport successful

Status Branch Result
8.x

kderusso added a commit to kderusso/elasticsearch that referenced this pull request Oct 14, 2024
* Add a query rules tester API call

* Update docs/changelog/114168.yaml

* Wrap client call in async with origin

* Remove unused param

* PR feedback

* Remove redundant test

* CI workaround - add ent-search as ml dependency so it can find node features
elasticsearchmachine pushed a commit that referenced this pull request Oct 14, 2024
* Add a query rules tester API call

* Update docs/changelog/114168.yaml

* Wrap client call in async with origin

* Remove unused param

* PR feedback

* Remove redundant test

* CI workaround - add ent-search as ml dependency so it can find node features
davidkyle pushed a commit to davidkyle/elasticsearch that referenced this pull request Oct 14, 2024
* Add a query rules tester API call

* Update docs/changelog/114168.yaml

* Wrap client call in async with origin

* Remove unused param

* PR feedback

* Remove redundant test

* CI workaround - add ent-search as ml dependency so it can find node features
davidkyle pushed a commit that referenced this pull request Oct 15, 2024
* Add a query rules tester API call

* Update docs/changelog/114168.yaml

* Wrap client call in async with origin

* Remove unused param

* PR feedback

* Remove redundant test

* CI workaround - add ent-search as ml dependency so it can find node features
georgewallace pushed a commit to georgewallace/elasticsearch that referenced this pull request Oct 25, 2024
* Add a query rules tester API call

* Update docs/changelog/114168.yaml

* Wrap client call in async with origin

* Remove unused param

* PR feedback

* Remove redundant test

* CI workaround - add ent-search as ml dependency so it can find node features
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

auto-backport Automatically create backport pull requests when merged >enhancement :SearchOrg/Relevance Label for the Search (solution/org) Relevance team v8.16.0 v9.0.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants