Skip to content

Commit 33a0f69

Browse files
authored
Merge pull request #318 from pyrra-dev/cli-filesystem-prometheusurl
Use correct Prometheus URL in filesystem sub command
2 parents b899897 + 61b8f87 commit 33a0f69

File tree

1 file changed

+31
-25
lines changed

1 file changed

+31
-25
lines changed

main.go

+31-25
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,9 @@ var CLI struct {
5454
PrometheusBearerTokenPath string `default:"" help:"Bearer token path"`
5555
} `cmd:"" help:"Runs Pyrra's API and UI."`
5656
Filesystem struct {
57-
ConfigFiles string `default:"/etc/pyrra/*.yaml" help:"The folder where Pyrra finds the config files to use."`
58-
PrometheusFolder string `default:"/etc/prometheus/pyrra/" help:"The folder where Pyrra writes the generates Prometheus rules and alerts."`
57+
ConfigFiles string `default:"/etc/pyrra/*.yaml" help:"The folder where Pyrra finds the config files to use."`
58+
PrometheusURL *url.URL `default:"http://localhost:9090" help:"The URL to the Prometheus to query."`
59+
PrometheusFolder string `default:"/etc/prometheus/pyrra/" help:"The folder where Pyrra writes the generates Prometheus rules and alerts."`
5960
} `cmd:"" help:"Runs Pyrra's filesystem operator and backend for the API."`
6061
Kubernetes struct {
6162
MetricsAddr string `default:":8080" help:"The address the metric endpoint binds to."`
@@ -77,31 +78,36 @@ func main() {
7778
collectors.NewProcessCollector(collectors.ProcessCollectorOpts{}),
7879
)
7980

80-
var client api.Client
81-
if CLI.API.PrometheusURL != nil {
82-
roundTripper, err := promconfig.NewRoundTripperFromConfig(promconfig.HTTPClientConfig{
83-
BearerTokenFile: CLI.API.PrometheusBearerTokenPath,
84-
}, "pyrra")
85-
if err != nil {
86-
level.Error(logger).Log("msg", "failed to create API client round tripper", "err", err)
87-
os.Exit(1)
88-
}
81+
var prometheusURL *url.URL
82+
switch ctx.Command() {
83+
case "api":
84+
prometheusURL = CLI.API.PrometheusURL
85+
case "filesystem":
86+
prometheusURL = CLI.Filesystem.PrometheusURL
87+
}
8988

90-
client, err = api.NewClient(api.Config{
91-
Address: CLI.API.PrometheusURL.String(),
92-
RoundTripper: roundTripper,
93-
})
94-
if err != nil {
95-
level.Error(logger).Log("msg", "failed to create API client", "err", err)
96-
os.Exit(1)
97-
}
98-
// Wrap client to add extra headers for Thanos.
99-
client = newThanosClient(client)
100-
level.Info(logger).Log("msg", "using Prometheus", "url", CLI.API.PrometheusURL.String())
89+
roundTripper, err := promconfig.NewRoundTripperFromConfig(promconfig.HTTPClientConfig{
90+
BearerTokenFile: CLI.API.PrometheusBearerTokenPath,
91+
}, "pyrra")
92+
if err != nil {
93+
level.Error(logger).Log("msg", "failed to create API client round tripper", "err", err)
94+
os.Exit(1)
95+
}
10196

102-
if CLI.API.PrometheusExternalURL == nil {
103-
CLI.API.PrometheusExternalURL = CLI.API.PrometheusURL
104-
}
97+
client, err := api.NewClient(api.Config{
98+
Address: prometheusURL.String(),
99+
RoundTripper: roundTripper,
100+
})
101+
if err != nil {
102+
level.Error(logger).Log("msg", "failed to create API client", "err", err)
103+
os.Exit(1)
104+
}
105+
// Wrap client to add extra headers for Thanos.
106+
client = newThanosClient(client)
107+
level.Info(logger).Log("msg", "using Prometheus", "url", prometheusURL.String())
108+
109+
if CLI.API.PrometheusExternalURL == nil {
110+
CLI.API.PrometheusExternalURL = prometheusURL
105111
}
106112

107113
var code int

0 commit comments

Comments
 (0)