mirror of
https://github.com/XRPLF/clio.git
synced 2025-12-05 08:48:13 +00:00
@@ -16,13 +16,24 @@
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
//==============================================================================
|
||||
#include <util/prometheus/Http.h>
|
||||
#include "util/MockPrometheus.h"
|
||||
#include "util/config/Config.h"
|
||||
#include "util/prometheus/Http.h"
|
||||
#include "util/prometheus/Label.h"
|
||||
#include "util/prometheus/Prometheus.h"
|
||||
|
||||
#include <util/MockPrometheus.h>
|
||||
|
||||
#include <fmt/format.h>
|
||||
#include <boost/beast/http/field.hpp>
|
||||
#include <boost/beast/http/message.hpp>
|
||||
#include <boost/beast/http/status.hpp>
|
||||
#include <boost/beast/http/string_body.hpp>
|
||||
#include <boost/beast/http/verb.hpp>
|
||||
#include <boost/json/object.hpp>
|
||||
#include <boost/json/value.hpp>
|
||||
#include <fmt/core.h>
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include <string>
|
||||
|
||||
using namespace util::prometheus;
|
||||
namespace http = boost::beast::http;
|
||||
|
||||
@@ -67,35 +78,40 @@ INSTANTIATE_TEST_CASE_P(
|
||||
.target = "/metrics",
|
||||
.isAdmin = true,
|
||||
.prometheusEnabled = true,
|
||||
.expected = true},
|
||||
.expected = true
|
||||
},
|
||||
PrometheusCheckRequestTestsParams{
|
||||
.testName = "validRequestPrometheusDisabled",
|
||||
.method = http::verb::get,
|
||||
.target = "/metrics",
|
||||
.isAdmin = true,
|
||||
.prometheusEnabled = false,
|
||||
.expected = true},
|
||||
.expected = true
|
||||
},
|
||||
PrometheusCheckRequestTestsParams{
|
||||
.testName = "notAdmin",
|
||||
.method = http::verb::get,
|
||||
.target = "/metrics",
|
||||
.isAdmin = false,
|
||||
.prometheusEnabled = true,
|
||||
.expected = true},
|
||||
.expected = true
|
||||
},
|
||||
PrometheusCheckRequestTestsParams{
|
||||
.testName = "wrongMethod",
|
||||
.method = http::verb::post,
|
||||
.target = "/metrics",
|
||||
.isAdmin = true,
|
||||
.prometheusEnabled = true,
|
||||
.expected = false},
|
||||
.expected = false
|
||||
},
|
||||
PrometheusCheckRequestTestsParams{
|
||||
.testName = "wrongTarget",
|
||||
.method = http::verb::get,
|
||||
.target = "/",
|
||||
.isAdmin = true,
|
||||
.prometheusEnabled = true,
|
||||
.expected = false},
|
||||
.expected = false
|
||||
},
|
||||
}),
|
||||
PrometheusCheckRequestTests::NameGenerator()
|
||||
);
|
||||
@@ -132,7 +148,7 @@ TEST_F(PrometheusHandleRequestTests, notAdmin)
|
||||
TEST_F(PrometheusHandleRequestTests, responseWithCounter)
|
||||
{
|
||||
auto const counterName = "test_counter";
|
||||
const Labels labels{{{"label1", "value1"}, Label{"label2", "value2"}}};
|
||||
Labels const labels{{{"label1", "value1"}, Label{"label2", "value2"}}};
|
||||
auto const description = "test_description";
|
||||
|
||||
auto& counter = PrometheusService::counterInt(counterName, labels, description);
|
||||
@@ -151,7 +167,7 @@ TEST_F(PrometheusHandleRequestTests, responseWithCounter)
|
||||
TEST_F(PrometheusHandleRequestTests, responseWithGauge)
|
||||
{
|
||||
auto const gaugeName = "test_gauge";
|
||||
const Labels labels{{{"label2", "value2"}, {"label3", "value3"}}};
|
||||
Labels const labels{{{"label2", "value2"}, {"label3", "value3"}}};
|
||||
auto const description = "test_description_gauge";
|
||||
|
||||
auto& gauge = PrometheusService::gaugeInt(gaugeName, labels, description);
|
||||
@@ -170,7 +186,7 @@ TEST_F(PrometheusHandleRequestTests, responseWithGauge)
|
||||
TEST_F(PrometheusHandleRequestTests, responseWithCounterAndGauge)
|
||||
{
|
||||
auto const counterName = "test_counter";
|
||||
const Labels counterLabels{{{"label1", "value1"}, {"label2", "value2"}}};
|
||||
Labels const counterLabels{{{"label1", "value1"}, {"label2", "value2"}}};
|
||||
auto const counterDescription = "test_description";
|
||||
|
||||
auto& counter = PrometheusService::counterInt(counterName, counterLabels, counterDescription);
|
||||
@@ -178,7 +194,7 @@ TEST_F(PrometheusHandleRequestTests, responseWithCounterAndGauge)
|
||||
counter += 3;
|
||||
|
||||
auto const gaugeName = "test_gauge";
|
||||
const Labels gaugeLabels{{{"label2", "value2"}, {"label3", "value3"}}};
|
||||
Labels const gaugeLabels{{{"label2", "value2"}, {"label3", "value3"}}};
|
||||
auto const gaugeDescription = "test_description_gauge";
|
||||
|
||||
auto& gauge = PrometheusService::gaugeInt(gaugeName, gaugeLabels, gaugeDescription);
|
||||
@@ -214,8 +230,9 @@ TEST_F(PrometheusHandleRequestTests, responseWithCounterAndGauge)
|
||||
|
||||
TEST_F(PrometheusHandleRequestTests, compressReply)
|
||||
{
|
||||
PrometheusService::init(util::Config(boost::json::value{
|
||||
{"prometheus", boost::json::object{{"compress_reply", true}}}}));
|
||||
PrometheusService::init(
|
||||
util::Config(boost::json::value{{"prometheus", boost::json::object{{"compress_reply", true}}}})
|
||||
);
|
||||
|
||||
auto& gauge = PrometheusService::gaugeInt("test_gauge", Labels{});
|
||||
++gauge;
|
||||
|
||||
Reference in New Issue
Block a user