Skip to content

Commit 39e239e

Browse files
Adding alerting for wait buffer (#172)
* adding logging for worker buffer * worker metric * add capacity to lable * rm unneeded metric: * alphabetize * revert * refactor * concurrecny * worker count * adding worker count metric' * lint * right metric * add test * rm method
1 parent b7b6557 commit 39e239e

3 files changed

Lines changed: 19 additions & 1 deletion

File tree

metrics/prometheus.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,13 +79,19 @@ var (
7979
Namespace: "rules",
8080
Help: "etcd rules engine crawler values count",
8181
}, []string{"name"})
82+
rulesEngineWorkerCount = prometheus.NewGauge(prometheus.GaugeOpts{
83+
Name: "worker_count",
84+
Subsystem: "etcd",
85+
Namespace: "rules",
86+
Help: "etcd rules engine worker count",
87+
})
8288
)
8389

8490
func init() {
8591
prometheus.MustRegister(rulesEngineLockCount, rulesEngineSatisfiedThenNot, rulesEngineEvaluations,
8692
rulesEngineWorkerQueueWait, rulesEngineWorkBufferWaitTime, rulesEngineCallbackWaitTime,
8793
rulesEngineKeyProcessBufferCap, rulesEngineWatcherErrors, rulesEngineCrawlerQueryTime,
88-
rulesEngineCrawlerEvalTime, rulesEngineCrawlerValues)
94+
rulesEngineCrawlerEvalTime, rulesEngineCrawlerValues, rulesEngineWorkerCount)
8995
}
9096

9197
// IncLockMetric increments the lock count.
@@ -145,3 +151,8 @@ func CrawlerEvalTime(name string, startTime time.Time) {
145151
func CrawlerValuesCount(name string, count int) {
146152
rulesEngineCrawlerValues.WithLabelValues(name).Set(float64(count))
147153
}
154+
155+
// WorkerCount tracks the number of workers
156+
func WorkersCount(count int) {
157+
rulesEngineWorkerCount.Set(float64(count))
158+
}

metrics/prometheus_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,3 +97,8 @@ func TestCrawlerValuesCount(t *testing.T) {
9797
CrawlerValuesCount("default", 100)
9898
checkMetrics(t, `rules_etcd_crawler_values_count{name="default"} 100`)
9999
}
100+
101+
func TestWorkersCount(t *testing.T) {
102+
WorkersCount(100)
103+
checkMetrics(t, `rules_etcd_worker_count 100`)
104+
}

rules/engine.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"golang.org/x/net/context"
1212

1313
"github.com/IBM-Cloud/go-etcd-rules/concurrency"
14+
"github.com/IBM-Cloud/go-etcd-rules/metrics"
1415
"github.com/IBM-Cloud/go-etcd-rules/rules/lock"
1516
)
1617

@@ -326,6 +327,7 @@ func (e *v3Engine) Run() {
326327
go c.run()
327328

328329
e.logger.Info("Starting workers", zap.Int("count", e.options.concurrency))
330+
metrics.WorkersCount(e.options.concurrency)
329331
for i := 0; i < e.options.concurrency; i++ {
330332
id := fmt.Sprintf("worker%d", i)
331333
w, err := newV3Worker(id, e)

0 commit comments

Comments
 (0)