Skip to content

Commit c83fc70

Browse files
committed
Various tweaks
- Allow specification of target in config file. - Allow sepcification of HTTP prefix (/api/prom), so we can drop it to look like a 'normal' prometheus. - Fix forwarding request to normal Prometheus. Signed-off-by: Tom Wilkie <[email protected]>
1 parent 365bd17 commit c83fc70

File tree

3 files changed

+15
-4
lines changed

3 files changed

+15
-4
lines changed

pkg/cortex/cortex.go

+2
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ type Config struct {
5353
Target moduleName `yaml:"target,omitempty"`
5454
AuthEnabled bool `yaml:"auth_enabled,omitempty"`
5555
PrintConfig bool `yaml:"-"`
56+
HTTPPrefix string `yaml:"http_prefix"`
5657

5758
Server server.Config `yaml:"server,omitempty"`
5859
Distributor distributor.Config `yaml:"distributor,omitempty"`
@@ -82,6 +83,7 @@ func (c *Config) RegisterFlags(f *flag.FlagSet) {
8283
f.Var(&c.Target, "target", "target module (default All)")
8384
f.BoolVar(&c.AuthEnabled, "auth.enabled", true, "Set to false to disable auth.")
8485
f.BoolVar(&c.PrintConfig, "print.config", false, "Print the config and exit.")
86+
f.StringVar(&c.HTTPPrefix, "http.prefix", "/api/prom", "HTTP path prefix for Cortex API.")
8587

8688
c.Server.RegisterFlags(f)
8789
c.Distributor.RegisterFlags(f)

pkg/cortex/modules.go

+9-1
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,14 @@ func (m *moduleName) Set(s string) error {
132132
}
133133
}
134134

135+
func (m *moduleName) UnmarshalYAML(unmarshal func(interface{}) error) error {
136+
var s string
137+
if err := unmarshal(&s); err != nil {
138+
return err
139+
}
140+
return m.Set(s)
141+
}
142+
135143
func (t *Cortex) initServer(cfg *Config) (err error) {
136144
t.server, err = server.New(cfg.Server)
137145
return
@@ -259,7 +267,7 @@ func (t *Cortex) initQueryFrontend(cfg *Config) (err error) {
259267
}
260268

261269
frontend.RegisterFrontendServer(t.server.GRPC, t.frontend)
262-
t.server.HTTP.PathPrefix("/api/prom").Handler(
270+
t.server.HTTP.PathPrefix(cfg.HTTPPrefix).Handler(
263271
t.httpAuthMiddleware.Wrap(
264272
t.frontend.Handler(),
265273
),

pkg/querier/frontend/frontend.go

+4-3
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ func (cfg *Config) RegisterFlags(f *flag.FlagSet) {
7171
f.BoolVar(&cfg.CacheResults, "querier.cache-results", false, "Cache query results.")
7272
f.BoolVar(&cfg.CompressResponses, "querier.compress-http-responses", false, "Compress HTTP responses.")
7373
cfg.ResultsCacheConfig.RegisterFlags(f)
74-
f.StringVar(&cfg.DownstreamURL, "querier.downstream-url", "", "URL of downstream Prometheus.")
74+
f.StringVar(&cfg.DownstreamURL, "frontend.downstream-url", "", "URL of downstream Prometheus.")
7575
}
7676

7777
// Frontend queues HTTP requests, dispatches them to backends, and handles retries
@@ -135,6 +135,7 @@ func New(cfg Config, log log.Logger, limits *validation.Overrides) (*Frontend, e
135135
}
136136

137137
roundTripper = RoundTripFunc(func(r *http.Request) (*http.Response, error) {
138+
r.URL.Scheme = u.Scheme
138139
r.URL.Host = u.Host
139140
r.URL.Path = path.Join(u.Path, r.URL.Path)
140141
return http.DefaultTransport.RoundTrip(r)
@@ -144,8 +145,8 @@ func New(cfg Config, log log.Logger, limits *validation.Overrides) (*Frontend, e
144145
// Finally, if the user selected any query range middleware, stitch it in.
145146
if len(queryRangeMiddleware) > 0 {
146147
roundTripper = queryrange.NewRoundTripper(
147-
f,
148-
queryrange.MergeMiddlewares(queryRangeMiddleware...).Wrap(&queryrange.ToRoundTripperMiddleware{Next: f}),
148+
roundTripper,
149+
queryrange.MergeMiddlewares(queryRangeMiddleware...).Wrap(&queryrange.ToRoundTripperMiddleware{Next: roundTripper}),
149150
limits,
150151
)
151152
}

0 commit comments

Comments
 (0)