Skip to content

Commit

Permalink
Fix bugs
Browse files Browse the repository at this point in the history
Signed-off-by: d-kuro <kurosawa7620@gmail.com>
  • Loading branch information
d-kuro committed Nov 2, 2023
1 parent 0f4527c commit 69b7f78
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 6 deletions.
3 changes: 3 additions & 0 deletions controllers/mysqlcluster_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -1718,6 +1718,9 @@ func (r *MySQLClusterReconciler) updateStatus(ctx context.Context, cluster *moco
}
log.Info("update status successfully")
}

metrics.ReconciliationStoppedVec.WithLabelValues(cluster.Name, cluster.Namespace).Set(0)

return nil
}

Expand Down
28 changes: 22 additions & 6 deletions e2e/stop_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ var stopYAML string
//go:embed testdata/stop_changed.yaml
var stopChangedYAML string

var _ = Context("stop", func() {
var _ = Context("stop reconciliation and clustering", func() {
if doUpgrade {
return
}
Expand Down Expand Up @@ -169,7 +169,7 @@ var _ = Context("stop", func() {
"-c", "mysqld",
"--", "kill", "1")

timeout := 5 * time.Minute
timeout := 3 * time.Minute
Consistently(func() error {
cluster, err := getCluster("stop", "test")
if err != nil {
Expand Down Expand Up @@ -230,6 +230,22 @@ var _ = Context("stop", func() {
})

It("active metrics", func() {
Eventually(func() error {
cluster, err := getCluster("stop", "test")
if err != nil {
return err
}
reconcileCond := meta.FindStatusCondition(cluster.Status.Conditions, mocov1beta2.ConditionReconciliationActive)
if reconcileCond.Status == metav1.ConditionFalse {
return fmt.Errorf("reconciliation is stopped: %s", reconcileCond.Status)
}
clusteringCond := meta.FindStatusCondition(cluster.Status.Conditions, mocov1beta2.ConditionClusteringActive)
if clusteringCond.Status == metav1.ConditionFalse {
return fmt.Errorf("clustering is stopped: %s", clusteringCond.Status)
}
return nil
}).Should(Succeed())

out := kubectlSafe(nil, "-n", "moco-system", "get", "pods", "-l", "app.kubernetes.io/component=moco-controller", "-o", "json")
pods := &corev1.PodList{}
err := json.Unmarshal(out, pods)
Expand All @@ -246,13 +262,13 @@ var _ = Context("stop", func() {
Expect(clusteringMf).NotTo(BeNil())
clusteringMetric := findMetric(clusteringMf, map[string]string{"namespace": "stop", "name": "test"})
Expect(clusteringMetric).NotTo(BeNil())
Expect(clusteringMetric.GetCounter().GetValue()).To(BeNumerically("==", 0))
Expect(clusteringMetric.GetGauge().GetValue()).To(BeNumerically("==", 0))

reconcileMf := mfs["moco_cluster_reconciliation_stopped"]
Expect(reconcileMf).NotTo(BeNil())
reconcileMetric := findMetric(reconcileMf, map[string]string{"namespace": "stop", "name": "test"})
Expect(reconcileMetric).NotTo(BeNil())
Expect(reconcileMetric.GetCounter().GetValue()).To(BeNumerically("==", 0))
Expect(reconcileMetric.GetGauge().GetValue()).To(BeNumerically("==", 0))
})

It("stopped metrics", func() {
Expand Down Expand Up @@ -291,13 +307,13 @@ var _ = Context("stop", func() {
Expect(clusteringMf).NotTo(BeNil())
clusteringMetric := findMetric(clusteringMf, map[string]string{"namespace": "stop", "name": "test"})
Expect(clusteringMetric).NotTo(BeNil())
Expect(clusteringMetric.GetCounter().GetValue()).To(BeNumerically("==", 1))
Expect(clusteringMetric.GetGauge().GetValue()).To(BeNumerically("==", 1))

reconcileMf := mfs["moco_cluster_reconciliation_stopped"]
Expect(reconcileMf).NotTo(BeNil())
reconcileMetric := findMetric(reconcileMf, map[string]string{"namespace": "stop", "name": "test"})
Expect(reconcileMetric).NotTo(BeNil())
Expect(reconcileMetric.GetCounter().GetValue()).To(BeNumerically("==", 1))
Expect(reconcileMetric.GetGauge().GetValue()).To(BeNumerically("==", 1))
})

It("should delete clusters", func() {
Expand Down

0 comments on commit 69b7f78

Please sign in to comment.