Skip to content

Add enrich policy PUT API #41383

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

Merged
merged 12 commits into from
Apr 25, 2019
Merged

Add enrich policy PUT API #41383

merged 12 commits into from
Apr 25, 2019

Conversation

hub-cap
Copy link
Contributor

@hub-cap hub-cap commented Apr 19, 2019

This commit wires up the Rest calls and Transport calls for PUT enrich
policy, as well as tests and rest spec additions.

This commit wires up the Rest calls and Transport calls for PUT enrich
policy, as well as tests and rest spec additions.
@hub-cap hub-cap added >enhancement :Data Management/Ingest Node Execution or management of Ingest Pipelines including GeoIP v8.0.0 labels Apr 19, 2019
@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-core-features

Copy link
Member

@martijnvg martijnvg left a comment

Choose a reason for hiding this comment

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

I left a number of small comments. Looks good otherwise!

}

public static class Request extends MasterNodeRequest<PutEnrichPolicyAction.Request> {
private final EnrichPolicy policy;
Copy link
Member

Choose a reason for hiding this comment

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

add newline before the first field

private final EnrichPolicy policy;
private final String name;


Copy link
Member

Choose a reason for hiding this comment

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

remove newline


@Override
public ActionRequestValidationException validate() {
return null;
Copy link
Member

Choose a reason for hiding this comment

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

add validation here that the name is required?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

im not sure we need this since the constructor for the request has an Objects.requireNotNull. I could add something to the streaminput constructor as well, but that does not look like its typically done, as we should be able to trust that more than a "user input" constructor, so to speak.

Copy link
Member

Choose a reason for hiding this comment

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

Good point. Maybe instead of using Objects.requireNotNull, use an if statement that checks now null and if so then throw a IllegalArgumentException? Objects.requireNotNull throws a NPE and that will result in a 500 response code, whilst a IllegalArgumentException translates to a 400 response code and that is a better response code in this case.

Copy link
Member

Choose a reason for hiding this comment

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

Never mind. This good as it is now.

In production, the constructor can't be invoked with a null name, because if the rest handler is invoked then the name had to provided.

}

static void putPolicy(String name, EnrichPolicy policy, EnrichStore store, ActionListener<AcknowledgedResponse> listener) {
if (Strings.isNullOrEmpty(name)) {
Copy link
Member

Choose a reason for hiding this comment

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

maybe add this if check to PolicyStore#putStore(...)?
and then replace testGetEnricyPolicyAction_emptyChecks test with a test in EnrichStoreTests

Copy link
Member

Choose a reason for hiding this comment

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

and I think that this method can be merged with masterOperation(...)

Copy link
Member

Choose a reason for hiding this comment

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

Also an IllegalArgumentException is properly better here. Specifying an empty name or no name is just not allowed when creating a policy. On the rest layer this is then translated to a 400 response code instead of a 404 response code.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Given this, I think Im just going to remove the transport test. the REST and other tests exercise the transport layer fully, as it is a wrapper w/o validation, and since there is no license checks, its literally now a 1 line passthru to the EnrichStore.

@Override
protected void masterOperation(PutEnrichPolicyAction.Request request, ClusterState state,
ActionListener<AcknowledgedResponse> listener) throws Exception {
// TODO license validation
Copy link
Member

Choose a reason for hiding this comment

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

This TODO can be removed. Enrich is going to be basic and for basic we don't need to add license validation.

hub-cap added 2 commits April 19, 2019 14:57
This commit also removes a unit test. This functionlity is tested
elsewhere, and the mocking that has to be done to test a thin wrapper is
not worth it, since basic PUT calls will fail if the logic is wrong.
enrich_values: ["a", "b"]
schedule: "*/120"

- is_true: acknowledged
Copy link
Member

Choose a reason for hiding this comment

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

iirc all yaml test files are required to end with a newline?


@Override
public ActionRequestValidationException validate() {
return null;
Copy link
Member

Choose a reason for hiding this comment

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

Good point. Maybe instead of using Objects.requireNotNull, use an if statement that checks now null and if so then throw a IllegalArgumentException? Objects.requireNotNull throws a NPE and that will result in a 500 response code, whilst a IllegalArgumentException translates to a 400 response code and that is a better response code in this case.

enrich.put_policy:
name: policy-crud
body:
policy:
Copy link
Member

Choose a reason for hiding this comment

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

The policy field isn't needed and this is why this test is failing in pr ci.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

oh geez, i removed that {"policy": wrapper I had initially put around the PUT... thank you for the catch.

@hub-cap hub-cap removed the v8.0.0 label Apr 23, 2019
@hub-cap
Copy link
Contributor Author

hub-cap commented Apr 24, 2019

@elasticmachine run elasticsearch-ci/1

@@ -20,7 +20,7 @@
/**
* Helper methods for access and storage of an enrich policy.
*/
public final class EnrichStore {
public class EnrichStore {
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 we can keep this class final now?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

oh, yes, now that it holds no state, good catch!

Copy link
Member

@martijnvg martijnvg left a comment

Choose a reason for hiding this comment

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

LGTM

@hub-cap hub-cap merged commit 1c28f30 into elastic:enrich Apr 25, 2019
hub-cap added a commit that referenced this pull request Apr 25, 2019
This commit wires up the Rest calls and Transport calls for PUT enrich
policy, as well as tests and rest spec additions.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
:Data Management/Ingest Node Execution or management of Ingest Pipelines including GeoIP >enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants