Skip to content

Commit

Permalink
fix: make API queries less restrictive
Browse files Browse the repository at this point in the history
Signed-off-by: SamMayWork <[email protected]>
  • Loading branch information
SamMayWork committed Jan 25, 2024
1 parent 120b559 commit 52c191e
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 1 deletion.
1 change: 1 addition & 0 deletions docs/reference/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -1395,6 +1395,7 @@ nav_order: 2
|Key|Description|Type|Default Value|
|---|-----------|----|-------------|
|maxScanLength|The maximum number of events a search for historical events matching a subscription will index from the database|`int`|`1000`
|skipLimit|The maximum number of events a search for historical events can skip when indexing events|`int`|`0`

## subscription.retry

Expand Down
9 changes: 8 additions & 1 deletion internal/apiserver/server.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright © 2023 Kaleido, Inc.
// Copyright © 2024 Kaleido, Inc.
//
// SPDX-License-Identifier: Apache-2.0
//
Expand Down Expand Up @@ -346,6 +346,13 @@ func (as *apiServer) createMuxRouter(ctx context.Context, mgr namespace.Manager)

for _, route := range routes {
if ce, ok := route.Extensions.(*coreExtensions); ok {
if route.Name == getSubscriptionEventsFiltered.Name {
nhf := as.handlerFactory()
nhf.MaxFilterSkip = uint64(config.GetInt(coreconfig.SubscriptionMaxHistoricalEventSkipLimit))
r.HandleFunc(fmt.Sprintf("/api/v1/%s", route.Path), as.routeHandler(nhf, mgr, "", route)).
Methods(route.Method)
}

if ce.CoreJSONHandler != nil {
r.HandleFunc(fmt.Sprintf("/api/v1/%s", route.Path), as.routeHandler(hf, mgr, "", route)).
Methods(route.Method)
Expand Down
3 changes: 3 additions & 0 deletions internal/coreconfig/coreconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,8 @@ var (
SubscriptionsRetryFactor = ffc("subscription.retry.factor")
// SubscriptionMaxHistoricalEventScanLength the maximum amount of historical events we scan for in the DB when indexing through old events against a subscription
SubscriptionMaxHistoricalEventScanLength = ffc("subscription.events.maxScanLength")
// SubscriptionMaxHistoricalEventSkipLimit is the maximum number of events that can be skipped for historical event queries
SubscriptionMaxHistoricalEventSkipLimit = ffc("subscription.events.skipLimit")
// TransactionWriterCount
TransactionWriterCount = ffc("transaction.writer.count")
// TransactionWriterBatchTimeout
Expand Down Expand Up @@ -462,6 +464,7 @@ func setDefaults() {
viper.SetDefault(string(SubscriptionsRetryMaxDelay), "30s")
viper.SetDefault(string(SubscriptionsRetryFactor), 2.0)
viper.SetDefault(string(SubscriptionMaxHistoricalEventScanLength), 1000)
viper.SetDefault(string(SubscriptionMaxHistoricalEventSkipLimit), 0)
viper.SetDefault(string(TransactionWriterBatchMaxTransactions), 100)
viper.SetDefault(string(TransactionWriterBatchTimeout), "10ms")
viper.SetDefault(string(TransactionWriterCount), 5)
Expand Down
1 change: 1 addition & 0 deletions internal/coremsgs/en_config_descriptions.go
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,7 @@ var (
ConfigSubscriptionDefaultsBatchSize = ffc("config.subscription.defaults.batchSize", "Default read ahead to enable for subscriptions that do not explicitly configure readahead", i18n.IntType)
ConfigSubscriptionDefaultsBatchTimeout = ffc("config.subscription.defaults.batchTimeout", "Default batch timeout", i18n.IntType)
ConfigSubscriptionMaxHistoricalEventScanLength = ffc("config.subscription.events.maxScanLength", "The maximum number of events a search for historical events matching a subscription will index from the database", i18n.IntType)
ConfigSubscriptionMaxHistoricalEventSkipLimit = ffc("config.subscription.events.skipLimit", "The maximum number of events a search for historical events can skip when indexing events", i18n.IntType)

ConfigTokensName = ffc("config.tokens[].name", "A name to identify this token plugin", i18n.StringType)
ConfigTokensPlugin = ffc("config.tokens[].plugin", "The type of the token plugin to use", i18n.StringType)
Expand Down

0 comments on commit 52c191e

Please sign in to comment.