Skip to content

Commit

Permalink
chore: removed .Active from metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
freak12techno committed Jun 12, 2024
1 parent 56b3d2d commit d625f2f
Show file tree
Hide file tree
Showing 11 changed files with 100 additions and 100 deletions.
67 changes: 33 additions & 34 deletions pkg/metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -374,93 +374,92 @@ func (m *Manager) LogNodeReconnect(chain string, node string) {

func (m *Manager) LogValidatorStats(
chain *configPkg.ChainConfig,
validator *types.Validator,
signatureInfo types.SignatureInto,
entry types.Entry,
) {
m.missingBlocksGauge.
With(prometheus.Labels{
"chain": chain.Name,
"moniker": validator.Moniker,
"address": validator.OperatorAddress,
"moniker": entry.Validator.Moniker,
"address": entry.Validator.OperatorAddress,
}).
Set(float64(signatureInfo.GetNotSigned()))
Set(float64(entry.SignatureInfo.GetNotSigned()))

m.activeBlocksGauge.
With(prometheus.Labels{
"chain": chain.Name,
"moniker": validator.Moniker,
"address": validator.OperatorAddress,
"moniker": entry.Validator.Moniker,
"address": entry.Validator.OperatorAddress,
}).
Set(float64(signatureInfo.Active))
Set(float64(entry.SignatureInfo.Active))

m.isActiveGauge.
With(prometheus.Labels{
"chain": chain.Name,
"moniker": validator.Moniker,
"address": validator.OperatorAddress,
"moniker": entry.Validator.Moniker,
"address": entry.Validator.OperatorAddress,
}).
Set(utils.BoolToFloat64(validator.Active()))
Set(utils.BoolToFloat64(entry.IsActive))

m.isJailedGauge.
With(prometheus.Labels{
"chain": chain.Name,
"moniker": validator.Moniker,
"address": validator.OperatorAddress,
"moniker": entry.Validator.Moniker,
"address": entry.Validator.OperatorAddress,
}).
Set(utils.BoolToFloat64(validator.Jailed))
Set(utils.BoolToFloat64(entry.Validator.Jailed))

m.missingBlocksGauge.
With(prometheus.Labels{
"chain": chain.Name,
"moniker": validator.Moniker,
"address": validator.OperatorAddress,
"moniker": entry.Validator.Moniker,
"address": entry.Validator.OperatorAddress,
}).
Set(float64(signatureInfo.GetNotSigned()))
Set(float64(entry.SignatureInfo.GetNotSigned()))

if validator.SigningInfo != nil {
if entry.Validator.SigningInfo != nil {
m.isTombstonedGauge.
With(prometheus.Labels{
"chain": chain.Name,
"moniker": validator.Moniker,
"address": validator.OperatorAddress,
"moniker": entry.Validator.Moniker,
"address": entry.Validator.OperatorAddress,

Check warning on line 424 in pkg/metrics/metrics.go

View check run for this annotation

Codecov / codecov/patch

pkg/metrics/metrics.go#L423-L424

Added lines #L423 - L424 were not covered by tests
}).
Set(utils.BoolToFloat64(validator.SigningInfo.Tombstoned))
Set(utils.BoolToFloat64(entry.Validator.SigningInfo.Tombstoned))

Check warning on line 426 in pkg/metrics/metrics.go

View check run for this annotation

Codecov / codecov/patch

pkg/metrics/metrics.go#L426

Added line #L426 was not covered by tests
}

if validator.Active() {
if entry.IsActive {
if chain.IsConsumer.Bool {
m.needsToSignGauge.
With(prometheus.Labels{
"chain": chain.Name,
"moniker": validator.Moniker,
"address": validator.OperatorAddress,
"moniker": entry.Validator.Moniker,
"address": entry.Validator.OperatorAddress,

Check warning on line 435 in pkg/metrics/metrics.go

View check run for this annotation

Codecov / codecov/patch

pkg/metrics/metrics.go#L434-L435

Added lines #L434 - L435 were not covered by tests
}).
Set(utils.BoolToFloat64(validator.NeedsToSign))
Set(utils.BoolToFloat64(entry.Validator.NeedsToSign))

Check warning on line 437 in pkg/metrics/metrics.go

View check run for this annotation

Codecov / codecov/patch

pkg/metrics/metrics.go#L437

Added line #L437 was not covered by tests
}

m.votingPowerGauge.
With(prometheus.Labels{
"chain": chain.Name,
"moniker": validator.Moniker,
"address": validator.OperatorAddress,
"moniker": entry.Validator.Moniker,
"address": entry.Validator.OperatorAddress,

Check warning on line 444 in pkg/metrics/metrics.go

View check run for this annotation

Codecov / codecov/patch

pkg/metrics/metrics.go#L443-L444

Added lines #L443 - L444 were not covered by tests
}).
Set(validator.VotingPowerPercent)
Set(entry.Validator.VotingPowerPercent)

Check warning on line 446 in pkg/metrics/metrics.go

View check run for this annotation

Codecov / codecov/patch

pkg/metrics/metrics.go#L446

Added line #L446 was not covered by tests

m.cumulativeVotingPowerGauge.
With(prometheus.Labels{
"chain": chain.Name,
"moniker": validator.Moniker,
"address": validator.OperatorAddress,
"moniker": entry.Validator.Moniker,
"address": entry.Validator.OperatorAddress,

Check warning on line 452 in pkg/metrics/metrics.go

View check run for this annotation

Codecov / codecov/patch

pkg/metrics/metrics.go#L451-L452

Added lines #L451 - L452 were not covered by tests
}).
Set(validator.CumulativeVotingPowerPercent)
Set(entry.Validator.CumulativeVotingPowerPercent)

Check warning on line 454 in pkg/metrics/metrics.go

View check run for this annotation

Codecov / codecov/patch

pkg/metrics/metrics.go#L454

Added line #L454 was not covered by tests

m.validatorRankGauge.
With(prometheus.Labels{
"chain": chain.Name,
"moniker": validator.Moniker,
"address": validator.OperatorAddress,
"moniker": entry.Validator.Moniker,
"address": entry.Validator.OperatorAddress,

Check warning on line 460 in pkg/metrics/metrics.go

View check run for this annotation

Codecov / codecov/patch

pkg/metrics/metrics.go#L459-L460

Added lines #L459 - L460 were not covered by tests
}).
Set(float64(validator.Rank))
Set(float64(entry.Validator.Rank))

Check warning on line 462 in pkg/metrics/metrics.go

View check run for this annotation

Codecov / codecov/patch

pkg/metrics/metrics.go#L462

Added line #L462 was not covered by tests
}
}

Expand Down
6 changes: 3 additions & 3 deletions pkg/reporters/discord/missing.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package discord
import (
"fmt"
"main/pkg/constants"
snapshotPkg "main/pkg/snapshot"
"main/pkg/types"
"main/pkg/utils"
"sort"

Expand All @@ -28,7 +28,7 @@ func (reporter *Reporter) GetMissingCommand() *Command {
}

validatorEntries := snapshot.Entries.ToSlice()
activeValidatorsEntries := utils.Filter(validatorEntries, func(v snapshotPkg.Entry) bool {
activeValidatorsEntries := utils.Filter(validatorEntries, func(v types.Entry) bool {
if !v.IsActive {

Check warning on line 32 in pkg/reporters/discord/missing.go

View check run for this annotation

Codecov / codecov/patch

pkg/reporters/discord/missing.go#L31-L32

Added lines #L31 - L32 were not covered by tests
return false
}
Expand All @@ -46,7 +46,7 @@ func (reporter *Reporter) GetMissingCommand() *Command {

render := missingValidatorsRender{
Config: reporter.Config,
Validators: utils.Map(activeValidatorsEntries, func(v snapshotPkg.Entry) missingValidatorsEntry {
Validators: utils.Map(activeValidatorsEntries, func(v types.Entry) missingValidatorsEntry {

Check warning on line 49 in pkg/reporters/discord/missing.go

View check run for this annotation

Codecov / codecov/patch

pkg/reporters/discord/missing.go#L49

Added line #L49 was not covered by tests
link := reporter.Config.ExplorerConfig.GetValidatorLink(v.Validator)
group, _, _ := reporter.Config.MissedBlocksGroups.GetGroup(v.SignatureInfo.GetNotSigned())
link.Text = fmt.Sprintf("%s %s", group.EmojiEnd, v.Validator.Moniker)
Expand Down
6 changes: 3 additions & 3 deletions pkg/reporters/discord/validators.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package discord
import (
"fmt"
"main/pkg/constants"
snapshotPkg "main/pkg/snapshot"
"main/pkg/types"
"main/pkg/utils"
"sort"

Expand All @@ -28,7 +28,7 @@ func (reporter *Reporter) GetValidatorsCommand() *Command {
}

validatorEntries := snapshot.Entries.ToSlice()
activeValidatorsEntries := utils.Filter(validatorEntries, func(v snapshotPkg.Entry) bool {
activeValidatorsEntries := utils.Filter(validatorEntries, func(v types.Entry) bool {
return v.IsActive

Check warning on line 32 in pkg/reporters/discord/validators.go

View check run for this annotation

Codecov / codecov/patch

pkg/reporters/discord/validators.go#L31-L32

Added lines #L31 - L32 were not covered by tests
})

Expand All @@ -41,7 +41,7 @@ func (reporter *Reporter) GetValidatorsCommand() *Command {

render := missingValidatorsRender{
Config: reporter.Config,
Validators: utils.Map(activeValidatorsEntries, func(v snapshotPkg.Entry) missingValidatorsEntry {
Validators: utils.Map(activeValidatorsEntries, func(v types.Entry) missingValidatorsEntry {

Check warning on line 44 in pkg/reporters/discord/validators.go

View check run for this annotation

Codecov / codecov/patch

pkg/reporters/discord/validators.go#L44

Added line #L44 was not covered by tests
link := reporter.Config.ExplorerConfig.GetValidatorLink(v.Validator)
group, _, _ := reporter.Config.MissedBlocksGroups.GetGroup(v.SignatureInfo.GetNotSigned())
link.Text = fmt.Sprintf("%s %s", group.EmojiEnd, v.Validator.Moniker)
Expand Down
6 changes: 3 additions & 3 deletions pkg/reporters/telegram/missing.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package telegram
import (
"fmt"
"main/pkg/constants"
snapshotPkg "main/pkg/snapshot"
"main/pkg/types"
"main/pkg/utils"
"sort"

Expand All @@ -28,7 +28,7 @@ func (reporter *Reporter) HandleMissingValidators(c tele.Context) error {
}

validatorEntries := snapshot.Entries.ToSlice()
activeValidatorsEntries := utils.Filter(validatorEntries, func(v snapshotPkg.Entry) bool {
activeValidatorsEntries := utils.Filter(validatorEntries, func(v types.Entry) bool {
if !v.IsActive {

Check warning on line 32 in pkg/reporters/telegram/missing.go

View check run for this annotation

Codecov / codecov/patch

pkg/reporters/telegram/missing.go#L31-L32

Added lines #L31 - L32 were not covered by tests
return false
}
Expand All @@ -46,7 +46,7 @@ func (reporter *Reporter) HandleMissingValidators(c tele.Context) error {

render := missingValidatorsRender{
Config: reporter.Config,
Validators: utils.Map(activeValidatorsEntries, func(v snapshotPkg.Entry) missingValidatorsEntry {
Validators: utils.Map(activeValidatorsEntries, func(v types.Entry) missingValidatorsEntry {

Check warning on line 49 in pkg/reporters/telegram/missing.go

View check run for this annotation

Codecov / codecov/patch

pkg/reporters/telegram/missing.go#L49

Added line #L49 was not covered by tests
link := reporter.Config.ExplorerConfig.GetValidatorLink(v.Validator)
group, _, _ := reporter.Config.MissedBlocksGroups.GetGroup(v.SignatureInfo.GetNotSigned())
link.Text = fmt.Sprintf("%s %s", group.EmojiEnd, v.Validator.Moniker)
Expand Down
6 changes: 3 additions & 3 deletions pkg/reporters/telegram/validators.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package telegram
import (
"fmt"
"main/pkg/constants"
snapshotPkg "main/pkg/snapshot"
"main/pkg/types"
"main/pkg/utils"
"sort"

Expand All @@ -28,7 +28,7 @@ func (reporter *Reporter) HandleListValidators(c tele.Context) error {
}

validatorEntries := snapshot.Entries.ToSlice()
activeValidatorsEntries := utils.Filter(validatorEntries, func(v snapshotPkg.Entry) bool {
activeValidatorsEntries := utils.Filter(validatorEntries, func(v types.Entry) bool {
return v.IsActive

Check warning on line 32 in pkg/reporters/telegram/validators.go

View check run for this annotation

Codecov / codecov/patch

pkg/reporters/telegram/validators.go#L31-L32

Added lines #L31 - L32 were not covered by tests
})

Expand All @@ -41,7 +41,7 @@ func (reporter *Reporter) HandleListValidators(c tele.Context) error {

render := missingValidatorsRender{
Config: reporter.Config,
Validators: utils.Map(activeValidatorsEntries, func(v snapshotPkg.Entry) missingValidatorsEntry {
Validators: utils.Map(activeValidatorsEntries, func(v types.Entry) missingValidatorsEntry {

Check warning on line 44 in pkg/reporters/telegram/validators.go

View check run for this annotation

Codecov / codecov/patch

pkg/reporters/telegram/validators.go#L44

Added line #L44 was not covered by tests
link := reporter.Config.ExplorerConfig.GetValidatorLink(v.Validator)
group, _, _ := reporter.Config.MissedBlocksGroups.GetGroup(v.SignatureInfo.GetNotSigned())
link.Text = fmt.Sprintf("%s %s", group.EmojiEnd, v.Validator.Moniker)
Expand Down
2 changes: 1 addition & 1 deletion pkg/snapshot/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func (m *Manager) CommitNewSnapshot(height int64, snapshot Snapshot) {
}

for _, entry := range snapshot.Entries {
m.metricsManager.LogValidatorStats(m.config, entry.Validator, entry.SignatureInfo)
m.metricsManager.LogValidatorStats(m.config, entry)
}
}

Expand Down
6 changes: 3 additions & 3 deletions pkg/snapshot/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@ func TestManagerCommitNewSnapshot(t *testing.T) {
manager := NewManager(*log, config, metricsManager)

manager.CommitNewSnapshot(10, Snapshot{
Entries: map[string]Entry{
Entries: map[string]types.Entry{
"validator": {Validator: &types.Validator{}},
},
})
manager.CommitNewSnapshot(20, Snapshot{
Entries: map[string]Entry{
Entries: map[string]types.Entry{
"validator": {Validator: &types.Validator{}},
},
})
Expand Down Expand Up @@ -77,7 +77,7 @@ func TestManagerGetNewerSnapshot(t *testing.T) {
assert.Nil(t, firstSnapshot, "Snapshot should not be presented!")

manager.CommitNewSnapshot(20, Snapshot{
Entries: map[string]Entry{
Entries: map[string]types.Entry{
"validator": {Validator: &types.Validator{}},
},
})
Expand Down
12 changes: 3 additions & 9 deletions pkg/snapshot/snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,10 @@ import (
"golang.org/x/exp/slices"
)

type Entry struct {
IsActive bool
Validator *types.Validator
SignatureInfo types.SignatureInto
}

type Entries map[string]Entry
type Entries map[string]types.Entry

func (e Entries) ToSlice() []Entry {
entries := make([]Entry, len(e))
func (e Entries) ToSlice() []types.Entry {
entries := make([]types.Entry, len(e))

index := 0
for _, entry := range e {
Expand Down
Loading

0 comments on commit d625f2f

Please sign in to comment.