Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions test/extended/etcd/leader_changes.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@ var _ = g.Describe("[sig-etcd] etcd", func() {
g.It("leader changes are not excessive [Late]", func(ctx g.SpecContext) {
controlPlaneTopology, err := exutil.GetControlPlaneTopology(oc)
o.Expect(err).NotTo(o.HaveOccurred())
etcdNamespace := "openshift-etcd"
if *controlPlaneTopology == configv1.ExternalTopologyMode {
_, etcdNamespace, err = exutil.GetHypershiftManagementClusterConfigAndNamespace()
o.Expect(err).NotTo(o.HaveOccurred())
oc = exutil.NewHypershiftManagementCLI("default").AsAdmin().WithoutNamespace()
}

Expand All @@ -39,11 +42,7 @@ var _ = g.Describe("[sig-etcd] etcd", func() {
testDuration := exutil.DurationSinceStartInSeconds().String()

g.By("Examining the number of etcd leadership changes over the run")
etcdNamespace := "openshift-etcd"
if *controlPlaneTopology == configv1.ExternalTopologyMode {
etcdNamespace = "clusters-.*"
}
result, _, err := prometheus.Query(context.Background(), fmt.Sprintf(`max(max by (pod,job) (increase(etcd_server_leader_changes_seen_total{namespace=~"%s"}[%s])))`, etcdNamespace, testDuration), time.Now())
result, _, err := prometheus.Query(ctx, etcdLeaderChangesQuery(etcdNamespace, testDuration), time.Now())
o.Expect(err).ToNot(o.HaveOccurred())

vec, ok := result.(model.Vector)
Expand All @@ -68,3 +67,7 @@ var _ = g.Describe("[sig-etcd] etcd", func() {
}
})
})

func etcdLeaderChangesQuery(namespace, testDuration string) string {
return fmt.Sprintf(`max(max by (pod,job) (increase(etcd_server_leader_changes_seen_total{namespace=%q}[%s])))`, namespace, testDuration)
}
31 changes: 31 additions & 0 deletions test/extended/etcd/leader_changes_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package etcd

import "testing"

func TestEtcdLeaderChangesQueryScopesNamespaceExactly(t *testing.T) {
testCases := []struct {
name string
namespace string
expected string
}{
{
name: "standalone control plane",
namespace: "openshift-etcd",
expected: `max(max by (pod,job) (increase(etcd_server_leader_changes_seen_total{namespace="openshift-etcd"}[1h])))`,
},
{
name: "hosted control plane",
namespace: "clusters-example",
expected: `max(max by (pod,job) (increase(etcd_server_leader_changes_seen_total{namespace="clusters-example"}[1h])))`,
},
}

for _, testCase := range testCases {
t.Run(testCase.name, func(t *testing.T) {
actual := etcdLeaderChangesQuery(testCase.namespace, "1h")
if actual != testCase.expected {
t.Fatalf("expected %q, got %q", testCase.expected, actual)
}
})
}
}