Skip to content

Commit 1e43a15

Browse files
authored
[processor/ratelimit] Fix gubernator peer info address in testing (#894)
* Fix gubernator peer info address * Use same address as gubernator functional test * Fix gubernatorRateLimiter.Start respawning existing daemon
1 parent e9b71e1 commit 1e43a15

File tree

2 files changed

+19
-12
lines changed

2 files changed

+19
-12
lines changed

processor/ratelimitprocessor/gubernator.go

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -159,19 +159,27 @@ func (r *gubernatorRateLimiter) Start(ctx context.Context, host component.Host)
159159
r.windowConfigurator = wc.(WindowConfigurator)
160160
}
161161

162-
r.daemon, err = gubernator.SpawnDaemon(ctx, r.daemonCfg)
163-
if err != nil {
164-
return fmt.Errorf("failed to spawn gubernator daemon: %w", err)
162+
if r.daemon == nil {
163+
r.daemon, err = gubernator.SpawnDaemon(ctx, r.daemonCfg)
164+
if err != nil {
165+
return fmt.Errorf("failed to spawn gubernator daemon: %w", err)
166+
}
165167
}
166168

167-
r.clientConn, err = grpc.NewClient(r.daemonCfg.GRPCListenAddress,
168-
grpc.WithTransportCredentials(insecure.NewCredentials()),
169-
grpc.WithStatsHandler(otelgrpc.NewClientHandler(otelgrpc.WithTracerProvider(r.tracerProvider))),
170-
)
171-
if err != nil {
172-
return fmt.Errorf("failed to create gRPC client connection: %w", err)
169+
if r.clientConn == nil {
170+
r.clientConn, err = grpc.NewClient(r.daemonCfg.GRPCListenAddress,
171+
grpc.WithTransportCredentials(insecure.NewCredentials()),
172+
grpc.WithStatsHandler(otelgrpc.NewClientHandler(otelgrpc.WithTracerProvider(r.tracerProvider))),
173+
)
174+
if err != nil {
175+
return fmt.Errorf("failed to create gRPC client connection: %w", err)
176+
}
173177
}
174-
r.client = gubernator.NewV1Client(r.clientConn)
178+
179+
if r.client == nil {
180+
r.client = gubernator.NewV1Client(r.clientConn)
181+
}
182+
175183
return nil
176184
}
177185

processor/ratelimitprocessor/gubernator_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,7 @@ func newGubernatorRateLimiterFrom(t *testing.T, cfg *Config, daemon *gubernator.
131131

132132
func startGubernatorCluster(t *testing.T, c chan<- gubernator.HitEvent) *gubernator.Daemon {
133133
var err error
134-
const local = "127.0.0.1:0"
135-
peers := []gubernator.PeerInfo{{GRPCAddress: local, HTTPAddress: local}}
134+
peers := []gubernator.PeerInfo{{GRPCAddress: "127.0.0.1:9990", HTTPAddress: "127.0.0.1:9980"}}
136135
if c != nil {
137136
err = cluster.StartWith(peers, cluster.WithEventChannel(c))
138137
} else {

0 commit comments

Comments
 (0)