Skip to content

Commit

Permalink
consolidated invariant failures into single metric
Browse files Browse the repository at this point in the history
  • Loading branch information
MonsieurNicolas committed Jan 7, 2019
1 parent 9defa61 commit 22c2c09
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 23 deletions.
2 changes: 1 addition & 1 deletion docs/metrics.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ history.download-<X>.success | meter | download of <X> completed succes
history.download-<X>.failure | meter | download of <X> failed
history.verify-<X>.success | meter | verification of <X> succeeded
history.verify-<X>.failure | meter | verification of <X> failed
invariant.does-not-hold.count.<X> | counter | number of times invariant <X> failed
ledger.invariant.failure | counter | number of times invariants failed
ledger.transaction.apply | timer | time to apply one transaction
ledger.transaction.count | histogram | number of transactions per ledger
ledger.transaction.internal-error | counter | number of internal errors since start
Expand Down
35 changes: 14 additions & 21 deletions src/invariant/InvariantManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,27 +32,26 @@ InvariantManager::create(Application& app)
}

InvariantManagerImpl::InvariantManagerImpl(medida::MetricsRegistry& registry)
: mMetricsRegistry(registry)
: mInvariantFailureCount(
registry.NewCounter({"ledger", "invariant", "failure"}))
{
}

Json::Value
InvariantManagerImpl::getJsonInfo()
{
Json::Value failures;
for (auto const& invariant : mInvariants)
{
auto& counter = mMetricsRegistry.NewCounter(
{"invariant", "does-not-hold", "count", invariant.first});
if (counter.count() > 0)
{
auto const& info = mFailureInformation.at(invariant.first);

auto& fail = failures[invariant.first];
fail["count"] = (Json::Int64)counter.count();
fail["last_failed_on_ledger"] = info.lastFailedOnLedger;
fail["last_failed_with_message"] = info.lastFailedWithMessage;
}
for (auto const& fi : mFailureInformation)
{
auto& fail = failures[fi.first];
auto& info = fi.second;
fail["last_failed_on_ledger"] = info.lastFailedOnLedger;
fail["last_failed_with_message"] = info.lastFailedWithMessage;
}
if (!failures.empty())
{
failures["count"] = (Json::Int64)mInvariantFailureCount.count();
}
return failures;
}
Expand Down Expand Up @@ -131,8 +130,6 @@ InvariantManagerImpl::registerInvariant(std::shared_ptr<Invariant> invariant)
if (iter == mInvariants.end())
{
mInvariants[name] = invariant;
mMetricsRegistry.NewCounter(
{"invariant", "does-not-hold", "count", invariant->getName()});
}
else
{
Expand Down Expand Up @@ -208,12 +205,8 @@ InvariantManagerImpl::onInvariantFailure(std::shared_ptr<Invariant> invariant,
std::string const& message,
uint32_t ledger)
{
mMetricsRegistry
.NewCounter(
{"invariant", "does-not-hold", "count", invariant->getName()})
.inc();
mFailureInformation[invariant->getName()].lastFailedOnLedger = ledger;
mFailureInformation[invariant->getName()].lastFailedWithMessage = message;
mInvariantFailureCount.inc();
mFailureInformation[invariant->getName()] = {ledger, message};
handleInvariantFailure(invariant, message);
}

Expand Down
3 changes: 2 additions & 1 deletion src/invariant/InvariantManagerImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
namespace medida
{
class MetricsRegistry;
class Counter;
}

namespace stellar
Expand All @@ -20,7 +21,7 @@ class InvariantManagerImpl : public InvariantManager
{
std::map<std::string, std::shared_ptr<Invariant>> mInvariants;
std::vector<std::shared_ptr<Invariant>> mEnabled;
medida::MetricsRegistry& mMetricsRegistry;
medida::Counter& mInvariantFailureCount;

struct InvariantFailureInformation
{
Expand Down
3 changes: 3 additions & 0 deletions src/ledger/LedgerManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1007,6 +1007,9 @@ LedgerManagerImpl::applyTransactions(std::vector<TransactionFramePtr>& txs,
}
catch (InvariantDoesNotHold&)
{
CLOG(ERROR, "Ledger")
<< "Invariant failure during tx->apply for tx "
<< tx->getFullHash();
throw;
}
catch (std::runtime_error& e)
Expand Down

9 comments on commit 22c2c09

@latobarita
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

saw approval from jonjove
at MonsieurNicolas@22c2c09

@latobarita
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging MonsieurNicolas/stellar-core/txLogging = 22c2c09 into auto

@latobarita
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MonsieurNicolas/stellar-core/txLogging = 22c2c09 merged ok, testing candidate = 55336ee2

@latobarita
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@latobarita
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

saw approval from jonjove
at MonsieurNicolas@22c2c09

@latobarita
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging MonsieurNicolas/stellar-core/txLogging = 22c2c09 into auto

@latobarita
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MonsieurNicolas/stellar-core/txLogging = 22c2c09 merged ok, testing candidate = 8ef5755

@latobarita
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@latobarita
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fast-forwarding master to auto = 8ef5755

Please sign in to comment.