Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[IMPROVEMENT] Add proxy for /api/v1/labels #140

Merged
merged 1 commit into from
Apr 9, 2019
Merged
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
19 changes: 18 additions & 1 deletion promgen/proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,24 @@ def get_context_data(self, **kwargs):
return context


class ProxyLabel(PrometheusProxy):
class ProxyLabels(PrometheusProxy):
def get(self, request):
data = set()
for future in self.proxy(request):
try:
result = future.result()
result.raise_for_status()
_json = result.json()
logger.debug("Appending data from %s", result.url)
data.update(_json["data"])
except HTTPError:
logger.warning("Error with response")
return proxy_error(result)

return JsonResponse({"status": "success", "data": sorted(data)})


class ProxyLabelValues(PrometheusProxy):
def get(self, request, label):
data = set()
for future in self.proxy(request):
Expand Down
2 changes: 1 addition & 1 deletion promgen/templates/promgen/rule_form_block.html
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@
<div class="panel-body">
<select
data-target="#id_clause"
data-ajax="{% url 'proxy-label' '__name__' %}"
data-ajax="{% url 'proxy-values' '__name__' %}"
data-append='{% templatetag openbrace %}{{rule.content_type.name}}="{{ rule.content_object.name }}"}'
class="form-control"
>
Expand Down
3 changes: 2 additions & 1 deletion promgen/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,8 @@
# Prometheus Proxy
# these apis need to match the same path because Promgen can pretend to be a Prometheus API
path("graph", proxy.ProxyGraph.as_view()),
path("api/v1/label/<label>/values", proxy.ProxyLabel.as_view(), name="proxy-label"),
path("api/v1/labels", proxy.ProxyLabels.as_view(), name="proxy-label"),
path("api/v1/label/<label>/values", proxy.ProxyLabelValues.as_view(), name="proxy-values"),
path("api/v1/query_range", proxy.ProxyQueryRange.as_view()),
path("api/v1/query", proxy.ProxyQuery.as_view(), name="proxy-query"),
path("api/v1/series", proxy.ProxySeries.as_view()),
Expand Down