Skip to content

Commit

Permalink
Merge pull request #32 from castaneai/fix-overlapping-checker
Browse files Browse the repository at this point in the history
Fix overlapping checker
  • Loading branch information
castaneai authored Nov 5, 2024
2 parents 420aad7 + 3613939 commit c4b6628
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 10 deletions.
14 changes: 14 additions & 0 deletions loadtest/cmd/backend/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,13 @@ import (

const (
minimatchComponentKey = attribute.Key("component")
roleKey = attribute.Key("role")
)

type config struct {
RedisAddr string `envconfig:"REDIS_ADDR" default:"127.0.0.1:6379"`
AssignmentRedisAddr string `envconfig:"REDIS_ADDR_ASSIGNMENT"`
RedisAddrReadReplica string `envconfig:"REDIS_ADDR_READ_REPLICA"`
TickRate time.Duration `envconfig:"TICK_RATE" default:"1s"`
TicketCacheTTL time.Duration `envconfig:"TICKET_CACHE_TTL" default:"10s"`
OverlappingCheckRedisAddr string `envconfig:"OVERLAPPING_CHECK_REDIS_ADDR"`
Expand Down Expand Up @@ -119,6 +121,16 @@ func newRedisStateStore(conf *config) (statestore.BackendStore, error) {
}
opts = append(opts, statestore.WithSeparatedAssignmentRedis(asRedis))
}
if conf.RedisAddrReadReplica != "" {
replica, err := rueidisotel.NewClient(rueidis.ClientOption{
InitAddress: []string{conf.RedisAddrReadReplica},
DisableCache: true,
}, rueidisotel.MetricAttrs(minimatchComponentKey.String("backend"), roleKey.String("replica")))
if err != nil {
return nil, fmt.Errorf("failed to new read-replica redis client: %w", err)
}
opts = append(opts, statestore.WithRedisReadReplicaClient(replica))
}
locker, err := rueidislock.NewLocker(rueidislock.LockerOption{
ClientOption: copt,
ExtendInterval: 200 * time.Millisecond,
Expand Down Expand Up @@ -218,6 +230,8 @@ func (a *assignerWithOverlappingChecker) Assign(ctx context.Context, matches []*
for _, ticket := range match.Tickets {
if _, ok := ticketIDMap[ticket.Id]; ok {
a.overlappingWithin.Add(ctx, 1)
} else {
ticketIDMap[ticket.Id] = struct{}{}
}
}
}
Expand Down
20 changes: 16 additions & 4 deletions loadtest/cmd/frontend/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,15 @@ import (

const (
minimatchComponentKey = attribute.Key("component")
roleKey = attribute.Key("role")
)

type config struct {
RedisAddr string `envconfig:"REDIS_ADDR" default:"127.0.0.1:6379"`
AssignmentRedisAddr string `envconfig:"REDIS_ADDR_ASSIGNMENT"`
Port string `envconfig:"PORT" default:"50504"`
TicketCacheTTL time.Duration `envconfig:"TICKET_CACHE_TTL" default:"10s"`
RedisAddr string `envconfig:"REDIS_ADDR" default:"127.0.0.1:6379"`
AssignmentRedisAddr string `envconfig:"REDIS_ADDR_ASSIGNMENT"`
RedisAddrReadReplica string `envconfig:"REDIS_ADDR_READ_REPLICA"`
Port string `envconfig:"PORT" default:"50504"`
TicketCacheTTL time.Duration `envconfig:"TICKET_CACHE_TTL" default:"10s"`
}

func main() {
Expand Down Expand Up @@ -102,6 +104,16 @@ func newRedisStateStore(conf *config) (statestore.FrontendStore, error) {
}
opts = append(opts, statestore.WithSeparatedAssignmentRedis(asRedis))
}
if conf.RedisAddrReadReplica != "" {
replica, err := rueidisotel.NewClient(rueidis.ClientOption{
InitAddress: []string{conf.RedisAddrReadReplica},
DisableCache: true,
}, rueidisotel.MetricAttrs(minimatchComponentKey.String("backend"), roleKey.String("replica")))
if err != nil {
return nil, fmt.Errorf("failed to new read-replica redis client: %w", err)
}
opts = append(opts, statestore.WithRedisReadReplicaClient(replica))
}
locker, err := rueidislock.NewLocker(rueidislock.LockerOption{
ClientOption: copt,
})
Expand Down
16 changes: 10 additions & 6 deletions loadtest/skaffold.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,21 @@ deploy:
frontend.deployment.replicas: 1
frontend.deployment.env:
- name: REDIS_ADDR
value: "10.23.1.3:6379"
# - name: REDIS_ADDR_ASSIGNMENT
# value: "10.23.1.11:6379"
value: "10.23.1.21:6379"
- name: REDIS_ADDR_ASSIGNMENT
value: "10.23.1.11:6379"
- name: REDIS_ADDR_READ_REPLICA
value: "10.23.1.20:6379"
backend.deployment.replicas: 1
backend.deployment.env:
- name: REDIS_ADDR
value: "10.23.1.3:6379"
value: "10.23.1.21:6379"
- name: OVERLAPPING_CHECK_REDIS_ADDR
value: "10.23.1.11:6379"
# - name: REDIS_ADDR_ASSIGNMENT
# value: "10.23.1.11:6379"
- name: REDIS_ADDR_ASSIGNMENT
value: "10.23.1.11:6379"
- name: REDIS_ADDR_READ_REPLICA
value: "10.23.1.20:6379"
- name: TICK_RATE
value: "100ms"
podMonitor.enabled: true
Expand Down

0 comments on commit c4b6628

Please sign in to comment.