diff --git a/cmd/run.go b/cmd/run.go index 0fedf3b..60a1b49 100644 --- a/cmd/run.go +++ b/cmd/run.go @@ -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) diff --git a/internal/pkg/daemon/daemon.go b/internal/pkg/daemon/daemon.go index 9ecdfde..04cf58b 100644 --- a/internal/pkg/daemon/daemon.go +++ b/internal/pkg/daemon/daemon.go @@ -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 @@ -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 { diff --git a/internal/pkg/daemon/daemon_test.go b/internal/pkg/daemon/daemon_test.go index cd773e1..c077987 100644 --- a/internal/pkg/daemon/daemon_test.go +++ b/internal/pkg/daemon/daemon_test.go @@ -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) diff --git a/internal/pkg/daemon/metrics.go b/internal/pkg/daemon/metrics.go index c77f2bc..efdb615 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 1525c73..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 @@ -23,7 +22,7 @@ type Metrics struct { 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{ @@ -35,15 +34,6 @@ 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, @@ -51,7 +41,7 @@ func NewMetrics(composeFile string, hostname string, version string) (*Metrics, 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{ @@ -87,7 +77,7 @@ func NewMetrics(composeFile string, hostname string, version string) (*Metrics, ), } - return metrics, nil + return metrics } func RegisterHandler(mux *runtime.ServeMux) error {