Repository navigation
Expand file tree
/
Copy pathindex.py
More file actions
84 lines (67 loc) · 2.01 KB
/
Copy pathindex.py
File metadata and controls
84 lines (67 loc) · 2.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#! /usr/local/bin/python
# -*- coding: utf-8 -*-
from calendar import timegm
from datetime import datetime
import _strptime # https://bugs.python.org/issue7980
from flask import Flask, request, jsonify
app = Flask(__name__)
app.debug = True
def convert_to_time_ms(timestamp):
return 1000 * timegm(datetime.strptime(timestamp, '%Y-%m-%dT%H:%M:%S.%fZ').timetuple())
@app.route('/')
def health_check():
return 'This datasource is healthy.'
@app.route('/search', methods=['POST'])
def search():
return jsonify(['my_series', 'another_series'])
@app.route('/query', methods=['POST'])
def query():
req = request.get_json()
data = [
{
"target": req['targets'][0]['target'],
"datapoints": [
[861, convert_to_time_ms(req['range']['from'])],
[767, convert_to_time_ms(req['range']['to'])]
]
}
]
return jsonify(data)
@app.route('/annotations', methods=['POST'])
def annotations():
req = request.get_json()
data = [
{
"annotation": 'This is the annotation',
"time": (convert_to_time_ms(req['range']['from']) +
convert_to_time_ms(req['range']['to'])) / 2,
"title": 'Deployment notes',
"tags": ['tag1', 'tag2'],
"text": 'Hm, something went wrong...'
}
]
return jsonify(data)
@app.route('/tag-keys', methods=['POST'])
def tag_keys():
data = [
{"type": "string", "text": "City"},
{"type": "string", "text": "Country"}
]
return jsonify(data)
@app.route('/tag-values', methods=['POST'])
def tag_values():
req = request.get_json()
if req['key'] == 'City':
return jsonify([
{'text': 'Tokyo'},
{'text': 'São Paulo'},
{'text': 'Jakarta'}
])
elif req['key'] == 'Country':
return jsonify([
{'text': 'China'},
{'text': 'India'},
{'text': 'United States'}
])
if __name__ == '__main__':
app.run()