Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add 'features' command to print available feature gates #6542

Merged
merged 11 commits into from
Jan 26, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions cmd/jaeger/internal/features/display.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// Copyright (c) 2025 The Jaeger Authors.
// SPDX-License-Identifier: Apache-2.0

package features

import (
"bytes"
"fmt"

"go.opentelemetry.io/collector/featuregate"
)

func DisplayFeatures() string {
f := featuregate.GlobalRegistry()
var buffer bytes.Buffer

f.VisitAll(func(g *featuregate.Gate) {
fmt.Fprintf(&buffer, "Feature:\t%s\n", g.ID())
if g.IsEnabled() {
fmt.Fprintf(&buffer, "Default state:\t%s\n", "On")
} else {
fmt.Fprintf(&buffer, "Default state:\t%s\n", "Off")
}
fmt.Fprintf(&buffer, "Description:\t%s\n", g.Description())
if ref := g.ReferenceURL(); ref != "" {
fmt.Fprintf(&buffer, "ReferenceURL:\t%s\n", ref)
}
fmt.Fprintln(&buffer)
})

return buffer.String()
}
41 changes: 41 additions & 0 deletions cmd/jaeger/internal/features/display_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// Copyright (c) 2025 The Jaeger Authors.
// SPDX-License-Identifier: Apache-2.0

package features

import (
"testing"

"github.com/stretchr/testify/require"
"go.opentelemetry.io/collector/featuregate"

"github.com/jaegertracing/jaeger/pkg/testutils"
)

func TestMain(m *testing.M) {
testutils.VerifyGoLeaks(m)
}

func TestDisplayStageAlpha(t *testing.T) {
featuregate.GlobalRegistry().MustRegister(
"jaeger.featuresdisplay.testgate1",
featuregate.StageAlpha,
featuregate.WithRegisterDescription("testdescription"),
featuregate.WithRegisterReferenceURL("https://testurl.com"),
)
out := DisplayFeatures()
require.Contains(t, out, "jaeger.featuresdisplay.testgate")
require.Contains(t, out, "Off")
}

func TestDisplayStageBeta(t *testing.T) {
featuregate.GlobalRegistry().MustRegister(
"jaeger.featuresdisplay.testgate2",
featuregate.StageBeta,
featuregate.WithRegisterDescription("testdescription"),
featuregate.WithRegisterReferenceURL("https://testurl.com"),
)
out := DisplayFeatures()
require.Contains(t, out, "jaeger.featuresdisplay.testgate")
require.Contains(t, out, "On")
}
15 changes: 15 additions & 0 deletions cmd/jaeger/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,15 @@
package main

import (
"fmt"
"log"

"github.com/spf13/cobra"
"github.com/spf13/viper"

"github.com/jaegertracing/jaeger/cmd/internal/docs"
"github.com/jaegertracing/jaeger/cmd/jaeger/internal"
"github.com/jaegertracing/jaeger/cmd/jaeger/internal/features"
"github.com/jaegertracing/jaeger/internal/storage/elasticsearch/mapping"
"github.com/jaegertracing/jaeger/pkg/config"
"github.com/jaegertracing/jaeger/pkg/version"
Expand All @@ -20,6 +23,7 @@ func main() {
command := internal.Command()
command.AddCommand(version.Command())
command.AddCommand(docs.Command(v))
command.AddCommand(featuresCommand())
command.AddCommand(mapping.Command())
config.AddFlags(
v,
Expand All @@ -30,3 +34,14 @@ func main() {
log.Fatal(err)
}
}

func featuresCommand() *cobra.Command {
return &cobra.Command{
Use: "features",
Short: "Displays the list of supported features",
Long: "The 'features' command shows all supported features in the current build of Jaeger.",
Run: func(_ *cobra.Command, _ []string) {
fmt.Print(features.DisplayFeatures())
},
}
}
Loading