[ML] Refactor method to process model size stats (elastic/x-pack-elasticsearch#4175)
Original commit: elastic/x-pack-elasticsearch@5cd52971147d964850d18c2b27b79f9df7377325
@@ -241,22 +241,7 @@ public class AutoDetectResultProcessor {
}
ModelSizeStats modelSizeStats = result.getModelSizeStats();
if (modelSizeStats != null) {
- LOGGER.trace("[{}] Parsed ModelSizeStats: {} / {} / {} / {} / {} / {}",
- context.jobId, modelSizeStats.getModelBytes(), modelSizeStats.getTotalByFieldCount(),
- modelSizeStats.getTotalOverFieldCount(), modelSizeStats.getTotalPartitionFieldCount(),
- modelSizeStats.getBucketAllocationFailuresCount(), modelSizeStats.getMemoryStatus());
-
- latestModelSizeStats = modelSizeStats;
- haveNewLatestModelSizeStats = true;
- persister.persistModelSizeStats(modelSizeStats);
- // This is a crude way to NOT refresh the index and NOT attempt to update established model memory during the first 20 buckets
- // because this is when the model size stats are likely to be least stable and lots of updates will be coming through, and
- // we'll NEVER consider memory usage to be established during this period
- if (restoredSnapshot || bucketCount >= JobProvider.BUCKETS_FOR_ESTABLISHED_MEMORY_SIZE) {
- // We need to make all results written up to and including these stats available for the established memory calculation
- persister.commitResultWrites(context.jobId);
- updateEstablishedModelMemoryOnJob(modelSizeStats.getTimestamp(), modelSizeStats);
- }
+ processModelSizeStats(context, modelSizeStats);
}
ModelSnapshot modelSnapshot = result.getModelSnapshot();
if (modelSnapshot != null) {
@@ -293,6 +278,25 @@ public class AutoDetectResultProcessor {
}
}
+ private void processModelSizeStats(Context context, ModelSizeStats modelSizeStats) {
+ LOGGER.trace("[{}] Parsed ModelSizeStats: {} / {} / {} / {} / {} / {}",
+ context.jobId, modelSizeStats.getModelBytes(), modelSizeStats.getTotalByFieldCount(),
+ modelSizeStats.getTotalOverFieldCount(), modelSizeStats.getTotalPartitionFieldCount(),
+ modelSizeStats.getBucketAllocationFailuresCount(), modelSizeStats.getMemoryStatus());
+
+ latestModelSizeStats = modelSizeStats;
+ haveNewLatestModelSizeStats = true;
+ persister.persistModelSizeStats(modelSizeStats);
+ // This is a crude way to NOT refresh the index and NOT attempt to update established model memory during the first 20 buckets
+ // because this is when the model size stats are likely to be least stable and lots of updates will be coming through, and
+ // we'll NEVER consider memory usage to be established during this period
+ if (restoredSnapshot || bucketCount >= JobProvider.BUCKETS_FOR_ESTABLISHED_MEMORY_SIZE) {
+ // We need to make all results written up to and including these stats available for the established memory calculation
+ persister.commitResultWrites(context.jobId);
+ updateEstablishedModelMemoryOnJob(modelSizeStats.getTimestamp(), modelSizeStats);
+ }
+ }
+
protected void updateModelSnapshotOnJob(ModelSnapshot modelSnapshot) {
JobUpdate update = new JobUpdate.Builder(jobId)
.setModelSnapshotId(modelSnapshot.getSnapshotId())
