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

Feature command #12014

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 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
16 changes: 16 additions & 0 deletions otelcol/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/spf13/cobra"

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

// NewCommand constructs a new cobra.Command using the given CollectorSettings.
Expand All @@ -36,6 +37,7 @@ func NewCommand(set CollectorSettings) *cobra.Command {
return col.Run(cmd.Context())
},
}
rootCmd.AddCommand(newFeaturesCommand())
rootCmd.AddCommand(newComponentsCommand(set))
rootCmd.AddCommand(newValidateSubCommand(set, flagSet))
rootCmd.Flags().AddGoFlagSet(flagSet)
Expand Down Expand Up @@ -63,3 +65,17 @@ func updateSettingsUsingFlags(set *CollectorSettings, flags *flag.FlagSet) error
}
return nil
}

func newFeaturesCommand() *cobra.Command {
return &cobra.Command{
Use: "features [feature-id]",
Copy link
Member

Choose a reason for hiding this comment

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

@open-telemetry/collector-approvers do you prefer features? gates? featuregates?

Copy link
Member

Choose a reason for hiding this comment

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

features sounds better to me

Short: "Display feature gates information",
Long: "Display information about available feature gates and their status",
RunE: func(cmd *cobra.Command, args []string) error {
if len(args) > 0 {
return service.DisplayFeature(args[0])
}
return service.DisplayFeatures()
},
}
}
44 changes: 44 additions & 0 deletions service/display_feature.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

package service // import "go.opentelemetry.io/collector/service"

import (
"fmt"
"os"
"text/tabwriter"

"go.opentelemetry.io/collector/service/internal/graph"
)

func DisplayFeatures() error {
bogdandrutu marked this conversation as resolved.
Show resolved Hide resolved
w := tabwriter.NewWriter(os.Stdout, 0, 0, 2, ' ', 0)
fmt.Fprintf(w, "ID\tEnabled\tStage\tDescription\n")
data := graph.GetFeaturesTableData()
for _, row := range data.Rows {
fmt.Fprintf(w, "%s\t%v\t%s\t%s\n",
row.ID,
row.Enabled,
row.Stage,
row.Description)
}
return w.Flush()
}

func DisplayFeature(id string) error {
bogdandrutu marked this conversation as resolved.
Show resolved Hide resolved
data := graph.GetFeaturesTableData()
bogdandrutu marked this conversation as resolved.
Show resolved Hide resolved
for _, row := range data.Rows {
if row.ID == id {
fmt.Printf("Feature: %s\n", row.ID)
fmt.Printf("Enabled: %v\n", row.Enabled)
fmt.Printf("Stage: %s\n", row.Stage)
fmt.Printf("Description: %s\n", row.Description)
fmt.Printf("From Version: %s\n", row.FromVersion)
if row.ToVersion != "" {
fmt.Printf("To Version: %s\n", row.ToVersion)
}
return nil
}
}
return fmt.Errorf("feature %q not found", id)
}
4 changes: 2 additions & 2 deletions service/internal/graph/host.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,11 +138,11 @@ func (host *Host) zPagesRequest(w http.ResponseWriter, _ *http.Request) {
func handleFeaturezRequest(w http.ResponseWriter, _ *http.Request) {
w.Header().Set("Content-Type", "text/html; charset=utf-8")
zpages.WriteHTMLPageHeader(w, zpages.HeaderData{Title: "Feature Gates"})
zpages.WriteHTMLFeaturesTable(w, getFeaturesTableData())
zpages.WriteHTMLFeaturesTable(w, GetFeaturesTableData())
zpages.WriteHTMLPageFooter(w)
}

func getFeaturesTableData() zpages.FeatureGateTableData {
func GetFeaturesTableData() zpages.FeatureGateTableData {
data := zpages.FeatureGateTableData{}
featuregate.GlobalRegistry().VisitAll(func(gate *featuregate.Gate) {
data.Rows = append(data.Rows, zpages.FeatureGateTableRowData{
Expand Down