Skip to content

Commit

Permalink
Adding alerting for wait buffer (#172)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
oliviagolden0 authored May 8, 2024
1 parent b7b6557 commit 39e239e
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
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

0 comments on commit 39e239e

Please sign in to comment.