1
1
local k = import 'ksonnet-util/kausal.libsonnet' ;
2
+ local configMap = k.core.v1.configMap;
3
+ local configVolumeMount = k.util.configVolumeMount;
2
4
local container = k.core.v1.container;
3
5
4
6
{
@@ -9,11 +11,16 @@ local container = k.core.v1.container;
9
11
user,
10
12
host,
11
13
port=3306 ,
12
- image='prom/mysqld-exporter:v0.13 .0' ,
14
+ image='prom/mysqld-exporter:v0.16 .0' ,
13
15
tlsMode='preferred' ,
16
+ configMapName='%s-cfg' % [name],
14
17
):: {
15
18
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 ,
17
24
envMap:: {
18
25
MYSQL_USER: user,
19
26
MYSQL_HOST: host,
@@ -25,9 +32,13 @@ local container = k.core.v1.container;
25
32
container::
26
33
container.new('mysqld-exporter' , image)
27
34
+ 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
+ )
31
42
+ container.withEnvMap(this.envMap)
32
43
,
33
44
@@ -43,10 +54,25 @@ local container = k.core.v1.container;
43
54
DATA_SOURCE_NAME: '$(MYSQL_USER):$(MYSQL_PASSWORD)@tcp($(MYSQL_HOST):$(MYSQL_PORT))/?tls=$(MYSQL_TLS_MODE)' ,
44
55
}),
45
56
]
46
- ),
57
+ ) + ( if needsConfigFile then configVolumeMount(configMapName, '/conf' ) else {}) ,
47
58
48
59
service:
49
60
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 {}),
50
76
},
51
77
52
78
withPassword(password):: {
0 commit comments