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 5 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 (
"fmt"

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

func DisplayFeatures() string {
f := featuregate.GlobalRegistry()
if f == nil {
return ""
}
ADI-ROXX marked this conversation as resolved.
Show resolved Hide resolved
out := ""
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why use out += concatenation?

        var buffer bytes.Buffer
        w := io.StringWriter(&buffer)
        // use fmt.Fprintf(w, format, values...)
        return buffer.String()	

f.VisitAll(func(g *featuregate.Gate) {
out += fmt.Sprintf("Feature:\t%s\n", g.ID())
if !g.IsEnabled() {
out += fmt.Sprintf("Default state:\t%s\n", "On")
} else {
out += fmt.Sprintf("Default state:\t%s\n", "Off")
}
out += fmt.Sprintf("Description:\t%s\n", g.Description())
if ref := g.ReferenceURL(); ref != "" {
out += fmt.Sprintf("ReferenceURL:\t%s\n", ref)
}
out += "\n"
})
return out
}
34 changes: 34 additions & 0 deletions cmd/jaeger/internal/features/display_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// Copyright (c) 2025 The Jaeger Authors.
// SPDX-License-Identifier: Apache-2.0

package features

import (
"regexp"
"strings"
"testing"

"github.com/stretchr/testify/require"

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

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

func TestDisplay(t *testing.T) {
internal.Command()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without running internal.Command(), featuregate.GlobalRegistry() returns an empty array, so the output string is empty.

After running internal.Command(), I am able to get the flags.

out := DisplayFeatures()
parts := strings.Split(out, "\n\n")
parts = parts[:len(parts)-1]
feature_re := regexp.MustCompile(`(?m)Feature:\s*(.*)`) // String between Feature: and the first \n after it
description_re := regexp.MustCompile(`(?m)Description:\s*(.*)`) // String between Description: and the first \n after it
for _, part := range parts {
feature_matches := feature_re.FindStringSubmatch(part)
require.Greater(t, len(feature_matches), 1)
description_matches := description_re.FindStringSubmatch(part)
require.Greater(t, len(description_matches), 1)
}
}
16 changes: 16 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/pkg/config"
"github.com/jaegertracing/jaeger/pkg/version"
)
Expand All @@ -19,6 +22,8 @@ func main() {
command := internal.Command()
command.AddCommand(version.Command())
command.AddCommand(docs.Command(v))
command.AddCommand(featuresCommand())

config.AddFlags(
v,
command,
Expand All @@ -28,3 +33,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())
},
}
}