Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
111 changes: 111 additions & 0 deletions graphite_api/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -548,6 +548,117 @@ def render():
return response


@app.route('/tags/tagSeries', methods=['POST'])
def tags_series():
path = RequestParams.get('path')
if not path:
return jsonify({'error': 'no path specified'}, status=400)

return jsonify(app.store.tagdb.tag_series(path))


@app.route('/tags/tagMultiSeries', methods=['POST'])
def tags_multiseries():
paths = []
# Normal format: ?path=name;tag1=value1;tag2=value2&path=name;tag1=value2;tag2=value2
if len(RequestParams.getlist('path')) > 0:
paths = RequestParams.getlist('path')
# Rails/PHP/jQuery common practice format: ?path[]=...&path[]=...
elif len(RequestParams.getlist('path[]')) > 0:
paths = RequestParams.getlist('path[]')
else:
return jsonify({'error': 'no paths specified'}, status=400)

return jsonify(app.store.tagdb.tag_multi_series(paths))


@app.route('/tags/delSeries', methods=['POST'])
def tags_delseries():
paths = []
# Normal format: ?path=name;tag1=value1;tag2=value2&path=name;tag1=value2;tag2=value2
if len(RequestParams.getlist('path')) > 0:
paths = RequestParams.getlist('path')
# Rails/PHP/jQuery common practice format: ?path[]=...&path[]=...
elif len(RequestParams.getlist('path[]')) > 0:
paths = RequestParams.getlist('path[]')
else:
return jsonify({'error': 'no path specified'}, status=400)

return jsonify(app.store.tagdb.del_multi_series(paths))


@app.route('/tags/findSeries', methods=methods)
def tags_findseries():
exprs = []
# Normal format: ?expr=tag1=value1&expr=tag2=value2
if len(RequestParams.getlist('expr')) > 0:
exprs = RequestParams.getlist('expr')
# Rails/PHP/jQuery common practice format: ?expr[]=tag1=value1&expr[]=tag2=value2
elif len(RequestParams.getlist('expr[]')) > 0:
exprs = RequestParams.getlist('expr[]')

if not exprs:
return jsonify({'error': 'no tag expressions specified'}, status=400)

return jsonify(app.store.tagdb.find_series(exprs))


@app.route('/tags', methods=['GET'])
def tags_taglist():
return jsonify(app.store.tagdb.list_tags(
tagFilter=RequestParams.get('filter'),
limit=RequestParams.get('limit'),
))


@app.route('/tags/<string:tag>', methods=['GET'])
def tags_tagdetails(tag):
return jsonify(app.store.tagdb.get_tag(
tag,
valueFilter=RequestParams.get('filter'),
limit=RequestParams.get('limit'),
))


@app.route('/tags/autoComplete/tags', methods=methods)
def tags_autocomplete_tags():
exprs = []
# Normal format: ?expr=tag1=value1&expr=tag2=value2
if len(RequestParams.getlist('expr')) > 0:
exprs = RequestParams.getlist('expr')
# Rails/PHP/jQuery common practice format: ?expr[]=tag1=value1&expr[]=tag2=value2
elif len(RequestParams.getlist('expr[]')) > 0:
exprs = RequestParams.getlist('expr[]')

return jsonify(app.store.tagdb_auto_complete_tags(
exprs,
tagPrefix=RequestParams.get('tagPrefix'),
limit=RequestParams.get('limit'),
))


@app.route('/tags/autoComplete/values', methods=methods)
def tags_autocomplete_values():
exprs = []
# Normal format: ?expr=tag1=value1&expr=tag2=value2
if len(RequestParams.getlist('expr')) > 0:
exprs = RequestParams.getlist('expr')
# Rails/PHP/jQuery common practice format: ?expr[]=tag1=value1&expr[]=tag2=value2
elif len(RequestParams.getlist('expr[]')) > 0:
exprs = RequestParams.getlist('expr[]')

tag = RequestParams.get('tag')
if not tag:
return jsonify({'error': 'no tag specified'}, status=400)

return jsonify(app.store.tagdb_auto_complete_values(
exprs,
tag,
valuePrefix=RequestParams.get('valuePrefix'),
limit=RequestParams.get('limit'),
))


def tree_json(nodes, base_path, wildcards=False):
results = []

Expand Down
20 changes: 19 additions & 1 deletion graphite_api/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,16 @@
'/srv/graphite/whisper',
],
},
'tagdb': {
'path': 'graphite_api.tags.redis.RedisTagDB',
'autocomplete_limit': 100,
'redis': {
'host': 'localhost',
'port': 6379,
'db': 0,
'password': '',
},
},
'time_zone': get_localzone().zone,
}
if default_conf['time_zone'] == 'local': # tzlocal didn't find anything
Expand Down Expand Up @@ -134,7 +144,9 @@ def configure(app):
finders = []
for finder in config['finders']:
finders.append(load_by_path(finder)(config))
loaded_config['store'] = Store(finders)
path = config.get('tagdb', {}).get('path') or 'graphite_api.tags.base.DummyTagDB'
tagdb = get_tagdb(path, config, app.cache)
loaded_config['store'] = Store(finders, tagdb=tagdb)
app.config['GRAPHITE'] = loaded_config
app.config['TIME_ZONE'] = config['time_zone']
logger.info("configured timezone", timezone=app.config['TIME_ZONE'])
Expand Down Expand Up @@ -185,3 +197,9 @@ def configure_logging(config):
logger.info("loading configuration", path=config['path'])
else:
logger.info("loading default configuration")


def get_tagdb(tagdb_path, config, cache=None):
module_name, class_name = tagdb_path.rsplit('.', 1)
module = import_module(module_name)
return getattr(module, class_name)(config, cache=cache)
3 changes: 2 additions & 1 deletion graphite_api/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@


class Store(object):
def __init__(self, finders=None):
def __init__(self, finders=None, tagdb=None):
self.finders = finders
self.tagdb = tagdb

def find(self, pattern, startTime=None, endTime=None, local=True):
query = FindQuery(pattern, startTime, endTime)
Expand Down
Empty file added graphite_api/tags/__init__.py
Empty file.
Loading