Skip to content

Commit 37d6690

Browse files
Always allow sample size for stacktraces (#103101)
The profiling get stacktraces API can be used in two different places: 1. In the native profiling UI 2. From within an APM context In the latter case we disallowed the `sample_size` request body parameter because the implementation always considers all samples. However, as this will change in the future and we need to accept the `sample_size` parameter this will lead to rejected requests during upgrades. With this commit we always accept the `sample_size` request body parameter to avoid such cases.
1 parent 077b47d commit 37d6690

File tree

2 files changed

+18
-8
lines changed

2 files changed

+18
-8
lines changed

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

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -247,22 +247,15 @@ public ActionRequestValidationException validate() {
247247
validationException
248248
);
249249
}
250-
// we don't do downsampling when a custom index is provided
251-
if (sampleSize != null) {
252-
validationException = addValidationError(
253-
"[" + SAMPLE_SIZE_FIELD.getPreferredName() + "] must not be set",
254-
validationException
255-
);
256-
}
257250
} else {
258251
if (stackTraceIds != null) {
259252
validationException = addValidationError(
260253
"[" + STACKTRACE_IDS_FIELD.getPreferredName() + "] must not be set",
261254
validationException
262255
);
263256
}
264-
validationException = requirePositive(SAMPLE_SIZE_FIELD, sampleSize, validationException);
265257
}
258+
validationException = requirePositive(SAMPLE_SIZE_FIELD, sampleSize, validationException);
266259
validationException = requirePositive(REQUESTED_DURATION_FIELD, requestedDuration, validationException);
267260
validationException = requirePositive(AWS_COST_FACTOR_FIELD, awsCostFactor, validationException);
268261
validationException = requirePositive(CUSTOM_CO2_PER_KWH, customCO2PerKWH, validationException);

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,23 @@ public void testValidateWrongSampleSize() {
170170
assertTrue(validationErrors.get(0).contains("[sample_size] must be greater than 0,"));
171171
}
172172

173+
public void testValidateSampleSizeIsValidWithCustomIndices() {
174+
GetStackTracesRequest request = new GetStackTracesRequest(
175+
10,
176+
1.0d,
177+
1.0d,
178+
null,
179+
randomAlphaOfLength(7),
180+
randomAlphaOfLength(3),
181+
null,
182+
null,
183+
null,
184+
null,
185+
null
186+
);
187+
assertNull("Expecting no validation errors", request.validate());
188+
}
189+
173190
public void testValidateStacktraceWithoutIndices() {
174191
GetStackTracesRequest request = new GetStackTracesRequest(
175192
1,

0 commit comments

Comments
 (0)