diff --git a/api/v1beta1/temporalcluster_types.go b/api/v1beta1/temporalcluster_types.go index e4282eee..3ce939af 100644 --- a/api/v1beta1/temporalcluster_types.go +++ b/api/v1beta1/temporalcluster_types.go @@ -85,6 +85,10 @@ type ServiceSpec struct { // 7243 for Frontend service // +optional HTTPPort *int `json:"httpPort"` + // PProfPort defines a custom pprof port for the service. + // The port is defined by the global config. + // +optional + PProfPort *int `json:"pprofPort,omitempty"` // Number of desired replicas for the service. Default to 1. // +kubebuilder:validation:Minimum=1 // +optional @@ -787,6 +791,15 @@ func (m *MetricsSpec) IsEnabled() bool { return m != nil && m.Enabled } +// PProfSpec determines parameters for configuring pprof. +type PProfSpec struct { + // Specifies the port that pprof's web server should run on. This must be specified to enable pprof. + Port int `json:"port"` + // Specifies the host that pprof's web server should run on. Defaults to "localhost" if not provided. + // +optional + Host *string `json:"host,omitempty"` +} + // Constraints is an alias for temporal's dynamicconfig.Constraints. // It describes under what conditions a ConstrainedValue should be used. type Constraints struct { @@ -1041,6 +1054,9 @@ type TemporalClusterSpec struct { // Metrics allows configuration of scraping endpoints for stats. prometheus or m3. // +optional Metrics *MetricsSpec `json:"metrics,omitempty"` + // PProf allows configuration of pprof. + // +optional + PProf *PProfSpec `json:"pprof,omitempty"` // DynamicConfig allows advanced configuration for the temporal cluster. // +optional DynamicConfig *DynamicConfigSpec `json:"dynamicConfig,omitempty"` diff --git a/api/v1beta1/zz_generated.deepcopy.go b/api/v1beta1/zz_generated.deepcopy.go index 3f2b8ad6..d0076086 100644 --- a/api/v1beta1/zz_generated.deepcopy.go +++ b/api/v1beta1/zz_generated.deepcopy.go @@ -714,6 +714,26 @@ func (in *ObjectMetaOverride) DeepCopy() *ObjectMetaOverride { return out } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *PProfSpec) DeepCopyInto(out *PProfSpec) { + *out = *in + if in.Host != nil { + in, out := &in.Host, &out.Host + *out = new(string) + **out = **in + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new PProfSpec. +func (in *PProfSpec) DeepCopy() *PProfSpec { + if in == nil { + return nil + } + out := new(PProfSpec) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *PodTemplateSpecOverride) DeepCopyInto(out *PodTemplateSpecOverride) { *out = *in @@ -938,6 +958,11 @@ func (in *ServiceSpec) DeepCopyInto(out *ServiceSpec) { *out = new(int) **out = **in } + if in.PProfPort != nil { + in, out := &in.PProfPort, &out.PProfPort + *out = new(int) + **out = **in + } if in.Replicas != nil { in, out := &in.Replicas, &out.Replicas *out = new(int32) @@ -1295,6 +1320,11 @@ func (in *TemporalClusterSpec) DeepCopyInto(out *TemporalClusterSpec) { *out = new(MetricsSpec) (*in).DeepCopyInto(*out) } + if in.PProf != nil { + in, out := &in.PProf, &out.PProf + *out = new(PProfSpec) + (*in).DeepCopyInto(*out) + } if in.DynamicConfig != nil { in, out := &in.DynamicConfig, &out.DynamicConfig *out = new(DynamicConfigSpec) diff --git a/config/crd/bases/temporal.io_temporalclusters.yaml b/config/crd/bases/temporal.io_temporalclusters.yaml index e018b5b9..52fc42ed 100644 --- a/config/crd/bases/temporal.io_temporalclusters.yaml +++ b/config/crd/bases/temporal.io_temporalclusters.yaml @@ -2088,6 +2088,18 @@ spec: - defaultStore - visibilityStore type: object + pprof: + description: PProf allows configuration of pprof. + properties: + host: + description: Specifies the host that pprof's web server should run on. Defaults to "localhost" if not provided. + type: string + port: + description: Specifies the port that pprof's web server should run on. This must be specified to enable pprof. + type: integer + required: + - port + type: object services: description: Services allows customizations for each temporal services deployment. properties: @@ -2158,6 +2170,9 @@ spec: port: description: 'Port defines a custom gRPC port for the service. Default values are: 7233 for Frontend service 7234 for History service 7235 for Matching service 7239 for Worker service' type: integer + pprofPort: + description: PProfPort defines a custom pprof port for the service. The port is defined by the global config. + type: integer replicas: description: Number of desired replicas for the service. Default to 1. format: int32 @@ -2268,6 +2283,9 @@ spec: port: description: 'Port defines a custom gRPC port for the service. Default values are: 7233 for Frontend service 7234 for History service 7235 for Matching service 7239 for Worker service' type: integer + pprofPort: + description: PProfPort defines a custom pprof port for the service. The port is defined by the global config. + type: integer replicas: description: Number of desired replicas for the service. Default to 1. format: int32 @@ -2382,6 +2400,9 @@ spec: port: description: 'Port defines a custom gRPC port for the service. Default values are: 7233 for Frontend service 7234 for History service 7235 for Matching service 7239 for Worker service' type: integer + pprofPort: + description: PProfPort defines a custom pprof port for the service. The port is defined by the global config. + type: integer replicas: description: Number of desired replicas for the service. Default to 1. format: int32 @@ -2492,6 +2513,9 @@ spec: port: description: 'Port defines a custom gRPC port for the service. Default values are: 7233 for Frontend service 7234 for History service 7235 for Matching service 7239 for Worker service' type: integer + pprofPort: + description: PProfPort defines a custom pprof port for the service. The port is defined by the global config. + type: integer replicas: description: Number of desired replicas for the service. Default to 1. format: int32 @@ -2650,6 +2674,9 @@ spec: port: description: 'Port defines a custom gRPC port for the service. Default values are: 7233 for Frontend service 7234 for History service 7235 for Matching service 7239 for Worker service' type: integer + pprofPort: + description: PProfPort defines a custom pprof port for the service. The port is defined by the global config. + type: integer replicas: description: Number of desired replicas for the service. Default to 1. format: int32 diff --git a/docs/api/v1beta1.md b/docs/api/v1beta1.md index 0ab9f058..ab5d7005 100644 --- a/docs/api/v1beta1.md +++ b/docs/api/v1beta1.md @@ -254,6 +254,20 @@ MetricsSpec +pprof
+ + +PProfSpec + + + + +(Optional) +

PProf allows configuration of pprof.

+ + + + dynamicConfig
@@ -2199,6 +2213,50 @@ set by external tools to store and retrieve arbitrary metadata.

+

PProfSpec +

+

+(Appears on: +TemporalClusterSpec) +

+

PProfSpec determines parameters for configuring pprof.

+
+
+ + + + + + + + + + + + + + + + + +
FieldDescription
+port
+ +int + +
+

Specifies the port that pprof’s web server should run on. This must be specified to enable pprof.

+
+host
+ +string + +
+(Optional) +

Specifies the host that pprof’s web server should run on. Defaults to “localhost” if not provided.

+
+
+

PodTemplateSpecOverride

@@ -2824,6 +2882,19 @@ Default values are: +pprofPort
+ +int + + + +(Optional) +

PProfPort defines a custom pprof port for the service. +The port is defined by the global config.

+ + + + replicas
int32 @@ -3560,6 +3631,20 @@ MetricsSpec +pprof
+ + +PProfSpec + + + + +(Optional) +

PProf allows configuration of pprof.

+ + + + dynamicConfig
diff --git a/internal/resource/base/deployment_builder.go b/internal/resource/base/deployment_builder.go index a90cab5a..b90e9f8b 100644 --- a/internal/resource/base/deployment_builder.go +++ b/internal/resource/base/deployment_builder.go @@ -326,6 +326,16 @@ func (b *DeploymentBuilder) Update(object client.Object) error { } } + if b.instance.Spec.PProf != nil && b.instance.Spec.PProf.Port > 0 { + b.service.PProfPort = &b.instance.Spec.PProf.Port + + containerPorts = append(containerPorts, corev1.ContainerPort{ + Name: "pprof", + ContainerPort: int32(*b.service.PProfPort), + Protocol: corev1.ProtocolTCP, + }) + } + if b.serviceName == string(primitives.FrontendService) && b.instance.Spec.Services.Frontend.HTTPPort != nil { containerPorts = append(containerPorts, corev1.ContainerPort{ Name: "http", diff --git a/internal/resource/config/configmap_builder.go b/internal/resource/config/configmap_builder.go index 1be97a63..56f96cac 100644 --- a/internal/resource/config/configmap_builder.go +++ b/internal/resource/config/configmap_builder.go @@ -350,6 +350,24 @@ func (b *ConfigmapBuilder) Update(object client.Object) error { } } + if b.instance.Spec.PProf != nil { + var pprofConfig = config.PProf{} + + // Host is optional. + if b.instance.Spec.PProf.Host != nil { + if *b.instance.Spec.PProf.Host != "" { + pprofConfig.Host = *b.instance.Spec.PProf.Host + } + } + + // Port is required. + // Do not set a pprof config if the port is 0. + if b.instance.Spec.PProf.Port > 0 { + pprofConfig.Port = b.instance.Spec.PProf.Port + temporalCfg.Global.PProf = pprofConfig + } + } + if b.instance.MTLSWithCertManagerEnabled() { temporalCfg.Global.TLS = config.RootTLS{ RefreshInterval: b.instance.Spec.MTLS.RefreshInterval.Duration,