-
Notifications
You must be signed in to change notification settings - Fork 81
Introduce Insights API #1610
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
base: main
Are you sure you want to change the base?
Introduce Insights API #1610
Conversation
Signed-off-by: Jackie <[email protected]>
Signed-off-by: Jackie <[email protected]>
Signed-off-by: Jackie <[email protected]>
Signed-off-by: Jackie <[email protected]>
Signed-off-by: Jackie <[email protected]>
Signed-off-by: Jackie <[email protected]>
4883d42 to
77fcda9
Compare
Signed-off-by: Jackie <[email protected]>
Signed-off-by: Jackie <[email protected]>
0eba385 to
49018e0
Compare
|
CI failed due to jacoco changes in build.gradle. Not sure how to fix. One naive way is to add correlation request, response, and Action in AD to avoid ml-commons dependency. |
kaituo
left a comment
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.
partial review
|
|
||
| log.info("Built correlation input: {} metrics × {} buckets", input.getNumMetrics(), input.getNumBuckets()); | ||
|
|
||
| log.info("Matrix contents: {}", input.getMatrix()); |
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.
The matrix can be huge and may expose metric/entity values. Recommend DEBUG with truncation or only log dimensions.
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.
added it for testing purpose, will clean up
| executionStartTime = executionEndTime.minus(24, ChronoUnit.HOURS); | ||
| // executionStartTime = executionEndTime.minus(intervalAmount, intervalUnit); |
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.
You want to use the commented out line instead of hard coded 24 hours?
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.
oops, changed it for testing purpose, will clean up
|
|
||
| InjectSecurity injectSecurity = new InjectSecurity(jobParameter.getName(), settings, localClient.threadPool().getThreadContext()); | ||
| try { | ||
| injectSecurity.inject(user, roles); |
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.
A normal user cannot query system index. Please add security tests.
| // Insights job | ||
| // ====================================== | ||
| // The Insights job name | ||
| public static final String INSIGHTS_JOB_NAME = "insights_job"; |
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.
how about changing to ad_insights_job in case we need forecasting job later?
kaituo
left a comment
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.
partial review
| return ImmutableList | ||
| .of( | ||
| // Start insights job | ||
| new ReplacedRoute( |
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.
You don't need ReplaceRoute as this is a new API. TimeSeriesAnalyticsPlugin.AD_BASE_URI alone is enough.
| builder.startObject(); | ||
|
|
||
| // Task metadata | ||
| builder.field("task_id", "task_" + ADCommonName.INSIGHTS_JOB_NAME + "_" + UUID.randomUUID().toString()); |
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 do you need task id? AD task id is the doc id of state index.
|
|
||
| if (parts.length > 1) { | ||
| String seriesKey = parts[1]; | ||
| seriesKeys.add(seriesKey); |
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.
Is the entities set redundant with seriesKeys set?
| // Use MAX score if multiple anomalies in same bucket | ||
| double currentScore = bucketScores.getOrDefault(bucketIndex, 0.0); | ||
| double newScore = anomaly.getAnomalyScore(); | ||
| bucketScores.put(bucketIndex, Math.max(currentScore, newScore)); |
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 we consider interval? Our anomalies are interval anomalies. We can put anomalies scores to all of the buckets interleaving current interval [data start, data end]. If you have already done it, can you point me the code? I cannot find it.
| "fields": { | ||
| "raw": { | ||
| "type": "keyword", | ||
| "ignore_above": 32766 | ||
| } |
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.
do you need keyword?
Signed-off-by: Jackie <[email protected]>
kaituo
left a comment
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.
partial review
| handleStartOperation(request, listener); | ||
| } else if (request.isStatusOperation()) { | ||
| handleStatusOperation(request, listener); | ||
| } else if (request.isStopOperation()) { | ||
| handleStopOperation(request, listener); |
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.
Do you need to stash context before accessing job index (system index)? Please add security tests.
| .sort("generated_at", SortOrder.DESC) | ||
| ); | ||
|
|
||
| client.search(searchRequest, ActionListener.wrap(searchResponse -> { |
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.
Do you need to add backend role filtering before search? Please add security tests with backend role filtering on.
|
|
||
| private static final Logger log = LogManager.getLogger(InsightsJobProcessor.class); | ||
|
|
||
| private static InsightsJobProcessor INSTANCE; |
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.
add volatile. read https://en.wikipedia.org/wiki/Double-checked_locking
| try { | ||
| injectSecurity.inject(user, roles); | ||
|
|
||
| localClient |
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.
We should verify if mapping is changed by customer before writing. If yes, report error/stop job and stop writing.
| Instant.now(), | ||
| lockDurationSeconds, | ||
| user, | ||
| ADCommonName.INSIGHTS_RESULT_INDEX_ALIAS, |
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.
Can you add this index in ADIndex? This would be consistent with other indexes.
Signed-off-by: Jackie <[email protected]>
3076f15 to
1356920
Compare
Description
Related Issues
Resolves #[Issue number to be closed when this PR is merged]
Check List
--signoff.By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.