8
8
9
9
package org .opensearch .plugin .insights .rules .model .healthStats ;
10
10
11
+ import static org .opensearch .plugin .insights .core .service .categorizer .QueryShapeGenerator .ENTRY_COUNT ;
12
+ import static org .opensearch .plugin .insights .core .service .categorizer .QueryShapeGenerator .EVICTION_COUNT ;
13
+ import static org .opensearch .plugin .insights .core .service .categorizer .QueryShapeGenerator .HIT_COUNT ;
14
+ import static org .opensearch .plugin .insights .core .service .categorizer .QueryShapeGenerator .MISS_COUNT ;
15
+ import static org .opensearch .plugin .insights .core .service .categorizer .QueryShapeGenerator .SIZE_IN_BYTES ;
16
+
11
17
import java .io .IOException ;
18
+ import java .util .List ;
12
19
import java .util .Map ;
20
+ import java .util .Objects ;
21
+ import org .opensearch .Version ;
13
22
import org .opensearch .core .common .io .stream .StreamInput ;
14
23
import org .opensearch .core .common .io .stream .StreamOutput ;
15
24
import org .opensearch .core .common .io .stream .Writeable ;
@@ -26,10 +35,12 @@ public class QueryInsightsHealthStats implements ToXContentFragment, Writeable {
26
35
private final ThreadPool .Info threadPoolInfo ;
27
36
private final int queryRecordsQueueSize ;
28
37
private final Map <MetricType , TopQueriesHealthStats > topQueriesHealthStats ;
38
+ private Map <String , Long > fieldTypeCacheStats ;
29
39
30
40
private static final String THREAD_POOL_INFO = "ThreadPoolInfo" ;
31
41
private static final String QUERY_RECORDS_QUEUE_SIZE = "QueryRecordsQueueSize" ;
32
42
private static final String TOP_QUERIES_HEALTH_STATS = "TopQueriesHealthStats" ;
43
+ private static final String FIELD_TYPE_CACHE_STATS = "FieldTypeCacheStats" ;
33
44
34
45
/**
35
46
* Constructor to read QueryInsightsHealthStats from a StreamInput.
@@ -41,6 +52,9 @@ public QueryInsightsHealthStats(final StreamInput in) throws IOException {
41
52
this .threadPoolInfo = new ThreadPool .Info (in );
42
53
this .queryRecordsQueueSize = in .readInt ();
43
54
this .topQueriesHealthStats = in .readMap (MetricType ::readFromStream , TopQueriesHealthStats ::new );
55
+ if (in .getVersion ().onOrAfter (Version .V_2_19_0 )) {
56
+ this .fieldTypeCacheStats = in .readMap (StreamInput ::readString , StreamInput ::readLong );
57
+ }
44
58
}
45
59
46
60
/**
@@ -53,14 +67,16 @@ public QueryInsightsHealthStats(final StreamInput in) throws IOException {
53
67
public QueryInsightsHealthStats (
54
68
final ThreadPool .Info threadPoolInfo ,
55
69
final int queryRecordsQueueSize ,
56
- final Map <MetricType , TopQueriesHealthStats > topQueriesHealthStats
70
+ final Map <MetricType , TopQueriesHealthStats > topQueriesHealthStats ,
71
+ final Map <String , Long > fieldTypeCacheStats
57
72
) {
58
73
if (threadPoolInfo == null || topQueriesHealthStats == null ) {
59
74
throw new IllegalArgumentException ("Parameters cannot be null" );
60
75
}
61
76
this .threadPoolInfo = threadPoolInfo ;
62
77
this .queryRecordsQueueSize = queryRecordsQueueSize ;
63
78
this .topQueriesHealthStats = topQueriesHealthStats ;
79
+ this .fieldTypeCacheStats = Objects .requireNonNull (fieldTypeCacheStats , "fieldTypeCacheStats cannot be null" );
64
80
}
65
81
66
82
/**
@@ -87,6 +103,12 @@ public XContentBuilder toXContent(final XContentBuilder builder, final Params pa
87
103
builder .endObject ();
88
104
}
89
105
builder .endObject ();
106
+ // Write field type cache stats
107
+ builder .startObject (FIELD_TYPE_CACHE_STATS );
108
+ for (String key : List .of (HIT_COUNT , MISS_COUNT , EVICTION_COUNT , ENTRY_COUNT , SIZE_IN_BYTES )) {
109
+ builder .field (key , fieldTypeCacheStats .getOrDefault (key , 0L ));
110
+ }
111
+ builder .endObject ();
90
112
return builder ;
91
113
}
92
114
@@ -105,6 +127,9 @@ public void writeTo(final StreamOutput out) throws IOException {
105
127
MetricType ::writeTo ,
106
128
(streamOutput , topQueriesHealthStats ) -> topQueriesHealthStats .writeTo (out )
107
129
);
130
+ if (out .getVersion ().onOrAfter (Version .V_2_19_0 )) {
131
+ out .writeMap (fieldTypeCacheStats , StreamOutput ::writeString , StreamOutput ::writeLong );
132
+ }
108
133
}
109
134
110
135
/**
@@ -133,4 +158,13 @@ public int getQueryRecordsQueueSize() {
133
158
public Map <MetricType , TopQueriesHealthStats > getTopQueriesHealthStats () {
134
159
return topQueriesHealthStats ;
135
160
}
161
+
162
+ /**
163
+ * Get the field type cache stats.
164
+ *
165
+ * @return the field type cache stats
166
+ */
167
+ public Map <String , Long > getFieldTypeCacheStats () {
168
+ return fieldTypeCacheStats ;
169
+ }
136
170
}
0 commit comments