Skip to content

Commit

Permalink
fix cacheHits query & remove liveness probe of juicefs worker (fluid-…
Browse files Browse the repository at this point in the history
…cloudnative#2212)

* fix cacheHits query & remove liveness probe of juicefs worker

Signed-off-by: zwwhdls <zww@hdls.me>

* add unittest

Signed-off-by: zwwhdls <zww@hdls.me>

Signed-off-by: zwwhdls <zww@hdls.me>
  • Loading branch information
zwwhdls authored and cheyang committed Feb 14, 2023
1 parent 4477f8f commit 34c32cc
Show file tree
Hide file tree
Showing 3 changed files with 114 additions and 19 deletions.
11 changes: 0 additions & 11 deletions charts/juicefs/templates/worker/statefuleset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -112,17 +112,6 @@ spec:
name: {{ .Values.configs.tokenSecret }}
key: token
{{- end }}
livenessProbe:
exec:
command:
- sh
- -c
- 'if [ x$({{ .Values.worker.statCmd }}) = x1 ]; then exit 0; else exit 1; fi '
failureThreshold: 3
initialDelaySeconds: 1
periodSeconds: 1
successThreshold: 1
timeoutSeconds: 1
lifecycle:
preStop:
exec:
Expand Down
21 changes: 16 additions & 5 deletions pkg/ddc/juicefs/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,22 @@ func (j *JuiceFSEngine) queryCacheStatus() (states cacheStates, err error) {

// get cacheHitRatio & cacheThroughputRatio from fuse pod
func (j *JuiceFSEngine) getCacheRatio(edition string, states *cacheStates) (err error) {
containerName := common.JuiceFSFuseContainer
stsName := j.getFuseDaemonsetName()
pods, err := j.GetRunningPodsOfDaemonset(stsName, j.namespace)
if err != nil || len(pods) == 0 {
return
var containerName string
var pods []v1.Pod
if edition == EnterpriseEdition {
containerName = common.JuiceFSWorkerContainer
stsName := j.getWorkerName()
pods, err = j.GetRunningPodsOfStatefulSet(stsName, j.namespace)
if err != nil || len(pods) == 0 {
return
}
} else {
containerName = common.JuiceFSFuseContainer
dsName := j.getFuseDaemonsetName()
pods, err = j.GetRunningPodsOfDaemonset(dsName, j.namespace)
if err != nil || len(pods) == 0 {
return
}
}

podMetrics := []fuseMetrics{}
Expand Down
101 changes: 98 additions & 3 deletions pkg/ddc/juicefs/cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ import (
)

func TestJuiceFSEngine_queryCacheStatus(t *testing.T) {
Convey("Test CleanupCache ", t, func() {
Convey("cleanup success", func() {
Convey("Test queryCacheStatus ", t, func() {
Convey("queryCacheStatus success", func() {
runtimeInfo, err := base.BuildRuntimeInfo("juicefs", "fluid", "juicefs", datav1alpha1.TieredStore{})
if err != nil {
t.Errorf("fail to create the runtimeInfo with error %v", err)
Expand Down Expand Up @@ -92,7 +92,7 @@ func TestJuiceFSEngine_queryCacheStatus(t *testing.T) {
t.Errorf("got=%v, want=%v", got, want)
}
})
Convey("cleanup", func() {
Convey("queryCacheStatus", func() {
runtimeInfo, err := base.BuildRuntimeInfo("juicefs", "fluid", "juicefs", datav1alpha1.TieredStore{
Levels: []datav1alpha1.Level{{
MediumType: "MEM",
Expand Down Expand Up @@ -158,3 +158,98 @@ func TestJuiceFSEngine_queryCacheStatus(t *testing.T) {
})
})
}

func TestJuiceFSEngine_getCacheRatio(t *testing.T) {
Convey("Test get cache ratio", t, func() {
Convey("enterprise mode", func() {
runtimeInfo, err := base.BuildRuntimeInfo("juicefs", "fluid", "juicefs", datav1alpha1.TieredStore{})
if err != nil {
t.Errorf("fail to create the runtimeInfo with error %v", err)
}
runtimeInfo.SetupFuseDeployMode(false, nil)
var engine *JuiceFSEngine
patch1 := ApplyMethod(reflect.TypeOf(engine), "GetPodMetrics",
func(_ *JuiceFSEngine, podName, containerName string) (string, error) {
return mockJuiceFSMetric(), nil
})
defer patch1.Reset()
patch2 := ApplyMethod(reflect.TypeOf(engine), "GetRunningPodsOfStatefulSet",
func(_ *JuiceFSEngine, stsName string, namespace string) ([]corev1.Pod, error) {
r := mockRunningPodsOfStatefulSet()
return r, nil
})
defer patch2.Reset()

a := &JuiceFSEngine{
name: "test",
namespace: "default",
runtimeType: "JuiceFSRuntime",
Log: fake.NullLogger(),
runtimeInfo: runtimeInfo,
runtime: &datav1alpha1.JuiceFSRuntime{
ObjectMeta: metav1.ObjectMeta{
Name: "test",
Namespace: "fluid",
},
},
}
want := cacheStates{
cacheHitRatio: "100.0%",
cacheThroughputRatio: "100.0%",
}
states := &cacheStates{}
err = a.getCacheRatio(EnterpriseEdition, states)
if err != nil {
t.Error("check failure, want err, got nil")
}
if want != *states {
t.Errorf("got=%v, want=%v", *states, want)
}
})
Convey("community mode", func() {
runtimeInfo, err := base.BuildRuntimeInfo("juicefs", "fluid", "juicefs", datav1alpha1.TieredStore{})
if err != nil {
t.Errorf("fail to create the runtimeInfo with error %v", err)
}
runtimeInfo.SetupFuseDeployMode(false, nil)
var engine *JuiceFSEngine
patch1 := ApplyMethod(reflect.TypeOf(engine), "GetRunningPodsOfDaemonset",
func(_ *JuiceFSEngine, dsName string, namespace string) ([]corev1.Pod, error) {
r := mockRunningPodsOfDaemonSet()
return r, nil
})
defer patch1.Reset()
patch2 := ApplyMethod(reflect.TypeOf(engine), "GetPodMetrics",
func(_ *JuiceFSEngine, podName, containerName string) (string, error) {
return mockJuiceFSMetricOfCommunity(), nil
})
defer patch2.Reset()

a := &JuiceFSEngine{
name: "test",
namespace: "default",
runtimeType: "JuiceFSRuntime",
Log: fake.NullLogger(),
runtimeInfo: runtimeInfo,
runtime: &datav1alpha1.JuiceFSRuntime{
ObjectMeta: metav1.ObjectMeta{
Name: "test",
Namespace: "fluid",
},
},
}
want := cacheStates{
cacheHitRatio: "100.0%",
cacheThroughputRatio: "100.0%",
}
states := &cacheStates{}
err = a.getCacheRatio(CommunityEdition, states)
if err != nil {
t.Error("check failure, want err, got nil")
}
if want != *states {
t.Errorf("got=%v, want=%v", *states, want)
}
})
})
}

0 comments on commit 34c32cc

Please sign in to comment.