Skip to content

Commit

Permalink
Add Metrics Port to EventListener service
Browse files Browse the repository at this point in the history
Metrics port in service is needed by metering serices like prometheus
servicemonitor. It's already there for controller and webhook but not
EventListener which is created.
  • Loading branch information
khrm committed Aug 19, 2021
1 parent 92eb943 commit fbbf27e
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions pkg/reconciler/eventlistener/eventlistener.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,12 @@ const (
eventListenerServicePortName = "http-listener"
// eventListenerServiceTLSPortName defines service TLS port name for EventListener Service
eventListenerServiceTLSPortName = "https-listener"
// eventListenerContainerPort defines the port exposed by the EventListener Container
// eventListenerMetricsPortName defines the metrics port name by the EventListener Container
eventListenerMetricsPortName = "http-metrics"
// eventListenerContainerPort defines service port for EventListener Service
eventListenerContainerPort = 8080
// eventListenerMetricsPort defines metrics port for EventListener Service
eventListenerMetricsPort = 9000
// GeneratedResourcePrefix is the name prefix for resources generated in the
// EventListener reconciler
GeneratedResourcePrefix = "el"
Expand Down Expand Up @@ -186,13 +190,21 @@ func (r *Reconciler) reconcileService(ctx context.Context, logger *zap.SugaredLo
}

servicePort := getServicePort(el, r.config)
metricsPort := corev1.ServicePort{
Name: eventListenerMetricsPortName,
Protocol: corev1.ProtocolTCP,
Port: int32(9000),
TargetPort: intstr.IntOrString{
IntVal: int32(eventListenerMetricsPort),
},
}

service := &corev1.Service{
ObjectMeta: generateObjectMeta(el, r.config.StaticResourceLabels),
Spec: corev1.ServiceSpec{
Selector: GenerateResourceLabels(el.Name, r.config.StaticResourceLabels),
Type: serviceType,
Ports: []corev1.ServicePort{servicePort}},
Ports: []corev1.ServicePort{servicePort, metricsPort}},
}
existingService, err := r.serviceLister.Services(el.Namespace).Get(el.Status.Configuration.GeneratedResourceName)
switch {
Expand Down

0 comments on commit fbbf27e

Please sign in to comment.