-
Notifications
You must be signed in to change notification settings - Fork 209
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add prometheus integration tests (#864)
- Loading branch information
1 parent
ac5733c
commit 2ec0f65
Showing
5 changed files
with
93 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -66,3 +66,6 @@ run-rust: | |
|
||
run-mysql: | ||
cd mysql && ./basic.sh | ||
|
||
run-prom: | ||
cd prom && ./run-tests.sh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
remote_read: | ||
- url: "http://127.0.0.1:5440/prom/v1/read" | ||
read_recent: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
#!/usr/bin/env python | ||
# coding: utf-8 | ||
|
||
import requests | ||
import time | ||
|
||
api_root = 'http://localhost:5440' | ||
prom_api_root = 'http://localhost:9090' | ||
headers = { | ||
'Content-Type': 'application/json' | ||
} | ||
|
||
def now(): | ||
return int(time.time()) * 1000 | ||
|
||
table = 'prom_remote_query_test' + str(now()) | ||
|
||
def execute_sql(sql): | ||
r = requests.post('{}/sql'.format(api_root), json={'query': sql}, headers=headers) | ||
assert r.status_code == 200, r.text | ||
|
||
def execute_pql(pql): | ||
r = requests.get('{}/api/v1/query?query={}'.format(prom_api_root, pql)) | ||
assert r.status_code == 200, r.text | ||
return r.json() | ||
|
||
def prepare_data(ts): | ||
execute_sql(""" | ||
CREATE TABLE if not exists `{}` ( | ||
`t` timestamp NOT NULL, | ||
`tag1` string TAG, | ||
`tag2` string TAG, | ||
`value` double NOT NULL, | ||
`value2` double NOT NULL, | ||
timestamp KEY (t) | ||
); | ||
""".format(table)) | ||
|
||
execute_sql(""" | ||
insert into {}(t, tag1, tag2, value, value2) | ||
values | ||
({}, "v1", "v2", 1, 2), | ||
({}, "v1", "v2", 11, 22) | ||
; | ||
""".format(table, ts-5000, ts)) | ||
|
||
|
||
def remote_query(ts): | ||
ts = ts/1000 # prom return seconds | ||
|
||
r = execute_pql(table + '{tag1="v1"}[5m]') | ||
result = r['data']['result'] | ||
assert result == [{'metric': {'__name__': table, 'tag1': 'v1', 'tag2': 'v2'}, 'values': [[ts-5, '1'], [ts, '11']]}] | ||
|
||
r = execute_pql(table + '{tag1=~"v1"}[5m]') | ||
result = r['data']['result'] | ||
assert result == [{'metric': {'__name__': table, 'tag1': 'v1', 'tag2': 'v2'}, 'values': [[ts-5, '1'], [ts, '11']]}] | ||
|
||
r = execute_pql(table + '{tag1!="v1"}[5m]') | ||
result = r['data']['result'] | ||
assert result == [] | ||
|
||
r = execute_pql(table + '{tag1!~"v1"}[5m]') | ||
result = r['data']['result'] | ||
assert result == [] | ||
|
||
def main(): | ||
ts = now() | ||
prepare_data(ts) | ||
remote_query(ts) | ||
|
||
if __name__ == '__main__': | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#!/usr/bin/env bash | ||
|
||
VERSION=prometheus-2.43.0.linux-amd64 | ||
wget "https://github.com/prometheus/prometheus/releases/download/v2.43.0/${VERSION}.tar.gz" | ||
|
||
tar xvf prometheus*.tar.gz | ||
nohup ./${VERSION}/prometheus --config.file ./prometheus.yml & | ||
sleep 5 | ||
|
||
python ./remote-query.py |