Skip to content

Commit

Permalink
Change default behavior and naming
Browse files Browse the repository at this point in the history
Signed-off-by: Alexey Kuzbekov <[email protected]>
  • Loading branch information
Kuzbekov committed May 30, 2024
1 parent 86e82c1 commit 9d06661
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 33 deletions.
32 changes: 16 additions & 16 deletions internal/server/event_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,23 +48,23 @@ type eventContextKey struct{}

// EventServer handles event POST requests
type EventServer struct {
port string
logger logr.Logger
kubeClient client.Client
noCrossNamespaceRefs bool
detailedMetrics bool
port string
logger logr.Logger
kubeClient client.Client
noCrossNamespaceRefs bool
exportHTTPPathMetrics bool
kuberecorder.EventRecorder
}

// NewEventServer returns an HTTP server that handles events
func NewEventServer(port string, logger logr.Logger, kubeClient client.Client, eventRecorder kuberecorder.EventRecorder, noCrossNamespaceRefs bool, detailedMetrics bool) *EventServer {
func NewEventServer(port string, logger logr.Logger, kubeClient client.Client, eventRecorder kuberecorder.EventRecorder, noCrossNamespaceRefs bool, exportHTTPPathMetrics bool) *EventServer {
return &EventServer{
port: port,
logger: logger.WithName("event-server"),
kubeClient: kubeClient,
EventRecorder: eventRecorder,
noCrossNamespaceRefs: noCrossNamespaceRefs,
detailedMetrics: detailedMetrics,
port: port,
logger: logger.WithName("event-server"),
kubeClient: kubeClient,
EventRecorder: eventRecorder,
noCrossNamespaceRefs: noCrossNamespaceRefs,
exportHTTPPathMetrics: exportHTTPPathMetrics,
}
}

Expand All @@ -86,11 +86,11 @@ func (s *EventServer) ListenAndServe(stopCh <-chan struct{}, mdlw middleware.Mid
mux := http.NewServeMux()
path := "/"
mux.Handle(path, handler)
middlewarePath := ""
if !s.detailedMetrics {
middlewarePath = path
handlerID := path
if s.exportHTTPPathMetrics {
handlerID = ""
}
h := std.Handler(middlewarePath, mdlw, mux)
h := std.Handler(handlerID, mdlw, mux)
srv := &http.Server{
Addr: s.port,
Handler: h,
Expand Down
26 changes: 13 additions & 13 deletions internal/server/receiver_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,31 +32,31 @@ import (

// ReceiverServer handles webhook POST requests
type ReceiverServer struct {
port string
logger logr.Logger
kubeClient client.Client
detailedMetrics bool
port string
logger logr.Logger
kubeClient client.Client
exportHTTPPathMetrics bool
}

// NewReceiverServer returns an HTTP server that handles webhooks
func NewReceiverServer(port string, logger logr.Logger, kubeClient client.Client, detailedMetrics bool) *ReceiverServer {
func NewReceiverServer(port string, logger logr.Logger, kubeClient client.Client, exportHTTPPathMetrics bool) *ReceiverServer {
return &ReceiverServer{
port: port,
logger: logger.WithName("receiver-server"),
kubeClient: kubeClient,
detailedMetrics: detailedMetrics,
port: port,
logger: logger.WithName("receiver-server"),
kubeClient: kubeClient,
exportHTTPPathMetrics: exportHTTPPathMetrics,
}
}

// ListenAndServe starts the HTTP server on the specified port
func (s *ReceiverServer) ListenAndServe(stopCh <-chan struct{}, mdlw middleware.Middleware) {
mux := http.NewServeMux()
mux.Handle(apiv1.ReceiverWebhookPath, http.HandlerFunc(s.handlePayload()))
middlewarePath := ""
if !s.detailedMetrics {
middlewarePath = apiv1.ReceiverWebhookPath
handlerID := apiv1.ReceiverWebhookPath
if s.exportHTTPPathMetrics {
handlerID = ""
}
h := std.Handler(middlewarePath, mdlw, mux)
h := std.Handler(handlerID, mdlw, mux)
srv := &http.Server{
Addr: s.port,
Handler: h,
Expand Down
8 changes: 4 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func main() {
aclOptions acl.Options
rateLimiterOptions helper.RateLimiterOptions
featureGates feathelper.FeatureGates
detailedMetrics bool
exportHTTPPathMetrics bool
)

flag.StringVar(&metricsAddr, "metrics-addr", ":8080", "The address the metric endpoint binds to.")
Expand All @@ -98,7 +98,7 @@ func main() {
flag.BoolVar(&watchAllNamespaces, "watch-all-namespaces", true,
"Watch for custom resources in all namespaces, if set to false it will only watch the runtime namespace.")
flag.DurationVar(&rateLimitInterval, "rate-limit-interval", 5*time.Minute, "Interval in which rate limit has effect.")
flag.BoolVar(&detailedMetrics, "detailed-metrics", true, "Count metrics for every requested path")
flag.BoolVar(&exportHTTPPathMetrics, "export-http-path-metrics", false, "When enabled, the requests full path is included in the HTTP server metrics (risk as high cardinality")

clientOptions.BindFlags(flag.CommandLine)
logOptions.BindFlags(flag.CommandLine)
Expand Down Expand Up @@ -222,11 +222,11 @@ func main() {
Registry: crtlmetrics.Registry,
}),
})
eventServer := server.NewEventServer(eventsAddr, ctrl.Log, mgr.GetClient(), mgr.GetEventRecorderFor(controllerName), aclOptions.NoCrossNamespaceRefs, detailedMetrics)
eventServer := server.NewEventServer(eventsAddr, ctrl.Log, mgr.GetClient(), mgr.GetEventRecorderFor(controllerName), aclOptions.NoCrossNamespaceRefs, exportHTTPPathMetrics)
go eventServer.ListenAndServe(ctx.Done(), eventMdlw, store)

setupLog.Info("starting webhook receiver server", "addr", receiverAddr)
receiverServer := server.NewReceiverServer(receiverAddr, ctrl.Log, mgr.GetClient(), detailedMetrics)
receiverServer := server.NewReceiverServer(receiverAddr, ctrl.Log, mgr.GetClient(), exportHTTPPathMetrics)
receiverMdlw := middleware.New(middleware.Config{
Recorder: prommetrics.NewRecorder(prommetrics.Config{
Prefix: "gotk_receiver",
Expand Down

0 comments on commit 9d06661

Please sign in to comment.