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

pkg/services: add ver & sha params to HealthChecker #265

Merged
merged 1 commit into from
Nov 30, 2023
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
2 changes: 1 addition & 1 deletion pkg/loop/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func (s *Server) start() error {
return fmt.Errorf("error starting prometheus server: %w", err)
}

s.checker = services.NewChecker()
s.checker = services.NewChecker("", "")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where would we expect NewChecker to be called with non-empty string values for ver and sha?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, my bad - didn't see smartcontractkit/chainlink#11432

if err := s.checker.Start(); err != nil {
return fmt.Errorf("error starting health checker: %w", err)
}
Expand Down
27 changes: 19 additions & 8 deletions pkg/services/health.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ type HealthChecker struct {
chStop chan struct{}
chDone chan struct{}

ver, sha string

servicesMu sync.RWMutex
services map[string]HealthReporter

Expand Down Expand Up @@ -70,8 +72,23 @@ var (
)
)

func NewChecker() *HealthChecker {
func NewChecker(ver, sha string) *HealthChecker {
if ver == "" || sha == "" {
if bi, ok := debug.ReadBuildInfo(); ok {
if ver == "" {
ver = bi.Main.Version
}
if sha == "" {
sha = bi.Main.Sum
}
}
}
if len(sha) > 7 {
sha = sha[:7]
}
return &HealthChecker{
ver: ver,
sha: sha,
services: make(map[string]HealthReporter, 10),
healthy: make(map[string]error, 10),
ready: make(map[string]error, 10),
Expand All @@ -82,13 +99,7 @@ func NewChecker() *HealthChecker {

func (c *HealthChecker) Start() error {
return c.StartOnce("HealthCheck", func() error {
if bi, ok := debug.ReadBuildInfo(); ok {
hash := bi.Main.Sum
if len(hash) > 7 {
hash = hash[:7]
}
version.WithLabelValues(bi.Main.Version, hash).Inc()
}
version.WithLabelValues(c.ver, c.sha).Inc()

// update immediately
c.update()
Expand Down
Loading