ソースを参照

Merge pull request #13259 from bergquist/disable_metrics_endpoint

[metrics]enabled = false should disable the /metrics endpoint.
Torkel Ödegaard 7 年 前
コミット
4b0eeab2b3
4 ファイル変更7 行追加6 行削除
  1. 4 0
      pkg/api/http_server.go
  2. 0 1
      pkg/metrics/service.go
  3. 0 5
      pkg/metrics/settings.go
  4. 3 0
      pkg/setting/setting.go

+ 4 - 0
pkg/api/http_server.go

@@ -233,6 +233,10 @@ func (hs *HTTPServer) addMiddlewaresAndStaticRoutes() {
 }
 
 func (hs *HTTPServer) metricsEndpoint(ctx *macaron.Context) {
+	if !hs.Cfg.MetricsEndpointEnabled {
+		return
+	}
+
 	if ctx.Req.Method != "GET" || ctx.Req.URL.Path != "/metrics" {
 		return
 	}

+ 0 - 1
pkg/metrics/service.go

@@ -28,7 +28,6 @@ func init() {
 type InternalMetricsService struct {
 	Cfg *setting.Cfg `inject:""`
 
-	enabled         bool
 	intervalSeconds int64
 	graphiteCfg     *graphitebridge.Config
 }

+ 0 - 5
pkg/metrics/settings.go

@@ -16,13 +16,8 @@ func (im *InternalMetricsService) readSettings() error {
 		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)
 
-	if !im.enabled {
-		return nil
-	}
-
 	if err := im.parseGraphiteSettings(); err != nil {
 		return fmt.Errorf("Unable to parse metrics graphite section, %v", err)
 	}

+ 3 - 0
pkg/setting/setting.go

@@ -203,6 +203,8 @@ type Cfg struct {
 	DisableBruteForceLoginProtection bool
 
 	TempDataLifetime time.Duration
+
+	MetricsEndpointEnabled bool
 }
 
 type CommandLineArgs struct {
@@ -659,6 +661,7 @@ func (cfg *Cfg) Load(args *CommandLineArgs) error {
 	cfg.ImagesDir = filepath.Join(DataPath, "png")
 	cfg.PhantomDir = filepath.Join(HomePath, "tools/phantomjs")
 	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")
 	ReportingEnabled = analytics.Key("reporting_enabled").MustBool(true)