33
33
import java .util .Objects ;
34
34
35
35
/**
36
- * Provide access to the C++ model memory usage numbers for the Java process.
36
+ * Provide access to the C++ model size stats for the Java process.
37
37
*/
38
38
public class ModelSizeStats implements ToXContentObject {
39
39
@@ -54,6 +54,12 @@ public class ModelSizeStats implements ToXContentObject {
54
54
public static final ParseField TOTAL_PARTITION_FIELD_COUNT_FIELD = new ParseField ("total_partition_field_count" );
55
55
public static final ParseField BUCKET_ALLOCATION_FAILURES_COUNT_FIELD = new ParseField ("bucket_allocation_failures_count" );
56
56
public static final ParseField MEMORY_STATUS_FIELD = new ParseField ("memory_status" );
57
+ public static final ParseField CATEGORIZED_DOC_COUNT_FIELD = new ParseField ("categorized_doc_count" );
58
+ public static final ParseField TOTAL_CATEGORY_COUNT_FIELD = new ParseField ("total_category_count" );
59
+ public static final ParseField FREQUENT_CATEGORY_COUNT_FIELD = new ParseField ("frequent_category_count" );
60
+ public static final ParseField RARE_CATEGORY_COUNT_FIELD = new ParseField ("rare_category_count" );
61
+ public static final ParseField DEAD_CATEGORY_COUNT_FIELD = new ParseField ("dead_category_count" );
62
+ public static final ParseField CATEGORIZATION_STATUS_FIELD = new ParseField ("categorization_status" );
57
63
public static final ParseField LOG_TIME_FIELD = new ParseField ("log_time" );
58
64
public static final ParseField TIMESTAMP_FIELD = new ParseField ("timestamp" );
59
65
@@ -69,6 +75,14 @@ public class ModelSizeStats implements ToXContentObject {
69
75
PARSER .declareLong (Builder ::setTotalByFieldCount , TOTAL_BY_FIELD_COUNT_FIELD );
70
76
PARSER .declareLong (Builder ::setTotalOverFieldCount , TOTAL_OVER_FIELD_COUNT_FIELD );
71
77
PARSER .declareLong (Builder ::setTotalPartitionFieldCount , TOTAL_PARTITION_FIELD_COUNT_FIELD );
78
+ PARSER .declareField (Builder ::setMemoryStatus , p -> MemoryStatus .fromString (p .text ()), MEMORY_STATUS_FIELD , ValueType .STRING );
79
+ PARSER .declareLong (Builder ::setCategorizedDocCount , CATEGORIZED_DOC_COUNT_FIELD );
80
+ PARSER .declareLong (Builder ::setTotalCategoryCount , TOTAL_CATEGORY_COUNT_FIELD );
81
+ PARSER .declareLong (Builder ::setFrequentCategoryCount , FREQUENT_CATEGORY_COUNT_FIELD );
82
+ PARSER .declareLong (Builder ::setRareCategoryCount , RARE_CATEGORY_COUNT_FIELD );
83
+ PARSER .declareLong (Builder ::setDeadCategoryCount , DEAD_CATEGORY_COUNT_FIELD );
84
+ PARSER .declareField (Builder ::setCategorizationStatus ,
85
+ p -> CategorizationStatus .fromString (p .text ()), CATEGORIZATION_STATUS_FIELD , ValueType .STRING );
72
86
PARSER .declareField (Builder ::setLogTime ,
73
87
(p ) -> TimeUtil .parseTimeField (p , LOG_TIME_FIELD .getPreferredName ()),
74
88
LOG_TIME_FIELD ,
@@ -77,7 +91,6 @@ public class ModelSizeStats implements ToXContentObject {
77
91
(p ) -> TimeUtil .parseTimeField (p , TIMESTAMP_FIELD .getPreferredName ()),
78
92
TIMESTAMP_FIELD ,
79
93
ValueType .VALUE );
80
- PARSER .declareField (Builder ::setMemoryStatus , p -> MemoryStatus .fromString (p .text ()), MEMORY_STATUS_FIELD , ValueType .STRING );
81
94
}
82
95
83
96
/**
@@ -99,6 +112,23 @@ public String toString() {
99
112
}
100
113
}
101
114
115
+ /**
116
+ * The status of categorization for a job. OK is default, WARN
117
+ * means that inappropriate numbers of categories are being found
118
+ */
119
+ public enum CategorizationStatus {
120
+ OK , WARN ;
121
+
122
+ public static CategorizationStatus fromString (String statusName ) {
123
+ return valueOf (statusName .trim ().toUpperCase (Locale .ROOT ));
124
+ }
125
+
126
+ @ Override
127
+ public String toString () {
128
+ return name ().toLowerCase (Locale .ROOT );
129
+ }
130
+ }
131
+
102
132
private final String jobId ;
103
133
private final long modelBytes ;
104
134
private final Long modelBytesExceeded ;
@@ -108,12 +138,20 @@ public String toString() {
108
138
private final long totalPartitionFieldCount ;
109
139
private final long bucketAllocationFailuresCount ;
110
140
private final MemoryStatus memoryStatus ;
141
+ private final long categorizedDocCount ;
142
+ private final long totalCategoryCount ;
143
+ private final long frequentCategoryCount ;
144
+ private final long rareCategoryCount ;
145
+ private final long deadCategoryCount ;
146
+ private final CategorizationStatus categorizationStatus ;
111
147
private final Date timestamp ;
112
148
private final Date logTime ;
113
149
114
150
private ModelSizeStats (String jobId , long modelBytes , Long modelBytesExceeded , Long modelBytesMemoryLimit , long totalByFieldCount ,
115
151
long totalOverFieldCount , long totalPartitionFieldCount , long bucketAllocationFailuresCount ,
116
- MemoryStatus memoryStatus , Date timestamp , Date logTime ) {
152
+ MemoryStatus memoryStatus , long categorizedDocCount , long totalCategoryCount , long frequentCategoryCount ,
153
+ long rareCategoryCount , long deadCategoryCount , CategorizationStatus categorizationStatus ,
154
+ Date timestamp , Date logTime ) {
117
155
this .jobId = jobId ;
118
156
this .modelBytes = modelBytes ;
119
157
this .modelBytesExceeded = modelBytesExceeded ;
@@ -123,6 +161,12 @@ private ModelSizeStats(String jobId, long modelBytes, Long modelBytesExceeded, L
123
161
this .totalPartitionFieldCount = totalPartitionFieldCount ;
124
162
this .bucketAllocationFailuresCount = bucketAllocationFailuresCount ;
125
163
this .memoryStatus = memoryStatus ;
164
+ this .categorizedDocCount = categorizedDocCount ;
165
+ this .totalCategoryCount = totalCategoryCount ;
166
+ this .frequentCategoryCount = frequentCategoryCount ;
167
+ this .rareCategoryCount = rareCategoryCount ;
168
+ this .deadCategoryCount = deadCategoryCount ;
169
+ this .categorizationStatus = categorizationStatus ;
126
170
this .timestamp = timestamp ;
127
171
this .logTime = logTime ;
128
172
}
@@ -145,6 +189,12 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
145
189
builder .field (TOTAL_PARTITION_FIELD_COUNT_FIELD .getPreferredName (), totalPartitionFieldCount );
146
190
builder .field (BUCKET_ALLOCATION_FAILURES_COUNT_FIELD .getPreferredName (), bucketAllocationFailuresCount );
147
191
builder .field (MEMORY_STATUS_FIELD .getPreferredName (), memoryStatus );
192
+ builder .field (CATEGORIZED_DOC_COUNT_FIELD .getPreferredName (), categorizedDocCount );
193
+ builder .field (TOTAL_CATEGORY_COUNT_FIELD .getPreferredName (), totalCategoryCount );
194
+ builder .field (FREQUENT_CATEGORY_COUNT_FIELD .getPreferredName (), frequentCategoryCount );
195
+ builder .field (RARE_CATEGORY_COUNT_FIELD .getPreferredName (), rareCategoryCount );
196
+ builder .field (DEAD_CATEGORY_COUNT_FIELD .getPreferredName (), deadCategoryCount );
197
+ builder .field (CATEGORIZATION_STATUS_FIELD .getPreferredName (), categorizationStatus );
148
198
builder .timeField (LOG_TIME_FIELD .getPreferredName (), LOG_TIME_FIELD .getPreferredName () + "_string" , logTime .getTime ());
149
199
if (timestamp != null ) {
150
200
builder .timeField (TIMESTAMP_FIELD .getPreferredName (), TIMESTAMP_FIELD .getPreferredName () + "_string" , timestamp .getTime ());
@@ -190,6 +240,30 @@ public MemoryStatus getMemoryStatus() {
190
240
return memoryStatus ;
191
241
}
192
242
243
+ public long getCategorizedDocCount () {
244
+ return categorizedDocCount ;
245
+ }
246
+
247
+ public long getTotalCategoryCount () {
248
+ return totalCategoryCount ;
249
+ }
250
+
251
+ public long getFrequentCategoryCount () {
252
+ return frequentCategoryCount ;
253
+ }
254
+
255
+ public long getRareCategoryCount () {
256
+ return rareCategoryCount ;
257
+ }
258
+
259
+ public long getDeadCategoryCount () {
260
+ return deadCategoryCount ;
261
+ }
262
+
263
+ public CategorizationStatus getCategorizationStatus () {
264
+ return categorizationStatus ;
265
+ }
266
+
193
267
/**
194
268
* The timestamp of the last processed record when this instance was created.
195
269
*
@@ -211,7 +285,8 @@ public Date getLogTime() {
211
285
@ Override
212
286
public int hashCode () {
213
287
return Objects .hash (jobId , modelBytes , modelBytesExceeded , modelBytesMemoryLimit , totalByFieldCount , totalOverFieldCount ,
214
- totalPartitionFieldCount , this .bucketAllocationFailuresCount , memoryStatus , timestamp , logTime );
288
+ totalPartitionFieldCount , this .bucketAllocationFailuresCount , memoryStatus , categorizedDocCount , totalCategoryCount ,
289
+ frequentCategoryCount , rareCategoryCount , deadCategoryCount , categorizationStatus , timestamp , logTime );
215
290
}
216
291
217
292
/**
@@ -233,7 +308,14 @@ public boolean equals(Object other) {
233
308
&& Objects .equals (this .modelBytesMemoryLimit , that .modelBytesMemoryLimit ) && this .totalByFieldCount == that .totalByFieldCount
234
309
&& this .totalOverFieldCount == that .totalOverFieldCount && this .totalPartitionFieldCount == that .totalPartitionFieldCount
235
310
&& this .bucketAllocationFailuresCount == that .bucketAllocationFailuresCount
236
- && Objects .equals (this .memoryStatus , that .memoryStatus ) && Objects .equals (this .timestamp , that .timestamp )
311
+ && Objects .equals (this .memoryStatus , that .memoryStatus )
312
+ && this .categorizedDocCount == that .categorizedDocCount
313
+ && this .totalCategoryCount == that .totalCategoryCount
314
+ && this .frequentCategoryCount == that .frequentCategoryCount
315
+ && this .rareCategoryCount == that .rareCategoryCount
316
+ && this .deadCategoryCount == that .deadCategoryCount
317
+ && Objects .equals (this .categorizationStatus , that .categorizationStatus )
318
+ && Objects .equals (this .timestamp , that .timestamp )
237
319
&& Objects .equals (this .logTime , that .logTime )
238
320
&& Objects .equals (this .jobId , that .jobId );
239
321
}
@@ -249,12 +331,19 @@ public static class Builder {
249
331
private long totalPartitionFieldCount ;
250
332
private long bucketAllocationFailuresCount ;
251
333
private MemoryStatus memoryStatus ;
334
+ private long categorizedDocCount ;
335
+ private long totalCategoryCount ;
336
+ private long frequentCategoryCount ;
337
+ private long rareCategoryCount ;
338
+ private long deadCategoryCount ;
339
+ private CategorizationStatus categorizationStatus ;
252
340
private Date timestamp ;
253
341
private Date logTime ;
254
342
255
343
public Builder (String jobId ) {
256
344
this .jobId = jobId ;
257
345
memoryStatus = MemoryStatus .OK ;
346
+ categorizationStatus = CategorizationStatus .OK ;
258
347
logTime = new Date ();
259
348
}
260
349
@@ -268,6 +357,12 @@ public Builder(ModelSizeStats modelSizeStats) {
268
357
this .totalPartitionFieldCount = modelSizeStats .totalPartitionFieldCount ;
269
358
this .bucketAllocationFailuresCount = modelSizeStats .bucketAllocationFailuresCount ;
270
359
this .memoryStatus = modelSizeStats .memoryStatus ;
360
+ this .categorizedDocCount = modelSizeStats .categorizedDocCount ;
361
+ this .totalCategoryCount = modelSizeStats .totalCategoryCount ;
362
+ this .frequentCategoryCount = modelSizeStats .frequentCategoryCount ;
363
+ this .rareCategoryCount = modelSizeStats .rareCategoryCount ;
364
+ this .deadCategoryCount = modelSizeStats .deadCategoryCount ;
365
+ this .categorizationStatus = modelSizeStats .categorizationStatus ;
271
366
this .timestamp = modelSizeStats .timestamp ;
272
367
this .logTime = modelSizeStats .logTime ;
273
368
}
@@ -313,6 +408,37 @@ public Builder setMemoryStatus(MemoryStatus memoryStatus) {
313
408
return this ;
314
409
}
315
410
411
+ public Builder setCategorizedDocCount (long categorizedDocCount ) {
412
+ this .categorizedDocCount = categorizedDocCount ;
413
+ return this ;
414
+ }
415
+
416
+ public Builder setTotalCategoryCount (long totalCategoryCount ) {
417
+ this .totalCategoryCount = totalCategoryCount ;
418
+ return this ;
419
+ }
420
+
421
+ public Builder setFrequentCategoryCount (long frequentCategoryCount ) {
422
+ this .frequentCategoryCount = frequentCategoryCount ;
423
+ return this ;
424
+ }
425
+
426
+ public Builder setRareCategoryCount (long rareCategoryCount ) {
427
+ this .rareCategoryCount = rareCategoryCount ;
428
+ return this ;
429
+ }
430
+
431
+ public Builder setDeadCategoryCount (long deadCategoryCount ) {
432
+ this .deadCategoryCount = deadCategoryCount ;
433
+ return this ;
434
+ }
435
+
436
+ public Builder setCategorizationStatus (CategorizationStatus categorizationStatus ) {
437
+ Objects .requireNonNull (categorizationStatus , "[" + CATEGORIZATION_STATUS_FIELD .getPreferredName () + "] must not be null" );
438
+ this .categorizationStatus = categorizationStatus ;
439
+ return this ;
440
+ }
441
+
316
442
public Builder setTimestamp (Date timestamp ) {
317
443
this .timestamp = timestamp ;
318
444
return this ;
@@ -325,7 +451,8 @@ public Builder setLogTime(Date logTime) {
325
451
326
452
public ModelSizeStats build () {
327
453
return new ModelSizeStats (jobId , modelBytes , modelBytesExceeded , modelBytesMemoryLimit , totalByFieldCount , totalOverFieldCount ,
328
- totalPartitionFieldCount , bucketAllocationFailuresCount , memoryStatus , timestamp , logTime );
454
+ totalPartitionFieldCount , bucketAllocationFailuresCount , memoryStatus , categorizedDocCount , totalCategoryCount ,
455
+ frequentCategoryCount , rareCategoryCount , deadCategoryCount , categorizationStatus , timestamp , logTime );
329
456
}
330
457
}
331
458
}
0 commit comments