Skip to content

Commit

Permalink
chore: update feature gate usage to new register API
Browse files Browse the repository at this point in the history
  • Loading branch information
aboguszewski-sumo committed Nov 14, 2022
1 parent 819030d commit b053ced
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 14 deletions.
22 changes: 9 additions & 13 deletions receiver/elasticsearchreceiver/scraper.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,20 +43,16 @@ var (
)

const (
readmeURL = "https://github.com/open-telemetry/opentelemetry-collector-contrib/blob/main/receiver/elasticsearchreceiver/README.md"
EmitClusterHealthDetailedShardMetrics = "receiver.elasticsearch.emitClusterHealthDetailedShardMetrics"
)

var (
emitClusterHealthDetailedShardMetrics = featuregate.Gate{
ID: EmitClusterHealthDetailedShardMetrics,
Enabled: false,
Description: "When enabled, the elasticsearch.cluster.shards metric will be emitted with two more datapoints.",
}
readmeURL = "https://github.com/open-telemetry/opentelemetry-collector-contrib/blob/main/receiver/elasticsearchreceiver/README.md"
emitClusterHealthDetailedShardMetricsID = "receiver.elasticsearch.emitClusterHealthDetailedShardMetrics"
)

func init() {
featuregate.GetRegistry().MustRegister(emitClusterHealthDetailedShardMetrics)
featuregate.GetRegistry().MustRegisterID(
emitClusterHealthDetailedShardMetricsID,
featuregate.StageAlpha,
featuregate.WithRegisterDescription("When enabled, the elasticsearch.cluster.shards metric will be emitted with two more datapoints."),
)
}

var errUnknownClusterStatus = errors.New("unknown cluster status")
Expand All @@ -81,12 +77,12 @@ func newElasticSearchScraper(
settings: settings.TelemetrySettings,
cfg: cfg,
mb: metadata.NewMetricsBuilder(cfg.Metrics, settings.BuildInfo),
emitClusterHealthDetailedShardMetrics: featuregate.GetRegistry().IsEnabled(EmitClusterHealthDetailedShardMetrics),
emitClusterHealthDetailedShardMetrics: featuregate.GetRegistry().IsEnabled(emitClusterHealthDetailedShardMetricsID),
}

if !e.emitClusterHealthDetailedShardMetrics {
settings.Logger.Warn(
fmt.Sprintf("Feature gate %s is not enabled. Please see the README for more information: %s", EmitClusterHealthDetailedShardMetrics, readmeURL),
fmt.Sprintf("Feature gate %s is not enabled. Please see the README for more information: %s", emitClusterHealthDetailedShardMetricsID, readmeURL),
)
}

Expand Down
2 changes: 1 addition & 1 deletion receiver/elasticsearchreceiver/scraper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ const noNodesExpectedMetricsPath = "./testdata/expected_metrics/noNodes.json"

func TestMain(m *testing.M) {
// Enable the feature gates before all tests to avoid flaky tests.
_ = featuregate.GetRegistry().Apply(map[string]bool{EmitClusterHealthDetailedShardMetrics: true})
_ = featuregate.GetRegistry().Apply(map[string]bool{emitClusterHealthDetailedShardMetricsID: true})
code := m.Run()
os.Exit(code)
}
Expand Down

0 comments on commit b053ced

Please sign in to comment.