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

allow override placeholders #103

Merged
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@ import (
"gopkg.in/yaml.v2"
)

func getenv(key, defaultVal string) string {
if val, found := os.LookupEnv(key); found {
return val
} else {
Copy link
Member

Choose a reason for hiding this comment

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

You can get rid of the else there and just unindent the return.

return defaultVal
}
}

var (
failedScrapes = prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Expand All @@ -25,7 +33,9 @@ var (
},
[]string{"driver", "host", "database", "user", "sql_job", "query"},
)
reEnvironmentPlaceholders = regexp.MustCompile(`{{.+?}}`)
tmplStart = getenv("TEMPLATE_START", "{{")
dewey marked this conversation as resolved.
Show resolved Hide resolved
tmplEnd = getenv("TEMPLATE_END", "}}")
reEnvironmentPlaceholders = regexp.MustCompile(fmt.Sprintf("%s.+?%s", tmplStart, tmplEnd))
)

func init() {
Expand All @@ -49,7 +59,7 @@ func Read(path string) (File, error) {
}

placeholders := reEnvironmentPlaceholders.FindAllString(string(buf), -1)
replacer := strings.NewReplacer("{{", "", "}}", "")
replacer := strings.NewReplacer(tmplStart, "", tmplEnd, "")
var replacements []string
for _, placeholder := range placeholders {
environmentVariableName := strings.ToUpper(replacer.Replace(placeholder))
Expand Down