-
Notifications
You must be signed in to change notification settings - Fork 25.2k
[Enterprise Search][Behavioral Analytics] Events ingest API #95027
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
Conversation
public static final Setting<TimeValue> FLUSH_DELAY_SETTING = Setting.timeSetting( | ||
Strings.format("%s.%s", SETTING_ROOT_PATH, "flush_delay"), | ||
TimeValue.timeValueSeconds(10), | ||
TimeValue.timeValueSeconds(1), | ||
TimeValue.timeValueSeconds(60), | ||
Setting.Property.NodeScope | ||
); | ||
|
||
public static final Setting<Integer> MAX_NUMBER_OF_EVENTS_PER_BULK_SETTING = Setting.intSetting( | ||
Strings.format("%s.%s", SETTING_ROOT_PATH, "max_events_per_bulk"), | ||
1000, | ||
1, | ||
10000, | ||
Setting.Property.NodeScope | ||
); | ||
|
||
public static final Setting<Integer> MAX_NUMBER_OF_RETRIES_SETTING = Setting.intSetting( | ||
Strings.format("%s.%s", SETTING_ROOT_PATH, "max_number_of_retries"), | ||
3, | ||
0, | ||
5, | ||
Setting.Property.NodeScope | ||
); |
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.
ℹ️ This settings will allow to make the bulk processor configurable
@Override | ||
protected void doClose() { | ||
// Ensure the bulk processor is closed, so pending requests are flushed. | ||
bulkProcessor.close(); |
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.
ℹ️ Ensure the bulk processor events are drained when closing.
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.
I think it should attempt to execute the remaining 'under construction' bulk request. But agree it would be great to double check this
public List<Setting<?>> getSettings() { | ||
return List.of( | ||
BulkProcessorConfig.MAX_NUMBER_OF_EVENTS_PER_BULK_SETTING, | ||
BulkProcessorConfig.FLUSH_DELAY_SETTING, | ||
BulkProcessorConfig.MAX_NUMBER_OF_RETRIES_SETTING | ||
); |
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.
ℹ️ Event ingest related settings.
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.
ℹ️ Changes to made to this class are syntaxic sugar.
) { | ||
this.eventCollectionName = eventCollectionName; | ||
this.eventType = eventType; | ||
this.debug = debug; |
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.
@kderusso I kept debug
instead of suggestions like verbose
.
Indeed it is intended to be used with the debug flag of the JS tag that will output event processed by the server into the dev console of the browser (feature that I plan to implement later).
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.
Nice work!
} | ||
|
||
try { | ||
if (eventType.toLowerCase(Locale.ROOT).equals(eventType) == false) throw new IllegalArgumentException(); |
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.
Nitpick: Curly brackets
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.
Fixed! Thank you.
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.
Looks really good to me. I just have a question on privileges for the POST action - could they be index privileges instead of manage cluster type privileges?
Very good job on tests! 💯
docs/reference/behavioral-analytics/apis/post-analytics-collection-event.asciidoc
Outdated
Show resolved
Hide resolved
...ain/java/org/elasticsearch/xpack/core/security/authz/privilege/ClusterPrivilegeResolver.java
Show resolved
Hide resolved
...c/yamlRestTest/resources/rest-api-spec/test/entsearch/90_behavioral_analytics_event_post.yml
Show resolved
Hide resolved
...c/yamlRestTest/resources/rest-api-spec/test/entsearch/90_behavioral_analytics_event_post.yml
Outdated
Show resolved
Hide resolved
...src/main/java/org/elasticsearch/xpack/application/analytics/AnalyticsEventIngestService.java
Outdated
Show resolved
Hide resolved
|
||
// This number must be incremented when we make changes to built-in templates. | ||
public static final int REGISTRY_VERSION = 1; | ||
protected static final int REGISTRY_VERSION = 1; |
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.
Why protected
? Are we expecting subclasses for AnalyticsTemplateRegistry
?
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.
I have another PR with a class in the same package that use this variable.
I will probably push those into a file that hold all these constant.
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.
I have another PR with a class in the same package that use this variable.
Maybe use default package visibility then? Sorry for nagging, I see protected
as a strong signal that it is used in a subclass. Let's use default package visibility if that's the use case 👍
...main/java/org/elasticsearch/xpack/application/analytics/action/PostAnalyticsEventAction.java
Outdated
Show resolved
Hide resolved
...org/elasticsearch/xpack/application/analytics/event/parser/event/AnalyticsEventPageView.java
Outdated
Show resolved
Hide resolved
...src/main/java/org/elasticsearch/xpack/application/analytics/ingest/BulkProcessorFactory.java
Show resolved
Hide resolved
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.
LGTM,
I left questions, but feel free to merge anyway once CI is green
} | ||
|
||
public BulkProcessor2 create(Client client) { | ||
return BulkProcessor2.builder(client::bulk, new BulkProcessorListener(), client.threadPool()) |
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.
this looks good, but do we want to have control over indexing being enabled or not?
let's say a user is sending a lot of requests that results in analyticsEventEmitter to keep on creating index requests What if cluster is struggling at the moment? Do we want to have control to turn that off( that would mean that data is lost ..)
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.
I will probably implement it into the AnalyticsEventEmitter
.
If you don't mind I will do it in a follow-up PR to be able to merge the PR and unblock other work streams that rely on the feature.
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.
yes, follow up is good. But I will this up to ent search team to decide if this is even needed at all. I thought that it might be good as an emergency switch off button
We have that for deprecation logging, but we started with that feature turned off so we needed this to enable this.
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.
This is a good call and I will add these feature. It will probably be part of the upcoming PR to add metering to the event ingest API.
...est/java/org/elasticsearch/xpack/application/analytics/ingest/BulkProcessorFactoryTests.java
Outdated
Show resolved
Hide resolved
@Override | ||
protected void doClose() { | ||
// Ensure the bulk processor is closed, so pending requests are flushed. | ||
bulkProcessor.close(); |
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.
I think it should attempt to execute the remaining 'under construction' bulk request. But agree it would be great to double check this
@elasticsearchmachine run elasticsearch-ci/part-2 |
The cluster privileges are listed in alphabetic order on get-privileges response. This PR ensures that is matched in doc. Relates: elastic#95027 Resolves: elastic#95210
Description:
In order to populate our analytics data streams we need an API to collect events.
This API will validate the event and emit them to bulk processor that will persist event into events data streams
Checklist