Skip to content

Commit 08e1a41

Browse files
committed
fix(filesystem): only watch for files with the .yaml extension
fixes #726
1 parent dfc8e4b commit 08e1a41

File tree

3 files changed

+25
-19
lines changed

3 files changed

+25
-19
lines changed

filesystem.go

+7-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"time"
1111

1212
"github.com/bufbuild/connect-go"
13+
1314
"github.com/fsnotify/fsnotify"
1415
"github.com/go-kit/log"
1516
"github.com/go-kit/log/level"
@@ -170,7 +171,12 @@ func cmdFilesystem(logger log.Logger, reg *prometheus.Registry, promClient api.C
170171
case <-ctx.Done():
171172
return nil
172173
case f := <-files:
173-
level.Debug(logger).Log("msg", "reading", "file", f)
174+
// We only care about watching for files with the .yaml extension
175+
if filepath.Ext(f) != ".yaml" {
176+
continue
177+
}
178+
179+
level.Debug(logger).Log("msg", "processing", "file", f)
174180
reconcilesTotal.Inc()
175181

176182
err := writeRuleFile(logger, f, prometheusFolder, genericRules, false)

filesystem_test.go

+17-17
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,16 @@ import (
1010
)
1111

1212
func TestMatchObjectives(t *testing.T) {
13-
o1 := slo.Objective{Labels: labels.FromStrings("foo", "bar")}
14-
o2 := slo.Objective{Labels: labels.FromStrings("foo", "bar", "ying", "yang")}
15-
o3 := slo.Objective{Labels: labels.FromStrings("foo", "bar", "yes", "no")}
16-
o4 := slo.Objective{Labels: labels.FromStrings("foo", "baz")}
13+
obj1 := slo.Objective{Labels: labels.FromStrings("foo", "bar")}
14+
obj2 := slo.Objective{Labels: labels.FromStrings("foo", "bar", "ying", "yang")}
15+
obj3 := slo.Objective{Labels: labels.FromStrings("foo", "bar", "yes", "no")}
16+
obj4 := slo.Objective{Labels: labels.FromStrings("foo", "baz")}
1717

1818
objectives := Objectives{objectives: map[string]slo.Objective{}}
19-
objectives.Set(o1)
20-
objectives.Set(o2)
21-
objectives.Set(o3)
22-
objectives.Set(o4)
19+
objectives.Set(obj1)
20+
objectives.Set(obj2)
21+
objectives.Set(obj3)
22+
objectives.Set(obj4)
2323

2424
matches := objectives.Match([]*labels.Matcher{
2525
labels.MustNewMatcher(labels.MatchEqual, "foo", "foo"),
@@ -30,29 +30,29 @@ func TestMatchObjectives(t *testing.T) {
3030
labels.MustNewMatcher(labels.MatchEqual, "foo", "bar"),
3131
})
3232
require.Len(t, matches, 3)
33-
require.Contains(t, matches, o1)
34-
require.Contains(t, matches, o2)
35-
require.Contains(t, matches, o3)
33+
require.Contains(t, matches, obj1)
34+
require.Contains(t, matches, obj2)
35+
require.Contains(t, matches, obj3)
3636

3737
matches = objectives.Match([]*labels.Matcher{
3838
labels.MustNewMatcher(labels.MatchEqual, "foo", "baz"),
3939
})
4040
require.Len(t, matches, 1)
41-
require.Contains(t, matches, o4)
41+
require.Contains(t, matches, obj4)
4242

4343
matches = objectives.Match([]*labels.Matcher{
4444
labels.MustNewMatcher(labels.MatchEqual, "foo", "bar"),
4545
labels.MustNewMatcher(labels.MatchEqual, "ying", "yang"),
4646
})
4747
require.Len(t, matches, 1)
48-
require.Contains(t, matches, o2)
48+
require.Contains(t, matches, obj2)
4949

5050
matches = objectives.Match([]*labels.Matcher{
5151
labels.MustNewMatcher(labels.MatchRegexp, "foo", "ba."),
5252
})
5353
require.Len(t, matches, 4)
54-
require.Contains(t, matches, o1)
55-
require.Contains(t, matches, o2)
56-
require.Contains(t, matches, o3)
57-
require.Contains(t, matches, o4)
54+
require.Contains(t, matches, obj1)
55+
require.Contains(t, matches, obj2)
56+
require.Contains(t, matches, obj3)
57+
require.Contains(t, matches, obj4)
5858
}

main.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ var CLI struct {
6161
PrometheusBasicAuthPassword promconfig.Secret `default:"" help:"The HTTP basic authentication password"`
6262
} `cmd:"" help:"Runs Pyrra's API and UI."`
6363
Filesystem struct {
64-
ConfigFiles string `default:"/etc/pyrra/*.yaml" help:"The folder where Pyrra finds the config files to use."`
64+
ConfigFiles string `default:"/etc/pyrra/*.yaml" help:"The folder where Pyrra finds the config files to use. Any non yaml files will be ignored."`
6565
PrometheusURL *url.URL `default:"http://localhost:9090" help:"The URL to the Prometheus to query."`
6666
PrometheusFolder string `default:"/etc/prometheus/pyrra/" help:"The folder where Pyrra writes the generates Prometheus rules and alerts."`
6767
GenericRules bool `default:"false" help:"Enabled generic recording rules generation to make it easier for tools like Grafana."`

0 commit comments

Comments
 (0)