mirror of
https://github.com/grafana/grafana.git
synced 2026-08-26 21:37:31 -05:00
API Server: Override k8s api server profile contention flag with custom ones (#90238)
Upgrades sdk ro v0.238.0
This commit is contained in:
+1
-1
@@ -3,7 +3,7 @@ module github.com/grafana/grafana/pkg/promlib
|
||||
go 1.21.10
|
||||
|
||||
require (
|
||||
github.com/grafana/grafana-plugin-sdk-go v0.237.0
|
||||
github.com/grafana/grafana-plugin-sdk-go v0.238.0
|
||||
github.com/json-iterator/go v1.1.12
|
||||
github.com/patrickmn/go-cache v2.1.0+incompatible
|
||||
github.com/prometheus/client_golang v1.19.1
|
||||
|
||||
+1
-1
@@ -80,7 +80,7 @@ github.com/gopherjs/gopherjs v0.0.0-20181103185306-d547d1d9531e h1:JKmoR8x90Iww1
|
||||
github.com/gopherjs/gopherjs v0.0.0-20181103185306-d547d1d9531e/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY=
|
||||
github.com/gorilla/mux v1.8.1 h1:TuBL49tXwgrFYWhqrNgrUNEY92u81SPhu7sTdzQEiWY=
|
||||
github.com/gorilla/mux v1.8.1/go.mod h1:AKf9I4AEqPTmMytcMc0KkNouC66V3BtZ4qD5fmWSiMQ=
|
||||
github.com/grafana/grafana-plugin-sdk-go v0.237.0 h1:sxif4tl9ocYSVyeCtGijWQbW2ygfEOFGKQTCQ/ZX99M=
|
||||
github.com/grafana/grafana-plugin-sdk-go v0.238.0 h1:+LPuhUCBiQJEd571+ymA4WsJiiafbRECdX67B6YYN64=
|
||||
github.com/grafana/otel-profiling-go v0.5.1 h1:stVPKAFZSa7eGiqbYuG25VcqYksR6iWvF3YH66t4qL8=
|
||||
github.com/grafana/pyroscope-go/godeltaprof v0.1.7 h1:C11j63y7gymiW8VugJ9ZW0pWfxTZugdSJyC48olk5KY=
|
||||
github.com/grafana/regexp v0.0.0-20221123153739-15dc172cd2db h1:7aN5cccjIqCLTzedH7MZzRZt5/lsAHch6Z3L2ZGn5FA=
|
||||
|
||||
@@ -15,6 +15,7 @@ type Options struct {
|
||||
RecommendedOptions *genericoptions.RecommendedOptions
|
||||
TracingOptions *TracingOptions
|
||||
MetricsOptions *MetricsOptions
|
||||
ProfilingOptions *ProfilingOptions
|
||||
ServerRunOptions *genericoptions.ServerRunOptions
|
||||
StorageOptions *options.StorageOptions
|
||||
}
|
||||
@@ -26,6 +27,7 @@ func New(logger log.Logger, codec runtime.Codec) *Options {
|
||||
RecommendedOptions: options.NewRecommendedOptions(codec),
|
||||
TracingOptions: NewTracingOptions(logger),
|
||||
MetricsOptions: NewMetricsOptions(logger),
|
||||
ProfilingOptions: NewProfilingOptions(logger),
|
||||
ServerRunOptions: genericoptions.NewServerRunOptions(),
|
||||
StorageOptions: options.NewStorageOptions(),
|
||||
}
|
||||
@@ -37,6 +39,7 @@ func (o *Options) AddFlags(fs *pflag.FlagSet) {
|
||||
o.RecommendedOptions.AddFlags(fs)
|
||||
o.TracingOptions.AddFlags(fs)
|
||||
o.MetricsOptions.AddFlags(fs)
|
||||
o.ProfilingOptions.AddFlags(fs)
|
||||
o.ServerRunOptions.AddUniversalFlags(fs)
|
||||
}
|
||||
|
||||
@@ -57,6 +60,10 @@ func (o *Options) Validate() []error {
|
||||
return errs
|
||||
}
|
||||
|
||||
if errs := o.ProfilingOptions.Validate(); len(errs) != 0 {
|
||||
return errs
|
||||
}
|
||||
|
||||
if errs := o.ServerRunOptions.Validate(); len(errs) != 0 {
|
||||
return errs
|
||||
}
|
||||
@@ -168,6 +175,12 @@ func (o *Options) ApplyTo(serverConfig *genericapiserver.RecommendedConfig) erro
|
||||
}
|
||||
}
|
||||
|
||||
if o.ProfilingOptions != nil {
|
||||
if err := o.ProfilingOptions.ApplyTo(serverConfig); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
if o.ServerRunOptions != nil {
|
||||
if err := o.ServerRunOptions.ApplyTo(&serverConfig.Config); err != nil {
|
||||
return err
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
package options
|
||||
|
||||
import (
|
||||
"runtime"
|
||||
|
||||
"github.com/grafana/grafana/pkg/infra/log"
|
||||
"github.com/spf13/pflag"
|
||||
genericapiserver "k8s.io/apiserver/pkg/server"
|
||||
)
|
||||
|
||||
type ProfilingOptions struct {
|
||||
logger log.Logger
|
||||
blockProfilingRate int
|
||||
mutexProfilingRate int
|
||||
}
|
||||
|
||||
func NewProfilingOptions(logger log.Logger) *ProfilingOptions {
|
||||
return &ProfilingOptions{
|
||||
logger: logger,
|
||||
}
|
||||
}
|
||||
|
||||
func (o *ProfilingOptions) AddFlags(fs *pflag.FlagSet) {
|
||||
fs.IntVar(&o.blockProfilingRate, "grafana.profiling.block-rate", 0, "Controls the fraction of goroutine blocking events that are reported in the blocking profile. The profiler aims to sample an average of one blocking event per rate nanoseconds spent blocked. To turn off profiling entirely, use 0.")
|
||||
fs.IntVar(&o.mutexProfilingRate, "grafana.profiling.mutex-rate", 0, "Controls the fraction of mutex contention events that are reported in the mutex profile. On average 1/rate events are reported. To turn off mutex profiling entirely, use 0.")
|
||||
}
|
||||
|
||||
func (o *ProfilingOptions) Validate() []error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (o *ProfilingOptions) ApplyTo(config *genericapiserver.RecommendedConfig) error {
|
||||
if !config.EnableProfiling {
|
||||
return nil
|
||||
}
|
||||
|
||||
// We bring our own block/mutex profiling configuration
|
||||
config.EnableContentionProfiling = false
|
||||
|
||||
runtime.SetBlockProfileRate(o.blockProfilingRate)
|
||||
runtime.SetMutexProfileFraction(o.mutexProfilingRate)
|
||||
|
||||
o.logger.Info("Profiling enabled", "blockProfileRate", o.blockProfilingRate, "mutexProfileRate", o.mutexProfilingRate)
|
||||
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user