Skip to content

Commit

Permalink
all: Set default pagination limit at Redis init
Browse files Browse the repository at this point in the history
  • Loading branch information
halimi committed Dec 5, 2024
1 parent e633570 commit b92700e
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 15 deletions.
48 changes: 44 additions & 4 deletions cmd/ttn-lw-stack/commands/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,16 @@ func NewNetworkServerDownlinkTaskRedis(conf *Config) *redis.Client {
return redis.New(conf.Redis.WithNamespace("ns", "tasks"))
}

// NewNetworkServerMACSettingsProfileRegistryRedis instantiates a new redis client
// with the Network Server MAC Settings Profile Registry namespace.
func NewNetworkServerMACSettingsProfileRegistryRedis(conf *Config) *redis.Client {
redis.SetPaginationDefaults(redis.PaginationDefaults{
DefaultLimit: conf.NS.Pagination.DefaultLimit,
})

return redis.New(conf.Redis.WithNamespace("ns", "mac-settings-profiles"))
}

// NewIdentityServerTelemetryTaskRedis instantiates a new redis client
// with the Identity Server Telemetry Task namespace.
func NewIdentityServerTelemetryTaskRedis(conf *Config) *redis.Client {
Expand All @@ -91,6 +101,36 @@ func NewApplicationServerDeviceRegistryRedis(conf *Config) *redis.Client {
return NewComponentDeviceRegistryRedis(conf, "as")
}

// NewApplicationServerPubSubRegistryRedis instantiates a new redis client
// with the Application Server PubSub Registry namespace.
func NewApplicationServerPubSubRegistryRedis(conf *Config) *redis.Client {
redis.SetPaginationDefaults(redis.PaginationDefaults{
DefaultLimit: conf.AS.Pagination.DefaultLimit,
})

return redis.New(config.Redis.WithNamespace("as", "io", "pubsub"))
}

// NewApplicationServerPackagesRegistryRedis instantiates a new redis client
// with the Application Server Packages Registry namespace.
func NewApplicationServerPackagesRegistryRedis(conf *Config) *redis.Client {
redis.SetPaginationDefaults(redis.PaginationDefaults{
DefaultLimit: conf.AS.Pagination.DefaultLimit,
})

return redis.New(config.Redis.WithNamespace("as", "io", "applicationpackages"))
}

// NewApplicationServerWebhookRegistryRedis instantiates a new redis client
// with the Application Server Webhook Registry namespace.
func NewApplicationServerWebhookRegistryRedis(conf *Config) *redis.Client {
redis.SetPaginationDefaults(redis.PaginationDefaults{
DefaultLimit: conf.AS.Pagination.DefaultLimit,
})

return redis.New(config.Redis.WithNamespace("as", "io", "webhooks"))
}

// NewJoinServerDeviceRegistryRedis instantiates a new redis client
// with the Join Server Device Registry namespace.
func NewJoinServerDeviceRegistryRedis(conf *Config) *redis.Client {
Expand Down Expand Up @@ -343,7 +383,7 @@ var startCommand = &cobra.Command{
Redis: redis.New(config.Cache.Redis.WithNamespace("ns", "scheduled-downlinks")),
}
macSettingsProfiles := &nsredis.MACSettingsProfileRegistry{
Redis: redis.New(config.Redis.WithNamespace("ns", "mac-settings-profiles")),
Redis: NewNetworkServerMACSettingsProfileRegistryRedis(config),
LockTTL: defaultLockTTL,
}
if err := macSettingsProfiles.Init(ctx); err != nil {
Expand Down Expand Up @@ -379,7 +419,7 @@ var startCommand = &cobra.Command{
Redis: redis.New(config.Cache.Redis.WithNamespace("as", "traffic")),
}
pubsubRegistry := &asiopsredis.PubSubRegistry{
Redis: redis.New(config.Redis.WithNamespace("as", "io", "pubsub")),
Redis: NewApplicationServerPubSubRegistryRedis(config),
LockTTL: defaultLockTTL,
}
if err := pubsubRegistry.Init(ctx); err != nil {
Expand All @@ -388,7 +428,7 @@ var startCommand = &cobra.Command{
config.AS.PubSub.Registry = pubsubRegistry
applicationPackagesRegistry, err := asioapredis.NewApplicationPackagesRegistry(
ctx,
redis.New(config.Redis.WithNamespace("as", "io", "applicationpackages")),
NewApplicationServerPackagesRegistryRedis(config),
defaultLockTTL,
)
if err != nil {
Expand All @@ -397,7 +437,7 @@ var startCommand = &cobra.Command{
config.AS.Packages.Registry = applicationPackagesRegistry
if config.AS.Webhooks.Target != "" {
webhookRegistry := &asiowebredis.WebhookRegistry{
Redis: redis.New(config.Redis.WithNamespace("as", "io", "webhooks")),
Redis: NewApplicationServerWebhookRegistryRedis(config),
LockTTL: defaultLockTTL,
}
if err := webhookRegistry.Init(ctx); err != nil {
Expand Down
5 changes: 0 additions & 5 deletions pkg/applicationserver/applicationserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ import (
"go.thethings.network/lorawan-stack/v3/pkg/messageprocessors/cayennelpp"
"go.thethings.network/lorawan-stack/v3/pkg/messageprocessors/devicerepository"
"go.thethings.network/lorawan-stack/v3/pkg/messageprocessors/javascript"
"go.thethings.network/lorawan-stack/v3/pkg/redis"
"go.thethings.network/lorawan-stack/v3/pkg/rpcmiddleware/hooks"
"go.thethings.network/lorawan-stack/v3/pkg/rpcmiddleware/rpclog"
"go.thethings.network/lorawan-stack/v3/pkg/rpcmiddleware/rpctracer"
Expand Down Expand Up @@ -156,10 +155,6 @@ func New(c *component.Component, conf *Config) (as *ApplicationServer, err error
return nil, err
}

redis.SetPaginationDefaults(redis.PaginationDefaults{
DefaultLimit: conf.Pagination.DefaultLimit,
})

as = &ApplicationServer{
Component: c,
ctx: ctx,
Expand Down
5 changes: 0 additions & 5 deletions pkg/networkserver/networkserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import (
"go.thethings.network/lorawan-stack/v3/pkg/log"
"go.thethings.network/lorawan-stack/v3/pkg/networkserver/internal/time"
"go.thethings.network/lorawan-stack/v3/pkg/random"
"go.thethings.network/lorawan-stack/v3/pkg/redis"
"go.thethings.network/lorawan-stack/v3/pkg/rpcmiddleware/hooks"
"go.thethings.network/lorawan-stack/v3/pkg/rpcmiddleware/rpclog"
"go.thethings.network/lorawan-stack/v3/pkg/rpcmiddleware/rpctracer"
Expand Down Expand Up @@ -319,10 +318,6 @@ func New(c *component.Component, conf *Config, opts ...Option) (*NetworkServer,
opt(ns)
}

redis.SetPaginationDefaults(redis.PaginationDefaults{
DefaultLimit: conf.Pagination.DefaultLimit,
})

for _, hook := range []struct {
name string
middleware hooks.UnaryHandlerMiddleware
Expand Down
4 changes: 3 additions & 1 deletion pkg/redis/pagination.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ type PaginationDefaults struct {
var paginationDefaults = PaginationDefaults{}

// SetPaginationDefaults should only be called at the initialization of the server.
func SetPaginationDefaults(d PaginationDefaults) { paginationDefaults = d }
func SetPaginationDefaults(d PaginationDefaults) {
paginationDefaults = d
}

type paginationOptionsKeyType struct{}

Expand Down

0 comments on commit b92700e

Please sign in to comment.