Skip to content

Commit b2f290f

Browse files
authored
[Profiling] Remove legacy aggregation_field (elastic#119770)
1 parent 0cf2ebb commit b2f290f

File tree

13 files changed

+41
-195
lines changed

13 files changed

+41
-195
lines changed

x-pack/plugin/profiling/src/internalClusterTest/java/org/elasticsearch/xpack/profiling/action/GetFlameGraphActionIT.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ public void testGetStackTracesUnfiltered() throws Exception {
2222
null,
2323
null,
2424
null,
25-
null,
2625
null
2726
);
2827
GetFlamegraphResponse response = client().execute(GetFlamegraphAction.INSTANCE, request).get();

x-pack/plugin/profiling/src/internalClusterTest/java/org/elasticsearch/xpack/profiling/action/GetStackTracesActionIT.java

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ public void testGetStackTracesUnfiltered() throws Exception {
2828
null,
2929
null,
3030
null,
31-
null,
3231
null
3332
);
3433
request.setAdjustSampleCount(true);
@@ -68,8 +67,7 @@ public void testGetStackTracesGroupedByServiceName() throws Exception {
6867
null,
6968
null,
7069
null,
71-
"service.name",
72-
null,
70+
new String[] { "service.name" },
7371
null,
7472
null,
7573
null,
@@ -117,8 +115,7 @@ public void testGetStackTracesFromAPMWithMatchNoDownsampling() throws Exception
117115
// also match an index that does not contain stacktrace ids to ensure it is ignored
118116
new String[] { "apm-test-*", "apm-legacy-test-*" },
119117
"transaction.profiler_stack_trace_ids",
120-
"transaction.name",
121-
null,
118+
new String[] { "transaction.name" },
122119
null,
123120
null,
124121
null,
@@ -168,7 +165,6 @@ public void testGetStackTracesFromAPMWithMatchAndDownsampling() throws Exception
168165
null,
169166
null,
170167
null,
171-
null,
172168
null
173169
);
174170
// ensures consistent results in the random sampler aggregation that is used internally
@@ -219,7 +215,6 @@ public void testGetStackTracesFromAPMNoMatch() throws Exception {
219215
null,
220216
null,
221217
null,
222-
null,
223218
null
224219
);
225220
GetStackTracesResponse response = client().execute(GetStackTracesAction.INSTANCE, request).get();
@@ -242,7 +237,6 @@ public void testGetStackTracesFromAPMIndexNotAvailable() throws Exception {
242237
null,
243238
null,
244239
null,
245-
null,
246240
null
247241
);
248242
GetStackTracesResponse response = client().execute(GetStackTracesAction.INSTANCE, request).get();
@@ -265,7 +259,6 @@ public void testGetStackTracesFromAPMStackTraceFieldNotAvailable() throws Except
265259
null,
266260
null,
267261
null,
268-
null,
269262
null
270263
);
271264
GetStackTracesResponse response = client().execute(GetStackTracesAction.INSTANCE, request).get();

x-pack/plugin/profiling/src/internalClusterTest/java/org/elasticsearch/xpack/profiling/action/GetTopNFunctionsActionIT.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ public void testGetTopNFunctionsUnfiltered() throws Exception {
2525
null,
2626
null,
2727
null,
28-
null,
2928
null
3029
);
3130
request.setAdjustSampleCount(true);
@@ -42,8 +41,7 @@ public void testGetTopNFunctionsGroupedByServiceName() throws Exception {
4241
null,
4342
null,
4443
null,
45-
"service.name",
46-
null,
44+
new String[] { "service.name" },
4745
null,
4846
null,
4947
null,
@@ -70,8 +68,7 @@ public void testGetTopNFunctionsFromAPM() throws Exception {
7068
// also match an index that does not contain stacktrace ids to ensure it is ignored
7169
new String[] { "apm-test-*", "apm-legacy-test-*" },
7270
"transaction.profiler_stack_trace_ids",
73-
"transaction.name",
74-
null,
71+
new String[] { "transaction.name" },
7572
null,
7673
null,
7774
null,

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

Lines changed: 2 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
import org.elasticsearch.action.support.TransportAction;
1414
import org.elasticsearch.common.ParsingException;
1515
import org.elasticsearch.common.io.stream.StreamOutput;
16-
import org.elasticsearch.core.UpdateForV9;
1716
import org.elasticsearch.index.query.QueryBuilder;
1817
import org.elasticsearch.tasks.CancellableTask;
1918
import org.elasticsearch.tasks.Task;
@@ -43,8 +42,6 @@ public class GetStackTracesRequest extends ActionRequest implements IndicesReque
4342
public static final ParseField LIMIT_FIELD = new ParseField("limit");
4443
public static final ParseField INDICES_FIELD = new ParseField("indices");
4544
public static final ParseField STACKTRACE_IDS_FIELD = new ParseField("stacktrace_ids_field");
46-
@UpdateForV9(owner = UpdateForV9.Owner.PROFILING) // Remove this BWC layer and allow only AGGREGATION_FIELDS
47-
public static final ParseField AGGREGATION_FIELD = new ParseField("aggregation_field");
4845
public static final ParseField AGGREGATION_FIELDS = new ParseField("aggregation_fields");
4946
public static final ParseField REQUESTED_DURATION_FIELD = new ParseField("requested_duration");
5047
public static final ParseField AWS_COST_FACTOR_FIELD = new ParseField("aws_cost_factor");
@@ -62,8 +59,6 @@ public class GetStackTracesRequest extends ActionRequest implements IndicesReque
6259
private String[] indices;
6360
private boolean userProvidedIndices;
6461
private String stackTraceIdsField;
65-
@UpdateForV9(owner = UpdateForV9.Owner.PROFILING) // Remove this BWC layer and allow only aggregationFields
66-
private String aggregationField;
6762
private String[] aggregationFields;
6863
private Double requestedDuration;
6964
private Double awsCostFactor;
@@ -83,7 +78,7 @@ public class GetStackTracesRequest extends ActionRequest implements IndicesReque
8378
private Integer shardSeed;
8479

8580
public GetStackTracesRequest() {
86-
this(null, null, null, null, null, null, null, null, null, null, null, null, null, null);
81+
this(null, null, null, null, null, null, null, null, null, null, null, null, null);
8782
}
8883

8984
public GetStackTracesRequest(
@@ -94,7 +89,6 @@ public GetStackTracesRequest(
9489
QueryBuilder query,
9590
String[] indices,
9691
String stackTraceIdsField,
97-
String aggregationField,
9892
String[] aggregationFields,
9993
Double customCO2PerKWH,
10094
Double customDatacenterPUE,
@@ -110,7 +104,6 @@ public GetStackTracesRequest(
110104
this.indices = indices;
111105
this.userProvidedIndices = indices != null && indices.length > 0;
112106
this.stackTraceIdsField = stackTraceIdsField;
113-
this.aggregationField = aggregationField;
114107
this.aggregationFields = aggregationFields;
115108
this.customCO2PerKWH = customCO2PerKWH;
116109
this.customDatacenterPUE = customDatacenterPUE;
@@ -184,23 +177,15 @@ public String getStackTraceIdsField() {
184177
return stackTraceIdsField;
185178
}
186179

187-
public String getAggregationField() {
188-
return aggregationField;
189-
}
190-
191180
public String[] getAggregationFields() {
192-
return aggregationField != null ? new String[] { aggregationField } : aggregationFields;
181+
return aggregationFields;
193182
}
194183

195184
public boolean hasAggregationFields() {
196185
String[] f = getAggregationFields();
197186
return f != null && f.length > 0;
198187
}
199188

200-
public boolean isLegacyAggregationField() {
201-
return aggregationField != null;
202-
}
203-
204189
public boolean isAdjustSampleCount() {
205190
return Boolean.TRUE.equals(adjustSampleCount);
206191
}
@@ -237,8 +222,6 @@ public void parseXContent(XContentParser parser) throws IOException {
237222
this.limit = parser.intValue();
238223
} else if (STACKTRACE_IDS_FIELD.match(currentFieldName, parser.getDeprecationHandler())) {
239224
this.stackTraceIdsField = parser.text();
240-
} else if (AGGREGATION_FIELD.match(currentFieldName, parser.getDeprecationHandler())) {
241-
this.aggregationField = parser.text();
242225
} else if (REQUESTED_DURATION_FIELD.match(currentFieldName, parser.getDeprecationHandler())) {
243226
this.requestedDuration = parser.doubleValue();
244227
} else if (AWS_COST_FACTOR_FIELD.match(currentFieldName, parser.getDeprecationHandler())) {
@@ -322,17 +305,6 @@ public ActionRequestValidationException validate() {
322305
);
323306
}
324307
}
325-
if (aggregationField != null && aggregationFields != null) {
326-
validationException = addValidationError(
327-
"["
328-
+ AGGREGATION_FIELD.getPreferredName()
329-
+ "] must not be set when ["
330-
+ AGGREGATION_FIELDS.getPreferredName()
331-
+ "] is also set",
332-
validationException
333-
);
334-
335-
}
336308
if (aggregationFields != null) {
337309
// limit so we avoid an explosion of buckets
338310
if (aggregationFields.length < 1 || aggregationFields.length > 2) {
@@ -348,13 +320,6 @@ public ActionRequestValidationException validate() {
348320

349321
}
350322

351-
if (aggregationField != null && aggregationField.isBlank()) {
352-
validationException = addValidationError(
353-
"[" + AGGREGATION_FIELD.getPreferredName() + "] must be non-empty",
354-
validationException
355-
);
356-
}
357-
358323
validationException = requirePositive(SAMPLE_SIZE_FIELD, sampleSize, validationException);
359324
validationException = requirePositive(LIMIT_FIELD, limit, validationException);
360325
validationException = requirePositive(REQUESTED_DURATION_FIELD, requestedDuration, validationException);
@@ -386,7 +351,6 @@ public String getDescription() {
386351
StringBuilder sb = new StringBuilder();
387352
appendField(sb, "indices", indices);
388353
appendField(sb, "stacktrace_ids_field", stackTraceIdsField);
389-
appendField(sb, "aggregation_field", aggregationField);
390354
appendField(sb, "aggregation_fields", aggregationFields);
391355
appendField(sb, "sample_size", sampleSize);
392356
appendField(sb, "limit", limit);

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

Lines changed: 15 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -20,23 +20,21 @@ public class SubGroup implements ToXContentFragment {
2020
private final String name;
2121
private Long count;
2222
@UpdateForV9(owner = UpdateForV9.Owner.PROFILING) // remove legacy XContent rendering
23-
private final boolean renderLegacyXContent;
2423
private final Map<String, SubGroup> subgroups;
2524

26-
public static SubGroup root(String name, boolean renderLegacyXContent) {
27-
return new SubGroup(name, null, renderLegacyXContent, new HashMap<>());
25+
public static SubGroup root(String name) {
26+
return new SubGroup(name, null, new HashMap<>());
2827
}
2928

30-
public SubGroup(String name, Long count, boolean renderLegacyXContent, Map<String, SubGroup> subgroups) {
29+
public SubGroup(String name, Long count, Map<String, SubGroup> subgroups) {
3130
this.name = name;
3231
this.count = count;
33-
this.renderLegacyXContent = renderLegacyXContent;
3432
this.subgroups = subgroups;
3533
}
3634

3735
public SubGroup addCount(String name, long count) {
3836
if (this.subgroups.containsKey(name) == false) {
39-
this.subgroups.put(name, new SubGroup(name, count, renderLegacyXContent, new HashMap<>()));
37+
this.subgroups.put(name, new SubGroup(name, count, new HashMap<>()));
4038
} else {
4139
SubGroup s = this.subgroups.get(name);
4240
s.count += count;
@@ -46,7 +44,7 @@ public SubGroup addCount(String name, long count) {
4644

4745
public SubGroup getOrAddChild(String name) {
4846
if (subgroups.containsKey(name) == false) {
49-
this.subgroups.put(name, new SubGroup(name, null, renderLegacyXContent, new HashMap<>()));
47+
this.subgroups.put(name, new SubGroup(name, null, new HashMap<>()));
5048
}
5149
return this.subgroups.get(name);
5250
}
@@ -65,32 +63,22 @@ public SubGroup copy() {
6563
for (Map.Entry<String, SubGroup> subGroup : subgroups.entrySet()) {
6664
copy.put(subGroup.getKey(), subGroup.getValue().copy());
6765
}
68-
return new SubGroup(name, count, renderLegacyXContent, copy);
66+
return new SubGroup(name, count, copy);
6967
}
7068

7169
@Override
7270
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
73-
if (renderLegacyXContent) {
74-
// This assumes that we only have one level of sub groups
75-
if (subgroups != null && subgroups.isEmpty() == false) {
76-
for (SubGroup subgroup : subgroups.values()) {
77-
builder.field(subgroup.name, subgroup.count);
78-
}
79-
}
80-
return builder;
81-
} else {
82-
builder.startObject(name);
83-
// only the root node has no count
84-
if (count != null) {
85-
builder.field("count", count);
86-
}
87-
if (subgroups != null && subgroups.isEmpty() == false) {
88-
for (SubGroup subgroup : subgroups.values()) {
89-
subgroup.toXContent(builder, params);
90-
}
71+
builder.startObject(name);
72+
// only the root node has no count
73+
if (count != null) {
74+
builder.field("count", count);
75+
}
76+
if (subgroups != null && subgroups.isEmpty() == false) {
77+
for (SubGroup subgroup : subgroups.values()) {
78+
subgroup.toXContent(builder, params);
9179
}
92-
return builder.endObject();
9380
}
81+
return builder.endObject();
9482
}
9583

9684
@Override

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

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,21 +26,15 @@ public final class SubGroupCollector {
2626
private static final Logger log = LogManager.getLogger(SubGroupCollector.class);
2727

2828
private final String[] aggregationFields;
29-
private final boolean legacyAggregationField;
30-
31-
public static SubGroupCollector attach(
32-
AbstractAggregationBuilder<?> parentAggregation,
33-
String[] aggregationFields,
34-
boolean legacyAggregationField
35-
) {
36-
SubGroupCollector c = new SubGroupCollector(aggregationFields, legacyAggregationField);
29+
30+
public static SubGroupCollector attach(AbstractAggregationBuilder<?> parentAggregation, String[] aggregationFields) {
31+
SubGroupCollector c = new SubGroupCollector(aggregationFields);
3732
c.addAggregations(parentAggregation);
3833
return c;
3934
}
4035

41-
private SubGroupCollector(String[] aggregationFields, boolean legacyAggregationField) {
36+
private SubGroupCollector(String[] aggregationFields) {
4237
this.aggregationFields = aggregationFields;
43-
this.legacyAggregationField = legacyAggregationField;
4438
}
4539

4640
private boolean hasAggregationFields() {
@@ -68,7 +62,7 @@ void collectResults(MultiBucketsAggregation.Bucket bucket, TraceEvent event) {
6862
void collectResults(Bucket bucket, TraceEvent event) {
6963
if (hasAggregationFields()) {
7064
if (event.subGroups == null) {
71-
event.subGroups = SubGroup.root(aggregationFields[0], legacyAggregationField);
65+
event.subGroups = SubGroup.root(aggregationFields[0]);
7266
}
7367
collectInternal(bucket.getAggregations(), event.subGroups, 0);
7468
}

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

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -255,11 +255,7 @@ private void searchGenericEventGroupedByStackTrace(
255255
CountedTermsAggregationBuilder groupByStackTraceId = new CountedTermsAggregationBuilder("group_by").size(
256256
MAX_TRACE_EVENTS_RESULT_SIZE
257257
).field(request.getStackTraceIdsField());
258-
SubGroupCollector subGroups = SubGroupCollector.attach(
259-
groupByStackTraceId,
260-
request.getAggregationFields(),
261-
request.isLegacyAggregationField()
262-
);
258+
SubGroupCollector subGroups = SubGroupCollector.attach(groupByStackTraceId, request.getAggregationFields());
263259
RandomSamplerAggregationBuilder randomSampler = new RandomSamplerAggregationBuilder("sample").setSeed(request.hashCode())
264260
.setProbability(responseBuilder.getSamplingRate())
265261
.subAggregation(groupByStackTraceId);
@@ -326,11 +322,7 @@ private void searchEventGroupedByStackTrace(
326322
// Especially with high cardinality fields, this makes aggregations really slow.
327323
.executionHint("map")
328324
.subAggregation(new SumAggregationBuilder("count").field("Stacktrace.count"));
329-
SubGroupCollector subGroups = SubGroupCollector.attach(
330-
groupByStackTraceId,
331-
request.getAggregationFields(),
332-
request.isLegacyAggregationField()
333-
);
325+
SubGroupCollector subGroups = SubGroupCollector.attach(groupByStackTraceId, request.getAggregationFields());
334326
client.prepareSearch(eventsIndex.getName())
335327
.setTrackTotalHits(false)
336328
.setSize(0)

0 commit comments

Comments
 (0)