Skip to content

Commit 5caf4e4

Browse files
authored
Add 'features' command to print available feature gates (jaegertracing#6542)
## Which problem is this PR solving? - Resolves jaegertracing#6442 ## Description of the changes - ## How was this change tested? - make features ## Checklist - [x] I have read https://github.com/jaegertracing/jaeger/blob/master/CONTRIBUTING_GUIDELINES.md - [x] I have signed all commits - [x] I have added unit tests for the new functionality - [x] I have run lint and test steps successfully - for `jaeger`: `make lint test` - for `jaeger-ui`: `npm run lint` and `npm run test` --------- Signed-off-by: cs-308-2023 <[email protected]>
1 parent 88e819e commit 5caf4e4

File tree

3 files changed

+88
-0
lines changed

3 files changed

+88
-0
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// Copyright (c) 2025 The Jaeger Authors.
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
package features
5+
6+
import (
7+
"bytes"
8+
"fmt"
9+
10+
"go.opentelemetry.io/collector/featuregate"
11+
)
12+
13+
func DisplayFeatures() string {
14+
f := featuregate.GlobalRegistry()
15+
var buffer bytes.Buffer
16+
17+
f.VisitAll(func(g *featuregate.Gate) {
18+
fmt.Fprintf(&buffer, "Feature:\t%s\n", g.ID())
19+
if g.IsEnabled() {
20+
fmt.Fprintf(&buffer, "Default state:\t%s\n", "On")
21+
} else {
22+
fmt.Fprintf(&buffer, "Default state:\t%s\n", "Off")
23+
}
24+
fmt.Fprintf(&buffer, "Description:\t%s\n", g.Description())
25+
if ref := g.ReferenceURL(); ref != "" {
26+
fmt.Fprintf(&buffer, "ReferenceURL:\t%s\n", ref)
27+
}
28+
fmt.Fprintln(&buffer)
29+
})
30+
31+
return buffer.String()
32+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// Copyright (c) 2025 The Jaeger Authors.
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
package features
5+
6+
import (
7+
"testing"
8+
9+
"github.com/stretchr/testify/require"
10+
"go.opentelemetry.io/collector/featuregate"
11+
12+
"github.com/jaegertracing/jaeger/pkg/testutils"
13+
)
14+
15+
func TestMain(m *testing.M) {
16+
testutils.VerifyGoLeaks(m)
17+
}
18+
19+
func TestDisplayStageAlpha(t *testing.T) {
20+
featuregate.GlobalRegistry().MustRegister(
21+
"jaeger.featuresdisplay.testgate1",
22+
featuregate.StageAlpha,
23+
featuregate.WithRegisterDescription("testdescription"),
24+
featuregate.WithRegisterReferenceURL("https://testurl.com"),
25+
)
26+
out := DisplayFeatures()
27+
require.Contains(t, out, "jaeger.featuresdisplay.testgate")
28+
require.Contains(t, out, "Off")
29+
}
30+
31+
func TestDisplayStageBeta(t *testing.T) {
32+
featuregate.GlobalRegistry().MustRegister(
33+
"jaeger.featuresdisplay.testgate2",
34+
featuregate.StageBeta,
35+
featuregate.WithRegisterDescription("testdescription"),
36+
featuregate.WithRegisterReferenceURL("https://testurl.com"),
37+
)
38+
out := DisplayFeatures()
39+
require.Contains(t, out, "jaeger.featuresdisplay.testgate")
40+
require.Contains(t, out, "On")
41+
}

cmd/jaeger/main.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,15 @@
44
package main
55

66
import (
7+
"fmt"
78
"log"
89

10+
"github.com/spf13/cobra"
911
"github.com/spf13/viper"
1012

1113
"github.com/jaegertracing/jaeger/cmd/internal/docs"
1214
"github.com/jaegertracing/jaeger/cmd/jaeger/internal"
15+
"github.com/jaegertracing/jaeger/cmd/jaeger/internal/features"
1316
"github.com/jaegertracing/jaeger/internal/storage/elasticsearch/mapping"
1417
"github.com/jaegertracing/jaeger/pkg/config"
1518
"github.com/jaegertracing/jaeger/pkg/version"
@@ -20,6 +23,7 @@ func main() {
2023
command := internal.Command()
2124
command.AddCommand(version.Command())
2225
command.AddCommand(docs.Command(v))
26+
command.AddCommand(featuresCommand())
2327
command.AddCommand(mapping.Command())
2428
config.AddFlags(
2529
v,
@@ -30,3 +34,14 @@ func main() {
3034
log.Fatal(err)
3135
}
3236
}
37+
38+
func featuresCommand() *cobra.Command {
39+
return &cobra.Command{
40+
Use: "features",
41+
Short: "Displays the list of supported features",
42+
Long: "The 'features' command shows all supported features in the current build of Jaeger.",
43+
Run: func(_ *cobra.Command, _ []string) {
44+
fmt.Print(features.DisplayFeatures())
45+
},
46+
}
47+
}

0 commit comments

Comments
 (0)