Skip to content

Commit ed380e0

Browse files
xmariachiamimart
authored andcommitted
Mint module metrics + refactor on metric names (#819)
<!-- < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < ☺ v ✰ Thanks for creating a PR! You're awesome! ✰ v Please note that maintainers will only review those PRs with a completed PR template. ☺ > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > --> ## Purpose of Changes and their Description * Add mint metrics on events ## Are these changes tested and documented? - [x] If tested, please describe how. If not, why tests are not needed. -- unit and integration tests - [x] If documented, please describe where. If not, describe why docs are not needed. -- fixed docs on module `README`s - [x] Added to `Unreleased` section of `CHANGELOG.md`? --------- Signed-off-by: Diego C <xmariachi@gmail.com> Co-authored-by: Arnaud Mimart <33665250+amimart@users.noreply.github.com>
1 parent e4d0886 commit ed380e0

8 files changed

Lines changed: 59 additions & 29 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7070
### Added
7171
* [#781](https://github.com/allora-network/allora-chain/pull/781) Enable pebbledb
7272
* [#818](https://github.com/allora-network/allora-chain/pull/818) Emit new `EventNetworkInferences` event when closing worker nonce
73+
* [#819](https://github.com/allora-network/allora-chain/pull/819) Mint module metrics + refactor on metric names
7374

7475
### Changed
7576
* [#815](https://github.com/allora-network/allora-chain/pull/815) Refund ecosystem account when invalid topic to reward

x/emissions/README.md

Lines changed: 14 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,21 @@
11
Emissions Module
22
=============================================
33

4-
## Dependencies
4+
The `emissions` module is a core component of the Allora Network that manages the topic definition, actor participation, economic incentives, rewards system and more. This is the main part of the implementation of the [Allora Whitepaper](https://research.assets.allora.network/allora.0x10001.pdf).
55

6-
golang v1.21+
7-
GNU make
8-
docker
6+
Key Features:
7+
- Topic Management: Creation and management of prediction topics
8+
- Stake Management: Handling of stakes for workers and reputers
9+
- Reward Distribution: Calculation and distribution of rewards based on performance
10+
- Delegation System: Support for stake delegation to reputers
11+
- Performance Metrics: Tracking of worker, reputer, and forecaster scores
12+
- Fee Collection: Management of network fees and revenue distribution
913

10-
## Build
11-
```bash
12-
# get deps
13-
go mod tidy
1414

15-
# rebuild the autogenerated protobuf files
16-
make proto-all
15+
## Monitoring
1716

18-
# build the module, making sure the source compiles
19-
make
20-
```
21-
22-
Then somewhere else you have a minimal-chain running:
23-
```bash
24-
cd ../minimal-chain
25-
go mod tidy
26-
make install
27-
make init
28-
allorad start
29-
```
17+
Allora node emits its own `emissions` module metrics in each event, query and tx.
18+
event: `allora_emissions_event_total`
19+
query/tx: `allora_emissions_request_total` for occurrences, `allora_emissions_request_duration_ms` for latency measures.
20+
Different labels are applied where appropriate (eg "topic_id", "address", "nonce", etc.)
21+
See `x/emissions/metrics/` for details.

x/emissions/metrics/metrics_util.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ import (
1313
// Measures RPC endpoint request throughput
1414
// Metric Name:
1515
//
16-
// allora_rpc_request_counter
16+
// allora_emissions_request_counter
1717
func IncrementRpcRequestCounter(endpoint string, err *error) {
1818
success := *err == nil
1919
telemetry.IncrCounterWithLabels(
20-
[]string{"allora", "request", "counter"},
20+
[]string{"allora", "emissions", "request", "counter"},
2121
float32(1),
2222
[]metrics.Label{
2323
telemetry.NewLabel("endpoint", endpoint),
@@ -29,10 +29,10 @@ func IncrementRpcRequestCounter(endpoint string, err *error) {
2929
// Measures the RPC request latency in milliseconds
3030
// Metric Name:
3131
//
32-
// allora_rpc_request_latency_ms
32+
// allora_request_duration_ms
3333
func MeasureRpcRequestLatency(endpoint string, startTime time.Time) {
3434
metrics.MeasureSinceWithLabels(
35-
[]string{"allora", "request", "latency_ms"},
35+
[]string{"allora", "emissions", "request", "duration_ms"},
3636
startTime.UTC(),
3737
[]metrics.Label{
3838
telemetry.NewLabel("endpoint", endpoint),
@@ -44,10 +44,10 @@ func MeasureRpcRequestLatency(endpoint string, startTime time.Time) {
4444
// This metric counts the number of events produced by the system.
4545
// Metric Name:
4646
//
47-
// allora_loadtest_produce_count
47+
// allora_emissions_produce_count
4848
func IncrProducerEventCount(msgType string) {
4949
telemetry.IncrCounterWithLabels(
50-
[]string{"allora", "loadtest", "produce", "count"},
50+
[]string{"allora", "emissions", "event", "total"},
5151
1,
5252
[]metrics.Label{telemetry.NewLabel("msg_type", msgType)},
5353
)

x/emissions/module/autocli.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -492,7 +492,7 @@ func (am AppModule) AutoCLIOptions() *autocliv1.ModuleOptions {
492492
{
493493
RpcMethod: "GetWorkerLatestInferenceByTopicId",
494494
Use: "worker-latest-inference [topic_id] [worker_address]",
495-
Short: "Get the latest inference for a given worker and topic",
495+
Short: "Get the latest inference for a given worker and topic within a worker submission window",
496496
PositionalArgs: []*autocliv1.PositionalArgDescriptor{
497497
{ProtoField: "topic_id"},
498498
{ProtoField: "worker_address"},

x/mint/README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Mint Module
2+
=============================================
3+
4+
The `mint` module is based on the `x/mint` module, modified to implement allora-specific tokenomics.

x/mint/metrics/labels.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package metrics
2+
3+
//nolint:gosec // These are event labels, not credentials
4+
const (
5+
TOKENOMICS_SET_EVENT = "tokenomics_set_event"
6+
ECOSYSTEM_TOKEN_MINT_SET_EVENT = "ecosystem_token_mint_set_event"
7+
REWARD_CURRENT_BLOCK_EMISSION_EVENT = "reward_current_block_emission_event"
8+
)

x/mint/metrics/metrics_util.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// This is copied from the sei-chain
2+
// source: https://github.com/sei-protocol/sei-chain/blob/main/utils/metrics/metrics_util.go
3+
package metrics
4+
5+
import (
6+
"github.com/cosmos/cosmos-sdk/telemetry"
7+
metrics "github.com/hashicorp/go-metrics"
8+
)
9+
10+
// IncrProducerEventCount increments the counter for events produced.
11+
// This metric counts the number of events produced by the system.
12+
// Metric Name:
13+
//
14+
// allora_mint_produce_count
15+
func IncrProducerEventCount(msgType string) {
16+
telemetry.IncrCounterWithLabels(
17+
[]string{"allora", "mint", "event", "total"},
18+
1,
19+
[]metrics.Label{telemetry.NewLabel("msg_type", msgType)},
20+
)
21+
}

x/mint/types/events.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@ package types
22

33
import (
44
"cosmossdk.io/math"
5+
metrics "github.com/allora-network/allora-chain/x/mint/metrics"
56
sdk "github.com/cosmos/cosmos-sdk/types"
67
"github.com/cosmos/gogoproto/proto"
78
)
89

910
func EmitNewTokenomicsSetEvent(ctx sdk.Context, stakedTokenAmount, circulatingAmount, emissionsAmount math.Int) {
11+
metrics.IncrProducerEventCount(metrics.TOKENOMICS_SET_EVENT)
1012
err := ctx.EventManager().EmitTypedEvent(NewTokenomicsSetEventBase(stakedTokenAmount, circulatingAmount, emissionsAmount))
1113
if err != nil {
1214
ctx.Logger().Warn("Error emitting EmitNewTokenomicsSetEvent", "error", err)
@@ -22,6 +24,7 @@ func NewTokenomicsSetEventBase(stakedTokenAmount, circulatingAmount, emissionsAm
2224
}
2325

2426
func EmitNewEcosystemTokenMintSetEvent(ctx sdk.Context, blockHeight uint64, amount math.Int) {
27+
metrics.IncrProducerEventCount(metrics.ECOSYSTEM_TOKEN_MINT_SET_EVENT)
2528
err := ctx.EventManager().EmitTypedEvent(EcosystemTokenMintSetEventBase(blockHeight, amount))
2629
if err != nil {
2730
ctx.Logger().Warn("Error emitting EmitNewEcosystemTokenMintSetEvent", "error", err)
@@ -36,6 +39,7 @@ func EcosystemTokenMintSetEventBase(blockHeight uint64, tokenAmount math.Int) pr
3639
}
3740

3841
func EmitNewRewardCurrentBlockEmissionEvent(ctx sdk.Context, blockHeight uint64, amount math.Int) {
42+
metrics.IncrProducerEventCount(metrics.REWARD_CURRENT_BLOCK_EMISSION_EVENT)
3943
err := ctx.EventManager().EmitTypedEvent(RewardCurrentBlockEmissionEventBase(blockHeight, amount))
4044
if err != nil {
4145
ctx.Logger().Warn("Error emitting EmitNewRewardCurrentBlockEmissionEvent", "error", err)

0 commit comments

Comments
 (0)