| 1 |
// Copyright The OpenTelemetry Authors |
| 2 |
// SPDX-License-Identifier: Apache-2.0 |
| 3 |
|
| 4 |
package featuregate // import "go.opentelemetry.io/collector/featuregate" |
| 5 |
|
| 6 |
import ( |
| 7 |
"fmt" |
| 8 |
"sync/atomic" |
| 9 |
|
| 10 |
"github.com/hashicorp/go-version" |
| 11 |
) |
| 12 |
|
| 13 |
// Gate is an immutable object that is owned by the Registry and represents an individual feature that |
| 14 |
// may be enabled or disabled based on the lifecycle state of the feature and CLI flags specified by the user. |
| 15 |
type Gate struct { |
| 16 |
id string |
| 17 |
description string |
| 18 |
referenceURL string |
| 19 |
fromVersion *version.Version |
| 20 |
toVersion *version.Version |
| 21 |
stage Stage |
| 22 |
enabled *atomic.Bool |
| 23 |
} |
| 24 |
|
| 25 |
// ID returns the id of the Gate. |
| 26 |
func (g *Gate) ID() string { |
| 27 |
return g.id |
| 28 |
} |
| 29 |
|
| 30 |
// IsEnabled returns true if the feature described by the Gate is enabled. |
| 31 |
func (g *Gate) IsEnabled() bool { |
| 32 |
return g.enabled.Load() |
| 33 |
} |
| 34 |
|
| 35 |
// Description returns the description for the Gate. |
| 36 |
func (g *Gate) Description() string { |
| 37 |
return g.description |
| 38 |
} |
| 39 |
|
| 40 |
// Stage returns the Gate's lifecycle stage. |
| 41 |
func (g *Gate) Stage() Stage { |
| 42 |
return g.stage |
| 43 |
} |
| 44 |
|
| 45 |
// ReferenceURL returns the URL to the contextual information about the Gate. |
| 46 |
func (g *Gate) ReferenceURL() string { |
| 47 |
return g.referenceURL |
| 48 |
} |
| 49 |
|
| 50 |
// FromVersion returns the version information when the Gate's was added. |
| 51 |
func (g *Gate) FromVersion() string { |
| 52 |
return fmt.Sprintf("v%s", g.fromVersion) |
| 53 |
} |
| 54 |
|
| 55 |
// ToVersion returns the version information when Gate's in StageStable. |
| 56 |
func (g *Gate) ToVersion() string { |
| 57 |
return fmt.Sprintf("v%s", g.toVersion) |
| 58 |
} |