Skip to content

Commit 45b5b92

Browse files
committed
feat: add switch PrometheusEnabled
1 parent 97dcaaf commit 45b5b92

3 files changed

Lines changed: 12 additions & 3 deletions

File tree

.env.example

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,9 @@ LOG_OUTPUT_FORMAT=text
136136
# pprof enabled, for debugging
137137
PPROF_ENABLED=false
138138

139+
# prometheus metrics enabled
140+
PROMETHEUS_ENABLED=true
141+
139142
# FORCE_VERIFYING_SIGNATURE, for security, you should set this to true, pls be sure you know what you are doing
140143
# if want to install plugin without verifying signature, set this to false
141144
FORCE_VERIFYING_SIGNATURE=true

internal/server/http_server.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,20 @@ func (app *App) server(config *app.Config) func() {
3333
engine.NoRoute(func(c *gin.Context) {
3434
c.JSON(http.StatusNotFound, gin.H{"code": "not_found", "message": "route not found"})
3535
})
36-
engine.Use(PrometheusMiddleware())
36+
if config.PrometheusEnabled {
37+
engine.Use(PrometheusMiddleware())
38+
}
3739
engine.GET("/health/check", controllers.HealthCheck(config))
3840

3941
endpointGroup := engine.Group("/e")
4042
serverlessTransactionGroup := engine.Group("/backwards-invocation")
4143
pluginGroup := engine.Group("/plugin/:tenant_id")
4244
pprofGroup := engine.Group("/debug/pprof")
4345

44-
metricsGroup := engine.Group("/metrics")
45-
metricsGroup.GET("/", gin.WrapH(promhttp.Handler()))
46+
if config.PrometheusEnabled {
47+
metricsGroup := engine.Group("/metrics")
48+
metricsGroup.GET("/", gin.WrapH(promhttp.Handler()))
49+
}
4650

4751
if config.AdminApiEnabled {
4852
if len(config.AdminApiKey) < 10 {

internal/types/app/config.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,8 @@ type Config struct {
194194

195195
PPROFEnabled bool `envconfig:"PPROF_ENABLED"`
196196

197+
PrometheusEnabled bool `envconfig:"PROMETHEUS_ENABLED" default:"true"`
198+
197199
SentryEnabled bool `envconfig:"SENTRY_ENABLED"`
198200
SentryDSN string `envconfig:"SENTRY_DSN"`
199201
SentryAttachStacktrace bool `envconfig:"SENTRY_ATTACH_STACKTRACE"`

0 commit comments

Comments
 (0)