Skip to content

Commit 295446d

Browse files
[fix] Workflow and test updated #274
Fixes #274
1 parent 2e3043c commit 295446d

2 files changed

Lines changed: 36 additions & 4 deletions

File tree

.github/workflows/ci.yml

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,23 @@ jobs:
2121
image: redis
2222
ports:
2323
- 6379:6379
24+
influxdb1:
25+
image: influxdb:1.8-alpine
26+
ports:
27+
- 8086:8086
28+
influxdb2:
29+
image: influxdb:2.0-alpine
30+
volumes:
31+
- influxdb2-data:/var/lib/influxdb2
32+
ports:
33+
- 8087:8086
34+
options: >-
35+
--env DOCKER_INFLUXDB_INIT_MODE=setup
36+
--env DOCKER_INFLUXDB_INIT_USERNAME=openwisp
37+
--env DOCKER_INFLUXDB_INIT_PASSWORD=openwisp
38+
--env DOCKER_INFLUXDB_INIT_ORG=openwisp
39+
--env DOCKER_INFLUXDB_INIT_BUCKET=openwisp2
40+
--env DOCKER_INFLUXDB_INIT_RETENTION=1w
2441
2542
strategy:
2643
fail-fast: false
@@ -33,6 +50,9 @@ jobs:
3350
- django~=3.2.0
3451
- django~=4.1.0
3552
- django~=4.2.0
53+
influxdb-version:
54+
- influxdb1
55+
- influxdb2
3656

3757
steps:
3858
- name: Install system packages
@@ -62,10 +82,10 @@ jobs:
6282
pip install -U pip wheel setuptools
6383
6484
- name: Install npm dependencies
65-
run: sudo npm install -g install jshint stylelint
85+
run: sudo npm install -g jshint stylelint
6686

67-
- name: Start InfluxDB container
68-
run: docker-compose up -d influxdb
87+
- name: Start InfluxDB ${{ matrix.influxdb-version }} container
88+
run: docker-compose up -d ${{ matrix.influxdb-version }}
6989

7090
- name: Install test dependencies
7191
run: |
@@ -77,6 +97,13 @@ jobs:
7797
pip uninstall -y django
7898
pip install ${{ matrix.django-version }}
7999
100+
- name: Set InfluxDB environment variables for InfluxDB 2.x
101+
if: matrix.influxdb-version == 'influxdb2'
102+
run: |
103+
export INFLUXDB_HOST=localhost
104+
export INFLUXDB_PORT=8087
105+
export USE_INFLUXDB2=True
106+
80107
- name: QA checks
81108
run: |
82109
./run-qa-checks

openwisp_monitoring/monitoring/tests/test_configuration.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,12 @@ def _get_new_metric(self):
3434
"SELECT {fields|SUM|/ 1} FROM {key} "
3535
"WHERE time >= '{time}' AND content_type = "
3636
"'{content_type}' AND object_id = '{object_id}'"
37-
)
37+
),
38+
'influxdb2': (
39+
'from(bucket: "{key}") |> range(start: {time}) '
40+
'|> filter(fn: (r) => r["_measurement"] == "{field_name}" and '
41+
'r["content_type"] == "{content_type}" and r["object_id"] == "{object_id}")'
42+
),
3843
},
3944
}
4045
},

0 commit comments

Comments
 (0)