Add utility for tracking licensed persistent tasks#76672
Conversation
Licensed feature tracking of long running features happens now by starting and stopping the tracking of a feature. This commit adds an intermediate base class to be used by features that utilize persistent tasks. The base class only requires specifying the feature and context, and then any tasks created automatically are tracked. An example using marchine learning's JobTask is also added here, using a new machine learning job feature object.
|
Pinging @elastic/es-security (Team:Security) |
benwtrent
left a comment
There was a problem hiding this comment.
Its really nice how simple this is. Integration with it will be 🍰
I have some comments around inheritance safety + weird exception paths.
| protected boolean markAsCancelled() { | ||
| stopTracking(); | ||
| return super.markAsCancelled(); | ||
| } | ||
|
|
||
| @Override | ||
| public void markAsCompleted() { | ||
| stopTracking(); | ||
| super.markAsCompleted(); | ||
| } | ||
|
|
||
| @Override | ||
| public void markAsFailed(Exception e) { | ||
| stopTracking(); | ||
| super.markAsFailed(e); | ||
| } | ||
|
|
||
| @Override | ||
| public void markAsLocallyAborted(String localAbortReason) { | ||
| stopTracking(); | ||
| super.markAsLocallyAborted(localAbortReason); | ||
| } |
There was a problem hiding this comment.
I think these should all be final and there should be new methods called doMarkAs... or something.
There is a nasty little tendency for persistent tasks to accidentally overwrite a method and not call super. This has caused non-trivial to debug bugs in the past.
| public static final boolean CATEGORIZATION_TOKENIZATION_IN_JAVA = true; | ||
|
|
||
| public static final LicensedFeature.Persistent ML_JOBS_FEATURE = | ||
| LicensedFeature.persistent("machine-learning-job", License.OperationMode.PLATINUM); |
There was a problem hiding this comment.
| LicensedFeature.persistent("machine-learning-job", License.OperationMode.PLATINUM); | |
| LicensedFeature.persistent("machine-learning-anomaly-detection-job", License.OperationMode.PLATINUM); |
Since we also have data-frame-analytics-job :D
| this.licensedFeature = feature; | ||
| this.featureContext = featureContext; | ||
| this.licenseState = licenseState; | ||
| licensedFeature.startTracking(licenseState, featureContext); |
There was a problem hiding this comment.
Looking at the taskManager code, I think there is a small chance that a task object is destroyed but none of the cancellations methods are called.
Note if init is called and throws, only taskManager.unregister(task); is called. I don't think this calls any of these internal life time tracking methods.
I am thinking that licensedFeature.startTracking(licenseState, featureContext); should probably be called in init to avoid this weird condition.
What do you think?
There was a problem hiding this comment.
It seems like init is being abused currently. It's purpose, IMO is to just set some references, not to do any work? But at least rollup seems to utilize this.
What if instead I were to make init public and final? Public is so that tests can still call it, and then final so that there is no chance some extra work is done that could actually throw an exception.
There was a problem hiding this comment.
@rjernst if we can make that guarantee of it not throwing, it makes sense to me. All it's doing is setting internal values...so I don't know why it would ever throw.
So, I think fix init, or somehow make sure that stopTracking is called if init throws in this execution path.
|
@elasticmachine run elasticsearch-ci/part-2-fips |
|
@benwtrent This is ready for another look. |
Licensed feature tracking of long running features happens now by starting and stopping the tracking of a feature. This commit adds an intermediate base class to be used by features that utilize persistent tasks. The base class only requires specifying the feature and context, and then any tasks created automatically are tracked. An example using marchine learning's JobTask is also added here, using a new machine learning job feature object.
* Add utility for tracking licensed persistent tasks (#76672) Licensed feature tracking of long running features happens now by starting and stopping the tracking of a feature. This commit adds an intermediate base class to be used by features that utilize persistent tasks. The base class only requires specifying the feature and context, and then any tasks created automatically are tracked. An example using marchine learning's JobTask is also added here, using a new machine learning job feature object. * fix java 8 * checkstyle * fix compile * checkstyle * fix test Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
Licensed feature tracking of long running features happens now by
starting and stopping the tracking of a feature. This commit adds an
intermediate base class to be used by features that utilize persistent
tasks. The base class only requires specifying the feature and context,
and then any tasks created automatically are tracked. An example using
marchine learning's JobTask is also added here, using a new machine
learning job feature object.