Skip to content

Commit

Permalink
Revert "Add accessor for global feature gate registry"
Browse files Browse the repository at this point in the history
This reverts commit 23c957c.
  • Loading branch information
Aneurysm9 committed Nov 18, 2021
1 parent d0faa47 commit a9c86ae
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 15 deletions.
11 changes: 0 additions & 11 deletions service/featuregate/gates.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,18 +53,11 @@ func Apply(cfg map[string]bool) {
reg.Apply(cfg)
}

// GlobalRegistry returns the Registry instance used by package-global functions in this package.
func GlobalRegistry() *Registry {
return reg
}

type Registry struct {
sync.RWMutex
gates map[string]Gate
}

// Apply a configuration in the form of a map of Gate identifiers to boolean values.
// Sets only those values provided in the map, other gate values are not changed.
func (r *Registry) Apply(cfg map[string]bool) {
r.Lock()
defer r.Unlock()
Expand All @@ -76,8 +69,6 @@ func (r *Registry) Apply(cfg map[string]bool) {
}
}

// Add a Gate. May only be called in an init() function.
// Returns an error if a Gate with the same ID is already registered.
func (r *Registry) Add(g Gate) error {
r.Lock()
defer r.Unlock()
Expand All @@ -89,15 +80,13 @@ func (r *Registry) Add(g Gate) error {
return nil
}

// IsEnabled returns true if a registered feature gate is enabled and false otherwise.
func (r *Registry) IsEnabled(id string) bool {
r.RLock()
defer r.RUnlock()
g, ok := r.gates[id]
return ok && g.Enabled
}

// List returns a slice of copies of all registered Gates.
func (r *Registry) List() []Gate {
r.RLock()
defer r.RUnlock()
Expand Down
4 changes: 0 additions & 4 deletions service/featuregate/gates_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,17 +51,13 @@ func TestGlobalRegistry(t *testing.T) {

assert.NotContains(t, List(), gate)
assert.False(t, IsEnabled(gate.ID))
assert.False(t, GlobalRegistry().IsEnabled(gate.ID))

assert.NotPanics(t, func() { Register(gate) })
assert.Contains(t, List(), gate)
assert.Contains(t, GlobalRegistry().List(), gate)
assert.True(t, IsEnabled(gate.ID))
assert.True(t, GlobalRegistry().IsEnabled(gate.ID))

Apply(map[string]bool{gate.ID: false})
assert.False(t, IsEnabled(gate.ID))
assert.False(t, GlobalRegistry().IsEnabled(gate.ID))

assert.Panics(t, func() { Register(gate) })
reg.Lock()
Expand Down

0 comments on commit a9c86ae

Please sign in to comment.