Skip to content

Commit 9f3262c

Browse files
committed
feat: add status cache
1 parent e2e7b91 commit 9f3262c

File tree

6 files changed

+256
-31
lines changed

6 files changed

+256
-31
lines changed

cmd/mc-router/main.go

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,9 @@ type Config struct {
7474
FakeOnline bool `default:"false" usage:"Enable fake online MOTD when backend is offline and auto-scale-up is enabled"`
7575
FakeOnlineMOTD string `default:"Server is sleeping\nJoin to wake it up" usage:"Custom MOTD to show when backend is offline and auto-scale-up is enabled"`
7676

77+
CacheStatus bool `default:"false" usage:"Cache status response for backends"`
78+
CacheStatusInterval string `default:"30s" usage:"Interval to update the status cache"`
79+
7780
Webhook WebhookConfig `usage:"Webhook configuration"`
7881
}
7982

@@ -141,7 +144,6 @@ func main() {
141144
// Only one instance should be created
142145
server.DownScaler = server.NewDownScaler(ctx, downScalerEnabled, downScalerDelay)
143146

144-
145147
c := make(chan os.Signal, 1)
146148
signal.Notify(c, syscall.SIGINT, syscall.SIGTERM)
147149

@@ -175,10 +177,11 @@ func main() {
175177
ReceiveProxyProto: config.ReceiveProxyProtocol,
176178
TrustedProxyNets: trustedIpNets,
177179
RecordLogins: config.RecordLogins,
178-
AutoScaleUpAllowDenyConfig: autoScaleUpAllowDenyConfig,
179-
AutoScaleUp: config.AutoScaleUp,
180+
AutoScaleUpAllowDenyConfig: autoScaleAllowDenyConfig,
181+
AutoScaleUp: config.AutoScale.Up,
180182
FakeOnline: config.FakeOnline,
181183
FakeOnlineMOTD: config.FakeOnlineMOTD,
184+
CacheStatus: config.CacheStatus,
182185
}
183186

184187
connector := server.NewConnector(metricsBuilder.BuildConnectorMetrics(), connectorConfig)
@@ -198,6 +201,15 @@ func main() {
198201
server.NewWebhookNotifier(config.Webhook.Url, config.Webhook.RequireUser))
199202
}
200203

204+
var cacheInterval time.Duration
205+
if config.CacheStatus {
206+
cacheInterval, err = time.ParseDuration(config.CacheStatusInterval)
207+
if err != nil {
208+
logrus.WithError(err).Fatal("Unable to parse cache status interval")
209+
}
210+
logrus.WithField("interval", config.CacheStatusInterval).Info("Using cache status interval")
211+
}
212+
201213
if config.NgrokToken != "" {
202214
connector.UseNgrok(config.NgrokToken)
203215
}
@@ -254,6 +266,15 @@ func main() {
254266
logrus.WithError(err).Fatal("Unable to start metrics reporter")
255267
}
256268

269+
if config.CacheStatus {
270+
logrus.Info("Starting status cache updater")
271+
connector.StatusCache.StartUpdater(connector, cacheInterval, func() map[string]string {
272+
mappings := server.Routes.GetMappings()
273+
logrus.WithField("mappings", mappings).Debug("Status cache updater")
274+
return mappings
275+
})
276+
}
277+
257278
// wait for process-stop signal
258279
<-c
259280
logrus.Info("Stopping. Waiting for connections to complete...")

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ require (
2323
)
2424

2525
require (
26+
github.com/Raqbit/mc-pinger v0.2.4 // indirect
2627
github.com/beorn7/perks v1.0.1 // indirect
2728
github.com/cespare/xxhash/v2 v2.3.0 // indirect
2829
github.com/containerd/log v0.1.0 // indirect

0 commit comments

Comments
 (0)