From 6a3750535f7586a70e6e99f87301ac643290c091 Mon Sep 17 00:00:00 2001 From: Bogdan Drutu Date: Mon, 23 Sep 2024 12:31:44 -0700 Subject: [PATCH] Change default metrics address to localhost:8888 Signed-off-by: Bogdan Drutu --- .../change-prom-address-to-localhost.yaml | 25 +++++++++++++++++++ service/telemetry/factory.go | 18 ++++++++++--- 2 files changed, 40 insertions(+), 3 deletions(-) create mode 100644 .chloggen/change-prom-address-to-localhost.yaml diff --git a/.chloggen/change-prom-address-to-localhost.yaml b/.chloggen/change-prom-address-to-localhost.yaml new file mode 100644 index 00000000000..3d27d391ce6 --- /dev/null +++ b/.chloggen/change-prom-address-to-localhost.yaml @@ -0,0 +1,25 @@ +# Use this changelog template to create an entry for release notes. + +# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix' +change_type: 'breaking' + +# The name of the component, or a single word describing the area of concern, (e.g. otlpreceiver) +component: service/telemetry + +# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). +note: + +# One or more tracking issues or pull requests related to the change +issues: [] + +# (Optional) One or more lines of additional information to render under the primary note. +# These lines will be padded with 2 spaces and then inserted directly into the document. +# Use pipe (|) for multiline entries. +subtext: This behavior can be disabled by disabling the feature gate 'telemetry.UseLocalHostAsDefaultMetricsAddress'. + +# Optional: The change log or logs in which this entry should be included. +# e.g. '[user]' or '[user, api]' +# Include 'user' if the change is relevant to end users. +# Include 'api' if there is a change to a library API. +# Default: '[user]' +change_logs: [user, api] diff --git a/service/telemetry/factory.go b/service/telemetry/factory.go index 474c245c22d..f611c560c33 100644 --- a/service/telemetry/factory.go +++ b/service/telemetry/factory.go @@ -18,9 +18,16 @@ import ( "go.opentelemetry.io/collector/service/internal/resource" ) +var useLocalHostAsDefaultMetricsAddressFeatureGate = featuregate.GlobalRegistry().MustRegister( + "telemetry.UseLocalHostAsDefaultMetricsAddress", + featuregate.StageBeta, + featuregate.WithRegisterFromVersion("v0.110.0"), + featuregate.WithRegisterDescription("controls whether default Prometheus metrics server use localhost as the default host for their endpoints"), +) + // disableHighCardinalityMetricsfeatureGate is the feature gate that controls whether the collector should enable // potentially high cardinality metrics. The gate will be removed when the collector allows for view configuration. -var disableHighCardinalityMetricsfeatureGate = featuregate.GlobalRegistry().MustRegister( +var disableHighCardinalityMetricsFeatureGate = featuregate.GlobalRegistry().MustRegister( "telemetry.disableHighCardinalityMetrics", featuregate.StageAlpha, featuregate.WithRegisterDescription("controls whether the collector should enable potentially high"+ @@ -67,7 +74,7 @@ func NewFactory() Factory { }), withMeterProvider(func(_ context.Context, set Settings, cfg component.Config) (metric.MeterProvider, error) { c := *cfg.(*Config) - disableHighCard := disableHighCardinalityMetricsfeatureGate.IsEnabled() + disableHighCard := disableHighCardinalityMetricsFeatureGate.IsEnabled() return newMeterProvider( meterProviderSettings{ res: resource.New(set.BuildInfo, c.Resource), @@ -81,6 +88,11 @@ func NewFactory() Factory { } func createDefaultConfig() component.Config { + metricsAddress := "localhost:8888" + if !useLocalHostAsDefaultMetricsAddressFeatureGate.IsEnabled() { + metricsAddress = ":8888" + } + return &Config{ Logs: LogsConfig{ Level: zapcore.InfoLevel, @@ -100,7 +112,7 @@ func createDefaultConfig() component.Config { }, Metrics: MetricsConfig{ Level: configtelemetry.LevelNormal, - Address: ":8888", + Address: metricsAddress, }, } }