Skip to content

Commit 52d909b

Browse files
committed
Fix yaml REST tests
1 parent cd3811a commit 52d909b

File tree

3 files changed

+38
-7
lines changed

3 files changed

+38
-7
lines changed

x-pack/plugin/profiling/src/main/java/org/elasticsearch/xpack/profiling/action/GetStackTracesResponseBuilder.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,22 @@ public void setTotalSamples(long totalSamples) {
137137
}
138138

139139
public GetStackTracesResponse build() {
140+
// Merge the TraceEvent data into the StackTraces.
141+
if (stackTraces != null) {
142+
for (Map.Entry<TraceEventID, TraceEvent> entry : stackTraceEvents.entrySet()) {
143+
TraceEventID traceEventID = entry.getKey();
144+
StackTrace stackTrace = stackTraces.get(traceEventID.stacktraceID());
145+
if (stackTrace != null) {
146+
TraceEvent event = entry.getValue();
147+
if (event.subGroups != null) {
148+
stackTrace.subGroups = event.subGroups;
149+
}
150+
stackTrace.count += event.count;
151+
stackTrace.annualCO2Tons += event.annualCO2Tons;
152+
stackTrace.annualCostsUSD += event.annualCostsUSD;
153+
}
154+
}
155+
}
140156
return new GetStackTracesResponse(stackTraces, stackFrames, executables, stackTraceEvents, totalFrames, samplingRate, totalSamples);
141157
}
142158
}

x-pack/plugin/profiling/src/main/java/org/elasticsearch/xpack/profiling/action/StackTrace.java

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,18 @@ final class StackTrace implements ToXContentObject {
2727
String[] frameIds;
2828
int[] typeIds;
2929
SubGroup subGroups;
30+
double annualCO2Tons;
31+
double annualCostsUSD;
32+
long count;
3033

3134
StackTrace(int[] addressOrLines, String[] fileIds, String[] frameIds, int[] typeIds) {
3235
this.addressOrLines = addressOrLines;
3336
this.fileIds = fileIds;
3437
this.frameIds = frameIds;
3538
this.typeIds = typeIds;
39+
annualCO2Tons = 0.0d;
40+
annualCostsUSD = 0.0d;
41+
count = 0;
3642
}
3743

3844
private static final int BASE64_FRAME_ID_LENGTH = 32;
@@ -210,12 +216,15 @@ public void forNativeAndKernelFrames(Consumer<String> consumer) {
210216

211217
@Override
212218
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
213-
builder.startObject();
214-
builder.field("address_or_lines", this.addressOrLines);
215-
builder.field("file_ids", this.fileIds);
216-
builder.field("frame_ids", this.frameIds);
217-
builder.field("type_ids", this.typeIds);
218-
builder.endObject();
219+
builder.startObject()
220+
.field("address_or_lines", this.addressOrLines)
221+
.field("file_ids", this.fileIds)
222+
.field("frame_ids", this.frameIds)
223+
.field("type_ids", this.typeIds)
224+
.field("annual_co2_tons", this.annualCO2Tons)
225+
.field("annual_costs_usd", this.annualCostsUSD)
226+
.field("count", this.count)
227+
.endObject();
219228
return builder;
220229
}
221230

@@ -230,7 +239,7 @@ public boolean equals(Object o) {
230239
&& Arrays.equals(fileIds, that.fileIds)
231240
&& Arrays.equals(frameIds, that.frameIds)
232241
&& Arrays.equals(typeIds, that.typeIds);
233-
// Don't compare metadata like subGroups.
242+
// Don't compare metadata like annualized co2, annualized costs, subGroups and count.
234243
}
235244

236245
// Don't hash metadata like annualized co2, annualized costs, subGroups and count.

x-pack/plugin/profiling/src/test/java/org/elasticsearch/xpack/profiling/action/StackTraceTests.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,9 @@ public void testToXContent() throws IOException {
8686
.array("file_ids", "AAAAAAAAAAUAAAAAAAAB3g")
8787
.array("frame_ids", "AAAAAAAAAAUAAAAAAAAB3gAAAAAAD67u")
8888
.array("type_ids", new int[] { 2 })
89+
.field("annual_co2_tons", 0.3d)
90+
.field("annual_costs_usd", 2.7d)
91+
.field("count", 1)
8992
.endObject();
9093

9194
XContentBuilder actualRequest = XContentFactory.contentBuilder(contentType);
@@ -95,6 +98,9 @@ public void testToXContent() throws IOException {
9598
new String[] { "AAAAAAAAAAUAAAAAAAAB3gAAAAAAD67u" },
9699
new int[] { 2 }
97100
);
101+
stackTrace.annualCO2Tons = 0.3d;
102+
stackTrace.annualCostsUSD = 2.7d;
103+
stackTrace.count = 1;
98104
stackTrace.toXContent(actualRequest, ToXContent.EMPTY_PARAMS);
99105

100106
assertToXContentEquivalent(BytesReference.bytes(expectedRequest), BytesReference.bytes(actualRequest), contentType);

0 commit comments

Comments
 (0)