Skip to content

Commit

Permalink
feat: configurable metrics (#573)
Browse files Browse the repository at this point in the history
  • Loading branch information
pboros committed Oct 3, 2022
1 parent 1d24c42 commit 765d8d8
Show file tree
Hide file tree
Showing 25 changed files with 862 additions and 602 deletions.
154 changes: 136 additions & 18 deletions server/config/options.go
Expand Up @@ -33,6 +33,7 @@ type Config struct {
Cdc CdcConfig `yaml:"cdc" json:"cdc"`
Search SearchConfig `yaml:"search" json:"search"`
Tracing TracingConfig `yaml:"tracing" json:"tracing"`
Metrics MetricsConfig `yaml:"metrics" json:"metrics"`
Profiling ProfilingConfig `yaml:"profiling" json:"profiling"`
FoundationDB FoundationDBConfig
Quota QuotaConfig
Expand Down Expand Up @@ -76,6 +77,74 @@ type TracingConfig struct {
WithDogStatsdAddr string `mapstructure:"dogstatsd_addr" yaml:"dogstatsd_addr" json:"dogstatsd_addr"`
}

type MetricsConfig struct {
Enabled bool `mapstructure:"enabled" yaml:"enabled" json:"enabled"`
TimerQuantiles []float64 `mapstructure:"quantiles" yaml:"quantiles" json:"quantiles"`
Requests RequestsMetricGroupConfig `mapstructure:"requests" yaml:"requests" json:"requests"`
Fdb FdbMetricGroupConfig `mapstructure:"fdb" yaml:"fdb" json:"fdb"`
Search SearchMetricGroupConfig `mapstructure:"search" yaml:"search" json:"search"`
Session SessionMetricGroupConfig `mapstructure:"session" yaml:"session" json:"session"`
Size SizeMetricGroupConfig `mapstructure:"size" yaml:"size" json:"size"`
Network NetworkMetricGroupConfig `mapstructure:"network" yaml:"network" json:"network"`
Auth AuthMetricsConfig `mapstructure:"auth" yaml:"auth" json:"auth"`
}

type TimerConfig struct {
TimerEnabled bool `mapstructure:"timer_enabled" yaml:"timer_enabled" json:"timer_enabled"`
HistogramEnabled bool `mapstructure:"histogram_enabled" yaml:"histogram_enabled" json:"histogram_enabled"`
}

type CounterConfig struct {
OkEnabled bool `mapstructure:"ok_enabled" yaml:"ok_enabled" json:"ok_enabled"`
ErrorEnabled bool `mapstructure:"error_enabled" yaml:"error_enabled" json:"error_enabled"`
}

type RequestsMetricGroupConfig struct {
Enabled bool `mapstructure:"enabled" yaml:"enabled" json:"enabled"`
Counter CounterConfig `mapstructure:"counter" yaml:"counter" json:"counter"`
Timer TimerConfig `mapstructure:"timer" yaml:"timer" json:"timer"`
FilteredTags []string `mapstructure:"filtered_tags" yaml:"filtered_tags" json:"filtered_tags"`
}

type FdbMetricGroupConfig struct {
Enabled bool `mapstructure:"enabled" yaml:"enabled" json:"enabled"`
Counter CounterConfig `mapstructure:"counter" yaml:"counter" json:"counter"`
Timer TimerConfig `mapstructure:"timer" yaml:"timer" json:"timer"`
FilteredTags []string `mapstructure:"filtered_tags" yaml:"filtered_tags" json:"filtered_tags"`
}

type SearchMetricGroupConfig struct {
Enabled bool `mapstructure:"enabled" yaml:"enabled" json:"enabled"`
Counter CounterConfig `mapstructure:"counter" yaml:"counter" json:"counter"`
Timer TimerConfig `mapstructure:"timer" yaml:"timer" json:"timer"`
FilteredTags []string `mapstructure:"filtered_tags" yaml:"filtered_tags" json:"filtered_tags"`
}

type SessionMetricGroupConfig struct {
Enabled bool `mapstructure:"enabled" yaml:"enabled" json:"enabled"`
Counter CounterConfig `mapstructure:"counter" yaml:"counter" json:"counter"`
Timer TimerConfig `mapstructure:"timer" yaml:"timer" json:"timer"`
FilteredTags []string `mapstructure:"filtered_tags" yaml:"filtered_tags" json:"filtered_tags"`
}

type SizeMetricGroupConfig struct {
Enabled bool `mapstructure:"enabled" yaml:"enabled" json:"enabled"`
Namespace bool `mapstructure:"namespace" yaml:"namespace" json:"namespace"`
Db bool `mapstructure:"db" yaml:"db" json:"db"`
Collection bool `mapstructure:"collection" yaml:"collection" json:"collection"`
FilteredTags []string `mapstructure:"filtered_tags" yaml:"filtered_tags" json:"filtered_tags"`
}

type NetworkMetricGroupConfig struct {
Enabled bool `mapstructure:"enabled" yaml:"enabled" json:"enabled"`
FilteredTags []string `mapstructure:"filtered_tags" yaml:"filtered_tags" json:"filtered_tags"`
}

type AuthMetricsConfig struct {
Enabled bool `mapstructure:"enabled" yaml:"enabled" json:"enabled"`
FilteredTags []string `mapstructure:"filtered_tags" yaml:"filtered_tags" json:"filtered_tags"`
}

type ProfilingConfig struct {
Enabled bool `mapstructure:"enabled" yaml:"enabled" json:"enabled"`
EnableCPU bool `mapstructure:"enable_cpu" yaml:"enable_cpu" json:"enable_cpu"`
Expand All @@ -85,24 +154,6 @@ type ProfilingConfig struct {
EnableGoroutine bool `mapstructure:"enable_goroutine" yaml:"enable_goroutine" json:"enable_goroutine"`
}

type GrpcMetricsConfig struct {
Enabled bool `mapstructure:"enabled" yaml:"enabled" json:"enabled"`
Counters bool `mapstructure:"counters" yaml:"counters" json:"counters"`
ResponseTime bool `mapstructure:"response_time" yaml:"response_time" json:"response_time"`
}

type FdbMetricsConfig struct {
Enabled bool `mapstructure:"enabled" yaml:"enabled" json:"enabled"`
Counters bool `mapstructure:"counters" yaml:"counters" json:"counters"`
ResponseTime bool `mapstructure:"response_time" yaml:"response_time" json:"response_time"`
}

type SearchMetricsConfig struct {
Enabled bool `mapstructure:"enabled" yaml:"enabled" json:"enabled"`
Counters bool `mapstructure:"counters" yaml:"counters" json:"counters"`
ResponseTime bool `mapstructure:"response_time" yaml:"response_time" json:"response_time"`
}

type ManagementConfig struct {
Enabled bool `mapstructure:"enabled" yaml:"enabled" json:"enabled"`
}
Expand Down Expand Up @@ -151,6 +202,73 @@ var DefaultConfig = Config{
CodeHotspotsEnabled: true,
EndpointsEnabled: true,
},
Metrics: MetricsConfig{
Enabled: true,
TimerQuantiles: []float64{0.5, 0.95},
Requests: RequestsMetricGroupConfig{
Enabled: true,
Counter: CounterConfig{
OkEnabled: true,
ErrorEnabled: true,
},
Timer: TimerConfig{
TimerEnabled: true,
HistogramEnabled: false,
},
FilteredTags: nil,
},
Fdb: FdbMetricGroupConfig{
Enabled: true,
Counter: CounterConfig{
OkEnabled: true,
ErrorEnabled: true,
},
Timer: TimerConfig{
TimerEnabled: true,
HistogramEnabled: false,
},
FilteredTags: nil,
},
Search: SearchMetricGroupConfig{
Enabled: true,
Counter: CounterConfig{
OkEnabled: true,
ErrorEnabled: true,
},
Timer: TimerConfig{
TimerEnabled: true,
HistogramEnabled: false,
},
FilteredTags: nil,
},
Session: SessionMetricGroupConfig{
Enabled: true,
Counter: CounterConfig{
OkEnabled: true,
ErrorEnabled: true,
},
Timer: TimerConfig{
TimerEnabled: true,
HistogramEnabled: false,
},
FilteredTags: nil,
},
Size: SizeMetricGroupConfig{
Enabled: true,
Namespace: true,
Db: true,
Collection: true,
FilteredTags: nil,
},
Network: NetworkMetricGroupConfig{
Enabled: true,
FilteredTags: nil,
},
Auth: AuthMetricsConfig{
Enabled: true,
FilteredTags: nil,
},
},
Profiling: ProfilingConfig{
Enabled: false,
EnableCPU: true,
Expand Down
8 changes: 2 additions & 6 deletions server/metrics/fdb.go
Expand Up @@ -28,9 +28,7 @@ var (
func getFdbOkTagKeys() []string {
return []string{
"grpc_method",
"grpc_service",
"tigris_tenant",
"grpc_service_type",
"env",
"db",
"collection",
Expand All @@ -41,9 +39,7 @@ func getFdbOkTagKeys() []string {
func getFdbErrorTagKeys() []string {
return []string{
"grpc_method",
"grpc_service",
"tigris_tenant",
"grpc_service_type",
"env",
"db",
"collection",
Expand All @@ -67,8 +63,8 @@ func GetFdbErrorTags(reqMethodName string, code string) map[string]string {
}
}

func GetFdbBaseTags(reqMthodName string) map[string]string {
return GetFdbOkTags(reqMthodName)
func GetFdbBaseTags(reqMethodName string) map[string]string {
return GetFdbOkTags(reqMethodName)
}

func initializeFdbScopes() {
Expand Down
3 changes: 2 additions & 1 deletion server/metrics/fdb_test.go
Expand Up @@ -55,6 +55,7 @@ func TestFdbMetrics(t *testing.T) {

t.Run("Test FDB timers", func(t *testing.T) {
testTimerTags := GetFdbOkTags("Insert")
defer FdbMetrics.Tagged(testTimerTags).Timer("time").Start().Stop()
defer FdbRespTime.Tagged(testTimerTags).Timer("time").Start().Stop()
defer FdbErrorRespTime.Tagged(testTimerTags).Timer("time").Start().Stop()
})
}

0 comments on commit 765d8d8

Please sign in to comment.