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

prober: Remove spam of changing probe status #5051

Merged
merged 4 commits into from
Jan 12, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ We use *breaking :warning:* to mark changes that are not backward compatible (re

### Fixed

- [#5051](https://github.com/thanos-io/thanos/pull/5051) Prober: Remove spam of changing probe status.
- [#4918](https://github.com/thanos-io/thanos/pull/4918) Tracing: Fixing force tracing with Jaeger.
- [#4879](https://github.com/thanos-io/thanos/pull/4879) Bucket verify: Fixed bug causing wrong number of blocks to be checked.
- [#4908](https://github.com/thanos-io/thanos/pull/4908) UI: Show 'minus' icon and add tooltip when store min / max time is not available.
Expand Down
35 changes: 25 additions & 10 deletions pkg/prober/intrumentation.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
package prober

import (
"sync"

"github.com/go-kit/log"
"github.com/go-kit/log/level"
"github.com/prometheus/client_golang/prometheus"
Expand All @@ -13,8 +15,9 @@ import (
)

const (
ready = "ready"
healthy = "healthy"
ready = "ready"
notReady = "not-ready"
GiedriusS marked this conversation as resolved.
Show resolved Hide resolved
healthy = "healthy"
)

// InstrumentationProbe stores instrumentation state of Probe.
Expand All @@ -23,15 +26,17 @@ type InstrumentationProbe struct {
component component.Component
logger log.Logger

status *prometheus.GaugeVec
statusMetric *prometheus.GaugeVec
mu sync.Mutex
statusString string
}

// NewInstrumentation returns InstrumentationProbe records readiness and healthiness for given component.
func NewInstrumentation(component component.Component, logger log.Logger, reg prometheus.Registerer) *InstrumentationProbe {
p := InstrumentationProbe{
component: component,
logger: logger,
status: promauto.With(reg).NewGaugeVec(prometheus.GaugeOpts{
statusMetric: promauto.With(reg).NewGaugeVec(prometheus.GaugeOpts{
Name: "status",
Help: "Represents status (0 indicates failure, 1 indicates success) of the component.",
ConstLabels: map[string]string{"component": component.String()},
Expand All @@ -44,24 +49,34 @@ func NewInstrumentation(component component.Component, logger log.Logger, reg pr

// Ready records the component status when Ready is called, if combined with other Probes.
func (p *InstrumentationProbe) Ready() {
p.status.WithLabelValues(ready).Set(1)
level.Info(p.logger).Log("msg", "changing probe status", "status", "ready")
p.statusMetric.WithLabelValues(ready).Set(1)
p.mu.Lock()
defer p.mu.Unlock()
if p.statusString != ready {
level.Info(p.logger).Log("msg", "changing probe status", "status", ready)
p.statusString = ready
}
}

// NotReady records the component status when NotReady is called, if combined with other Probes.
func (p *InstrumentationProbe) NotReady(err error) {
p.status.WithLabelValues(ready).Set(0)
level.Warn(p.logger).Log("msg", "changing probe status", "status", "not-ready", "reason", err)
p.statusMetric.WithLabelValues(ready).Set(0)
p.mu.Lock()
defer p.mu.Unlock()
if p.statusString != notReady {
level.Warn(p.logger).Log("msg", "changing probe status", "status", notReady, "reason", err)
p.statusString = notReady
}
}

// Healthy records the component status when Healthy is called, if combined with other Probes.
func (p *InstrumentationProbe) Healthy() {
p.status.WithLabelValues(healthy).Set(1)
p.statusMetric.WithLabelValues(healthy).Set(1)
level.Info(p.logger).Log("msg", "changing probe status", "status", "healthy")
}

// NotHealthy records the component status when NotHealthy is called, if combined with other Probes.
func (p *InstrumentationProbe) NotHealthy(err error) {
p.status.WithLabelValues(healthy).Set(0)
p.statusMetric.WithLabelValues(healthy).Set(0)
level.Info(p.logger).Log("msg", "changing probe status", "status", "not-healthy", "reason", err)
}