Skip to content
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

Add QPS settings to Allocation endpoints #1863

Merged
merged 3 commits into from
Oct 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions cmd/allocator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func main() {
// http.DefaultServerMux is used for http connection, not for https
http.Handle("/", health)

kubeClient, agonesClient, err := getClients()
kubeClient, agonesClient, err := getClients(conf)
if err != nil {
logger.WithError(err).Fatal("could not create clients")
}
Expand Down Expand Up @@ -312,13 +312,16 @@ func (h *serviceHandler) verifyClientCertificate(rawCerts [][]byte, verifiedChai
}

// Set up our client which we will use to call the API
func getClients() (*kubernetes.Clientset, *versioned.Clientset, error) {
func getClients(ctlConfig config) (*kubernetes.Clientset, *versioned.Clientset, error) {
// Create the in-cluster config
config, err := rest.InClusterConfig()
if err != nil {
return nil, nil, errors.New("Could not create in cluster config")
}

config.QPS = float32(ctlConfig.APIServerSustainedQPS)
config.Burst = ctlConfig.APIServerBurstQPS

// Access to the Agones resources through the Agones Clientset
kubeClient, err := kubernetes.NewForConfig(config)
if err != nil {
Expand Down
12 changes: 12 additions & 0 deletions cmd/allocator/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,17 @@ const (
tlsDisabledFlag = "disable-tls"
remoteAllocationTimeoutFlag = "remote-allocation-timeout"
totalRemoteAllocationTimeoutFlag = "total-remote-allocation-timeout"
apiServerSustainedQPSFlag = "api-server-qps"
apiServerBurstQPSFlag = "api-server-qps-burst"
)

func init() {
registerMetricViews()
}

type config struct {
APIServerSustainedQPS int
APIServerBurstQPS int
TLSDisabled bool
MTLSDisabled bool
PrometheusMetrics bool
Expand All @@ -56,6 +60,8 @@ type config struct {

func parseEnvFlags() config {

viper.SetDefault(apiServerSustainedQPSFlag, 400)
viper.SetDefault(apiServerBurstQPSFlag, 500)
viper.SetDefault(enablePrometheusMetricsFlag, true)
viper.SetDefault(enableStackdriverMetricsFlag, false)
viper.SetDefault(projectIDFlag, "")
Expand All @@ -65,6 +71,8 @@ func parseEnvFlags() config {
viper.SetDefault(remoteAllocationTimeoutFlag, 10*time.Second)
viper.SetDefault(totalRemoteAllocationTimeoutFlag, 30*time.Second)

pflag.Int32(apiServerSustainedQPSFlag, viper.GetInt32(apiServerSustainedQPSFlag), "Maximum sustained queries per second to send to the API server")
pflag.Int32(apiServerBurstQPSFlag, viper.GetInt32(apiServerBurstQPSFlag), "Maximum burst queries per second to send to the API server")
pflag.Bool(enablePrometheusMetricsFlag, viper.GetBool(enablePrometheusMetricsFlag), "Flag to activate metrics of Agones. Can also use PROMETHEUS_EXPORTER env variable.")
pflag.Bool(enableStackdriverMetricsFlag, viper.GetBool(enableStackdriverMetricsFlag), "Flag to activate stackdriver monitoring metrics for Agones. Can also use STACKDRIVER_EXPORTER env variable.")
pflag.String(projectIDFlag, viper.GetString(projectIDFlag), "GCP ProjectID used for Stackdriver, if not specified ProjectID from Application Default Credentials would be used. Can also use GCP_PROJECT_ID env variable.")
Expand All @@ -77,6 +85,8 @@ func parseEnvFlags() config {
pflag.Parse()

viper.SetEnvKeyReplacer(strings.NewReplacer("-", "_"))
runtime.Must(viper.BindEnv(apiServerSustainedQPSFlag))
runtime.Must(viper.BindEnv(apiServerBurstQPSFlag))
runtime.Must(viper.BindEnv(enablePrometheusMetricsFlag))
runtime.Must(viper.BindEnv(enableStackdriverMetricsFlag))
runtime.Must(viper.BindEnv(projectIDFlag))
Expand All @@ -89,6 +99,8 @@ func parseEnvFlags() config {
runtime.Must(runtime.ParseFeaturesFromEnv())

return config{
APIServerSustainedQPS: int(viper.GetInt32(apiServerSustainedQPSFlag)),
APIServerBurstQPS: int(viper.GetInt32(apiServerBurstQPSFlag)),
PrometheusMetrics: viper.GetBool(enablePrometheusMetricsFlag),
Stackdriver: viper.GetBool(enableStackdriverMetricsFlag),
GCPProjectID: viper.GetString(projectIDFlag),
Expand Down
4 changes: 4 additions & 0 deletions install/helm/agones/templates/service/allocation.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,10 @@ spec:
path: /ready
port: 8080
env:
- name: API_SERVER_QPS
value: {{ .Values.agones.allocator.apiServerQPS | quote }}
- name: API_SERVER_QPS_BURST
value: {{ .Values.agones.allocator.apiServerQPSBurst | quote }}
- name: PROMETHEUS_EXPORTER
value: {{ .Values.agones.metrics.prometheusEnabled | quote }}
- name: STACKDRIVER_EXPORTER
Expand Down
2 changes: 2 additions & 0 deletions install/helm/agones/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ agones:
timeoutSeconds: 1
allocator:
install: true
apiServerQPS: 400
apiServerQPSBurst: 500
annotations: {}
healthCheck:
initialDelaySeconds: 3
Expand Down
4 changes: 4 additions & 0 deletions install/yaml/install.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1569,6 +1569,10 @@ spec:
path: /ready
port: 8080
env:
- name: API_SERVER_QPS
value: "400"
- name: API_SERVER_QPS_BURST
value: "500"
- name: PROMETHEUS_EXPORTER
value: "true"
- name: STACKDRIVER_EXPORTER
Expand Down
2 changes: 2 additions & 0 deletions site/content/en/docs/Installation/Install Agones/helm.md
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,8 @@ The following tables lists the configurable parameters of the Agones chart and t

| Parameter | Description | Default |
| --------------------------------------------------- | ----------------------------------------------------------------------------------------------- | ---------------------- |
| `agones.allocator.apiServerQPS` | Maximum sustained queries per second that an allocator should be making against API Server | `400` |
| `agones.allocator.apiServerQPSBurst` | Maximum burst queries per second that an allocator should be making against API Server | `500` |
| `agones.allocator.allocationTimeout` | Remote allocation call timeout. | `10s` |
| `agones.allocator.remoteAllocationTimeout` | Total remote allocation timeout including retries. | `30s` |
| `agones.controller.annotations` | [Annotations][annotations] added to the Agones controller pods | `{}` |
Expand Down