forked from osmosis-labs/osmosis
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat/refactor/docs(observability): epoch hook, txfees epoch, existing…
… metric clean up (osmosis-labs#7515) * feat/refactor/docs(observability): epoch hook, txfees epoch, existing metric clean up * go mod * updates * updates * format error in txfees counters * updates * updates * lint * fix * updates
- Loading branch information
Showing
21 changed files
with
393 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package observability | ||
|
||
// FormatMetricName helper to format a metric name given SDK module name and extension. | ||
func FormatMetricName(moduleName, extension string) string { | ||
return moduleName + "_" + extension | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
package concentrated_liquidity | ||
|
||
import ( | ||
"strconv" | ||
|
||
"github.com/armon/go-metrics" | ||
"github.com/cosmos/cosmos-sdk/telemetry" | ||
|
||
"github.com/osmosis-labs/osmosis/osmomath" | ||
types "github.com/osmosis-labs/osmosis/v23/x/concentrated-liquidity/types" | ||
) | ||
|
||
// emitAccumulatorUpdateTelemetry emits telemetry for accumulator updates | ||
// It detects whether an accumulator update does not occur when expected due to truncation or does occur and emits the appropriate telemetry | ||
func emitAccumulatorUpdateTelemetry(truncatedPlaceholder string, rewardsPerUnitOfLiquidity, rewardsTotal osmomath.Dec, poolID uint64, liquidityInAccum osmomath.Dec, extraKeyVals ...string) { | ||
// If truncation occurs, we emit events to alert us of the issue. | ||
if rewardsPerUnitOfLiquidity.IsZero() && !rewardsTotal.IsZero() { | ||
labels := []metrics.Label{ | ||
{ | ||
Name: "pool_id", | ||
Value: strconv.FormatUint(poolID, 10), | ||
}, | ||
{ | ||
Name: "total_liq", | ||
Value: liquidityInAccum.String(), | ||
}, | ||
{ | ||
Name: "per_unit_liq", | ||
Value: rewardsPerUnitOfLiquidity.String(), | ||
}, | ||
{ | ||
Name: "total_amt", | ||
Value: rewardsTotal.String(), | ||
}, | ||
} | ||
|
||
// Append additional labels | ||
for i := 0; i < len(extraKeyVals); i += 2 { | ||
// This might skip applying the last label pair if key or value is missing | ||
if i+1 > len(labels)-1 { | ||
break | ||
} | ||
|
||
key := extraKeyVals[i] | ||
value := extraKeyVals[i+1] | ||
|
||
labels = append(labels, metrics.Label{ | ||
Name: key, | ||
Value: value, | ||
}) | ||
} | ||
|
||
telemetry.IncrCounterWithLabels([]string{truncatedPlaceholder}, 1, labels) | ||
} | ||
} | ||
|
||
// emitIncentiveOverflowTelemetry emits telemetry for incentive overflow in intermediaty calculations | ||
func emitIncentiveOverflowTelemetry(poolID, incentiveRecordID uint64, timeElapsed, emissionRate osmomath.Dec, err error) { | ||
telemetry.IncrCounterWithLabels([]string{types.IncentiveOverflowTelemetryName}, 1, []metrics.Label{ | ||
{ | ||
Name: "pool_id", | ||
Value: strconv.FormatUint(poolID, 10), | ||
}, | ||
{ | ||
Name: "incentive_id", | ||
Value: strconv.FormatUint(incentiveRecordID, 10), | ||
}, | ||
{ | ||
Name: "time_elapsed", | ||
Value: timeElapsed.String(), | ||
}, | ||
{ | ||
Name: "emission_rate", | ||
Value: emissionRate.String(), | ||
}, | ||
{ | ||
Name: "error", | ||
Value: err.Error(), | ||
}, | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,45 @@ | ||
package types | ||
|
||
const ( | ||
IncentiveEmissionTelemetryName = "concentrated_liquidity_incentive_emission" | ||
IncentiveTruncationTelemetryName = "concentrated_liquidity_incentive_truncation" | ||
IncentiveOverflowTelemetryName = "concentrated_liquidity_incentive_overflow" | ||
import "github.com/osmosis-labs/osmosis/osmoutils/observability" | ||
|
||
SpreadRewardEmissionTelemetryName = "concentrated_liquidity_spread_reward_emission" | ||
SpreadFactorTruncationTelemetryName = "concentrated_liquidity_sptread_factor_truncation" | ||
var ( | ||
// concentrated_liquidity_incentive_truncation | ||
// | ||
// counter that is increased if the incentive accumulator update gets truncated due to division. | ||
// | ||
// Has the following labels: | ||
// * pool_id - the ID of the pool. | ||
// * total_liq - the liquidity amount in the denominator. | ||
// * per_unit_liq - the resulting rewards per unit of liquidity (zero if truncated). | ||
// * total_amt - the total reward amount before dividing by the liquidity value. | ||
IncentiveTruncationTelemetryName = formatConcentratedMetricName("incentive_truncation") | ||
// concentrated_liquidity_incentive_overflow | ||
// | ||
// counter that is increased if an intermediary math operation in the incentives flow overflows. | ||
// | ||
// Has the following labels: | ||
// * pool_id - the ID of the pool. | ||
// * incentive_id - the incentive record ID. | ||
// * time_elapsed - the time elapsed in seconds since the last pool update | ||
// * emission_rate - the emission rate per second from the incentive record. | ||
// * error - the error/panic from the failing math operation | ||
IncentiveOverflowTelemetryName = formatConcentratedMetricName("incentive_overflow") | ||
// concentrated_liquidity_sptread_factor_truncation | ||
// | ||
// counter that is increased if spread factor accumulator update gets truncated due to division by large | ||
// liquidity value. | ||
// | ||
// Has the following labels: | ||
// * pool_id - the ID of the pool. | ||
// * incentive_id - the incentive record ID. | ||
// * time_elapsed - the time elapsed in seconds since the last pool update | ||
// * emission_rate - the emission rate per second from the incentive record. | ||
// * error - the error/panic from the failing math operation | ||
// * is_out_given_in - boolean flag specifying which swap method caused the truncation. | ||
SpreadFactorTruncationTelemetryName = formatConcentratedMetricName("spread_factor_truncation") | ||
) | ||
|
||
// formatConcentratedMetricName formats the concentrated module metric name. | ||
func formatConcentratedMetricName(metricName string) string { | ||
return observability.FormatMetricName(ModuleName, metricName) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package types | ||
|
||
import "github.com/osmosis-labs/osmosis/osmoutils/observability" | ||
|
||
var ( | ||
// epoch_hook_failed | ||
// | ||
// counter that is increased if epoch hook fails | ||
// | ||
// Has the following labels: | ||
// * module_name - the name of the module that errored or panicked | ||
// * err - the error or panic returned | ||
// * is_before_hook - true if this is a before epoch hook. False otherwise. | ||
EpochHookFailedMetricName = formatEpochMetricName("hook_failed") | ||
) | ||
|
||
// formatTxFeesMetricName formats the epochs module metric name. | ||
func formatEpochMetricName(metricName string) string { | ||
return observability.FormatMetricName(ModuleName, metricName) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.