Skip to content

Commit 09ca0a6

Browse files
Add support for newer mysqld-versions. (#1397)
1 parent ef841d5 commit 09ca0a6

File tree

1 file changed

+32
-6
lines changed

1 file changed

+32
-6
lines changed

mysqld-exporter/main.libsonnet

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
local k = import 'ksonnet-util/kausal.libsonnet';
2+
local configMap = k.core.v1.configMap;
3+
local configVolumeMount = k.util.configVolumeMount;
24
local container = k.core.v1.container;
35

46
{
@@ -9,11 +11,16 @@ local container = k.core.v1.container;
911
user,
1012
host,
1113
port=3306,
12-
image='prom/mysqld-exporter:v0.13.0',
14+
image='prom/mysqld-exporter:v0.16.0',
1315
tlsMode='preferred',
16+
configMapName='%s-cfg' % [name],
1417
):: {
1518
local this = self,
16-
19+
local versionParts = std.split(std.split(image, ':')[1], '.'),
20+
local majorVersion = std.parseInt(std.strReplace(versionParts[0], 'v', '')),
21+
local minorVersion = std.parseInt(versionParts[1]),
22+
// Ref: https://github.com/prometheus/mysqld_exporter/releases/tag/v0.15.0
23+
local needsConfigFile = majorVersion > 0 || minorVersion > 14,
1724
envMap:: {
1825
MYSQL_USER: user,
1926
MYSQL_HOST: host,
@@ -25,9 +32,13 @@ local container = k.core.v1.container;
2532
container::
2633
container.new('mysqld-exporter', image)
2734
+ container.withPorts(k.core.v1.containerPort.new('http-metrics', 9104))
28-
+ container.withArgsMixin([
29-
'--collect.info_schema.innodb_metrics',
30-
])
35+
+ container.withArgsMixin(
36+
[
37+
'--collect.info_schema.innodb_metrics',
38+
] + (if needsConfigFile then [
39+
'--config.my-cnf=/conf/config.cnf',
40+
] else [])
41+
)
3142
+ container.withEnvMap(this.envMap)
3243
,
3344

@@ -43,10 +54,25 @@ local container = k.core.v1.container;
4354
DATA_SOURCE_NAME: '$(MYSQL_USER):$(MYSQL_PASSWORD)@tcp($(MYSQL_HOST):$(MYSQL_PORT))/?tls=$(MYSQL_TLS_MODE)',
4455
}),
4556
]
46-
),
57+
) + (if needsConfigFile then configVolumeMount(configMapName, '/conf') else {}),
4758

4859
service:
4960
k.util.serviceFor(this.deployment),
61+
62+
configMap: (if needsConfigFile then configMap.new(configMapName)
63+
+ configMap.withData({
64+
'config.cnf': std.manifestIni({
65+
sections: {
66+
client: {
67+
host: '${MYSQL_HOST}',
68+
port: '${MYSQL_PORT}',
69+
user: '${MYSQL_USER}',
70+
password: '${MYSQL_PASSWORD}',
71+
tls: '${MYSQL_TLS_MODE}',
72+
},
73+
},
74+
}),
75+
}) else {}),
5076
},
5177

5278
withPassword(password):: {

0 commit comments

Comments
 (0)