Skip to content

Commit

Permalink
Change default metrics address to localhost:8888
Browse files Browse the repository at this point in the history
Signed-off-by: Bogdan Drutu <bogdandrutu@gmail.com>
  • Loading branch information
bogdandrutu committed Sep 23, 2024
1 parent fe10446 commit 6a37505
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 3 deletions.
25 changes: 25 additions & 0 deletions .chloggen/change-prom-address-to-localhost.yaml
Original file line number Diff line number Diff line change
@@ -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]
18 changes: 15 additions & 3 deletions service/telemetry/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"+
Expand Down Expand Up @@ -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),
Expand All @@ -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,
Expand All @@ -100,7 +112,7 @@ func createDefaultConfig() component.Config {
},
Metrics: MetricsConfig{
Level: configtelemetry.LevelNormal,
Address: ":8888",
Address: metricsAddress,
},
}
}

0 comments on commit 6a37505

Please sign in to comment.