cloudflare/pint
Publicmirrored from https://github.com/cloudflare/pintAvailable
internal/config/prometheus.go
38lines · modecode
| 1 | package config |
| 2 | |
| 3 | import "regexp" |
| 4 | |
| 5 | type PrometheusConfig struct { |
| 6 | Name string `hcl:",label"` |
| 7 | URI string `hcl:"uri"` |
| 8 | Timeout string `hcl:"timeout"` |
| 9 | Paths []string `hcl:"paths,optional"` |
| 10 | } |
| 11 | |
| 12 | func (pc PrometheusConfig) validate() error { |
| 13 | if _, err := parseDuration(pc.Timeout); err != nil { |
| 14 | return err |
| 15 | } |
| 16 | |
| 17 | for _, path := range pc.Paths { |
| 18 | if _, err := regexp.Compile(path); err != nil { |
| 19 | return err |
| 20 | } |
| 21 | |
| 22 | } |
| 23 | |
| 24 | return nil |
| 25 | } |
| 26 | |
| 27 | func (pc PrometheusConfig) isEnabledForPath(path string) bool { |
| 28 | if len(pc.Paths) == 0 { |
| 29 | return true |
| 30 | } |
| 31 | for _, pattern := range pc.Paths { |
| 32 | re := strictRegex(pattern) |
| 33 | if re.MatchString(path) { |
| 34 | return true |
| 35 | } |
| 36 | } |
| 37 | return false |
| 38 | } |
| 39 | |