From: Peter van Dijk Date: Wed, 5 Feb 2020 16:19:05 +0000 (+0100) Subject: auth api: add includerings option to statistics endpoint X-Git-Tag: auth-4.3.0-beta2~43^2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=refs%2Fpull%2F8784%2Fhead;p=thirdparty%2Fpdns.git auth api: add includerings option to statistics endpoint --- diff --git a/docs/http-api/swagger/authoritative-api-swagger.yaml b/docs/http-api/swagger/authoritative-api-swagger.yaml index ab0cbdf903..be8ca834a2 100644 --- a/docs/http-api/swagger/authoritative-api-swagger.yaml +++ b/docs/http-api/swagger/authoritative-api-swagger.yaml @@ -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 diff --git a/pdns/ws-api.cc b/pdns/ws-api.cc index 54dde00791..64c87efa33 100644 --- a/pdns/ws-api.cc +++ b/pdns/ws-api.cc @@ -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