Commit 4b0eeab2 by Torkel Ödegaard Committed by GitHub

Merge pull request #13259 from bergquist/disable_metrics_endpoint

[metrics]enabled = false should disable the /metrics endpoint.
parents ec5aa332 bff35016
...@@ -233,6 +233,10 @@ func (hs *HTTPServer) addMiddlewaresAndStaticRoutes() { ...@@ -233,6 +233,10 @@ func (hs *HTTPServer) addMiddlewaresAndStaticRoutes() {
} }
func (hs *HTTPServer) metricsEndpoint(ctx *macaron.Context) { func (hs *HTTPServer) metricsEndpoint(ctx *macaron.Context) {
if !hs.Cfg.MetricsEndpointEnabled {
return
}
if ctx.Req.Method != "GET" || ctx.Req.URL.Path != "/metrics" { if ctx.Req.Method != "GET" || ctx.Req.URL.Path != "/metrics" {
return return
} }
......
...@@ -28,7 +28,6 @@ func init() { ...@@ -28,7 +28,6 @@ func init() {
type InternalMetricsService struct { type InternalMetricsService struct {
Cfg *setting.Cfg `inject:""` Cfg *setting.Cfg `inject:""`
enabled bool
intervalSeconds int64 intervalSeconds int64
graphiteCfg *graphitebridge.Config graphiteCfg *graphitebridge.Config
} }
......
...@@ -16,13 +16,8 @@ func (im *InternalMetricsService) readSettings() error { ...@@ -16,13 +16,8 @@ func (im *InternalMetricsService) readSettings() error {
return fmt.Errorf("Unable to find metrics config section %v", err) return fmt.Errorf("Unable to find metrics config section %v", err)
} }
im.enabled = section.Key("enabled").MustBool(false)
im.intervalSeconds = section.Key("interval_seconds").MustInt64(10) im.intervalSeconds = section.Key("interval_seconds").MustInt64(10)
if !im.enabled {
return nil
}
if err := im.parseGraphiteSettings(); err != nil { if err := im.parseGraphiteSettings(); err != nil {
return fmt.Errorf("Unable to parse metrics graphite section, %v", err) return fmt.Errorf("Unable to parse metrics graphite section, %v", err)
} }
......
...@@ -203,6 +203,8 @@ type Cfg struct { ...@@ -203,6 +203,8 @@ type Cfg struct {
DisableBruteForceLoginProtection bool DisableBruteForceLoginProtection bool
TempDataLifetime time.Duration TempDataLifetime time.Duration
MetricsEndpointEnabled bool
} }
type CommandLineArgs struct { type CommandLineArgs struct {
...@@ -659,6 +661,7 @@ func (cfg *Cfg) Load(args *CommandLineArgs) error { ...@@ -659,6 +661,7 @@ func (cfg *Cfg) Load(args *CommandLineArgs) error {
cfg.ImagesDir = filepath.Join(DataPath, "png") cfg.ImagesDir = filepath.Join(DataPath, "png")
cfg.PhantomDir = filepath.Join(HomePath, "tools/phantomjs") cfg.PhantomDir = filepath.Join(HomePath, "tools/phantomjs")
cfg.TempDataLifetime = iniFile.Section("paths").Key("temp_data_lifetime").MustDuration(time.Second * 3600 * 24) cfg.TempDataLifetime = iniFile.Section("paths").Key("temp_data_lifetime").MustDuration(time.Second * 3600 * 24)
cfg.MetricsEndpointEnabled = iniFile.Section("metrics").Key("enabled").MustBool(true)
analytics := iniFile.Section("analytics") analytics := iniFile.Section("analytics")
ReportingEnabled = analytics.Key("reporting_enabled").MustBool(true) ReportingEnabled = analytics.Key("reporting_enabled").MustBool(true)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment