From 37d6690d9b6556cceef005465d810c1325786945 Mon Sep 17 00:00:00 2001 From: Daniel Mitterdorfer Date: Thu, 7 Dec 2023 10:07:37 +0100 Subject: [PATCH] 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. --- .../xpack/profiling/GetStackTracesRequest.java | 9 +-------- .../profiling/GetStackTracesRequestTests.java | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/x-pack/plugin/profiling/src/main/java/org/elasticsearch/xpack/profiling/GetStackTracesRequest.java b/x-pack/plugin/profiling/src/main/java/org/elasticsearch/xpack/profiling/GetStackTracesRequest.java index 3ab797e4b16ad..f81b5f01caae3 100644 --- a/x-pack/plugin/profiling/src/main/java/org/elasticsearch/xpack/profiling/GetStackTracesRequest.java +++ b/x-pack/plugin/profiling/src/main/java/org/elasticsearch/xpack/profiling/GetStackTracesRequest.java @@ -247,13 +247,6 @@ public ActionRequestValidationException validate() { validationException ); } - // we don't do downsampling when a custom index is provided - if (sampleSize != null) { - validationException = addValidationError( - "[" + SAMPLE_SIZE_FIELD.getPreferredName() + "] must not be set", - validationException - ); - } } else { if (stackTraceIds != null) { validationException = addValidationError( @@ -261,8 +254,8 @@ public ActionRequestValidationException validate() { validationException ); } - validationException = requirePositive(SAMPLE_SIZE_FIELD, sampleSize, validationException); } + validationException = requirePositive(SAMPLE_SIZE_FIELD, sampleSize, validationException); validationException = requirePositive(REQUESTED_DURATION_FIELD, requestedDuration, validationException); validationException = requirePositive(AWS_COST_FACTOR_FIELD, awsCostFactor, validationException); validationException = requirePositive(CUSTOM_CO2_PER_KWH, customCO2PerKWH, validationException); diff --git a/x-pack/plugin/profiling/src/test/java/org/elasticsearch/xpack/profiling/GetStackTracesRequestTests.java b/x-pack/plugin/profiling/src/test/java/org/elasticsearch/xpack/profiling/GetStackTracesRequestTests.java index 5b6befbe5a2c2..8bf4598cf75f7 100644 --- a/x-pack/plugin/profiling/src/test/java/org/elasticsearch/xpack/profiling/GetStackTracesRequestTests.java +++ b/x-pack/plugin/profiling/src/test/java/org/elasticsearch/xpack/profiling/GetStackTracesRequestTests.java @@ -170,6 +170,23 @@ public void testValidateWrongSampleSize() { assertTrue(validationErrors.get(0).contains("[sample_size] must be greater than 0,")); } + public void testValidateSampleSizeIsValidWithCustomIndices() { + GetStackTracesRequest request = new GetStackTracesRequest( + 10, + 1.0d, + 1.0d, + null, + randomAlphaOfLength(7), + randomAlphaOfLength(3), + null, + null, + null, + null, + null + ); + assertNull("Expecting no validation errors", request.validate()); + } + public void testValidateStacktraceWithoutIndices() { GetStackTracesRequest request = new GetStackTracesRequest( 1,