From 2b3567d0ee422264f5b97bafbedf76b6f7de026e Mon Sep 17 00:00:00 2001 From: Sergey Stankevich Date: Tue, 28 Jan 2020 16:50:22 +0100 Subject: [PATCH] Parameterize metrics collector args Allows passing extra args to metrics exporter to e.g. enable/configure additional metrics collectors. --- config/crds/mysql_v1alpha1_mysqlcluster.yaml | 7 +++++++ pkg/apis/mysql/v1alpha1/mysqlcluster_types.go | 5 +++++ .../mysql/v1alpha1/zz_generated.deepcopy.go | 5 +++++ .../internal/syncer/statefullset.go | 19 +++++++++++++------ 4 files changed, 30 insertions(+), 6 deletions(-) diff --git a/config/crds/mysql_v1alpha1_mysqlcluster.yaml b/config/crds/mysql_v1alpha1_mysqlcluster.yaml index 33eaf442d..0cf1cedd2 100644 --- a/config/crds/mysql_v1alpha1_mysqlcluster.yaml +++ b/config/crds/mysql_v1alpha1_mysqlcluster.yaml @@ -84,6 +84,13 @@ spec: is removed from service. format: int64 type: integer + metricsExporterExtraArgs: + description: MetricsExporterExtraArgs is a list of extra command line + arguments to pass to MySQL metrics exporter. See https://github.com/prometheus/mysqld_exporter + for the list of available flags. + items: + type: string + type: array minAvailable: description: The number of pods from that set that must still be available after the eviction, even in the absence of the evicted pod Defaults diff --git a/pkg/apis/mysql/v1alpha1/mysqlcluster_types.go b/pkg/apis/mysql/v1alpha1/mysqlcluster_types.go index b3cbc1243..cbe116e50 100644 --- a/pkg/apis/mysql/v1alpha1/mysqlcluster_types.go +++ b/pkg/apis/mysql/v1alpha1/mysqlcluster_types.go @@ -123,6 +123,11 @@ type MysqlClusterSpec struct { // Set a custom offset for Server IDs. ServerID for each node will be the index of the statefulset, plus offset // +optional ServerIDOffset *int `json:"serverIDOffset,omitempty"` + + // MetricsExporterExtraArgs is a list of extra command line arguments to pass to MySQL metrics exporter. + // See https://github.com/prometheus/mysqld_exporter for the list of available flags. + // +optional + MetricsExporterExtraArgs []string `json:"metricsExporterExtraArgs,omitempty"` } // MysqlConf defines type for extra cluster configs. It's a simple map between diff --git a/pkg/apis/mysql/v1alpha1/zz_generated.deepcopy.go b/pkg/apis/mysql/v1alpha1/zz_generated.deepcopy.go index 31e57d220..40b9da9e5 100644 --- a/pkg/apis/mysql/v1alpha1/zz_generated.deepcopy.go +++ b/pkg/apis/mysql/v1alpha1/zz_generated.deepcopy.go @@ -257,6 +257,11 @@ func (in *MysqlClusterSpec) DeepCopyInto(out *MysqlClusterSpec) { *out = new(int) **out = **in } + if in.MetricsExporterExtraArgs != nil { + in, out := &in.MetricsExporterExtraArgs, &out.MetricsExporterExtraArgs + *out = make([]string, len(*in)) + copy(*out, *in) + } return } diff --git a/pkg/controller/mysqlcluster/internal/syncer/statefullset.go b/pkg/controller/mysqlcluster/internal/syncer/statefullset.go index a6bc45397..208c0995e 100644 --- a/pkg/controller/mysqlcluster/internal/syncer/statefullset.go +++ b/pkg/controller/mysqlcluster/internal/syncer/statefullset.go @@ -333,15 +333,22 @@ func (s *sfsSyncer) ensureContainersSpec() []core.Container { }) // METRICS container + exporterCommand := []string{ + fmt.Sprintf("--web.listen-address=0.0.0.0:%d", ExporterPort), + fmt.Sprintf("--web.telemetry-path=%s", ExporterPath), + "--collect.heartbeat", + fmt.Sprintf("--collect.heartbeat.database=%s", constants.OperatorDbName), + } + + if len(s.cluster.Spec.MetricsExporterExtraArgs) > 0 { + exporterCommand = append(exporterCommand, s.cluster.Spec.MetricsExporterExtraArgs...) + } + exporter := s.ensureContainer(containerExporterName, s.opt.MetricsExporterImage, - []string{ - fmt.Sprintf("--web.listen-address=0.0.0.0:%d", ExporterPort), - fmt.Sprintf("--web.telemetry-path=%s", ExporterPath), - "--collect.heartbeat", - fmt.Sprintf("--collect.heartbeat.database=%s", constants.OperatorDbName), - }, + exporterCommand, ) + exporter.Ports = ensurePorts(core.ContainerPort{ Name: ExporterPortName, ContainerPort: ExporterPort,