diff --git a/internal/pkg/daemon/daemon.go b/internal/pkg/daemon/daemon.go index a48d03f..6dfe4a0 100644 --- a/internal/pkg/daemon/daemon.go +++ b/internal/pkg/daemon/daemon.go @@ -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" @@ -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 // tracking current height currHeight int64 @@ -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) diff --git a/internal/pkg/daemon/daemon_test.go b/internal/pkg/daemon/daemon_test.go index 618f00e..c077987 100644 --- a/internal/pkg/daemon/daemon_test.go +++ b/internal/pkg/daemon/daemon_test.go @@ -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) diff --git a/internal/pkg/daemon/metrics.go b/internal/pkg/daemon/metrics.go index c77f2bc..2d9ce66 100644 --- a/internal/pkg/daemon/metrics.go +++ b/internal/pkg/daemon/metrics.go @@ -6,7 +6,6 @@ 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) @@ -14,7 +13,7 @@ func (d *Daemon) updateMetrics() { 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)) } } diff --git a/internal/pkg/metrics/metrics.go b/internal/pkg/metrics/metrics.go index af5846f..fe46ba1 100644 --- a/internal/pkg/metrics/metrics.go +++ b/internal/pkg/metrics/metrics.go @@ -15,7 +15,6 @@ const ( type Metrics struct { Up prometheus.Gauge - Step *prometheus.GaugeVec BlocksToUpgrade *prometheus.GaugeVec UpwErrs prometheus.Counter UiwErrs prometheus.Counter @@ -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, @@ -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) {