Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #815: move "max filter properties" to OperationsConfig where it belongs #816

Merged
merged 3 commits into from
Jan 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CONFIGURATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ Here are some Stargate-relevant property groups that are necessary for correct s
| `stargate.jsonapi.document.limits.max-property-path-length` | `int` | `250` | The maximum length of property paths in a document (segments and separating periods) |
| `stargate.jsonapi.document.limits.max-object-properties` | `int` | `1000` | The maximum number of properties any single object in a document can contain. |
| `stargate.jsonapi.document.limits.max-document-properties` | `int` | `2000` | The maximum total number of properties all objects in a document can contain. |
| `stargate.jsonapi.document.limits.max-filter-object-properties` | `int` | `64` | The maximum number of properties a single filter clause can contain. |
| `stargate.jsonapi.document.limits.max-number-length` | `int` | `50` | The maximum length (in characters) of a single number value in a document. |
| `stargate.jsonapi.document.limits.max-string-length-in-bytes` | `int` | `8000` | The maximum length (in bytes) of a single string value in a document. |
| `stargate.jsonapi.document.limits.max-array-length` | `int` | `1000` | The maximum length (in elements) of a single array in a document. |
Expand All @@ -48,6 +47,7 @@ Here are some Stargate-relevant property groups that are necessary for correct s
| `stargate.jsonapi.operations.max-document-insert-count` | `int` | `20` | The maximum amount of documents that can be inserted in a single operation. The request will fail fast without inserts if the limit is broken. |
| `stargate.jsonapi.operations.max-document-update-count` | `int` | `20` | The maximum amount of documents that can be updated in a single operation. In case there are more documents that could be updated, the operation will set the `moreData` response status to `true`. |
| `stargate.jsonapi.operations.max-document-delete-count` | `int` | `20` | The maximum amount of documents that can be deleted in a single operation. In case there are more documents that could be deleted, the operation will set the `moreData` response status to `true`. |
| `stargate.jsonapi.operations.max-filter-object-properties` | `int` | `64` | The maximum number of properties a single filter clause can contain. |
| `stargate.jsonapi.operations.max-in-operator-value-size` | `int` | `100` | The maximum number of _id values that can be passed for `$in` operator. |
| `stargate.jsonapi.operations.lwt.retries` | `int` | `3` | The amount of client side retries in case of a LWT failure. |
| `stargate.jsonapi.operations.database-config.session-cache-ttl-seconds` | `int` | `300` | The amount of seconds that the cql session will be kept in memory after last access. |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,6 @@
@StaticInitSafe
@ConfigMapping(prefix = "stargate.jsonapi.document.limits")
public interface DocumentLimitsConfig {

/** Defines the default max size of filter fields. */
int DEFAULT_MAX_FILTER_SIZE = 64;

/** Defines the default maximum document size. */
int DEFAULT_MAX_DOCUMENT_SIZE = 1_000_000;

Expand Down Expand Up @@ -105,14 +101,6 @@ public interface DocumentLimitsConfig {
@WithDefault("" + DEFAULT_MAX_DOC_PROPERTIES)
int maxDocumentProperties();

/**
* @return Defines the max size of filter fields, defaults to {@code 64}. (note: this does not
* count the fields in '$operation' such as $in, $all)
*/
@Positive
@WithDefault("" + DEFAULT_MAX_FILTER_SIZE)
int maxFilterObjectProperties();

/** @return Defines the maximum length of a single Number value (in characters). */
@Positive
@WithDefault("" + DEFAULT_MAX_NUMBER_LENGTH)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
/** Configuration for the operation execution. */
@ConfigMapping(prefix = "stargate.jsonapi.operations")
public interface OperationsConfig {
/** Defines the default max size of filter fields. */
int DEFAULT_MAX_FILTER_SIZE = 64;

/** @return Defines the default document page size, defaults to <code>20</code>. */
@Max(500)
Expand Down Expand Up @@ -85,6 +87,14 @@ public interface OperationsConfig {
@WithDefault("20")
int maxDocumentInsertCount();

/**
* @return Defines the max size of filter fields, defaults to {@code 64}. (note: this does not
* count the fields in '$operation' such as $in, $all)
*/
@Positive
@WithDefault("" + DEFAULT_MAX_FILTER_SIZE)
int maxFilterObjectProperties();

/** @return Maximum size of values array that can be sent in $in/$nin operator */
@Max(100)
@Positive
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import io.stargate.sgv2.jsonapi.api.model.command.CommandContext;
import io.stargate.sgv2.jsonapi.api.model.command.Filterable;
import io.stargate.sgv2.jsonapi.api.model.command.clause.filter.*;
import io.stargate.sgv2.jsonapi.config.DocumentLimitsConfig;
import io.stargate.sgv2.jsonapi.config.OperationsConfig;
import io.stargate.sgv2.jsonapi.config.constants.DocumentConstants;
import io.stargate.sgv2.jsonapi.exception.ErrorCode;
import io.stargate.sgv2.jsonapi.exception.JsonApiException;
Expand Down Expand Up @@ -44,7 +44,7 @@ public abstract class FilterableResolver<T extends Command & Filterable> {
private static final Object ARRAY_EQUALS = new Object();
private static final Object SUB_DOC_EQUALS = new Object();

@Inject DocumentLimitsConfig docLimits;
@Inject OperationsConfig operationsConfig;

@Inject
public FilterableResolver() {
Expand Down Expand Up @@ -147,14 +147,14 @@ protected LogicalExpression resolve(CommandContext commandContext, T command) {
command.filterClause().validate(commandContext);
}
LogicalExpression filter = matchRules.apply(commandContext, command);
if (filter.getTotalComparisonExpressionCount() > docLimits.maxFilterObjectProperties()) {
if (filter.getTotalComparisonExpressionCount() > operationsConfig.maxFilterObjectProperties()) {
throw new JsonApiException(
ErrorCode.FILTER_FIELDS_LIMIT_VIOLATION,
String.format(
"%s: filter has %d fields, exceeds maximum allowed %s",
ErrorCode.FILTER_FIELDS_LIMIT_VIOLATION.getMessage(),
filter.getTotalComparisonExpressionCount(),
docLimits.maxFilterObjectProperties()));
operationsConfig.maxFilterObjectProperties()));
}
return filter;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import io.quarkus.test.common.QuarkusTestResource;
import io.quarkus.test.junit.QuarkusIntegrationTest;
import io.restassured.http.ContentType;
import io.stargate.sgv2.jsonapi.config.DocumentLimitsConfig;
import io.stargate.sgv2.jsonapi.config.OperationsConfig;
import io.stargate.sgv2.jsonapi.config.constants.HttpConstants;
import io.stargate.sgv2.jsonapi.testresource.DseTestResource;
import org.junit.jupiter.api.*;
Expand Down Expand Up @@ -1335,7 +1335,7 @@ public void exceedMaxFieldInFilter() {
"errors[0].message",
endsWith(
" filter has 65 fields, exceeds maximum allowed "
+ DocumentLimitsConfig.DEFAULT_MAX_FILTER_SIZE))
+ OperationsConfig.DEFAULT_MAX_FILTER_SIZE))
.body("errors[0].errorCode", is("FILTER_FIELDS_LIMIT_VIOLATION"))
.body("errors[0].exceptionClass", is("JsonApiException"));
}
Expand Down