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