Skip to content

Commit

Permalink
Deprecate Get prefix funcs for featuregate.Gate
Browse files Browse the repository at this point in the history
Signed-off-by: Bogdan Drutu <bogdandrutu@gmail.com>
  • Loading branch information
bogdandrutu committed Nov 11, 2022
1 parent b3c8744 commit 20e9967
Show file tree
Hide file tree
Showing 6 changed files with 129 additions and 62 deletions.
18 changes: 18 additions & 0 deletions .chloggen/deprecateget.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: deprecation

# The name of the component, or a single word describing the area of concern, (e.g. otlpreceiver)
component: featuregate

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Deprecate Get prefix funcs for `featuregate.Gate`

# One or more tracking issues or pull requests related to the change
issues: [6528]

# (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: |
`featuregate.Gate.GetID` -> `featuregate.Gate.ID`
`featuregate.Gate.GetDescription` -> `featuregate.Gate.Description`
66 changes: 66 additions & 0 deletions featuregate/gate.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
// Copyright The OpenTelemetry Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package featuregate // import "go.opentelemetry.io/collector/featuregate"

// Gate is an immutable object that is owned by the Registry and represents an individual feature that
// may be enabled or disabled based on the lifecycle state of the feature and CLI flags specified by the user.
type Gate struct {
id string
description string
referenceURL string
removalVersion string
stage Stage
enabled bool
}

// Deprecated: [v0.65.0] use ID.
func (g *Gate) GetID() string {
return g.ID()
}

// ID returns the id of the Gate.
func (g *Gate) ID() string {
return g.id
}

// IsEnabled returns true if the feature described by the Gate is enabled.
func (g *Gate) IsEnabled() bool {
return g.enabled
}

// Deprecated: [v0.65.0] use Description.
func (g *Gate) GetDescription() string {
return g.Description()
}

// Description returns the description for the Gate.
func (g *Gate) Description() string {
return g.description
}

// Stage returns the Gate's lifecycle stage.
func (g *Gate) Stage() Stage {
return g.stage
}

// ReferenceURL returns the URL to the contextual information about the Gate.
func (g *Gate) ReferenceURL() string {
return g.referenceURL
}

// RemovalVersion returns the removal version information for Gate's in StageStable.
func (g *Gate) RemovalVersion() string {
return g.removalVersion
}
39 changes: 39 additions & 0 deletions featuregate/gate_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// Copyright The OpenTelemetry Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package featuregate

import (
"testing"

"github.com/stretchr/testify/assert"
)

func TestGate(t *testing.T) {
g := &Gate{
id: "test",
description: "test gate",
enabled: false,
stage: StageAlpha,
referenceURL: "http://example.com",
removalVersion: "v0.64.0",
}

assert.Equal(t, "test", g.ID())
assert.Equal(t, "test gate", g.Description())
assert.Equal(t, false, g.IsEnabled())
assert.Equal(t, StageAlpha, g.Stage())
assert.Equal(t, "http://example.com", g.ReferenceURL())
assert.Equal(t, "v0.64.0", g.RemovalVersion())
}
46 changes: 4 additions & 42 deletions featuregate/gates.go → featuregate/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,69 +19,31 @@ import (
"sync"
)

// Gate is an immutable object that is owned by the `Registry`
// to represents an individual feature that may be enabled or disabled based
// on the lifecycle state of the feature and CLI flags specified by the user.
type Gate struct {
id string
description string
referenceURL string
removalVersion string
stage Stage
enabled bool
}

// RegistryOption allows for configuration additional information
// about a gate that can be exposed throughout the application
// RegistryOption allows for configuration additional information about a Gate that can be exposed throughout the application.
type RegistryOption func(g *Gate)

// WithRegisterDescription adds the description to the provided `Gate.
// WithRegisterDescription adds description for the Gate.
func WithRegisterDescription(description string) RegistryOption {
return func(g *Gate) {
g.description = description
}
}

// WithRegisterReferenceURL adds an URL that has
// all the contextual information about the `Gate`.
// WithRegisterReferenceURL adds an URL that has all the contextual information about the Gate.
func WithRegisterReferenceURL(url string) RegistryOption {
return func(g *Gate) {
g.referenceURL = url
}
}

// WithRegisterRemovalVersion is used when the `Gate` is considered `StageStable`,
// WithRegisterRemovalVersion is used when the Gate is considered StageStable,
// to inform users that referencing the gate is no longer needed.
func WithRegisterRemovalVersion(version string) RegistryOption {
return func(g *Gate) {
g.removalVersion = version
}
}

func (g *Gate) GetID() string {
return g.id
}

func (g *Gate) IsEnabled() bool {
return g.enabled
}

func (g *Gate) GetDescription() string {
return g.description
}

func (g *Gate) Stage() Stage {
return g.stage
}

func (g *Gate) ReferenceURL() string {
return g.referenceURL
}

func (g *Gate) RemovalVersion() string {
return g.removalVersion
}

var reg = NewRegistry()

// GetRegistry returns the global Registry.
Expand Down
18 changes: 0 additions & 18 deletions featuregate/gates_test.go → featuregate/registry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,21 +165,3 @@ func TestRegisterGateLifecycle(t *testing.T) {
})
}
}

func TestGateMethods(t *testing.T) {
g := &Gate{
id: "test",
description: "test gate",
enabled: false,
stage: StageAlpha,
referenceURL: "http://example.com",
removalVersion: "v0.64.0",
}

assert.Equal(t, "test", g.GetID())
assert.Equal(t, "test gate", g.GetDescription())
assert.Equal(t, false, g.IsEnabled())
assert.Equal(t, StageAlpha, g.Stage())
assert.Equal(t, "http://example.com", g.ReferenceURL())
assert.Equal(t, "v0.64.0", g.RemovalVersion())
}
4 changes: 2 additions & 2 deletions service/zpages.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,9 @@ func getFeaturesTableData() zpages.FeatureGateTableData {
data := zpages.FeatureGateTableData{}
for _, g := range featuregate.GetRegistry().List() {
data.Rows = append(data.Rows, zpages.FeatureGateTableRowData{
ID: g.GetID(),
ID: g.ID(),
Enabled: g.IsEnabled(),
Description: g.GetDescription(),
Description: g.Description(),
ReferenceURL: g.ReferenceURL(),
Stage: g.Stage().String(),
RemovalVersion: g.RemovalVersion(),
Expand Down

0 comments on commit 20e9967

Please sign in to comment.