Skip to content

Commit

Permalink
auth api: add includerings option to statistics endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
Habbie committed Feb 5, 2020
1 parent 87354cd commit c65b5e1
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 18 deletions.
7 changes: 6 additions & 1 deletion docs/http-api/swagger/authoritative-api-swagger.yaml
Expand Up @@ -412,7 +412,12 @@ paths:
description: |
When set to the name of a specific statistic, only this value is returned.
If no statistic with that name exists, the response has a 422 status and an error message.
- name: includerings
in: query
required: false
type: boolean
default: true
description: '“true” (default) or “false”, whether to include the Ring items, which can contain thousands of log messages or queried domains. Setting this to ”false” may make the response a lot smaller.'
responses:
'200':
description: List of Statistic Items
Expand Down
37 changes: 20 additions & 17 deletions pdns/ws-api.cc
Expand Up @@ -248,25 +248,28 @@ void apiServerStatistics(HttpRequest* req, HttpResponse* resp) {
}

#ifndef RECURSOR
for(const auto& ringName : S.listRings()) {
Json::array values;
const auto& ring = S.getRing(ringName);
for(const auto& item : ring) {
if (item.second == 0)
continue;

values.push_back(Json::object {
{ "name", item.first },
{ "value", std::to_string(item.second) },
if (!req->getvars.count("includerings") ||
req->getvars["includerings"] != "false") {
for(const auto& ringName : S.listRings()) {
Json::array values;
const auto& ring = S.getRing(ringName);
for(const auto& item : ring) {
if (item.second == 0)
continue;

values.push_back(Json::object {
{ "name", item.first },
{ "value", std::to_string(item.second) },
});
}

doc.push_back(Json::object {
{ "type", "RingStatisticItem" },
{ "name", ringName },
{ "size", std::to_string(S.getRingSize(ringName)) },
{ "value", values },
});
}

doc.push_back(Json::object {
{ "type", "RingStatisticItem" },
{ "name", ringName },
{ "size", std::to_string(S.getRingSize(ringName)) },
{ "value", values },
});
}
#endif

Expand Down

0 comments on commit c65b5e1

Please sign in to comment.