Skip to content

Commit 3992999

Browse files
committed
Remove unneeded metrics
1 parent 57437b1 commit 3992999

File tree

3 files changed

+18
-52
lines changed

3 files changed

+18
-52
lines changed

src/rpc/Counters.cpp

Lines changed: 3 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -144,27 +144,6 @@ Counters::Counters(Reportable const& wq)
144144
"Total number of internal errors"
145145
)
146146
)
147-
, ledgerCurrentCounter_(
148-
PrometheusService::counterInt(
149-
"rpc_ledger_requests_total",
150-
Labels({Label{"ledger_type", "current"}}),
151-
"Total number of RPC requests for current ledger"
152-
)
153-
)
154-
, ledgerValidatedCounter_(
155-
PrometheusService::counterInt(
156-
"rpc_ledger_requests_total",
157-
Labels({Label{"ledger_type", "validated"}}),
158-
"Total number of RPC requests for validated ledger"
159-
)
160-
)
161-
, ledgerSpecificCounter_(
162-
PrometheusService::counterInt(
163-
"rpc_ledger_requests_total",
164-
Labels({Label{"ledger_type", "specific"}}),
165-
"Total number of RPC requests for specific ledger sequence"
166-
)
167-
)
168147
, ledgerAgeLedgersHistogram_(
169148
PrometheusService::histogramInt(
170149
"rpc_requested_ledger_age_histogram",
@@ -256,22 +235,19 @@ void
256235
Counters::recordLedgerRequest(boost::json::object const& params, std::uint32_t currentLedgerSequence)
257236
{
258237
if (not params.contains("ledger_index")) {
259-
++ledgerValidatedCounter_.get();
238+
ledgerAgeLedgersHistogram_.get().observe(0);
260239
return;
261240
}
262241
auto const& indexValue = params.at("ledger_index");
263242
if (auto const parsed = util::getLedgerIndex(indexValue); parsed.has_value()) {
264-
++ledgerSpecificCounter_.get();
265243
if (*parsed <= currentLedgerSequence) {
266244
auto const ageLedgers = static_cast<std::int64_t>(currentLedgerSequence - *parsed);
267245
ledgerAgeLedgersHistogram_.get().observe(ageLedgers);
268246
}
269247
} else if (indexValue.is_string()) {
270248
auto const indexStr = boost::json::value_to<std::string>(indexValue);
271-
if (indexStr == "current") {
272-
++ledgerCurrentCounter_.get();
273-
} else if (indexStr == "validated") {
274-
++ledgerValidatedCounter_.get();
249+
if (indexStr == "validated") {
250+
ledgerAgeLedgersHistogram_.get().observe(0);
275251
}
276252
}
277253
}

src/rpc/Counters.hpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,6 @@ class Counters {
6868
CounterType unknownCommandCounter_;
6969
CounterType internalErrorCounter_;
7070

71-
// ledger request tracking metrics
72-
CounterType ledgerCurrentCounter_;
73-
CounterType ledgerValidatedCounter_;
74-
CounterType ledgerSpecificCounter_;
7571
std::reference_wrapper<util::prometheus::HistogramInt> ledgerAgeLedgersHistogram_;
7672

7773
std::reference_wrapper<Reportable const> workQueue_;

tests/unit/rpc/CountersTests.cpp

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#include <xrpl/protocol/jss.h>
3232

3333
#include <chrono>
34+
#include <cstdint>
3435
#include <string>
3536

3637
using namespace rpc;
@@ -197,67 +198,60 @@ TEST_F(RPCCountersMockPrometheusTests, onInternalError)
197198
counters.onInternalError();
198199
}
199200

200-
TEST_F(RPCCountersMockPrometheusTests, recordLedgerRequestCurrent)
201+
struct RPCCountersMockPrometheusRecotdLedgerRequestTest : RPCCountersMockPrometheusTests {
202+
testing::StrictMock<util::prometheus::MockHistogramImpl<int64_t>>& ageLedgersHistogramMock =
203+
makeMock<util::prometheus::HistogramInt>("rpc_requested_ledger_age_histogram", "");
204+
};
205+
TEST_F(RPCCountersMockPrometheusRecotdLedgerRequestTest, currentLedger)
201206
{
202-
auto& currentCounterMock = makeMock<CounterInt>("rpc_ledger_requests_total", "{ledger_type=\"current\"}");
203-
EXPECT_CALL(currentCounterMock, add(1));
204-
207+
// "current" is not tracked in the histogram (it's not a historical ledger lookup)
208+
// No mock expectations needed
205209
boost::json::object params;
206210
params["ledger_index"] = "current";
207211
counters.recordLedgerRequest(params, 1000);
208212
}
209213

210-
TEST_F(RPCCountersMockPrometheusTests, recordLedgerRequestValidated)
214+
TEST_F(RPCCountersMockPrometheusRecotdLedgerRequestTest, validateLedger)
211215
{
212-
auto& validatedCounterMock = makeMock<CounterInt>("rpc_ledger_requests_total", "{ledger_type=\"validated\"}");
213-
EXPECT_CALL(validatedCounterMock, add(1));
216+
EXPECT_CALL(ageLedgersHistogramMock, observe(0));
214217

215218
boost::json::object params;
216219
params["ledger_index"] = "validated";
217220
counters.recordLedgerRequest(params, 1000);
218221
}
219222

220-
TEST_F(RPCCountersMockPrometheusTests, recordLedgerRequestValidatedDefault)
223+
TEST_F(RPCCountersMockPrometheusRecotdLedgerRequestTest, validatedDefaultLedger)
221224
{
222-
auto& validatedCounterMock = makeMock<CounterInt>("rpc_ledger_requests_total", "{ledger_type=\"validated\"}");
223-
EXPECT_CALL(validatedCounterMock, add(1));
225+
EXPECT_CALL(ageLedgersHistogramMock, observe(0));
224226

225227
boost::json::object params;
226228
counters.recordLedgerRequest(params, 1000);
227229
}
228230

229-
TEST_F(RPCCountersMockPrometheusTests, recordLedgerRequestSpecificNumber)
231+
TEST_F(RPCCountersMockPrometheusRecotdLedgerRequestTest, specificLedger)
230232
{
231-
auto& specificCounterMock = makeMock<CounterInt>("rpc_ledger_requests_total", "{ledger_type=\"specific\"}");
232233
auto& ageLedgersHistogramMock = makeMock<util::prometheus::HistogramInt>("rpc_requested_ledger_age_histogram", "");
233234

234-
EXPECT_CALL(specificCounterMock, add(1));
235235
EXPECT_CALL(ageLedgersHistogramMock, observe(100)); // age is 1000 - 900 = 100
236236

237237
boost::json::object params;
238238
params["ledger_index"] = 900;
239239
counters.recordLedgerRequest(params, 1000);
240240
}
241241

242-
TEST_F(RPCCountersMockPrometheusTests, recordLedgerRequestSpecificStringNumber)
242+
TEST_F(RPCCountersMockPrometheusRecotdLedgerRequestTest, stringNumberLedger)
243243
{
244-
auto& specificCounterMock = makeMock<CounterInt>("rpc_ledger_requests_total", "{ledger_type=\"specific\"}");
245-
auto& ageLedgersHistogramMock = makeMock<util::prometheus::HistogramInt>("rpc_requested_ledger_age_histogram", "");
246-
247-
EXPECT_CALL(specificCounterMock, add(1));
248244
EXPECT_CALL(ageLedgersHistogramMock, observe(50)); // 1000 - 950 = 50 ledgers
249245

250246
boost::json::object params;
251247
params["ledger_index"] = "950";
252248
counters.recordLedgerRequest(params, 1000);
253249
}
254250

255-
TEST_F(RPCCountersMockPrometheusTests, recordLedgerRequestZeroAge)
251+
TEST_F(RPCCountersMockPrometheusRecotdLedgerRequestTest, zeroAgeLedger)
256252
{
257-
auto& specificCounterMock = makeMock<CounterInt>("rpc_ledger_requests_total", "{ledger_type=\"specific\"}");
258253
auto& ageLedgersHistogramMock = makeMock<util::prometheus::HistogramInt>("rpc_requested_ledger_age_histogram", "");
259254

260-
EXPECT_CALL(specificCounterMock, add(1));
261255
EXPECT_CALL(ageLedgersHistogramMock, observe(0)); // 1000 - 1000 = 0 ledgers
262256

263257
boost::json::object params;

0 commit comments

Comments
 (0)