@@ -54,8 +54,9 @@ var CLI struct {
54
54
PrometheusBearerTokenPath string `default:"" help:"Bearer token path"`
55
55
} `cmd:"" help:"Runs Pyrra's API and UI."`
56
56
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."`
59
60
} `cmd:"" help:"Runs Pyrra's filesystem operator and backend for the API."`
60
61
Kubernetes struct {
61
62
MetricsAddr string `default:":8080" help:"The address the metric endpoint binds to."`
@@ -77,31 +78,36 @@ func main() {
77
78
collectors .NewProcessCollector (collectors.ProcessCollectorOpts {}),
78
79
)
79
80
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
+ }
89
88
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
+ }
101
96
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
105
111
}
106
112
107
113
var code int
0 commit comments