Skip to content

Commit c0ac4b6

Browse files
stankevichAMecea
authored andcommitted
Set metrics exporter port based on extra_port
1 parent a01133d commit c0ac4b6

File tree

3 files changed

+30
-2
lines changed

3 files changed

+30
-2
lines changed

Changelog.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,16 @@ adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
5959
* Change default resource requests/limits for `sidecar` container: requested=10m/32Mi, limit=the same as `.spec.podSpec.resources.limit`
6060
* Change default resource requests/limits for `exporter` container: requested=10m/32Mi, limit=100m/128Mi
6161
* Change default resource requests/limits for `heartbeat` container: requested=10m/32Mi, limit=100m/64Mi
62+
* If [`extra_port`](https://www.percona.com/doc/percona-server/5.7/performance/threadpool.html#extra_port)
63+
is defined in the cluster spec, metrics exporter will use it to connect to MySQL providing that
64+
[`extra_max_connections`](https://www.percona.com/doc/percona-server/5.7/performance/threadpool.html#extra_max_connections)
65+
is larger than the default `1`. If MySQL server runs out of available connections, using `extra_port`
66+
allows the exporter to continue collecting MySQL metrics.
6267
### Removed
6368
### Fixed
6469
* Update and fix e2e tests
6570
* Fix double date string in backup path
71+
* Fix double date string in bakup path
6672
* Copy the nodeSelector as-is in the statefulset (fixes #454)
6773
* Fix flakines in ReadOnly cluster condition (fixes #434)
6874
* Fix rounding in computing `innodb-buffer-pool-size` (fixes #501)

pkg/controller/mysqlcluster/internal/syncer/statefullset.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ func (s *sfsSyncer) getEnvFor(name string) []core.EnvVar {
290290
env = append(env, s.envVarFromSecret(sctOpName, "PASSWORD", "METRICS_EXPORTER_PASSWORD", false))
291291
env = append(env, core.EnvVar{
292292
Name: "DATA_SOURCE_NAME",
293-
Value: fmt.Sprintf("$(USER):$(PASSWORD)@(127.0.0.1:%d)/", MysqlPort),
293+
Value: fmt.Sprintf("$(USER):$(PASSWORD)@(127.0.0.1:%d)/", s.cluster.ExporterDataSourcePort()),
294294
})
295295
case containerMySQLInitName:
296296
// set MySQL init only flag for init container

pkg/internal/mysqlcluster/mysqlcluster.go

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,10 @@ package mysqlcluster
1818

1919
import (
2020
"fmt"
21-
"github.com/presslabs/mysql-operator/pkg/options"
2221
"strings"
2322

23+
"github.com/presslabs/mysql-operator/pkg/options"
24+
2425
"github.com/blang/semver"
2526
core "k8s.io/api/core/v1"
2627
"k8s.io/apimachinery/pkg/labels"
@@ -230,3 +231,24 @@ func (c *MysqlCluster) ShouldHaveInitContainerForMysql() bool {
230231
func (c *MysqlCluster) String() string {
231232
return fmt.Sprintf("%s/%s", c.Namespace, c.Name)
232233
}
234+
235+
// ExporterDataSourcePort returns a MySQL port mysqld-exporter should connect to.
236+
// Returns `extra_port` if defined in the cluster spec and if `extra_max_connections`
237+
// is defined and larger than the default 1. Otherwise, returns the default MySQL port.
238+
// https://www.percona.com/doc/percona-server/5.7/performance/threadpool.html#extra_port
239+
func (c *MysqlCluster) ExporterDataSourcePort() int {
240+
extraPortSettings := []string{"extra_port", "extra-port"}
241+
extraMaxConnectionsSettings := []string{"extra_max_connections", "extra-max-connections"}
242+
243+
for _, setting := range extraPortSettings {
244+
if port, ok := c.Spec.MysqlConf[setting]; ok {
245+
for _, setting := range extraMaxConnectionsSettings {
246+
if conns, ok := c.Spec.MysqlConf[setting]; ok && conns.IntValue() > 1 {
247+
return port.IntValue()
248+
}
249+
}
250+
}
251+
}
252+
253+
return constants.MysqlPort
254+
}

0 commit comments

Comments
 (0)