Skip to content

Commit

Permalink
[chore] Sync internal/common/localhostgate (#31965)
Browse files Browse the repository at this point in the history
**Description:** Syncs localhostgate with core after changes in
open-telemetry/opentelemetry-collector/pull/9852
  • Loading branch information
mx-psi authored Mar 27, 2024
1 parent 101b8b1 commit 80bbf5e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
8 changes: 4 additions & 4 deletions internal/common/localhostgate/featuregate.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ import (

const UseLocalHostAsDefaultHostID = "component.UseLocalHostAsDefaultHost"

// useLocalHostAsDefaultHostfeatureGate is the feature gate that controls whether
// UseLocalHostAsDefaultHostfeatureGate is the feature gate that controls whether
// server-like receivers and extensions such as the OTLP receiver use localhost as the default host for their endpoints.
var useLocalHostAsDefaultHostfeatureGate = mustRegisterOrLoad(
var UseLocalHostAsDefaultHostfeatureGate = mustRegisterOrLoad(
featuregate.GlobalRegistry(),
UseLocalHostAsDefaultHostID,
featuregate.StageAlpha,
Expand Down Expand Up @@ -51,15 +51,15 @@ func mustRegisterOrLoad(reg *featuregate.Registry, id string, stage featuregate.
// EndpointForPort gets the endpoint for a given port using localhost or 0.0.0.0 depending on the feature gate.
func EndpointForPort(port int) string {
host := "localhost"
if !useLocalHostAsDefaultHostfeatureGate.IsEnabled() {
if !UseLocalHostAsDefaultHostfeatureGate.IsEnabled() {
host = "0.0.0.0"
}
return fmt.Sprintf("%s:%d", host, port)
}

// LogAboutUseLocalHostAsDefault logs about the upcoming change from 0.0.0.0 to localhost on server-like components.
func LogAboutUseLocalHostAsDefault(logger *zap.Logger) {
if !useLocalHostAsDefaultHostfeatureGate.IsEnabled() {
if !UseLocalHostAsDefaultHostfeatureGate.IsEnabled() {
logger.Warn(
"The default endpoints for all servers in components will change to use localhost instead of 0.0.0.0 in a future version. Use the feature gate to preview the new default.",
zap.String("feature gate ID", UseLocalHostAsDefaultHostID),
Expand Down
2 changes: 1 addition & 1 deletion internal/common/localhostgate/featuregate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func TestEndpointForPort(t *testing.T) {

for _, tt := range tests {
t.Run(tt.endpoint, func(t *testing.T) {
defer setFeatureGateForTest(t, useLocalHostAsDefaultHostfeatureGate, tt.enabled)()
defer setFeatureGateForTest(t, UseLocalHostAsDefaultHostfeatureGate, tt.enabled)()
assert.Equal(t, EndpointForPort(tt.port), tt.endpoint)
})
}
Expand Down

0 comments on commit 80bbf5e

Please sign in to comment.