|
7 | 7 |
|
8 | 8 | #include <utility> |
9 | 9 |
|
| 10 | +#include "common/prometheus/metrics.hpp" |
| 11 | +#include "common/prometheus/since.hpp" |
10 | 12 | #include "const.hpp" |
11 | 13 | #include "primitives/tipset/load.hpp" |
12 | 14 | #include "vm/actor/builtin/v0/cron/cron_actor.hpp" |
@@ -70,6 +72,61 @@ namespace fc::vm::interpreter { |
70 | 72 | std::vector<MessageReceipt> *all_receipts) const { |
71 | 73 | const auto &ipld{env_context_.ipld}; |
72 | 74 |
|
| 75 | + static auto &metricFailure{ |
| 76 | + prometheus::BuildCounter() |
| 77 | + .Name("lotus_block_failure") |
| 78 | + .Help("Counter for block validation failures") |
| 79 | + .Register(prometheusRegistry()) |
| 80 | + .Add({})}; |
| 81 | + static auto &metricSuccess{ |
| 82 | + prometheus::BuildCounter() |
| 83 | + .Name("lotus_block_success") |
| 84 | + .Help("Counter for block validation successes") |
| 85 | + .Register(prometheusRegistry()) |
| 86 | + .Add({})}; |
| 87 | + static auto &metricTotal{prometheus::BuildHistogram() |
| 88 | + .Name("lotus_vm_applyblocks_total_ms") |
| 89 | + .Help("Time spent applying block state") |
| 90 | + .Register(prometheusRegistry()) |
| 91 | + .Add({}, kDefaultPrometheusMsBuckets)}; |
| 92 | + static auto &metricMessages{prometheus::BuildHistogram() |
| 93 | + .Name("lotus_vm_applyblocks_messages") |
| 94 | + .Help("Time spent applying block messages") |
| 95 | + .Register(prometheusRegistry()) |
| 96 | + .Add({}, kDefaultPrometheusMsBuckets)}; |
| 97 | + static auto &metricEarly{ |
| 98 | + prometheus::BuildHistogram() |
| 99 | + .Name("lotus_vm_applyblocks_early") |
| 100 | + .Help("Time spent in early apply-blocks (null cron, upgrades)") |
| 101 | + .Register(prometheusRegistry()) |
| 102 | + .Add({}, kDefaultPrometheusMsBuckets)}; |
| 103 | + static auto &metricCron{prometheus::BuildHistogram() |
| 104 | + .Name("lotus_vm_applyblocks_cron") |
| 105 | + .Help("Time spent in cron") |
| 106 | + .Register(prometheusRegistry()) |
| 107 | + .Add({}, kDefaultPrometheusMsBuckets)}; |
| 108 | + static auto &metricFlush{prometheus::BuildHistogram() |
| 109 | + .Name("lotus_vm_applyblocks_flush") |
| 110 | + .Help("Time spent flushing vm state") |
| 111 | + .Register(prometheusRegistry()) |
| 112 | + .Add({}, kDefaultPrometheusMsBuckets)}; |
| 113 | + |
| 114 | + bool success{false}; |
| 115 | + const Since since; |
| 116 | + std::pair<::prometheus::Histogram *, Since> last_step; |
| 117 | + auto nextStep{[&](auto metric) { |
| 118 | + if (last_step.first) { |
| 119 | + last_step.first->Observe(last_step.second.ms()); |
| 120 | + } |
| 121 | + last_step = std::make_pair(metric, Since{}); |
| 122 | + }}; |
| 123 | + auto BOOST_OUTCOME_TRY_UNIQUE_NAME{gsl::finally([&] { |
| 124 | + metricTotal.Observe(since.ms()); |
| 125 | + nextStep(nullptr); |
| 126 | + (success ? metricSuccess : metricFailure).Increment(); |
| 127 | + })}; |
| 128 | + nextStep(&metricEarly); |
| 129 | + |
73 | 130 | auto on_receipt{[&](auto &receipt) { |
74 | 131 | if (all_receipts) { |
75 | 132 | all_receipts->push_back(receipt); |
@@ -111,6 +168,8 @@ namespace fc::vm::interpreter { |
111 | 168 | env->setHeight(tipset->height()); |
112 | 169 | } |
113 | 170 |
|
| 171 | + nextStep(&metricMessages); |
| 172 | + |
114 | 173 | adt::Array<MessageReceipt> receipts{ipld}; |
115 | 174 | MessageVisitor message_visitor{ipld, true, true}; |
116 | 175 | for (const auto &block : tipset->blks) { |
@@ -147,15 +206,21 @@ namespace fc::vm::interpreter { |
147 | 206 | on_receipt(receipt); |
148 | 207 | } |
149 | 208 |
|
| 209 | + nextStep(&metricCron); |
| 210 | + |
150 | 211 | OUTCOME_TRY(cron()); |
151 | 212 |
|
| 213 | + nextStep(&metricFlush); |
| 214 | + |
152 | 215 | OUTCOME_TRY(new_state_root, env->state_tree->flush()); |
153 | 216 | OUTCOME_TRY(env->ipld->flush(new_state_root)); |
154 | 217 |
|
155 | 218 | OUTCOME_TRY(receipts.amt.flush()); |
156 | 219 |
|
157 | 220 | OUTCOME_TRY(weight, getWeight(tipset)); |
158 | 221 |
|
| 222 | + success = true; |
| 223 | + |
159 | 224 | return Result{new_state_root, receipts.amt.cid(), std::move(weight)}; |
160 | 225 | } |
161 | 226 |
|
|
0 commit comments