Skip to content

Commit

Permalink
add feature command
Browse files Browse the repository at this point in the history
Signed-off-by: danish9039 <[email protected]>
  • Loading branch information
danish9039 committed Jan 4, 2025
1 parent ffcef93 commit 864fe0d
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 2 deletions.
19 changes: 19 additions & 0 deletions otelcol/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,16 @@
package otelcol // import "go.opentelemetry.io/collector/otelcol"

import (
// Standard library
"errors"
"flag"

// Third party
"github.com/spf13/cobra"

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

// NewCommand constructs a new cobra.Command using the given CollectorSettings.
Expand All @@ -36,6 +40,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 +68,17 @@ func updateSettingsUsingFlags(set *CollectorSettings, flags *flag.FlagSet) error
}
return nil
}

func newFeaturesCommand() *cobra.Command {
return &cobra.Command{
Use: "features [feature-id]",
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 {
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 {
data := graph.GetFeaturesTableData()
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

0 comments on commit 864fe0d

Please sign in to comment.