Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove blazar_upgrade_step metric and add validator_address, chain_id labels to blazar_blocks_to_upgrade_height #27

Merged
merged 6 commits into from
Dec 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,7 @@ var runCmd = &cobra.Command{

// setup metrics
hostname := util.GetHostname()
metrics, err := metrics.NewMetrics(cfg.ComposeFile, hostname, BinVersion)
if err != nil {
return errors.Wrapf(err, "error creating metrics server")
}
metrics := metrics.NewMetrics(cfg.ComposeFile, hostname, BinVersion)

// setup notifier
notifier := notification.NewFallbackNotifier(cfg, metrics, lg, hostname)
Expand Down
11 changes: 9 additions & 2 deletions internal/pkg/daemon/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,12 @@ type Daemon struct {

// initial counters
startupHeight int64
nodeAddress bytes.HexBytes
nodeInfo *tmservice.GetNodeInfoResponse

// node information
nodeAddress bytes.HexBytes
nodeInfo *tmservice.GetNodeInfoResponse
validatorAddress string
chainID string

// tracking current height
currHeight int64
Expand Down Expand Up @@ -131,6 +135,9 @@ func (d *Daemon) Init(ctx context.Context, cfg *config.Config) error {
return errors.Wrapf(err, "failed to get status response")
}

d.chainID = status.NodeInfo.Network
d.validatorAddress = status.ValidatorInfo.Address.String()

// display information about the node
d.nodeInfo, err = d.cosmosClient.NodeInfo(ctx)
if err != nil {
Expand Down
3 changes: 1 addition & 2 deletions internal/pkg/daemon/daemon_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,7 @@ func TestIntegrationDaemon(t *testing.T) {
}()

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

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))
}
}
16 changes: 3 additions & 13 deletions internal/pkg/metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,14 @@ const (

type Metrics struct {
Up prometheus.Gauge
Step *prometheus.GaugeVec
BlocksToUpgrade *prometheus.GaugeVec
UpwErrs prometheus.Counter
UiwErrs prometheus.Counter
HwErrs prometheus.Counter
NotifErrs prometheus.Counter
}

func NewMetrics(composeFile string, hostname string, version string) (*Metrics, error) {
func NewMetrics(composeFile, hostname, version string) *Metrics {
labels := prometheus.Labels{"hostname": hostname, "compose_file": composeFile, "version": version}

metrics := &Metrics{
Expand All @@ -35,23 +34,14 @@ func NewMetrics(composeFile string, hostname string, version string) (*Metrics,
ConstLabels: labels,
},
),
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"},
),
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"},
[]string{"upgrade_height", "upgrade_name", "upgrade_status", "upgrade_step", "chain_id", "validator_address"},
),
UpwErrs: promauto.NewCounter(
prometheus.CounterOpts{
Expand Down Expand Up @@ -87,7 +77,7 @@ func NewMetrics(composeFile string, hostname string, version string) (*Metrics,
),
}

return metrics, nil
return metrics
}

func RegisterHandler(mux *runtime.ServeMux) error {
Expand Down
Loading