From dc98361a2c14ea764db25851156469efde7db892 Mon Sep 17 00:00:00 2001 From: sevennt Date: Thu, 2 Nov 2023 15:27:12 +0800 Subject: [PATCH] disable EnableMetricInterceptor by default --- client/ehttp/config.go | 4 ++-- client/ehttp/interceptor.go | 5 +++-- client/ehttp/options.go | 6 +++--- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/client/ehttp/config.go b/client/ehttp/config.go index d12900df..78afdb27 100644 --- a/client/ehttp/config.go +++ b/client/ehttp/config.go @@ -26,7 +26,7 @@ type Config struct { PathRelabel []Relabel // path 重命名 (metric 用) cookieJar http.CookieJar // 用于缓存cookie httpClient *http.Client // 自定义http client - EnableMetricsInterceptor bool // 是否开启监控,默认开启 + EnableMetricInterceptor bool // 是否开启Metric采集,默认禁用,开启metrics采集,可能造成metrics在prometheus中膨胀会导致占用大量的prometheus内存 } // Relabel ... @@ -50,6 +50,6 @@ func DefaultConfig() *Config { EnableTraceInterceptor: true, EnableAccessInterceptor: false, EnableAccessInterceptorRes: false, - EnableMetricsInterceptor: true, + EnableMetricInterceptor: false, } } diff --git a/client/ehttp/interceptor.go b/client/ehttp/interceptor.go index ba9f984c..50c9546c 100644 --- a/client/ehttp/interceptor.go +++ b/client/ehttp/interceptor.go @@ -11,12 +11,13 @@ import ( "time" "github.com/go-resty/resty/v2" - "github.com/gotomicro/ego/client/ehttp/resolver" "go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/codes" semconv "go.opentelemetry.io/otel/semconv/v1.7.0" "go.opentelemetry.io/otel/trace" + "github.com/gotomicro/ego/client/ehttp/resolver" + "github.com/gotomicro/ego/core/eapp" "github.com/gotomicro/ego/core/elog" "github.com/gotomicro/ego/core/emetric" @@ -140,7 +141,7 @@ func logInterceptor(name string, config *Config, logger *elog.Component, builder } func metricInterceptor(name string, config *Config, logger *elog.Component, builder resolver.Resolver) (resty.RequestMiddleware, resty.ResponseMiddleware, resty.ErrorHook) { - if !config.EnableMetricsInterceptor { + if !config.EnableMetricInterceptor { return nil, nil, nil } addr := strings.TrimRight(config.Addr, "/") diff --git a/client/ehttp/options.go b/client/ehttp/options.go index 4adf092c..1d8908a7 100644 --- a/client/ehttp/options.go +++ b/client/ehttp/options.go @@ -68,10 +68,10 @@ func WithEnableTraceInterceptor(enableTraceInterceptor bool) Option { } } -// WithEnableMetricsInterceptor 设置开启 Metrics 拦截器 -func WithEnableMetricsInterceptor(enableMetricsInterceptor bool) Option { +// WithEnableMetricInterceptor 设置开启 Metrics 拦截器 +func WithEnableMetricInterceptor(enableMetricsInterceptor bool) Option { return func(c *Container) { - c.config.EnableMetricsInterceptor = enableMetricsInterceptor + c.config.EnableMetricInterceptor = enableMetricsInterceptor } }