Skip to content

Commit

Permalink
give the possibility to define a set of a rule collectors instead of …
Browse files Browse the repository at this point in the history
…a single one

Signed-off-by: Augustin Husson <[email protected]>
  • Loading branch information
Nexucis committed Oct 28, 2024
1 parent d49b3fc commit 16ed30a
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 19 deletions.
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,17 +92,19 @@ metric_collector:
This collector gets the Prometheus Rules Group using the HTTP API. Then it extracts the metric used in the alert rule or in the recording rule.
You define a set of rule collectors as we are assuming rules can com from various Prometheus / Thanos rulers.
#### Configuration
See the doc for the complete configuration [here](./docs/configuration.md#rules_collector-config)
Example:
```yaml
rules_collector:
enable: true
prometheus_client:
url: "https://prometheus.demo.do.prometheus.io"
rules_collectors:
- enable: true
prometheus_client:
url: "https://prometheus.demo.do.prometheus.io"
```
### Perses Collector
Expand Down
8 changes: 4 additions & 4 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ package config
import "github.com/perses/common/config"

type Config struct {
MetricCollector MetricCollector `yaml:"metric_collector,omitempty"`
RulesCollector RulesCollector `yaml:"rules_collector,omitempty"`
PersesCollector PersesCollector `yaml:"perses_collector,omitempty"`
GrafanaCollector GrafanaCollector `yaml:"grafana_collector,omitempty"`
MetricCollector MetricCollector `yaml:"metric_collector,omitempty"`
RulesCollectors []*RulesCollector `yaml:"rules_collectors,omitempty"`
PersesCollector PersesCollector `yaml:"perses_collector,omitempty"`
GrafanaCollector GrafanaCollector `yaml:"grafana_collector,omitempty"`
}

func Resolve(configFile string) (Config, error) {
Expand Down
8 changes: 4 additions & 4 deletions dev/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ metric_collector:
http_client:
url: "https://prometheus.demo.do.prometheus.io"

rules_collector:
enable: true
http_client:
url: "https://prometheus.demo.do.prometheus.io"
rules_collectors:
- enable: true
http_client:
url: "https://prometheus.demo.do.prometheus.io"

perses_collector:
enable: true
Expand Down
13 changes: 7 additions & 6 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,14 @@ func main() {
runner.WithTimerTasks(time.Duration(metricCollectorConfig.Period), metricCollector)
}

if conf.RulesCollector.Enable {
rulesCollectorConfig := conf.RulesCollector
rulesCollector, collectorErr := rules.NewCollector(db, rulesCollectorConfig)
if collectorErr != nil {
logrus.WithError(collectorErr).Fatal("unable to create the rules collector")
for i, rulesCollectorConfig := range conf.RulesCollectors {
if rulesCollectorConfig.Enable {
rulesCollector, collectorErr := rules.NewCollector(db, rulesCollectorConfig)
if collectorErr != nil {
logrus.WithError(collectorErr).Fatalf("unable to create the rules collector number %d", i)
}
runner.WithTimerTasks(time.Duration(rulesCollectorConfig.Period), rulesCollector)
}
runner.WithTimerTasks(time.Duration(rulesCollectorConfig.Period), rulesCollector)
}

if conf.PersesCollector.Enable {
Expand Down
2 changes: 1 addition & 1 deletion source/rules/rules.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
"github.com/sirupsen/logrus"
)

func NewCollector(db database.Database, cfg config.RulesCollector) (async.SimpleTask, error) {
func NewCollector(db database.Database, cfg *config.RulesCollector) (async.SimpleTask, error) {
promClient, err := prometheus.NewClient(cfg.HTTPClient)
if err != nil {
return nil, err
Expand Down

0 comments on commit 16ed30a

Please sign in to comment.