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

Making possible to add rules via docker secret #57

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
5 changes: 3 additions & 2 deletions prometheus/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,12 @@ func WriteConfig(configPath string, scrapes map[string]Scrape,
c.InsertScrapesFromDir(configsDir)
}

c.RuleFiles = []string{"/run/secrets/*.rules"}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How do you feel about using: https://godoc.org/github.com/spf13/afero#Glob to explicitly scan for all the rules, adding these rules to prometheus.yml and logging the rules here?

Copy link
Author

@albertogviana albertogviana Aug 28, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @thomasjpfan,

I am using secrets because since the beginning I am injecting the scrapes via secret, so this was my first approach.

I believe I don't need to use https://godoc.org/github.com/spf13/afero#Glob because Prometheus already implemented it.

Yes @vfarcic , I can provide some documentation and release notes.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@albertogviana Yes. Please add the docs and release notes.

@thomasjpfan Do you think we can merge this after the docs and RNs are done by @albertogviana ?

if len(alerts) > 0 {
logPrintf("Writing to alert.rules")
afero.WriteFile(FS, alertRulesPath, []byte(GetAlertConfig(alerts)), 0644)
c.RuleFiles = []string{"alert.rules"}
// c.RuleFiles = []string{"alert.rules"}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This commented line can be removed.

c.RuleFiles = append(c.RuleFiles, "alert.rules")
}

alertmanagerURLs := os.Getenv("ARG_ALERTMANAGER_URL")
Expand Down Expand Up @@ -66,7 +68,6 @@ func WriteConfig(configPath string, scrapes map[string]Scrape,
logPrintf("Writing to prometheus.yml")
configYAML, _ := yaml.Marshal(c)
afero.WriteFile(FS, configPath, configYAML, 0644)

}

// InsertEnv inserts envKey/envValue into config
Expand Down
2 changes: 1 addition & 1 deletion prometheus/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -848,7 +848,7 @@ func (s *ConfigTestSuite) Test_WriteConfig_WriteAlerts() {
}

c := &Config{}
c.RuleFiles = []string{"alert.rules"}
c.RuleFiles = []string{"/run/secrets/*.rules", "alert.rules"}
cYAML, _ := yaml.Marshal(c)
expectedAlerts := GetAlertConfig(alerts)

Expand Down
10 changes: 10 additions & 0 deletions server/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,8 @@ alerting:
- targets:
- alert-manager:9093
scheme: http
rule_files:
- /run/secrets/*.rules
`
fsOrig := prometheus.FS
defer func() { prometheus.FS = fsOrig }()
Expand Down Expand Up @@ -952,6 +954,7 @@ alerting:
- alert-manager:9093
scheme: http
rule_files:
- /run/secrets/*.rules
- alert.rules
scrape_configs:
- job_name: my-service
Expand Down Expand Up @@ -995,6 +998,7 @@ alerting:
- alert-manager:9093
scheme: http
rule_files:
- /run/secrets/*.rules
- alert.rules
scrape_configs:
- job_name: my-service
Expand Down Expand Up @@ -1271,6 +1275,8 @@ alerting:
- targets:
- alert-manager:9093
scheme: http
rule_files:
- /run/secrets/*.rules
scrape_configs:
- job_name: my-service
metrics_path: /metrics
Expand Down Expand Up @@ -1301,6 +1307,8 @@ alerting:
- targets:
- alert-manager:9093
scheme: http
rule_files:
- /run/secrets/*.rules
`
addr = "/v1/docker-flow-monitor?serviceName=my-service"
req, _ = http.NewRequest("DELETE", addr, nil)
Expand Down Expand Up @@ -1450,6 +1458,8 @@ alerting:
- targets:
- alert-manager:9093
scheme: http
rule_files:
- /run/secrets/*.rules
`

actualConfig, _ := afero.ReadFile(prometheus.FS, "/etc/prometheus/prometheus.yml")
Expand Down