-
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
[ML] Add audit warning for 1000 categories found early in job #51146
Merged
droberts195
merged 3 commits into
elastic:master
from
droberts195:excessive_categories_audit_message
Jan 17, 2020
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -74,6 +74,9 @@ public class AutodetectResultProcessor { | |
|
||
private static final Logger LOGGER = LogManager.getLogger(AutodetectResultProcessor.class); | ||
|
||
static final long EARLY_BUCKET_THRESHOLD = 100; | ||
static final int EXCESSIVE_EARLY_CATEGORY_COUNT = 1000; | ||
|
||
private final Client client; | ||
private final AnomalyDetectionAuditor auditor; | ||
private final String jobId; | ||
|
@@ -87,7 +90,9 @@ public class AutodetectResultProcessor { | |
private final FlushListener flushListener; | ||
private volatile boolean processKilled; | ||
private volatile boolean failed; | ||
private int bucketCount; // only used from the process() thread, so doesn't need to be volatile | ||
private long priorRunsBucketCount; | ||
private long currentRunBucketCount; // only used from the process() thread, so doesn't need to be volatile | ||
private boolean excessiveCategoryWarningIssued; // only used from the process() thread, so doesn't need to be volatile | ||
private final JobResultsPersister.Builder bulkResultsPersister; | ||
private boolean deleteInterimRequired; | ||
|
||
|
@@ -122,6 +127,7 @@ public AutodetectResultProcessor(Client client, | |
this.bulkResultsPersister = persister.bulkPersisterBuilder(jobId, this::isAlive); | ||
this.timingStatsReporter = new TimingStatsReporter(timingStats, bulkResultsPersister); | ||
this.deleteInterimRequired = true; | ||
this.priorRunsBucketCount = timingStats.getBucketCount(); | ||
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 was wondering where we'd get this from but it's cool we already pass it in! |
||
} | ||
|
||
public void process() { | ||
|
@@ -140,7 +146,7 @@ public void process() { | |
} catch (Exception e) { | ||
LOGGER.warn(new ParameterizedMessage("[{}] Error persisting autodetect results", jobId), e); | ||
} | ||
LOGGER.info("[{}] {} buckets parsed from autodetect output", jobId, bucketCount); | ||
LOGGER.info("[{}] {} buckets parsed from autodetect output", jobId, currentRunBucketCount); | ||
|
||
} catch (Exception e) { | ||
failed = true; | ||
|
@@ -166,15 +172,15 @@ public void process() { | |
} | ||
|
||
private void readResults() { | ||
bucketCount = 0; | ||
currentRunBucketCount = 0; | ||
try { | ||
Iterator<AutodetectResult> iterator = process.readAutodetectResults(); | ||
while (iterator.hasNext()) { | ||
try { | ||
AutodetectResult result = iterator.next(); | ||
processResult(result); | ||
if (result.getBucket() != null) { | ||
LOGGER.trace("[{}] Bucket number {} parsed from output", jobId, bucketCount); | ||
LOGGER.trace("[{}] Bucket number {} parsed from output", jobId, currentRunBucketCount); | ||
} | ||
} catch (Exception e) { | ||
if (isAlive() == false) { | ||
|
@@ -212,7 +218,7 @@ void processResult(AutodetectResult result) { | |
// results are also interim | ||
timingStatsReporter.reportBucket(bucket); | ||
bulkResultsPersister.persistBucket(bucket).executeRequest(); | ||
++bucketCount; | ||
++currentRunBucketCount; | ||
} | ||
List<AnomalyRecord> records = result.getRecords(); | ||
if (records != null && !records.isEmpty()) { | ||
|
@@ -224,7 +230,7 @@ void processResult(AutodetectResult result) { | |
} | ||
CategoryDefinition categoryDefinition = result.getCategoryDefinition(); | ||
if (categoryDefinition != null) { | ||
persister.persistCategoryDefinition(categoryDefinition, this::isAlive); | ||
processCategoryDefinition(categoryDefinition); | ||
} | ||
ModelPlot modelPlot = result.getModelPlot(); | ||
if (modelPlot != null) { | ||
|
@@ -308,6 +314,22 @@ void processResult(AutodetectResult result) { | |
} | ||
} | ||
|
||
private void processCategoryDefinition(CategoryDefinition categoryDefinition) { | ||
persister.persistCategoryDefinition(categoryDefinition, this::isAlive); | ||
if (categoryDefinition.getCategoryId() == EXCESSIVE_EARLY_CATEGORY_COUNT && | ||
priorRunsBucketCount + currentRunBucketCount < EARLY_BUCKET_THRESHOLD && | ||
excessiveCategoryWarningIssued == false) { | ||
auditor.warning(jobId, Messages.getMessage(Messages.JOB_AUDIT_EXCESSIVE_EARLY_CATEGORIES, EXCESSIVE_EARLY_CATEGORY_COUNT, | ||
// Add 1 because category definitions are written before buckets | ||
1L + priorRunsBucketCount + currentRunBucketCount)); | ||
// This flag won't be retained if the job is closed and reopened, or if the job migrates to another node. | ||
// This means it's possible the audit message is generated multiple times. However, that's not a | ||
// disaster, and is also very unlikely in the the (best practice) cases where initial lookback covers | ||
// more than 100 buckets. | ||
excessiveCategoryWarningIssued = true; | ||
} | ||
} | ||
|
||
private void processModelSizeStats(ModelSizeStats modelSizeStats) { | ||
LOGGER.trace("[{}] Parsed ModelSizeStats: {} / {} / {} / {} / {} / {}", | ||
jobId, modelSizeStats.getModelBytes(), modelSizeStats.getTotalByFieldCount(), | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back 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.
We have square brackets about the second number in this message but not the first. Should we make it consistent?
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 reason I didn't put the first one in square brackets is that it won't vary (at least for a particular version of the product). The first number will always be 1000 unless somebody changes the code, whereas the second number can vary between different occurrences of the audit message.