Merge ~hloeung/influxdb-charm:master into influxdb-charm:master

Proposed by Haw Loeung
Status: Merged
Merged at revision: c4731b9410873ec304103f52ae3197d5e7360626
Proposed branch: ~hloeung/influxdb-charm:master
Merge into: influxdb-charm:master
Diff against target: 347 lines (+136/-67)
4 files modified
Makefile (+1/-1)
config.yaml (+11/-2)
files/influxdb.conf (+32/-40)
reactive/influxdb.py (+92/-24)
Reviewer Review Type Date Requested Status
Paul Collins lgtm Approve
Review via email: mp+333123@code.launchpad.net

Description of the change

Allow overriding configs with extra_config

There's a lot of configuration options to tune and set, instead of
implementing all of them as charm config options, we use
extra_config. This is basically section.config=value. For example, to
change/set the below:

| [http]
| auth-enabled = true

We can use this:

| extra_config:
| - http.auth-enabled=true

To post a comment you must log in.
Revision history for this message
Haw Loeung (hloeung) wrote :

$ juju config influxdb ip_address='127.0.0.1'

| ubuntu@juju-b884ff-canonistack-haw-lcy02-4:~$ diff -Naurp /etc/influxdb/{influxdb.conf.orig,influxdb.conf}
| --- /etc/influxdb/influxdb.conf.orig 2017-11-03 00:10:10.743762811 +0000
| +++ /etc/influxdb/influxdb.conf 2017-11-03 00:22:05.160094893 +0000
| @@ -201,7 +201,7 @@
| # enabled = true
|
| # The bind address used by the HTTP service.
| - # bind-address = ":8086"
| + bind-address = "127.0.0.1:8086"
|
| # Determines whether user authentication is enabled over HTTP/HTTPS.
| # auth-enabled = false
| ===

$ juju config influxdb ip_address='127.0.0.1' bind_port='8087'

| ubuntu@juju-b884ff-canonistack-haw-lcy02-4:~$ diff -Naurp /etc/influxdb/{influxdb.conf.orig,influxdb.conf}
| --- /etc/influxdb/influxdb.conf.orig 2017-11-03 00:10:10.743762811 +0000
| +++ /etc/influxdb/influxdb.conf 2017-11-03 00:24:00.227707065 +0000
| @@ -201,7 +201,7 @@
| # enabled = true
|
| # The bind address used by the HTTP service.
| - # bind-address = ":8086"
| + bind-address = "127.0.0.1:8087"
|
| # Determines whether user authentication is enabled over HTTP/HTTPS.
| # auth-enabled = false

$ juju config influxdb extra_config="- global.hostname=myhost
- http.auth-enabled=true
- data.max-series-per-database=0
"

| ubuntu@juju-b884ff-canonistack-haw-lcy02-4:~$ diff -Naurp /etc/influxdb/{influxdb.conf.orig,influxdb.conf}
| --- /etc/influxdb/influxdb.conf.orig 2017-11-03 00:10:10.743762811 +0000
| +++ /etc/influxdb/influxdb.conf 2017-11-03 00:25:45.242181284 +0000
| @@ -14,6 +14,8 @@
| # Bind address to use for the RPC service for backup and restore.
| # bind-address = "127.0.0.1:8088"
|
| +hostname = "myhost"
| +
| ###
| ### [meta]
| ###
| @@ -95,7 +97,7 @@
| # The maximum series allowed per database before writes are dropped. This limit can prevent
| # high cardinality issues at the database level. This limit can be disabled by setting it to
| # 0.
| - # max-series-per-database = 1000000
| + max-series-per-database = 0
|
| # The maximum number of tag values per tag that are allowed before writes are dropped. This limit
| # can prevent high cardinality tag values from being written to a measurement. This limit can be
| @@ -204,7 +206,7 @@
| # bind-address = ":8086"
|
| # Determines whether user authentication is enabled over HTTP/HTTPS.
| - # auth-enabled = false
| + auth-enabled = true
|
| # The default realm sent back when issuing a basic auth challenge.
| # realm = "InfluxDB"

Revision history for this message
Paul Collins (pjdc) :
review: Approve (lgtm)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
diff --git a/Makefile b/Makefile
index 5dd0577..efec4a7 100644
--- a/Makefile
+++ b/Makefile
@@ -12,7 +12,7 @@ clean:
12 rm -f $(REACTIVE_DIR)/*.pyc12 rm -f $(REACTIVE_DIR)/*.pyc
1313
14lint:14lint:
15 @flake8 $(REACTIVE_DIR)15 @flake8 --max-line-length=120 $(REACTIVE_DIR)
1616
17git:17git:
18 git push $(PERSONAL_REPO)18 git push $(PERSONAL_REPO)
diff --git a/config.yaml b/config.yaml
index 917e93a..840eb7b 100644
--- a/config.yaml
+++ b/config.yaml
@@ -62,7 +62,7 @@ options:
62 ip_address:62 ip_address:
63 description: "Which IP to bind on"63 description: "Which IP to bind on"
64 type: string64 type: string
65 default: "0.0.0.0"65 default: ""
66 bind_port:66 bind_port:
67 description: "Which port to bind to"67 description: "Which port to bind to"
68 type: int68 type: int
@@ -80,4 +80,13 @@ options:
80 default: 100000080 default: 1000000
81 description: |81 description: |
82 Maximum series allowed per database before writes are dropped.82 Maximum series allowed per database before writes are dropped.
83 Specify 0 for no limit.83 Specify 0 for no limit. (DEPRECATED) Please use extra_config instead.
84 extra_config:
85 type: string
86 default: ""
87 description: |
88 YAML-formatted list of extra configuration options to override.
89 For example:
90 - global.hostname=myhost
91 - http.auth-enabled=true
92 - data.max-series-per-database=0
diff --git a/templates/influxdb.conf b/files/influxdb.conf
index 77ed982..23c4e03 100644
--- a/templates/influxdb.conf
+++ b/files/influxdb.conf
@@ -1,8 +1,8 @@
1### Welcome to the InfluxDB configuration file.1### Welcome to the InfluxDB configuration file.
22
3# The values in this file override the default values used by the system if3# The values in this file override the default values used by the system if
4# a config option is not specified. The commented out lines are the the configuration4# a config option is not specified. The commented out lines are the configuration
5# field and the default value used. Uncommentting a line and changing the value5# field and the default value used. Uncommenting a line and changing the value
6# will change the value used at runtime when the process is restarted.6# will change the value used at runtime when the process is restarted.
77
8# Once every 24 hours InfluxDB will report usage data to usage.influxdata.com8# Once every 24 hours InfluxDB will report usage data to usage.influxdata.com
@@ -11,10 +11,8 @@
11# Change this option to true to disable reporting.11# Change this option to true to disable reporting.
12# reporting-disabled = false12# reporting-disabled = false
1313
14# we'll try to get the hostname automatically, but if it the os returns something14# Bind address to use for the RPC service for backup and restore.
15# that isn't resolvable by other servers in the cluster, use this option to15# bind-address = "127.0.0.1:8088"
16# manually set the hostname
17# hostname = "localhost"
1816
19###17###
20### [meta]18### [meta]
@@ -49,6 +47,18 @@
49 # The directory where the TSM storage engine stores WAL files.47 # The directory where the TSM storage engine stores WAL files.
50 wal-dir = "/var/lib/influxdb/wal"48 wal-dir = "/var/lib/influxdb/wal"
5149
50 # The amount of time that a write will wait before fsyncing. A duration
51 # greater than 0 can be used to batch up multiple fsync calls. This is useful for slower
52 # disks or when WAL write contention is seen. A value of 0s fsyncs every write to the WAL.
53 # Values in the range of 0-100ms are recommended for non-SSD disks.
54 # wal-fsync-delay = "0s"
55
56
57 # The type of shard index to use for new shards. The default is an in-memory index that is
58 # recreated at startup. A value of "tsi1" will use a disk based index that supports higher
59 # cardinality datasets.
60 # index-version = "inmem"
61
52 # Trace logging provides more verbose output around the tsm engine. Turning62 # Trace logging provides more verbose output around the tsm engine. Turning
53 # this on can provide more useful output for debugging tsm engine issues.63 # this on can provide more useful output for debugging tsm engine issues.
54 # trace-logging-enabled = false64 # trace-logging-enabled = false
@@ -77,10 +87,15 @@
77 # write or delete87 # write or delete
78 # compact-full-write-cold-duration = "4h"88 # compact-full-write-cold-duration = "4h"
7989
90 # The maximum number of concurrent full and level compactions that can run at one time. A
91 # value of 0 results in runtime.GOMAXPROCS(0) used at runtime. This setting does not apply
92 # to cache snapshotting.
93 # max-concurrent-compactions = 0
94
80 # The maximum series allowed per database before writes are dropped. This limit can prevent95 # The maximum series allowed per database before writes are dropped. This limit can prevent
81 # high cardinality issues at the database level. This limit can be disabled by setting it to96 # high cardinality issues at the database level. This limit can be disabled by setting it to
82 # 0.97 # 0.
83 max-series-per-database = {{max_series_per_database}}98 # max-series-per-database = 1000000
8499
85 # The maximum number of tag values per tag that are allowed before writes are dropped. This limit100 # The maximum number of tag values per tag that are allowed before writes are dropped. This limit
86 # can prevent high cardinality tag values from being written to a measurement. This limit can be101 # can prevent high cardinality tag values from being written to a measurement. This limit can be
@@ -106,22 +121,20 @@
106 # can help prevent run away queries. Setting the value to 0 disables the limit.121 # can help prevent run away queries. Setting the value to 0 disables the limit.
107 # query-timeout = "0s"122 # query-timeout = "0s"
108123
109 # The the time threshold when a query will be logged as a slow query. This limit can be set to help124 # The time threshold when a query will be logged as a slow query. This limit can be set to help
110 # discover slow or resource intensive queries. Setting the value to 0 disables the slow query logging.125 # discover slow or resource intensive queries. Setting the value to 0 disables the slow query logging.
111 # log-queries-after = "0s"126 # log-queries-after = "0s"
112127
113 # The maximum number of points a SELECT can process. A value of 0 will make the maximum128 # The maximum number of points a SELECT can process. A value of 0 will make
114 # point count unlimited.129 # the maximum point count unlimited. This will only be checked every 10 seconds so queries will not
130 # be aborted immediately when hitting the limit.
115 # max-select-point = 0131 # max-select-point = 0
116132
117 # The maximum number of series a SELECT can run. A value of 0 will make the maximum series133 # The maximum number of series a SELECT can run. A value of 0 will make the maximum series
118 # count unlimited.134 # count unlimited.
119
120 # The maximum number of series a SELECT can run. A value of zero will make the maximum series
121 # count unlimited.
122 # max-select-series = 0135 # max-select-series = 0
123136
124 # The maxium number of group by time bucket a SELECt can create. A value of zero will max the maximum137 # The maxium number of group by time bucket a SELECT can create. A value of zero will max the maximum
125 # number of buckets unlimited.138 # number of buckets unlimited.
126 # max-select-buckets = 0139 # max-select-buckets = 0
127140
@@ -132,7 +145,7 @@
132###145###
133146
134[retention]147[retention]
135 # Determines whether retention policy enforcment enabled.148 # Determines whether retention policy enforcement enabled.
136 # enabled = true149 # enabled = true
137150
138 # The interval of time when retention policy enforcement checks run.151 # The interval of time when retention policy enforcement checks run.
@@ -177,27 +190,6 @@
177 # store-interval = "10s"190 # store-interval = "10s"
178191
179###192###
180### [admin]
181###
182### Controls the availability of the built-in, web-based admin interface. If HTTPS is
183### enabled for the admin interface, HTTPS must also be enabled on the [http] service.
184###
185### NOTE: This interface is deprecated as of 1.1.0 and will be removed in a future release.
186
187[admin]
188 # Determines whether the admin service is enabled.
189 enabled = {{ admin }}
190
191 # The default bind address used by the admin service.
192 # bind-address = ":8083"
193
194 # Whether the admin service should use HTTPS.
195 # https-enabled = false
196
197 # The SSL certificate used when HTTPS is enabled.
198 # https-certificate = "/etc/ssl/influxdb.pem"
199
200###
201### [http]193### [http]
202###194###
203### Controls how the HTTP endpoints are configured. These are the primary195### Controls how the HTTP endpoints are configured. These are the primary
@@ -209,15 +201,15 @@
209 # enabled = true201 # enabled = true
210202
211 # The bind address used by the HTTP service.203 # The bind address used by the HTTP service.
212 bind-address = "{{ip_address}}:{{bind_port}}"204 # bind-address = ":8086"
213205
214 # Determines whether HTTP authentication is enabled.206 # Determines whether user authentication is enabled over HTTP/HTTPS.
215 # auth-enabled = false207 # auth-enabled = false
216208
217 # The default realm sent back when issuing a basic auth challenge.209 # The default realm sent back when issuing a basic auth challenge.
218 # realm = "InfluxDB"210 # realm = "InfluxDB"
219211
220 # Determines whether HTTP request logging is enable.d212 # Determines whether HTTP request logging is enabled.
221 # log-enabled = true213 # log-enabled = true
222214
223 # Determines whether detailed write logging is enabled.215 # Determines whether detailed write logging is enabled.
@@ -429,7 +421,7 @@
429###421###
430422
431[continuous_queries]423[continuous_queries]
432 # Determiens whether the continuous query service is enabled.424 # Determines whether the continuous query service is enabled.
433 # enabled = true425 # enabled = true
434426
435 # Controls whether queries are logged when executed by the CQ service.427 # Controls whether queries are logged when executed by the CQ service.
diff --git a/reactive/influxdb.py b/reactive/influxdb.py
index 856c9bb..a8394de 100644
--- a/reactive/influxdb.py
+++ b/reactive/influxdb.py
@@ -1,11 +1,13 @@
1from charmhelpers.contrib.charmsupport import nrpe1from charmhelpers.contrib.charmsupport import nrpe
2from charmhelpers.core.host import service_start, service_stop
3from charmhelpers.core import hookenv2from charmhelpers.core import hookenv
3from charmhelpers.core import host
4from charmhelpers.core.templating import render4from charmhelpers.core.templating import render
5from charms.reactive import hook, set_state, when, when_any, when_not5from charms.reactive import hook, set_state, remove_state, when, when_all, when_not
66
7import re
7import os8import os
8import shutil9import shutil
10import yaml
911
10CRONFILE = '/etc/cron.daily/influxdb-charm-backup'12CRONFILE = '/etc/cron.daily/influxdb-charm-backup'
11CHECK_SRC = 'files/check_influxdb.py'13CHECK_SRC = 'files/check_influxdb.py'
@@ -28,29 +30,97 @@ def install_influx():
28 hookenv.open_port(8083)30 hookenv.open_port(8083)
29 hookenv.open_port(port)31 hookenv.open_port(port)
30 config_changed()32 config_changed()
31 service_start('influxdb')33 host.service_start('influxdb')
32 hookenv.status_set('active', '')34 hookenv.status_set('active', '')
33 set_state('influxdb.configured')35 set_state('influxdb.configured')
3436 set_state('config.changed')
3537
36@when_any('config.changed.bind_port', 'config.changed.ip_address', 'config.changed.max_series_per_database')38
39def apply_configs(fh, config):
40 new_config = []
41
42 section = 'global'
43 indent = ''
44
45 section_keys_found = {
46 'global': {},
47 }
48 initial_comments = True
49 for line in fh:
50 # Start after initial comments "Welcome to the InfluxDB configur..."
51 if initial_comments and not line.startswith('##'):
52 initial_comments = False
53 if line.startswith('[') or (not initial_comments and line.startswith('##')):
54 if section in config:
55 # If the configs weren't found in this section let's add them.
56 for key in config[section].keys():
57 if key in section_keys_found[section]:
58 break
59 section_keys_found[section][key] = ''
60 new_config.append("{}{} = {}\n\n".format(indent, key, config[section][key]))
61 new_config.append(line)
62 if line.startswith('['):
63 section = line[1:][:-2]
64 # Apart from global config options, indent the rest.
65 indent = ' '
66 continue
67 # Format is 'key = value' or '# key = value'
68 match = re.match('^([\s#]*)(\S+)(\s*=.*)', line)
69 if not match:
70 new_config.append(line)
71 continue
72 key = match.group(2)
73 value = match.group(3)
74 # Store all config options we found per section.
75 if section not in section_keys_found:
76 section_keys_found[section] = {}
77 section_keys_found[section][key] = ''
78 if section not in config or key not in config[section]:
79 # We want to keep {meta,data}.{dir,wal-dir} always.
80 if section in ['meta', 'data'] and key in ['dir', 'wal-dir']:
81 new_config.append(line)
82 else:
83 new_config.append("{}# {}{}\n".format(indent, key, value))
84 continue
85 new_config.append("{}{} = {}\n".format(indent, key, config[section][key]))
86
87 return ''.join(new_config)
88
89
90@when_all('influxdb.configured', 'config.changed')
37def config_changed():91def config_changed():
38 config = hookenv.config()92 config = hookenv.config()
39 port = config.get('bind_port')93 conf = {
40 ip_address = config.get('ip_address')94 'global': {},
41 max_series_per_database = config.get('max_series_per_database')95 }
42 render(source='influxdb.conf',96
43 target='/etc/influxdb/influxdb.conf',97 # Only write out the bind-address if it differs from the default.
44 owner='root',98 if config.get('ip_address') or config.get('bind_port') != 8086:
45 perms=0o644,99 conf['http'] = {}
46 context={100 conf['http']['bind-address'] = '"{}:{}"'.format(config.get('ip_address', ''),
47 'admin': 'true',101 config.get('bind_port'))
48 'bind_port': port,102
49 'ip_address': ip_address,103 # Construct our dict of configs from the extra_config charm option.
50 'max_series_per_database': max_series_per_database,104 if config.get('extra_config', None):
51 })105 for c in yaml.safe_load(config.get('extra_config', '[]')):
52 service_stop('influxdb')106 k, value = c.split('=', 1)
53 service_start('influxdb')107 section, key = k.split('.', 1)
108 if section not in conf:
109 conf[section] = {}
110 if str(value) in ('true', 'false') or value.isdigit():
111 conf[section][key] = value
112 else:
113 conf[section][key] = '"{}"'.format(value)
114
115 target = '/etc/influxdb/influxdb.conf'
116 if not os.path.exists(target):
117 shutil.copy2('files/influxdb.conf', target)
118 with open(target, 'r') as f:
119 updated_config = apply_configs(f, conf)
120 host.write_file(target, updated_config.encode("utf-8"), perms=0o644)
121
122 host.service_stop('influxdb')
123 host.service_start('influxdb')
54124
55125
56@when('config.changed.backup_dir')126@when('config.changed.backup_dir')
@@ -77,10 +147,8 @@ def create_backup_job():
77147
78@hook('upgrade-charm')148@hook('upgrade-charm')
79def upgrade_charm():149def upgrade_charm():
80 # Force config changed on upgrade-charm in case one of the templates changed.150 remove_state('influxdb.configured')
81 set_state('config.changed.backup_dir')151 set_state('config.changed.backup_dir')
82 set_state('config.changed.bind_port')
83 set_state('config.changed.ip_address')
84 # If we have an NRPE relation, force run of that as well152 # If we have an NRPE relation, force run of that as well
85 if hookenv.relation_ids('nrpe-exteral-master'):153 if hookenv.relation_ids('nrpe-exteral-master'):
86 set_state('nrpe-external-master.available')154 set_state('nrpe-external-master.available')

Subscribers

People subscribed via source and target branches

to all changes: