Adds an operator to create enrich policies#2045
Conversation
b6bdff7 to
69b48e4
Compare
craigtaverner
left a comment
There was a problem hiding this comment.
This looks like a nice addition. But there are a few things to fix or change. At the very least fix the docs. The suggestions I made for supporting more flexible combinations of the delete/create/execute actions could be done here or in a followup PR.
| Properties | ||
| """""""""" | ||
|
|
||
| Meta-data |
There was a problem hiding this comment.
This meta-data section seems to have been incorrectly placed inside the esql section, instead of the create-enrich-policy section below.
There was a problem hiding this comment.
Thanks for reviewing it. The docs were mixed during a merge, I've rebased the changes instead so its fixed now.
| Properties | ||
| """""""""" | ||
|
|
||
| It's properties follows the request body of the `Create an enrich policy API <https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-enrich-put-policy>`_ |
There was a problem hiding this comment.
This link should rather be moved into the policies list item below.
| { | ||
| "name": "create-enrich-policy", | ||
| "operation": { | ||
| "operation-type": "create-enrich-policy", |
There was a problem hiding this comment.
Since the operation does more than just create, I think it should be named enrich-policy, and it can delete, create and execute the policy (or any combination of those actions).
There was a problem hiding this comment.
renamed it, the combinations will be part of another PR
| } | ||
| } | ||
| }, | ||
| "delete": true |
There was a problem hiding this comment.
Shouldn't the flag be inside the operation? Having it outside the operation makes it seem like it is not tied to enrich policy management at all, but part of generic challenges.
There was a problem hiding this comment.
fixed, good catch. it was already part of the operation but I've misplace it in the docs.
| return "run-until" | ||
|
|
||
|
|
||
| class CreateEnrichPolicy(Runner): |
There was a problem hiding this comment.
Since this can do much more than just create the policy, I think it should be renamed EnrichPolicy, and take optional boolean flags for delete, create and execute, and only create requires the policy bodies, while all the rest require at least the policy name.
There was a problem hiding this comment.
Renamed it for now, I'll work on a separate PR for the new format.
I gave it some thought, wdyt of removing policies and then having lists on the delete and execute? that gives more control over what is done to each policy.
example:
{
"operation-type": "enrich-policy",
"delete": [
"a-policy-name",
"another-policy",
"yet-another-one"
],
"create": {
"a-policy-name": {
"match": {
"indices": "nyc_rate_codes",
"match_field": "id",
"enrich_fields": [
"name"
]
}
}
},
"execute": [
"a-policy-name",
"a-completely-different-policy"
]
}I will work on this version if I find the time, since it's easy to change to your suggestion if you prefer later
There was a problem hiding this comment.
Got to implement this, it's as a draft in case you decide it's no good, but it is working and ready to review: #2101
| "name": "create-enrich-policy", | ||
| "operation": { | ||
| "operation-type": "create-enrich-policy", | ||
| "policies": { |
There was a problem hiding this comment.
I wonder if it would be nicer to have a list instead of an object as the value of policies. Then we could, for example, just list the names if all we want to do it re-execute existing policies:
{
"name": "re-execute-enrich-policies",
"operation": {
"operation-type": "enrich-policy",
"policies": [ "nyc_rate_codes", "nyc_payment_types" ],
"delete": false,
"create": false,
"execute": true
}
}
If we have "create": true(which can be the default), then the values inside the list of policies must be objects with a single key, the name of the policy, and it's value would be the policy body. This is one level nesting deeper than your example.
There was a problem hiding this comment.
will do that or my suggestion in another PR
| async def __call__(self, es, params): | ||
| enrich_policies = mandatory(params, "policies", self) | ||
|
|
||
| if params.get("delete", True): |
There was a problem hiding this comment.
I think it would be nicer to have three booleans: delete, create, execute. The defaults could be: false, true, true.
There was a problem hiding this comment.
will do that or my suggestion in another PR
| self.logger.debug("Executed %s enrich policies: %s", len(res), [r.body for r in res]) | ||
|
|
||
| async def __call__(self, es, params): | ||
| enrich_policies = mandatory(params, "policies", self) |
There was a problem hiding this comment.
If we supported the nested arrays approach I described above, we could have a normalize option here to bring the multiple formats into a single version so the functions below do not need to care about that.
There was a problem hiding this comment.
will do that or my suggestion in another PR
| /.project | ||
| /.pydevproject | ||
| /.vscode | ||
| /.zed |
There was a problem hiding this comment.
What does this mean? Should this be in this PR?
There was a problem hiding this comment.
this is a folder to be ignored from the zed IDE, which I use. I've removed it to avoid friction
|
@slDias let us know if you have any questions regarding @craigtaverner 's review. I'm going to change this to draft, please switch back to "ready for review" when you have addressed the feedback - thanks! |
As suggested in Issue elastic#1796, this commit adds a new operator that combines the delete, creation and execution of enrich policies within a single operation.
bc1f5f1 to
88c5eec
Compare
As discussed in MR elastic#2045, this commit makes it possible to execute different enrichment policies operation separately in the enrich-policy runner.
|
@elasticmachine update branch |
|
Thanks @slDias ! |
As suggested in Issue #1796, this commit adds a new operator that combines the delete, creation and execution of enrich policies within a single operation.
I've added a new challenge to nyc_taxis track to test this it is equivalent to the esql challenge, it can be found here (I can also open a MR replacing the 'esql' one, if desired).
Happy to change anything if needed.