Skip to content

Commit

Permalink
fix: Properly escape special characters in Prometheus YAML template
Browse files Browse the repository at this point in the history
  • Loading branch information
pcfreak30 committed Dec 28, 2024
1 parent 36e2d9a commit d5e1686
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 16 deletions.
14 changes: 7 additions & 7 deletions cmd/promster/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ import (
"context"
"fmt"
"go.lumeweb.com/etcd-registry/types"
"sort"
"io"
"net/http"
"os"
"os/signal"
"reflect"
"sort"
"strings"
"sync"
"text/template"
Expand Down Expand Up @@ -273,13 +273,13 @@ func updatePrometheusConfig(configFile string, serviceGroups []ServiceGroup) err
"yaml": contents,
}).Debug("Writing new configuration")

if err := writeConfigFile(configFile, []byte(contents)); err != nil {
return false, fmt.Errorf("failed to write config: %w", err)
}
/* if err := writeConfigFile(configFile, []byte(contents)); err != nil {
return false, fmt.Errorf("failed to write config: %w", err)
}
if err := reloadPrometheus(); err != nil {
return false, fmt.Errorf("failed to reload prometheus: %w", err)
}
if err := reloadPrometheus(); err != nil {
return false, fmt.Errorf("failed to reload prometheus: %w", err)
}*/

return true, nil
},
Expand Down
21 changes: 12 additions & 9 deletions cmd/promster/prometheus.yml.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,30 @@ scrape_configs:
- targets: ['localhost:9090']
{{ if .AdminPassword }}
basic_auth:
username: "{{.AdminUsername}}"
password: "{{.AdminPassword}}"
username: {{printf "%q" .AdminUsername}}
password: {{printf "%q" .AdminPassword}}
{{ end }}

{{- if .ServiceGroups }}
{{- range .ServiceGroups }}
- job_name: '{{ .Name }}'
scheme: "{{$.Scheme}}"
- job_name: {{printf "%q" .Name}}
scheme: {{printf "%q" $.Scheme}}
tls_config:
insecure_skip_verify: {{if eq $.TlsInsecure "true"}}true{{else}}false{{end}}
static_configs:
- targets: {{ .Targets }}
- targets:
{{- range .Targets}}
- {{printf "%q" .}}
{{- end}}
labels:
{{- range $key, $value := .Labels }}
{{ $key }}: "{{ $value }}"
{{$key}}: {{printf "%q" $value}}
{{- end }}
{{ if .BasicAuth }}
basic_auth:
username: "{{ .BasicAuth.Username }}"
password: "{{ .BasicAuth.Password }}"
username: {{printf "%q" .BasicAuth.Username}}
password: {{printf "%q" .BasicAuth.Password}}
{{ end }}
metrics_path: "{{ .MetricsPath }}"
metrics_path: {{printf "%q" .MetricsPath}}
{{- end }}
{{- end }}

0 comments on commit d5e1686

Please sign in to comment.