Skip to content

Commit

Permalink
Remove blazar_upgrade_step and export step as label in blocks_to_upgr…
Browse files Browse the repository at this point in the history
…ade_height
  • Loading branch information
sin3point14 committed Dec 12, 2024
1 parent abb6b4d commit 72a17e3
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 34 deletions.
11 changes: 7 additions & 4 deletions internal/pkg/daemon/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (
"blazar/internal/pkg/config"
"blazar/internal/pkg/cosmos"
"blazar/internal/pkg/daemon/checks"
"blazar/internal/pkg/daemon/util"
"blazar/internal/pkg/docker"
"blazar/internal/pkg/errors"
"blazar/internal/pkg/log"
Expand Down Expand Up @@ -50,7 +49,11 @@ type Daemon struct {
// initial counters
startupHeight int64
nodeAddress bytes.HexBytes
nodeInfo *tmservice.GetNodeInfoResponse

// node information
nodeInfo *tmservice.GetNodeInfoResponse
validatorAddress string
chainId string

Check warning on line 56 in internal/pkg/daemon/daemon.go

View workflow job for this annotation

GitHub Actions / lint

var-naming: struct field chainId should be chainID (revive)

// tracking current height
currHeight int64
Expand Down Expand Up @@ -132,8 +135,8 @@ func (d *Daemon) Init(ctx context.Context, cfg *config.Config, version string) e
return errors.Wrapf(err, "failed to get status response")
}

hostname := util.GetHostname()
d.metrics.RegisterValidatorInfoMetrics(cfg.ComposeFile, hostname, version, status.NodeInfo.Network, status.ValidatorInfo.Address.String())
d.chainId = status.NodeInfo.Network
d.validatorAddress = status.ValidatorInfo.Address.String()

// display information about the node
d.nodeInfo, err = d.cosmosClient.NodeInfo(ctx)
Expand Down
1 change: 0 additions & 1 deletion internal/pkg/daemon/daemon_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ func TestIntegrationDaemon(t *testing.T) {

// we can't register 2 metrics, but this sharing this should probably cause no problems
metrics := metrics.NewMetrics("/path/to/docker-compose.yml", "dummy", "test")
metrics.RegisterValidatorInfoMetrics("/path/to/docker-compose.yml", "dummy", "test", "test-chain-id", "AABBCCDD")

ports := getFreePorts(t, 6)

Expand Down
5 changes: 2 additions & 3 deletions internal/pkg/daemon/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,14 @@ import (

func (d *Daemon) updateMetrics() {
// the upgrade state may change, we don't want to persist the metric with the old status
d.metrics.Step.Reset()
d.metrics.BlocksToUpgrade.Reset()

upcomingUpgrades := d.ur.GetUpcomingUpgradesWithCache(d.currHeight)
for _, upgrade := range upcomingUpgrades {
upgradeHeight := strconv.FormatInt(upgrade.Height, 10)
status := d.stateMachine.GetStatus(upgrade.Height)

d.metrics.Step.WithLabelValues(upgradeHeight, upgrade.Name, status.String()).Set(float64(d.stateMachine.GetStep(upgrade.Height)))
d.metrics.BlocksToUpgrade.WithLabelValues(upgradeHeight, upgrade.Name, status.String()).Set(float64(upgrade.Height - d.currHeight))
d.metrics.BlocksToUpgrade.WithLabelValues(upgradeHeight, upgrade.Name, status.String(),
d.stateMachine.GetStep(upgrade.Height).String(), d.chainId, d.validatorAddress).Set(float64(upgrade.Height - d.currHeight))
}
}
35 changes: 9 additions & 26 deletions internal/pkg/metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ const (

type Metrics struct {
Up prometheus.Gauge
Step *prometheus.GaugeVec
BlocksToUpgrade *prometheus.GaugeVec
UpwErrs prometheus.Counter
UiwErrs prometheus.Counter
Expand All @@ -35,9 +34,15 @@ func NewMetrics(composeFile, hostname, version string) *Metrics {
ConstLabels: labels,
},
),
// Filled by RegisterValidatorInfoMetrics
Step: nil,
BlocksToUpgrade: nil,
BlocksToUpgrade: promauto.NewGaugeVec(
prometheus.GaugeOpts{
Namespace: namespace,
Name: "blocks_to_upgrade_height",
Help: "Number of blocks to the upgrade height",
ConstLabels: labels,
},
[]string{"upgrade_height", "upgrade_name", "upgrade_status", "upgrade_step", "chain_id", "validator_address"},
),
UpwErrs: promauto.NewCounter(
prometheus.CounterOpts{
Namespace: namespace,
Expand Down Expand Up @@ -75,28 +80,6 @@ func NewMetrics(composeFile, hostname, version string) *Metrics {
return metrics
}

func (m *Metrics) RegisterValidatorInfoMetrics(composeFile, hostname, version, chain_id, validator_address string) {
labels := prometheus.Labels{"hostname": hostname, "compose_file": composeFile, "version": version, "chain_id": chain_id, "validator_address": validator_address}
m.Step = promauto.NewGaugeVec(
prometheus.GaugeOpts{
Namespace: namespace,
Name: "upgrade_step",
Help: "ID of the current step of the upgrade process",
ConstLabels: labels,
},
[]string{"upgrade_height", "upgrade_name", "upgrade_status"},
)
m.BlocksToUpgrade = promauto.NewGaugeVec(
prometheus.GaugeOpts{
Namespace: namespace,
Name: "blocks_to_upgrade_height",
Help: "Number of blocks to the upgrade height",
ConstLabels: labels,
},
[]string{"upgrade_height", "upgrade_name", "upgrade_status"},
)
}

func RegisterHandler(mux *runtime.ServeMux) error {
handler := promhttp.Handler()
return mux.HandlePath("GET", "/metrics", func(w http.ResponseWriter, r *http.Request, _ map[string]string) {
Expand Down

0 comments on commit 72a17e3

Please sign in to comment.