From f25328fde2ae925ded7218c284db565b30fa3855 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20L=C3=A9ger?= Date: Tue, 4 Aug 2020 20:18:39 +0200 Subject: [PATCH 1/2] Enable influxdb basic Auth settings --- docker/compose/docker-compose.yml | 17 +++++++++++++---- docker/compose/etc/influx_init.iql | 14 ++++++++++++++ docker/compose/etc/loudml.yml | 9 +++++++-- docker/compose/etc/telegraf.conf | 4 ++-- loudml/influx.py | 1 - loudml/worker.py | 2 +- 6 files changed, 37 insertions(+), 10 deletions(-) create mode 100644 docker/compose/etc/influx_init.iql diff --git a/docker/compose/docker-compose.yml b/docker/compose/docker-compose.yml index 3a5d5734..d92a44c4 100644 --- a/docker/compose/docker-compose.yml +++ b/docker/compose/docker-compose.yml @@ -4,7 +4,7 @@ version: "3.6" services: loudml: - image: loudml/loudml:1.6.0 + image: loudml/loudml volumes: - ./etc/loudml.yml:/etc/loudml/config.yml:ro - var_loudml @@ -14,11 +14,16 @@ services: - influxdb influxdb: - image: influxdb + image: influxdb:alpine ports: - "8086:8086" volumes: - var_influxdb + - ./etc/influx_init.iql:/docker-entrypoint-initdb.d/influx_init.iql + environment: + INFLUXDB_HTTP_AUTH_ENABLED: "true" + INFLUXDB_ADMIN_USER: "admin" + INFLUXDB_ADMIN_PASSWORD: "passw0rd" chronograf: image: loudml/chronograf @@ -31,21 +36,25 @@ services: volumes: - var_chronograf environment: + INFLUXDB_USERNAME: "admin" + INFLUXDB_PASSWORD: "passw0rd" INFLUXDB_URL: http://influxdb:8086 LOUDML_URL: http://loudml:8077 KAPACITOR_URL: http://kapacitor:9092 kapacitor: - image: kapacitor + image: kapacitor:alpine depends_on: - influxdb volumes: - var_kapacitor environment: KAPACITOR_INFLUXDB_0_URLS_0: http://influxdb:8086 + KAPACITOR_INFLUXDB_0_USERNAME: "admin" + KAPACITOR_INFLUXDB_0_PASSWORD: "passw0rd" telegraf: - image: telegraf + image: telegraf:alpine volumes: - ./etc/telegraf.conf:/etc/telegraf/telegraf.conf:ro depends_on: diff --git a/docker/compose/etc/influx_init.iql b/docker/compose/etc/influx_init.iql new file mode 100644 index 00000000..6bb5dbcb --- /dev/null +++ b/docker/compose/etc/influx_init.iql @@ -0,0 +1,14 @@ +CREATE DATABASE "telegraf" +CREATE DATABASE "loudml" +CREATE DATABASE "chronograf" +CREATE USER telegraf WITH PASSWORD 'metricsmetricsmetricsmetrics' +REVOKE ALL PRIVILEGES FROM telegraf +GRANT WRITE ON telegraf TO telegraf +CREATE USER reader WITH PASSWORD 'metricsmetricsmetricsmetrics' +REVOKE ALL PRIVILEGES FROM reader +GRANT READ ON telegraf TO reader +GRANT READ ON chronograf TO reader +CREATE USER loudml WITH PASSWORD 'metricsmetricsmetricsmetrics' +REVOKE ALL PRIVILEGES FROM loudml +GRANT WRITE ON loudml TO loudml +GRANT ALL ON chronograf TO loudml diff --git a/docker/compose/etc/loudml.yml b/docker/compose/etc/loudml.yml index cf46c551..42b99d13 100644 --- a/docker/compose/etc/loudml.yml +++ b/docker/compose/etc/loudml.yml @@ -4,14 +4,19 @@ buckets: type: influxdb addr: influxdb:8086 database: loudml + dbuser: loudml + dbuser_password: "metricsmetricsmetricsmetrics" retention_policy: autogen measurement: loudml + create_database: false - name: data type: influxdb addr: influxdb:8086 - database: data + database: telegraf + dbuser: reader + dbuser_password: "metricsmetricsmetricsmetrics" retention_policy: autogen - measurement: sinus + create_database: false storage: path: /var/lib/loudml diff --git a/docker/compose/etc/telegraf.conf b/docker/compose/etc/telegraf.conf index 61b59e99..ec8eb7b1 100644 --- a/docker/compose/etc/telegraf.conf +++ b/docker/compose/etc/telegraf.conf @@ -113,8 +113,8 @@ # timeout = "5s" ## HTTP Basic Auth - # username = "telegraf" - # password = "metricsmetricsmetricsmetrics" + username = "telegraf" + password = "metricsmetricsmetricsmetrics" ## HTTP User-Agent # user_agent = "telegraf" diff --git a/loudml/influx.py b/loudml/influx.py index c293c04c..0daee373 100644 --- a/loudml/influx.py +++ b/loudml/influx.py @@ -414,7 +414,6 @@ def annotationdb(self): ssl=self.use_ssl, verify_ssl=self.verify_ssl, ) - self._annotationdb.create_database(db) return self._annotationdb diff --git a/loudml/worker.py b/loudml/worker.py index d27201a1..858e6bf5 100644 --- a/loudml/worker.py +++ b/loudml/worker.py @@ -255,7 +255,7 @@ def predict( if detect_anomalies: hooks = self.storage.load_model_hooks( model.settings, - bucket, + output_bucket or bucket, ) model.detect_anomalies(prediction, hooks) if save_run_state: From 5371e9435826622eb1a2df5c5bc97efa7a8cfea4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20L=C3=A9ger?= Date: Tue, 4 Aug 2020 21:57:45 +0200 Subject: [PATCH 2/2] Catch 401 warning in list_anomalies() --- loudml/influx.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/loudml/influx.py b/loudml/influx.py index 0daee373..f7b10e17 100644 --- a/loudml/influx.py +++ b/loudml/influx.py @@ -678,7 +678,16 @@ def list_anomalies( ) query = ''.join(query) - result = self.annotationdb.query(query) + try: + result = self.annotationdb.query(query) + except influxdb.exceptions.InfluxDBClientError as exn: + logging.warning( + "could not load annotations, got error '%d'", + exn.code, + ) + if exn.code == 401: + return [] + raise exn windows = [] for j, point in enumerate(result.get_points()):