Skip to content

Commit

Permalink
distinct liveness and readeness
Browse files Browse the repository at this point in the history
  • Loading branch information
intelligentfu8 committed Dec 15, 2023
1 parent 0490294 commit aae597c
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 26 deletions.
6 changes: 1 addition & 5 deletions api/doris/v1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,11 +142,6 @@ type BaseSpec struct {
// +patchStrategy=merge
ImagePullSecrets []corev1.LocalObjectReference `json:"imagePullSecrets,omitempty" patchStrategy:"merge" patchMergeKey:"name" protobuf:"bytes,15,rep,name=imagePullSecrets"`

//+optional
//set the fe service for register cn, when not set, will use the fe config to find.
//Deprecated,
//FeServiceName string `json:"feServiceName,omitempty"`

//the reference for cn configMap.
//+optional
ConfigMapInfo ConfigMapInfo `json:"configMapInfo,omitempty"`
Expand Down Expand Up @@ -227,6 +222,7 @@ type ConfigMapInfo struct {
ConfigMapName string `json:"configMapName,omitempty"`

//the config response key in configmap.
//the config file name for
ResolveKey string `json:"resolveKey,omitempty"`
}

Expand Down
6 changes: 3 additions & 3 deletions cmd/doris-debug/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func main() {

fmt.Println("start component " + componentType + "for debugging.....")
listenPort := readConfigListenPort()
registerMockApiHealth()
//registerMockApiHealth()
if err := http.ListenAndServe(":"+listenPort, nil); err != nil {
fmt.Println("listenAndServe failed," + err.Error())
os.Exit(1)
Expand Down Expand Up @@ -57,9 +57,9 @@ func readConfigListenPort() string {

var listenPort string
if componentType == "fe" {
listenPort = viper.GetString(resource.HTTP_PORT)
listenPort = viper.GetString(resource.QUERY_PORT)
} else if componentType == "be" {
listenPort = viper.GetString(resource.WEBSERVER_PORT)
listenPort = viper.GetString(resource.HEARTBEAT_SERVICE_PORT)
}

return listenPort
Expand Down
12 changes: 8 additions & 4 deletions config/crd/bases/doris.selectdb.com_dorisclusters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -967,7 +967,8 @@ spec:
description: the config info for start progress.
type: string
resolveKey:
description: the config response key in configmap.
description: the config response key in configmap. the config
file name for
type: string
type: object
envVars:
Expand Down Expand Up @@ -2453,7 +2454,8 @@ spec:
description: the config info for start progress.
type: string
resolveKey:
description: the config response key in configmap.
description: the config response key in configmap. the config
file name for
type: string
type: object
envVars:
Expand Down Expand Up @@ -4624,7 +4626,8 @@ spec:
description: the config info for start progress.
type: string
resolveKey:
description: the config response key in configmap.
description: the config response key in configmap. the config
file name for
type: string
type: object
envVars:
Expand Down Expand Up @@ -6111,7 +6114,8 @@ spec:
description: the config info for start progress.
type: string
resolveKey:
description: the config response key in configmap.
description: the config response key in configmap. the config
file name for
type: string
type: object
electionNumber:
Expand Down
60 changes: 46 additions & 14 deletions pkg/common/utils/resource/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,14 @@ const (
DEFAULT_INIT_IMAGE = "selectdb/alpine:latest"
)

type probeType string

var (
httpGet probeType = "httpGet"
tcpSocket probeType = "tcpSocket"
exec probeType = "exec"
)

func NewPodTemplateSpec(dcr *v1.DorisCluster, componentType v1.ComponentType) corev1.PodTemplateSpec {
spec := getBaseSpecFromCluster(dcr, componentType)
var volumes []corev1.Volume
Expand Down Expand Up @@ -238,32 +246,36 @@ func NewBaseMainContainer(dcr *v1.DorisCluster, config map[string]interface{}, c
Resources: spec.ResourceRequirements,
}

var healthPort int32
//livenessPort use heartbeat port for probe service alive.
var livenessPort int32
//readnessPort use http port for confirm the service can provider service to client.
var readnessPort int32
var prestopScript string
var health_api_path string
switch componentType {
case v1.Component_FE:
healthPort = GetPort(config, HTTP_PORT)
readnessPort = GetPort(config, HTTP_PORT)
livenessPort = GetPort(config, QUERY_PORT)
prestopScript = FE_PRESTOP
health_api_path = HEALTH_API_PATH
case v1.Component_BE, v1.Component_CN:
healthPort = GetPort(config, WEBSERVER_PORT)
readnessPort = GetPort(config, WEBSERVER_PORT)
livenessPort = GetPort(config, HEARTBEAT_SERVICE_PORT)
prestopScript = BE_PRESTOP
health_api_path = HEALTH_API_PATH
case v1.Component_Broker:
healthPort = GetPort(config, BROKER_IPC_PORT)
livenessPort = GetPort(config, BROKER_IPC_PORT)
readnessPort = GetPort(config, BROKER_IPC_PORT)
prestopScript = BROKER_PRESTOP
health_api_path = ""
default:
klog.Infof("the componentType %s is not supported in probe.")
}

if healthPort != 0 {
c.LivenessProbe = livenessProbe(healthPort, health_api_path)
c.StartupProbe = startupProbe(healthPort, health_api_path)
c.ReadinessProbe = readinessProbe(healthPort, health_api_path)
c.Lifecycle = lifeCycle(prestopScript)
}
c.LivenessProbe = livenessProbe(livenessPort, "")
c.StartupProbe = startupProbe(readnessPort, health_api_path)
c.ReadinessProbe = readinessProbe(readnessPort, health_api_path)
c.Lifecycle = lifeCycle(prestopScript)

return c
}
Expand Down Expand Up @@ -488,7 +500,7 @@ func startupProbe(port int32, path string) *corev1.Probe {
return &corev1.Probe{
FailureThreshold: 60,
PeriodSeconds: 5,
ProbeHandler: getProbe(port, path),
ProbeHandler: getProbe(port, path, httpGet),
}
}

Expand All @@ -500,7 +512,7 @@ func livenessProbe(port int32, path string) *corev1.Probe {
// for pulling image and start doris
InitialDelaySeconds: 80,
TimeoutSeconds: 180,
ProbeHandler: getProbe(port, path),
ProbeHandler: getProbe(port, path, tcpSocket),
}
}

Expand All @@ -509,7 +521,7 @@ func readinessProbe(port int32, path string) *corev1.Probe {
return &corev1.Probe{
PeriodSeconds: 5,
FailureThreshold: 3,
ProbeHandler: getProbe(port, path),
ProbeHandler: getProbe(port, path, httpGet),
}
}

Expand All @@ -524,7 +536,27 @@ func lifeCycle(preStopScriptPath string) *corev1.Lifecycle {
}
}

func getProbe(port int32, path string) corev1.ProbeHandler {
// getProbe describe a health check.
func getProbe(port int32, path string, probeType probeType) corev1.ProbeHandler {
switch probeType {
case tcpSocket:
return getTcpSocket(port)
case httpGet:
return getHttpProbe(port, path)
default:
}
return corev1.ProbeHandler{}
}

func getTcpSocket(port int32) corev1.ProbeHandler {
return corev1.ProbeHandler{
TCPSocket: &corev1.TCPSocketAction{
Port: intstr.FromInt(int(port)),
},
}
}

func getHttpProbe(port int32, path string) corev1.ProbeHandler {
var p corev1.ProbeHandler
if path != "" {
p = corev1.ProbeHandler{
Expand Down

0 comments on commit aae597c

Please sign in to comment.