Skip to content

Commit

Permalink
internal: add grpc timing bucket config
Browse files Browse the repository at this point in the history
Signed-off-by: Amirsalar Safaei <amirsalar.safaei@divar.ir>
  • Loading branch information
amirsalarsafaei committed Jun 12, 2024
1 parent 094e1cc commit fade176
Showing 1 changed file with 38 additions and 34 deletions.
72 changes: 38 additions & 34 deletions internal/internal.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,18 +72,33 @@ const (
PluginName = "envoy_ext_authz_grpc"
)

var defaultGRPCRequestDurationSecondsBuckets = []float64{
1e-6,
5e-6,
1e-5,
5e-5,
1e-4,
5e-4,
1e-3,
3e-3,
5e-3,
0.1,
1,
}

// Validate receives a slice of bytes representing the plugin's
// configuration and returns a configuration value that can be used to
// instantiate the plugin.
func Validate(m *plugins.Manager, bs []byte) (*Config, error) {
cfg := Config{
Addr: defaultAddr,
DryRun: defaultDryRun,
EnableReflection: defaultEnableReflection,
GRPCMaxRecvMsgSize: defaultGRPCServerMaxReceiveMessageSize,
GRPCMaxSendMsgSize: defaultGRPCServerMaxSendMessageSize,
SkipRequestBodyParse: defaultSkipRequestBodyParse,
EnablePerformanceMetrics: defaultEnablePerformanceMetrics,
Addr: defaultAddr,
DryRun: defaultDryRun,
EnableReflection: defaultEnableReflection,
GRPCMaxRecvMsgSize: defaultGRPCServerMaxReceiveMessageSize,
GRPCMaxSendMsgSize: defaultGRPCServerMaxSendMessageSize,
SkipRequestBodyParse: defaultSkipRequestBodyParse,
EnablePerformanceMetrics: defaultEnablePerformanceMetrics,
GRPCRequestDurationSecondsBuckets: defaultGRPCRequestDurationSecondsBuckets,
}

if err := util.Unmarshal(bs, &cfg); err != nil {
Expand Down Expand Up @@ -168,21 +183,9 @@ func New(m *plugins.Manager, cfg *Config) plugins.Plugin {
}
if cfg.EnablePerformanceMetrics {
histogramAuthzDuration := prometheus.NewHistogramVec(prometheus.HistogramOpts{
Name: "grpc_request_duration_seconds",
Help: "A histogram of duration for grpc authz requests.",
Buckets: []float64{
1e-6,
5e-6,
1e-5,
5e-5,
1e-4,
5e-4,
1e-3,
3e-3,
5e-3,
0.1,
1,
},
Name: "grpc_request_duration_seconds",
Help: "A histogram of duration for grpc authz requests.",
Buckets: cfg.GRPCRequestDurationSecondsBuckets,
}, []string{"handler"})
plugin.metricAuthzDuration = *histogramAuthzDuration
errorCounter := prometheus.NewCounterVec(prometheus.CounterOpts{
Expand All @@ -201,18 +204,19 @@ func New(m *plugins.Manager, cfg *Config) plugins.Plugin {

// Config represents the plugin configuration.
type Config struct {
Addr string `json:"addr"`
Query string `json:"query"` // Deprecated: Use Path instead
Path string `json:"path"`
DryRun bool `json:"dry-run"`
EnableReflection bool `json:"enable-reflection"`
parsedQuery ast.Body
ProtoDescriptor string `json:"proto-descriptor"`
protoSet *protoregistry.Files
GRPCMaxRecvMsgSize int `json:"grpc-max-recv-msg-size"`
GRPCMaxSendMsgSize int `json:"grpc-max-send-msg-size"`
SkipRequestBodyParse bool `json:"skip-request-body-parse"`
EnablePerformanceMetrics bool `json:"enable-performance-metrics"`
Addr string `json:"addr"`
Query string `json:"query"` // Deprecated: Use Path instead
Path string `json:"path"`
DryRun bool `json:"dry-run"`
EnableReflection bool `json:"enable-reflection"`
parsedQuery ast.Body
ProtoDescriptor string `json:"proto-descriptor"`
protoSet *protoregistry.Files
GRPCMaxRecvMsgSize int `json:"grpc-max-recv-msg-size"`
GRPCMaxSendMsgSize int `json:"grpc-max-send-msg-size"`
SkipRequestBodyParse bool `json:"skip-request-body-parse"`
EnablePerformanceMetrics bool `json:"enable-performance-metrics"`
GRPCRequestDurationSecondsBuckets []float64 `json:"grpc-request-duration-seconds-buckets"`
}

type envoyExtAuthzGrpcServer struct {
Expand Down

0 comments on commit fade176

Please sign in to comment.