feature.go 819 B

1234567891011121314151617181920212223242526272829303132
  1. package options
  2. import "github.com/spf13/pflag"
  3. // FeatureOptions 开启性能分析和指标选项
  4. type FeatureOptions struct {
  5. EnableProfiling bool `json:"profiling" mapstructure:"profiling"`
  6. EnableMetrics bool `json:"enable-metrics" mapstructure:"enable-metrics"`
  7. }
  8. func NewFeatureOptions() *FeatureOptions {
  9. return &FeatureOptions{
  10. EnableMetrics: false,
  11. EnableProfiling: false,
  12. }
  13. }
  14. func (o *FeatureOptions) Validate() []error {
  15. return []error{}
  16. }
  17. func (o *FeatureOptions) AddFlags(fs *pflag.FlagSet) {
  18. if fs == nil {
  19. return
  20. }
  21. fs.BoolVar(&o.EnableProfiling, "feature.profiling", o.EnableProfiling,
  22. "Enable profiling via web interface host:port/debug/pprof/")
  23. fs.BoolVar(&o.EnableMetrics, "feature.enable-metrics", o.EnableMetrics,
  24. "Enables metrics on the apiserver at /metrics")
  25. }