Skip to content

Commit

Permalink
fix(exporter): handle pool sync time metrics collection gracefully (#…
Browse files Browse the repository at this point in the history
…1616)

This PR fixes a bug in pool sync time metrics collector in maya exporter.
If last request is in progress, don't queue the current request during pool
last Sync time metrics collection and increment the reject request counter.

Signed-off-by: mittachaitu <[email protected]>
  • Loading branch information
sai chaithanya authored Feb 26, 2020
1 parent 3ce311e commit 9417d96
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
12 changes: 12 additions & 0 deletions cmd/maya-exporter/app/collector/zvol/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ type poolSyncMetrics struct {
zpoolLastSyncTime *prometheus.GaugeVec
zpoolStateUnknown *prometheus.GaugeVec
zpoolLastSyncTimeCommandError *prometheus.GaugeVec
cspiRequestRejectCounter prometheus.Counter
}

// poolfields struct is for pool last sync time metric
Expand Down Expand Up @@ -437,6 +438,17 @@ func (p *poolSyncMetrics) withZpoolStateUnknown() *poolSyncMetrics {
return p
}

func (p *poolSyncMetrics) withRequestRejectCounter() *poolSyncMetrics {
p.cspiRequestRejectCounter = prometheus.NewGauge(
prometheus.GaugeOpts{
Namespace: "openebs",
Name: "zfs_get_livenesstimestamp_request_reject_count",
Help: "Total no of rejected requests for pool liveness",
},
)
return p
}

func (p *poolSyncMetrics) withzpoolLastSyncTimeCommandError() *poolSyncMetrics {

p.zpoolLastSyncTimeCommandError = prometheus.NewGaugeVec(
Expand Down
11 changes: 11 additions & 0 deletions cmd/maya-exporter/app/collector/zvol/pool_synctime.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,16 @@ func NewPoolSyncMetric(runner types.Runner) col.Collector {
poolSyncMetrics: newPoolMetrics().
withZpoolLastSyncTime().
withZpoolStateUnknown().
withRequestRejectCounter().
withzpoolLastSyncTimeCommandError(),
runner: runner,
}
}

func (p *poolMetrics) isRequestInProgress() bool {
return p.request
}

func (p *poolMetrics) setRequestToFalse() {
p.Lock()
p.request = false
Expand Down Expand Up @@ -110,6 +115,12 @@ func (p *poolMetrics) get() *poolfields {
// Collect is implementation of prometheus's prometheus.Collector interface
func (p *poolMetrics) Collect(ch chan<- prometheus.Metric) {
p.Lock()
if p.isRequestInProgress() {
p.cspiRequestRejectCounter.Inc()
p.Unlock()
p.cspiRequestRejectCounter.Collect(ch)
return
}
p.request = true
p.Unlock()

Expand Down

0 comments on commit 9417d96

Please sign in to comment.