9
9
package org .opensearch .plugin .insights .rules .model .healthStats ;
10
10
11
11
import java .io .IOException ;
12
+ import java .util .List ;
12
13
import java .util .Map ;
14
+ import org .opensearch .Version ;
13
15
import org .opensearch .core .common .io .stream .StreamInput ;
14
16
import org .opensearch .core .common .io .stream .StreamOutput ;
15
17
import org .opensearch .core .common .io .stream .Writeable ;
@@ -26,10 +28,12 @@ public class QueryInsightsHealthStats implements ToXContentFragment, Writeable {
26
28
private final ThreadPool .Info threadPoolInfo ;
27
29
private final int queryRecordsQueueSize ;
28
30
private final Map <MetricType , TopQueriesHealthStats > topQueriesHealthStats ;
31
+ private Map <String , Long > fieldTypeCacheStats ;
29
32
30
33
private static final String THREAD_POOL_INFO = "ThreadPoolInfo" ;
31
34
private static final String QUERY_RECORDS_QUEUE_SIZE = "QueryRecordsQueueSize" ;
32
35
private static final String TOP_QUERIES_HEALTH_STATS = "TopQueriesHealthStats" ;
36
+ private static final String FIELD_TYPE_CACHE_STATS = "FieldTypeCacheStats" ;
33
37
34
38
/**
35
39
* Constructor to read QueryInsightsHealthStats from a StreamInput.
@@ -41,6 +45,9 @@ public QueryInsightsHealthStats(final StreamInput in) throws IOException {
41
45
this .threadPoolInfo = new ThreadPool .Info (in );
42
46
this .queryRecordsQueueSize = in .readInt ();
43
47
this .topQueriesHealthStats = in .readMap (MetricType ::readFromStream , TopQueriesHealthStats ::new );
48
+ if (in .getVersion ().onOrAfter (Version .V_2_19_0 )) {
49
+ this .fieldTypeCacheStats = in .readMap (StreamInput ::readString , StreamInput ::readLong );
50
+ }
44
51
}
45
52
46
53
/**
@@ -53,14 +60,16 @@ public QueryInsightsHealthStats(final StreamInput in) throws IOException {
53
60
public QueryInsightsHealthStats (
54
61
final ThreadPool .Info threadPoolInfo ,
55
62
final int queryRecordsQueueSize ,
56
- final Map <MetricType , TopQueriesHealthStats > topQueriesHealthStats
63
+ final Map <MetricType , TopQueriesHealthStats > topQueriesHealthStats ,
64
+ final Map <String , Long > fieldTypeCacheStats
57
65
) {
58
66
if (threadPoolInfo == null || topQueriesHealthStats == null ) {
59
67
throw new IllegalArgumentException ("Parameters cannot be null" );
60
68
}
61
69
this .threadPoolInfo = threadPoolInfo ;
62
70
this .queryRecordsQueueSize = queryRecordsQueueSize ;
63
71
this .topQueriesHealthStats = topQueriesHealthStats ;
72
+ this .fieldTypeCacheStats = fieldTypeCacheStats ;
64
73
}
65
74
66
75
/**
@@ -87,6 +96,12 @@ public XContentBuilder toXContent(final XContentBuilder builder, final Params pa
87
96
builder .endObject ();
88
97
}
89
98
builder .endObject ();
99
+ // Write field type cache stats
100
+ builder .startObject (FIELD_TYPE_CACHE_STATS );
101
+ for (String key : List .of ("hits" , "misses" , "bytes" )) {
102
+ builder .field (key , fieldTypeCacheStats .getOrDefault (key , 0L ));
103
+ }
104
+ builder .endObject ();
90
105
return builder ;
91
106
}
92
107
@@ -105,6 +120,9 @@ public void writeTo(final StreamOutput out) throws IOException {
105
120
MetricType ::writeTo ,
106
121
(streamOutput , topQueriesHealthStats ) -> topQueriesHealthStats .writeTo (out )
107
122
);
123
+ if (out .getVersion ().onOrAfter (Version .V_2_19_0 )) {
124
+ out .writeMap (fieldTypeCacheStats , StreamOutput ::writeString , StreamOutput ::writeLong );
125
+ }
108
126
}
109
127
110
128
/**
@@ -133,4 +151,13 @@ public int getQueryRecordsQueueSize() {
133
151
public Map <MetricType , TopQueriesHealthStats > getTopQueriesHealthStats () {
134
152
return topQueriesHealthStats ;
135
153
}
154
+
155
+ /**
156
+ * Get the field type cache stats.
157
+ *
158
+ * @return the field type cache stats
159
+ */
160
+ public Map <String , Long > getFieldTypeCacheStats () {
161
+ return fieldTypeCacheStats ;
162
+ }
136
163
}
0 commit comments