-
Notifications
You must be signed in to change notification settings - Fork 45
feat: observability into cluster scheduling state #342
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,111 @@ | ||
| /* | ||
| Copyright 2025 Valkey Contributors. | ||
|
|
||
| Licensed under the Apache License, Version 2.0 (the "License"); | ||
| you may not use this file except in compliance with the License. | ||
| You may obtain a copy of the License at | ||
|
|
||
| http://www.apache.org/licenses/LICENSE-2.0 | ||
|
|
||
| Unless required by applicable law or agreed to in writing, software | ||
| distributed under the License is distributed on an "AS IS" BASIS, | ||
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| See the License for the specific language governing permissions and | ||
| limitations under the License. | ||
| */ | ||
|
|
||
| package controller | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| "github.com/prometheus/client_golang/prometheus/testutil" | ||
| metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
|
|
||
| valkeyiov1alpha1 "github.com/valkey-io/valkey-operator/api/v1alpha1" | ||
| ) | ||
|
|
||
| // testNamespace is the namespace used by all metrics tests. | ||
| const testNamespace = "default" | ||
|
|
||
| func conditionGaugeValue(t *testing.T, name, condType, status string) float64 { | ||
| t.Helper() | ||
| return testutil.ToFloat64(clusterCondition.WithLabelValues(name, testNamespace, condType, status)) | ||
| } | ||
|
|
||
| // expectConditionSeries asserts the three status series for a condition type. | ||
| func expectConditionSeries(t *testing.T, name, condType string, wantTrue, wantFalse, wantUnknown float64) { | ||
| t.Helper() | ||
| if got := conditionGaugeValue(t, name, condType, "true"); got != wantTrue { | ||
| t.Errorf("%s{status=true} = %v, want %v", condType, got, wantTrue) | ||
| } | ||
| if got := conditionGaugeValue(t, name, condType, "false"); got != wantFalse { | ||
| t.Errorf("%s{status=false} = %v, want %v", condType, got, wantFalse) | ||
| } | ||
| if got := conditionGaugeValue(t, name, condType, "unknown"); got != wantUnknown { | ||
| t.Errorf("%s{status=unknown} = %v, want %v", condType, got, wantUnknown) | ||
| } | ||
| } | ||
|
|
||
| func TestInitClusterMetrics_PreCreatesConditionSeries(t *testing.T) { | ||
| const name, ns = "metrics-cond-init-test", "default" | ||
| before := testutil.CollectAndCount(clusterCondition) | ||
| initClusterMetrics(name, ns) | ||
|
|
||
| want := before + len(valkeyiov1alpha1.ClusterConditionTypes)*3 | ||
| if got := testutil.CollectAndCount(clusterCondition); got != want { | ||
| t.Fatalf("expected %d condition series after init, got %d", want, got) | ||
| } | ||
|
|
||
| deleteClusterMetrics(name, ns) | ||
| if got := testutil.CollectAndCount(clusterCondition); got != before { | ||
| t.Fatalf("expected %d condition series after delete, got %d", before, got) | ||
| } | ||
| } | ||
|
|
||
| func TestUpdateClusterMetrics_ClusterCondition(t *testing.T) { | ||
| const name, ns = "metrics-cond-test", "default" | ||
| const condType = valkeyiov1alpha1.ConditionSchedulingSatisfied | ||
| initClusterMetrics(name, ns) | ||
| defer deleteClusterMetrics(name, ns) | ||
|
|
||
| cluster := &valkeyiov1alpha1.ValkeyCluster{} | ||
| cluster.Name = name | ||
| cluster.Namespace = ns | ||
|
|
||
| // Condition absent -> all three status series read 0. | ||
| updateClusterMetrics(cluster) | ||
| expectConditionSeries(t, name, condType, 0, 0, 0) | ||
|
|
||
| setCondition(cluster, condType, valkeyiov1alpha1.ReasonAllPodsScheduled, "ok", metav1.ConditionTrue) | ||
| updateClusterMetrics(cluster) | ||
| expectConditionSeries(t, name, condType, 1, 0, 0) | ||
|
|
||
| setCondition(cluster, condType, valkeyiov1alpha1.ReasonPodsPendingScheduling, "pending", metav1.ConditionFalse) | ||
| updateClusterMetrics(cluster) | ||
| expectConditionSeries(t, name, condType, 0, 1, 0) | ||
|
|
||
| setCondition(cluster, condType, valkeyiov1alpha1.ReasonPodsPendingScheduling, "unknown", metav1.ConditionUnknown) | ||
| updateClusterMetrics(cluster) | ||
| expectConditionSeries(t, name, condType, 0, 0, 1) | ||
|
|
||
| // Condition removed again -> back to all zeros. | ||
| cluster.Status.Conditions = nil | ||
| updateClusterMetrics(cluster) | ||
| expectConditionSeries(t, name, condType, 0, 0, 0) | ||
| } | ||
|
|
||
| func TestUpdateClusterMetrics_UnregisteredConditionType(t *testing.T) { | ||
| const name, ns = "metrics-cond-unregistered-test", "default" | ||
| const condType = "NotInClusterConditionTypes" | ||
| initClusterMetrics(name, ns) | ||
| defer deleteClusterMetrics(name, ns) | ||
|
|
||
| cluster := &valkeyiov1alpha1.ValkeyCluster{} | ||
| cluster.Name = name | ||
| cluster.Namespace = ns | ||
| setCondition(cluster, condType, "SomeReason", "some message", metav1.ConditionTrue) | ||
|
|
||
| updateClusterMetrics(cluster) | ||
| expectConditionSeries(t, name, condType, 1, 0, 0) | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -415,6 +415,7 @@ func (r *ValkeyClusterReconciler) handlePodSchedulingIssues(ctx context.Context, | |
| if issue == nil { | ||
| removeConditionIfReason(&cluster.Status.Conditions, valkeyiov1alpha1.ConditionDegraded, valkeyiov1alpha1.ReasonPodUnschedulable) | ||
| removeConditionIfReason(&cluster.Status.Conditions, valkeyiov1alpha1.ConditionReady, valkeyiov1alpha1.ReasonPodUnschedulable) | ||
| setCondition(cluster, valkeyiov1alpha1.ConditionSchedulingSatisfied, valkeyiov1alpha1.ReasonAllPodsScheduled, "All pods are scheduled", metav1.ConditionTrue) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
ArtifactsFocused controller validation script source
Captured focused controller validation script source
Focused validation output against expected Pending behavior
Focused validation output confirming current controller behavior
|
||
| return ctrl.Result{}, false, nil | ||
| } | ||
|
|
||
|
|
@@ -426,6 +427,7 @@ func (r *ValkeyClusterReconciler) handlePodSchedulingIssues(ctx context.Context, | |
| setCondition(cluster, valkeyiov1alpha1.ConditionDegraded, valkeyiov1alpha1.ReasonPodUnschedulable, message, metav1.ConditionTrue) | ||
| setCondition(cluster, valkeyiov1alpha1.ConditionReady, valkeyiov1alpha1.ReasonPodUnschedulable, message, metav1.ConditionFalse) | ||
| setCondition(cluster, valkeyiov1alpha1.ConditionProgressing, valkeyiov1alpha1.ReasonReconciling, "Waiting for unschedulable pods to be scheduled", metav1.ConditionTrue) | ||
| setCondition(cluster, valkeyiov1alpha1.ConditionSchedulingSatisfied, valkeyiov1alpha1.ReasonPodsPendingScheduling, message, metav1.ConditionFalse) | ||
| if err := r.updateStatus(ctx, cluster, nil); err != nil { | ||
| return ctrl.Result{}, false, err | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Arbitrary condition types are exported while present, but this loop only visits types in the current status. After an unregistered condition is removed, its existing Prometheus series is neither reset nor deleted. A prior
Truevalue therefore remains at1.Artifacts
Evidence from the check
Command output from the check