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

Adding alerting for wait buffer #172

Merged
merged 15 commits into from
May 8, 2024
13 changes: 12 additions & 1 deletion metrics/prometheus.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,19 @@ var (
Namespace: "rules",
Help: "etcd rules engine crawler values count",
}, []string{"name"})
rulesEngineWorkerCount = prometheus.NewGauge(prometheus.GaugeOpts{
Name: "worker_count",
Subsystem: "etcd",
Namespace: "rules",
Help: "etcd rules engine worker count",
})
)

func init() {
prometheus.MustRegister(rulesEngineLockCount, rulesEngineSatisfiedThenNot, rulesEngineEvaluations,
rulesEngineWorkerQueueWait, rulesEngineWorkBufferWaitTime, rulesEngineCallbackWaitTime,
rulesEngineKeyProcessBufferCap, rulesEngineWatcherErrors, rulesEngineCrawlerQueryTime,
rulesEngineCrawlerEvalTime, rulesEngineCrawlerValues)
rulesEngineCrawlerEvalTime, rulesEngineCrawlerValues, rulesEngineWorkerCount)
}

// IncLockMetric increments the lock count.
Expand Down Expand Up @@ -145,3 +151,8 @@ func CrawlerEvalTime(name string, startTime time.Time) {
func CrawlerValuesCount(name string, count int) {
rulesEngineCrawlerValues.WithLabelValues(name).Set(float64(count))
}

// WorkerCount tracks the number of workers
func WorkersCount(count int) {
rulesEngineWorkerCount.Set(float64(count))
}
5 changes: 5 additions & 0 deletions metrics/prometheus_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,3 +97,8 @@ func TestCrawlerValuesCount(t *testing.T) {
CrawlerValuesCount("default", 100)
checkMetrics(t, `rules_etcd_crawler_values_count{name="default"} 100`)
}

func TestWorkersCount(t *testing.T) {
WorkersCount(100)
checkMetrics(t, `rules_etcd_worker_count 100`)
}
2 changes: 2 additions & 0 deletions rules/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"golang.org/x/net/context"

"github.com/IBM-Cloud/go-etcd-rules/concurrency"
"github.com/IBM-Cloud/go-etcd-rules/metrics"
"github.com/IBM-Cloud/go-etcd-rules/rules/lock"
)

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

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