-
-
Notifications
You must be signed in to change notification settings - Fork 49
feat(auto-scale-up): add fake online, server status cache, and seamless connection during scale-up #406
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
alexfrs69
wants to merge
13
commits into
itzg:main
Choose a base branch
from
alexfrs69:feat/autoscale-status-response
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
feat(auto-scale-up): add fake online, server status cache, and seamless connection during scale-up #406
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
e5ad0f3
feat: add a fake status response when autoscaling is up
alexfrs69 5c0baf8
feat: add client connection hang
alexfrs69 18f8aaa
fix: indentation convertion
alexfrs69 0132bac
refactor: use retry library
alexfrs69 b0a5a2e
refactor: bundle config for connector
alexfrs69 e2e7b91
fix: fmt
alexfrs69 9f3262c
feat: add status cache
alexfrs69 9ef5492
fix: test
alexfrs69 8e71b2a
fix: enable fakeOnline only if autoscale up && kube
alexfrs69 861322b
fix: logs
alexfrs69 9cb38c6
refactor: separate functions
alexfrs69 8b02552
fix: remove ttl from cache
alexfrs69 096cdb6
fix: `StatusPlayerEntry`
alexfrs69 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -34,10 +34,14 @@ type WebhookConfig struct { | |
| } | ||
|
|
||
| type AutoScale struct { | ||
| Up bool `usage:"Increase Kubernetes StatefulSet Replicas (only) from 0 to 1 on respective backend servers when accessed"` | ||
| Down bool `default:"false" usage:"Decrease Kubernetes StatefulSet Replicas (only) from 1 to 0 on respective backend servers after there are no connections"` | ||
| DownAfter string `default:"10m" usage:"Server scale down delay after there are no connections"` | ||
| AllowDeny string `usage:"Path to config for server allowlists and denylists. If a global/server entry is specified, only players allowed to connect to the server will be able to trigger a scale up when -auto-scale-up is enabled or cancel active down scalers when -auto-scale-down is enabled"` | ||
| Up bool `usage:"Increase Kubernetes StatefulSet Replicas (only) from 0 to 1 on respective backend servers when accessed"` | ||
| Down bool `default:"false" usage:"Decrease Kubernetes StatefulSet Replicas (only) from 1 to 0 on respective backend servers after there are no connections"` | ||
| DownAfter string `default:"10m" usage:"Server scale down delay after there are no connections"` | ||
| AllowDeny string `usage:"Path to config for server allowlists and denylists. If a global/server entry is specified, only players allowed to connect to the server will be able to trigger a scale up when -auto-scale-up is enabled or cancel active down scalers when -auto-scale-down is enabled"` | ||
| FakeOnline bool `default:"false" usage:"Enable fake online status when backend is offline and auto-scale-up is enabled"` | ||
| FakeOnlineMOTD string `default:"Server is sleeping\nJoin to wake it up" usage:"Custom MOTD to show when backend is offline, status has been cached and auto-scale-up is enabled"` | ||
| CacheStatus bool `default:"false" usage:"Cache status response for backends"` | ||
| CacheStatusInterval string `default:"30s" usage:"Interval to update the status cache"` | ||
| } | ||
|
|
||
| type Config struct { | ||
|
|
@@ -138,7 +142,6 @@ func main() { | |
| // Only one instance should be created | ||
| server.DownScaler = server.NewDownScaler(ctx, downScalerEnabled, downScalerDelay) | ||
|
|
||
|
|
||
| c := make(chan os.Signal, 1) | ||
| signal.Notify(c, syscall.SIGINT, syscall.SIGTERM) | ||
|
|
||
|
|
@@ -167,7 +170,21 @@ func main() { | |
| trustedIpNets = append(trustedIpNets, ipNet) | ||
| } | ||
|
|
||
| connector := server.NewConnector(metricsBuilder.BuildConnectorMetrics(), config.UseProxyProtocol, config.ReceiveProxyProtocol, trustedIpNets, config.RecordLogins, autoScaleAllowDenyConfig) | ||
| fakeOnlineEnabled := config.AutoScale.FakeOnline && config.AutoScale.Up && (config.InKubeCluster || config.KubeConfig != "") | ||
|
|
||
| connectorConfig := server.ConnectorConfig{ | ||
| SendProxyProto: config.UseProxyProtocol, | ||
| ReceiveProxyProto: config.ReceiveProxyProtocol, | ||
| TrustedProxyNets: trustedIpNets, | ||
| RecordLogins: config.RecordLogins, | ||
| AutoScaleUpAllowDenyConfig: autoScaleAllowDenyConfig, | ||
| AutoScaleUp: config.AutoScale.Up, | ||
| FakeOnline: fakeOnlineEnabled, | ||
| FakeOnlineMOTD: config.AutoScale.FakeOnlineMOTD, | ||
| CacheStatus: config.AutoScale.CacheStatus, | ||
| } | ||
|
|
||
| connector := server.NewConnector(metricsBuilder.BuildConnectorMetrics(), connectorConfig) | ||
|
|
||
| clientFilter, err := server.NewClientFilter(config.ClientsToAllow, config.ClientsToDeny) | ||
| if err != nil { | ||
|
|
@@ -184,6 +201,15 @@ func main() { | |
| server.NewWebhookNotifier(config.Webhook.Url, config.Webhook.RequireUser)) | ||
| } | ||
|
|
||
| var cacheInterval time.Duration | ||
| if config.AutoScale.CacheStatus { | ||
| cacheInterval, err = time.ParseDuration(config.AutoScale.CacheStatusInterval) | ||
| if err != nil { | ||
| logrus.WithError(err).Fatal("Unable to parse cache status interval") | ||
| } | ||
| logrus.WithField("interval", config.AutoScale.CacheStatusInterval).Debug("Using cache status interval") | ||
| } | ||
|
|
||
| if config.NgrokToken != "" { | ||
| connector.UseNgrok(config.NgrokToken) | ||
| } | ||
|
|
@@ -240,6 +266,15 @@ func main() { | |
| logrus.WithError(err).Fatal("Unable to start metrics reporter") | ||
| } | ||
|
|
||
| if config.AutoScale.CacheStatus { | ||
| logrus.Info("Starting status cache updater") | ||
| connector.StatusCache.StartUpdater(connector, cacheInterval, func() map[string]string { | ||
| mappings := server.Routes.GetMappings() | ||
| logrus.WithField("mappings", mappings).Debug("Updating status cache with mappings") | ||
| return mappings | ||
| }) | ||
|
Comment on lines
+271
to
+275
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ...and that starting of the cache updater should be encapsulated inside of the As it is, it's leaking a bit too much of runtime behavior into the main method. |
||
| } | ||
|
|
||
| // wait for process-stop signal | ||
| <-c | ||
| logrus.Info("Stopping. Waiting for connections to complete...") | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems like this config processing and then ultimately
cacheIntervalshould be fed into server.ConnectorConfig