Skip to content

Commit

Permalink
Allow enabling profiler port in FLP (#167)
Browse files Browse the repository at this point in the history
* Allow enabling profiler port in FLP

* Allow enabling profiler port in FLP

* fixed container port protocol

* updated flowcollector doc
  • Loading branch information
Mario Macias authored Sep 21, 2022
1 parent 4e7d9bd commit b04cdad
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 0 deletions.
6 changes: 6 additions & 0 deletions api/v1alpha1/flowcollector_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,12 @@ type FlowCollectorFLP struct {
// healthPort is a collector HTTP port in the Pod that exposes the health check API
HealthPort int32 `json:"healthPort,omitempty"`

//+kubebuilder:validation:Minimum=0
//+kubebuilder:validation:Maximum=65535
//+optional
// profilePort allows setting up a Go pprof profiler listening to this port
ProfilePort int32 `json:"profilePort,omitempty"`

//+kubebuilder:default:="quay.io/netobserv/flowlogs-pipeline:main"
// image of the collector container (including domain and tag)
Image string `json:"image,omitempty"`
Expand Down
7 changes: 7 additions & 0 deletions config/crd/bases/flows.netobserv.io_flowcollectors.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1714,6 +1714,13 @@ spec:
maximum: 65535
minimum: 1025
type: integer
profilePort:
description: profilePort allows setting up a Go pprof profiler
listening to this port
format: int32
maximum: 65535
minimum: 0
type: integer
prometheus:
description: Prometheus endpoint configuration
properties:
Expand Down
1 change: 1 addition & 0 deletions config/samples/flows_v1alpha1_flowcollector.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ spec:
logLevel: info
enableKubeProbes: true
healthPort: 8080
profilePort: 6060
prometheus:
port: 9102
ignoreMetrics: []
Expand Down
14 changes: 14 additions & 0 deletions controllers/flowlogspipeline/flp_objects.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ const (
promCerts = "prom-certs"
healthServiceName = "health"
prometheusServiceName = "prometheus"
profilePortName = "pprof"
healthTimeoutSeconds = 5
livenessPeriodSeconds = 10
startupFailureThreshold = 5
Expand Down Expand Up @@ -175,6 +176,14 @@ func (b *builder) podTemplate(hostNetwork bool, configDigest string) corev1.PodT
ContainerPort: b.desired.Prometheus.Port,
})

if b.desired.ProfilePort > 0 {
ports = append(ports, corev1.ContainerPort{
Name: profilePortName,
ContainerPort: b.desired.ProfilePort,
Protocol: corev1.ProtocolTCP,
})
}

volumeMounts := []corev1.VolumeMount{{
MountPath: configPath,
Name: configVolume,
Expand Down Expand Up @@ -483,6 +492,11 @@ func (b *builder) configMap() (*corev1.ConfigMap, string, error) {
"pipeline": stages,
"parameters": parameters,
}
if b.desired.ProfilePort > 0 {
config["profile"] = map[string]interface{}{
"port": b.desired.ProfilePort,
}
}

bs, err := json.Marshal(config)
if err != nil {
Expand Down
11 changes: 11 additions & 0 deletions docs/FlowCollector.md
Original file line number Diff line number Diff line change
Expand Up @@ -2167,6 +2167,17 @@ processor defines the settings of the component that receives the flows from the
<i>Maximum</i>: 65535<br/>
</td>
<td>false</td>
</tr><tr>
<td><b>profilePort</b></td>
<td>integer</td>
<td>
profilePort allows setting up a Go pprof profiler listening to this port<br/>
<br/>
<i>Format</i>: int32<br/>
<i>Minimum</i>: 0<br/>
<i>Maximum</i>: 65535<br/>
</td>
<td>false</td>
</tr><tr>
<td><b><a href="#flowcollectorspecprocessorprometheus">prometheus</a></b></td>
<td>object</td>
Expand Down

0 comments on commit b04cdad

Please sign in to comment.