Skip to content

Commit

Permalink
Always allow sample size for stacktraces (elastic#103101)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
danielmitterdorfer authored Dec 7, 2023
1 parent 077b47d commit 37d6690
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -247,22 +247,15 @@ 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(
"[" + STACKTRACE_IDS_FIELD.getPreferredName() + "] must not be set",
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 37d6690

Please sign in to comment.