Skip to content

Commit 88cf248

Browse files
authored
Fixing serialization of ScriptStats cache_evictions_history (#123384)
1 parent 48d2083 commit 88cf248

File tree

3 files changed

+38
-1
lines changed

3 files changed

+38
-1
lines changed

docs/changelog/123384.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
pr: 123384
2+
summary: Fixing serialization of `ScriptStats` `cache_evictions_history`
3+
area: Stats
4+
type: bug
5+
issues: []

server/src/main/java/org/elasticsearch/script/ScriptStats.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import java.util.Objects;
2929

3030
import static org.elasticsearch.common.collect.Iterators.single;
31+
import static org.elasticsearch.script.ScriptContextStats.Fields.CACHE_EVICTIONS_HISTORY;
3132
import static org.elasticsearch.script.ScriptContextStats.Fields.COMPILATIONS_HISTORY;
3233
import static org.elasticsearch.script.ScriptStats.Fields.CACHE_EVICTIONS;
3334
import static org.elasticsearch.script.ScriptStats.Fields.COMPILATIONS;
@@ -205,7 +206,7 @@ public Iterator<? extends ToXContent> toXContentChunked(ToXContent.Params outerP
205206
builder.endObject();
206207
}
207208
if (cacheEvictionsHistory != null && cacheEvictionsHistory.areTimingsEmpty() == false) {
208-
builder.startObject(COMPILATIONS_HISTORY);
209+
builder.startObject(CACHE_EVICTIONS_HISTORY);
209210
cacheEvictionsHistory.toXContent(builder, params);
210211
builder.endObject();
211212
}

server/src/test/java/org/elasticsearch/script/ScriptStatsTests.java

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,37 @@ public void testXContentChunked() throws IOException {
7878
assertThat(Strings.toString(builder), equalTo(expected));
7979
}
8080

81+
public void testXContentChunkedHistory() throws Exception {
82+
ScriptStats stats = new ScriptStats(5, 6, 7, new TimeSeries(10, 20, 30, 40), new TimeSeries(100, 200, 300, 400));
83+
final XContentBuilder builder = XContentFactory.jsonBuilder().prettyPrint();
84+
85+
builder.startObject();
86+
for (var it = stats.toXContentChunked(ToXContent.EMPTY_PARAMS); it.hasNext();) {
87+
it.next().toXContent(builder, ToXContent.EMPTY_PARAMS);
88+
}
89+
builder.endObject();
90+
String expected = """
91+
{
92+
"script" : {
93+
"compilations" : 5,
94+
"cache_evictions" : 6,
95+
"compilation_limit_triggered" : 7,
96+
"compilations_history" : {
97+
"5m" : 10,
98+
"15m" : 20,
99+
"24h" : 30
100+
},
101+
"cache_evictions_history" : {
102+
"5m" : 100,
103+
"15m" : 200,
104+
"24h" : 300
105+
},
106+
"contexts" : [ ]
107+
}
108+
}""";
109+
assertThat(Strings.toString(builder), equalTo(expected));
110+
}
111+
81112
public void testSerializeEmptyTimeSeries() throws IOException {
82113
ScriptContextStats stats = new ScriptContextStats("c", 3333, new TimeSeries(1111), new TimeSeries(2222));
83114

0 commit comments

Comments
 (0)