-
Notifications
You must be signed in to change notification settings - Fork 24.8k
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
Preserve grok pattern ordering and add sort option #61671
Changes from 2 commits
aa6f186
26294d9
d647372
9d3a31a
503ebd5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,6 +40,7 @@ | |
import java.io.IOException; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.TreeMap; | ||
|
||
import static org.elasticsearch.ingest.common.IngestCommonPlugin.GROK_PATTERNS; | ||
import static org.elasticsearch.rest.RestRequest.Method.GET; | ||
|
@@ -55,16 +56,31 @@ private GrokProcessorGetAction() { | |
|
||
public static class Request extends ActionRequest { | ||
|
||
public Request() {} | ||
private final boolean sorted; | ||
|
||
public Request(boolean sorted) { | ||
this.sorted = sorted; | ||
} | ||
|
||
Request(StreamInput in) throws IOException { | ||
super(in); | ||
this.sorted = in.readBoolean(); | ||
} | ||
|
||
@Override | ||
public ActionRequestValidationException validate() { | ||
return null; | ||
} | ||
|
||
@Override | ||
public void writeTo(StreamOutput out) throws IOException { | ||
super.writeTo(out); | ||
out.writeBoolean(sorted); | ||
} | ||
|
||
public boolean sorted() { | ||
return sorted; | ||
} | ||
} | ||
|
||
public static class Response extends ActionResponse implements ToXContentObject { | ||
|
@@ -108,11 +124,15 @@ public TransportAction(TransportService transportService, ActionFilters actionFi | |
@Override | ||
protected void doExecute(Task task, Request request, ActionListener<Response> listener) { | ||
try { | ||
listener.onResponse(new Response(GROK_PATTERNS)); | ||
listener.onResponse(new Response(getGrokPatternsResponse(GROK_PATTERNS, request.sorted()))); | ||
} catch (Exception e) { | ||
listener.onFailure(e); | ||
} | ||
} | ||
|
||
static Map<String, String> getGrokPatternsResponse(Map<String, String> patterns, boolean sorted) { | ||
return sorted ? new TreeMap<>(patterns) : patterns; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We could extract this There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I shuffled around a few things in 9d3a31a to sort the patterns only once while retaining the ability to test the sort option. If you think it's useful, the sorted patterns member could be pulled into a singleton enum or the like for lazy loading. I was on the fence as to whether that would be particularly beneficial. |
||
} | ||
} | ||
|
||
public static class RestAction extends BaseRestHandler { | ||
|
@@ -129,7 +149,9 @@ public String getName() { | |
|
||
@Override | ||
protected RestChannelConsumer prepareRequest(RestRequest request, NodeClient client) { | ||
return channel -> client.executeLocally(INSTANCE, new Request(), new RestToXContentListener<>(channel)); | ||
boolean sorted = request.paramAsBoolean("s", false); | ||
Request grokPatternsRequest = new Request(sorted); | ||
return channel -> client.executeLocally(INSTANCE, grokPatternsRequest, new RestToXContentListener<>(channel)); | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be guarded with version check? What will happen if we receive request from older node where there where no
sorted
field?