Skip to content

Commit 2559e5d

Browse files
authored
feat: enable profile in agents (#54)
1 parent 71b967a commit 2559e5d

File tree

7 files changed

+47
-2
lines changed

7 files changed

+47
-2
lines changed

charts/hub-agent/templates/deployment.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ spec:
3333
- --enable-cluster-inventory-apis={{ .Values.enableClusterInventoryAPI }}
3434
- --enable-staged-update-run-apis={{ .Values.enableStagedUpdateRunAPIs }}
3535
- --enable-eviction-apis={{ .Values.enableEvictionAPIs}}
36+
- --enable-pprof={{ .Values.enablePprof }}
37+
- --pprof-port={{ .Values.pprofPort }}
3638
- --max-concurrent-cluster-placement={{ .Values.MaxConcurrentClusterPlacement }}
3739
- --concurrent-resource-change-syncs={{ .Values.ConcurrentResourceChangeSyncs }}
3840
- --log_file_max_size={{ .Values.logFileMaxSize }}
@@ -48,6 +50,11 @@ spec:
4850
- name: healthz
4951
containerPort: 8081
5052
protocol: TCP
53+
{{- if .Values.enablePprof }}
54+
- containerPort: {{ .Values.pprofPort }}
55+
name: pprof
56+
protocol: TCP
57+
{{- end }}
5158
livenessProbe:
5259
httpGet:
5360
path: /healthz

charts/hub-agent/values.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ enableClusterInventoryAPI: true
3939
enableStagedUpdateRunAPIs: true
4040
enableEvictionAPIs: true
4141

42+
enablePprof: true
43+
pprofPort: 6065
44+
4245
hubAPIQPS: 250
4346
hubAPIBurst: 1000
4447
MaxConcurrentClusterPlacement: 100

charts/member-agent/templates/deployment.yaml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ spec:
3434
- -add_dir_header
3535
- --enable-v1alpha1-apis={{ .Values.enableV1Alpha1APIs }}
3636
- --enable-v1beta1-apis={{ .Values.enableV1Beta1APIs }}
37+
- --enable-pprof={{ .Values.enablePprof }}
38+
- --pprof-port={{ .Values.pprofPort }}
39+
- --hub-pprof-port={{ .Values.hubPprofPort }}
3740
{{- if .Values.propertyProvider }}
3841
- --property-provider={{ .Values.propertyProvider }}
3942
{{- end }}
@@ -75,6 +78,14 @@ spec:
7578
- containerPort: 8091
7679
name: memberhealthz
7780
protocol: TCP
81+
{{- if .Values.enablePprof }}
82+
- containerPort: {{ .Values.pprofPort }}
83+
name: memberpprof
84+
protocol: TCP
85+
- containerPort: {{ .Values.hubPprofPort }}
86+
name: hubpprof
87+
protocol: TCP
88+
{{- end }}
7889
livenessProbe:
7990
httpGet:
8091
path: /healthz

charts/member-agent/values.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,3 +61,7 @@ useCAAuth: false
6161

6262
enableV1Alpha1APIs: true
6363
enableV1Beta1APIs: false
64+
65+
enablePprof: true
66+
pprofPort: 6065
67+
hubPprofPort: 6066

cmd/hubagent/main.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package main
1818

1919
import (
2020
"flag"
21+
"fmt"
2122
"math"
2223
"os"
2324
"strings"
@@ -113,7 +114,7 @@ func main() {
113114
config := ctrl.GetConfigOrDie()
114115
config.QPS, config.Burst = float32(opts.HubQPS), opts.HubBurst
115116

116-
mgr, err := ctrl.NewManager(config, ctrl.Options{
117+
mgrOpts := ctrl.Options{
117118
Scheme: scheme,
118119
Cache: cache.Options{
119120
SyncPeriod: &opts.ResyncPeriod.Duration,
@@ -130,7 +131,11 @@ func main() {
130131
Port: FleetWebhookPort,
131132
CertDir: FleetWebhookCertDir,
132133
}),
133-
})
134+
}
135+
if opts.EnablePprof {
136+
mgrOpts.PprofBindAddress = fmt.Sprintf(":%d", opts.PprofPort)
137+
}
138+
mgr, err := ctrl.NewManager(config, mgrOpts)
134139
if err != nil {
135140
klog.ErrorS(err, "unable to start controller manager.")
136141
exitWithErrorFunc()

cmd/hubagent/options/options.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,10 @@ type Options struct {
9898
EnableStagedUpdateRunAPIs bool
9999
// EnableEvictionAPIs enables to agents to watch the eviction and placement disruption budget CRs.
100100
EnableEvictionAPIs bool
101+
// EnablePprof enables the pprof profiling.
102+
EnablePprof bool
103+
// PprofPort is the port for pprof profiling.
104+
PprofPort int
101105
// DenyModifyMemberClusterLabels indicates if the member cluster labels cannot be modified by groups (excluding system:masters)
102106
DenyModifyMemberClusterLabels bool
103107
}
@@ -117,6 +121,8 @@ func NewOptions() *Options {
117121
EnableV1Alpha1APIs: false,
118122
EnableClusterInventoryAPIs: true,
119123
EnableStagedUpdateRunAPIs: true,
124+
EnablePprof: false,
125+
PprofPort: 6065,
120126
}
121127
}
122128

@@ -160,6 +166,8 @@ func (o *Options) AddFlags(flags *flag.FlagSet) {
160166
flags.DurationVar(&o.ForceDeleteWaitTime.Duration, "force-delete-wait-time", 15*time.Minute, "The duration the hub agent waits before force deleting a member cluster.")
161167
flags.BoolVar(&o.EnableStagedUpdateRunAPIs, "enable-staged-update-run-apis", true, "If set, the agents will watch for the ClusterStagedUpdateRun APIs.")
162168
flags.BoolVar(&o.EnableEvictionAPIs, "enable-eviction-apis", true, "If set, the agents will watch for the Eviction and PlacementDisruptionBudget APIs.")
169+
flags.BoolVar(&o.EnablePprof, "enable-pprof", false, "If set, the pprof profiling is enabled.")
170+
flags.IntVar(&o.PprofPort, "pprof-port", 6065, "The port for pprof profiling.")
163171
flags.BoolVar(&o.DenyModifyMemberClusterLabels, "deny-modify-member-cluster-labels", false, "If set, users not in the system:masters cannot modify member cluster labels.")
164172

165173
o.RateLimiterOpts.AddFlags(flags)

cmd/memberagent/main.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,9 @@ var (
9191
driftDetectionInterval = flag.Int("drift-detection-interval", 15, "The interval in seconds between attempts to detect configuration drifts in the cluster.")
9292
watchWorkWithPriorityQueue = flag.Bool("enable-watch-work-with-priority-queue", false, "If set, the apply_work controller will watch/reconcile work objects that are created new or have recent updates")
9393
watchWorkReconcileAgeMinutes = flag.Int("watch-work-reconcile-age", 60, "maximum age (in minutes) of work objects for apply_work controller to watch/reconcile")
94+
enablePprof = flag.Bool("enable-pprof", false, "enable pprof profiling")
95+
pprofPort = flag.Int("pprof-port", 6065, "port for pprof profiling")
96+
hubPprofPort = flag.Int("hub-pprof-port", 6066, "port for hub pprof profiling")
9497
)
9598

9699
func init() {
@@ -185,6 +188,10 @@ func main() {
185188
LeaderElectionID: "136224848560.member.fleet.azure.com",
186189
}
187190
//+kubebuilder:scaffold:builder
191+
if *enablePprof {
192+
memberOpts.PprofBindAddress = fmt.Sprintf(":%d", *pprofPort)
193+
hubOpts.PprofBindAddress = fmt.Sprintf(":%d", *hubPprofPort)
194+
}
188195

189196
if err := Start(ctrl.SetupSignalHandler(), hubConfig, memberConfig, hubOpts, memberOpts); err != nil {
190197
klog.ErrorS(err, "Failed to start the controllers for the member agent")

0 commit comments

Comments
 (0)