Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow enabling profiler port in FLP #167

Merged
merged 4 commits into from
Sep 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe add: "Use only for debugging", or something along that line?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As mentioned face-to-face last week, leaving this port open does not affect performance. It could have some impact just during the profile session, which is at most few seconds.

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