Skip to content
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

tests(*) fix flaky test for locality aware loadbalancing #2564

Merged
merged 1 commit into from
Aug 16, 2021
Merged
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
46 changes: 0 additions & 46 deletions test/e2e/deploy/kuma_deploy_universal.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ name: %s
`, mesh)
}

const iterations = 100
const defaultMesh = "default"
const nonDefaultMesh = "non-default"

Expand Down Expand Up @@ -156,49 +155,4 @@ name: %s
return "should retry", errors.Errorf("should retry")
})
})

It("should distribute requests cross zones", func() {
// given services in zone1 and zone2 in a mesh with disabled Locality Aware Load Balancing

// when executing requests from zone 1
responses := 0
for i := 0; i < iterations; i++ {
stdout, _, err := zone1.ExecWithRetries("", "", "demo-client",
"curl", "-v", "-m", "3", "--fail", "test-server.mesh")
Expect(err).ToNot(HaveOccurred())
Expect(stdout).To(ContainSubstring("HTTP/1.1 200 OK"))
Expect(stdout).To(ContainSubstring("universal"))

if strings.Contains(stdout, "universal1") {
responses++
}
}

// then some requests are routed to the same zone and some are not
Expect(responses > iterations/8).To(BeTrue())
Expect(responses < iterations*7/8).To(BeTrue())
})

It("should use locality aware load balancing", func() {
// given services in zone1 and zone2 in a mesh with enabled Locality Aware Load Balancing
err := YamlUniversal(meshMTLSOn(nonDefaultMesh, "true"))(global)
Expect(err).ToNot(HaveOccurred())

// when executing requests from zone 2
responses := 0
for i := 0; i < iterations; i++ {
stdout, _, err := zone2.ExecWithRetries("", "", "demo-client",
"curl", "-v", "-m", "3", "--fail", "test-server.mesh")
Expect(err).ToNot(HaveOccurred())
Expect(stdout).To(ContainSubstring("HTTP/1.1 200 OK"))
Expect(stdout).To(ContainSubstring("universal"))

if strings.Contains(stdout, "universal2") {
responses++
}
}

// then all the requests are routed to the same zone 2
Expect(responses).To(Equal(iterations))
})
}
46 changes: 42 additions & 4 deletions test/e2e/trafficroute/universal_multizone/traffic_route.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ routing:
Install(Kuma(core.Zone, optsZone1...)).
Install(DemoClientUniversal(AppModeDemoClient, defaultMesh, demoClientToken, WithTransparentProxy(true))).
Install(IngressUniversal(ingressTokenKuma3)).
Install(TestServerUniversal("dp-echo-1", defaultMesh, testServerToken,
WithArgs([]string{"echo", "--instance", "echo-v1"}),
WithServiceVersion("v1"),
)).
Setup(zone1)
Expect(err).ToNot(HaveOccurred())
err = zone1.VerifyKuma()
Expand All @@ -80,10 +84,6 @@ routing:

err = NewClusterSetup().
Install(Kuma(core.Zone, optsZone2...)).
Install(TestServerUniversal("dp-echo-1", defaultMesh, testServerToken,
WithArgs([]string{"echo", "--instance", "echo-v1"}),
WithServiceVersion("v1"),
)).
Install(TestServerUniversal("dp-echo-2", defaultMesh, testServerToken,
WithArgs([]string{"echo", "--instance", "echo-v2"}),
WithServiceVersion("v2"),
Expand Down Expand Up @@ -118,6 +118,9 @@ routing:
err := global.GetKumactlOptions().KumactlDelete("traffic-route", item, "default")
Expect(err).ToNot(HaveOccurred())
}

// reapply Mesh with localityawareloadbalancing off
YamlUniversal(meshMTLSOn(defaultMesh, "false"))
})

E2EAfterSuite(func() {
Expand Down Expand Up @@ -364,4 +367,39 @@ conf:
)
})
})

Context("locality aware loadbalancing", func() {
It("should loadbalance all requests equally by default", func() {
Eventually(func() (map[string]int, error) {
return CollectResponsesByInstance(zone1, "demo-client", "test-server.mesh/split", WithNumberOfRequests(40))
}, "30s", "500ms").Should(
And(
HaveLen(4),
HaveKeyWithValue(MatchRegexp(`.*echo-v1.*`), Not(BeNil())),
HaveKeyWithValue(MatchRegexp(`.*echo-v2.*`), Not(BeNil())),
HaveKeyWithValue(MatchRegexp(`.*echo-v3.*`), Not(BeNil())),
HaveKeyWithValue(MatchRegexp(`.*echo-v4.*`), Not(BeNil())),
// todo(jakubdyszkiewicz) uncomment when https://github.com/kumahq/kuma/issues/2563 is fixed
// HaveKeyWithValue(MatchRegexp(`.*echo-v1.*`), ApproximatelyEqual(10, 1)),
// HaveKeyWithValue(MatchRegexp(`.*echo-v2.*`), ApproximatelyEqual(10, 1)),
// HaveKeyWithValue(MatchRegexp(`.*echo-v3.*`), ApproximatelyEqual(10, 1)),
// HaveKeyWithValue(MatchRegexp(`.*echo-v4.*`), ApproximatelyEqual(10, 1)),
),
)
})

It("should keep the request in the zone when locality aware loadbalancing is enabled", func() {
// given
Expect(YamlUniversal(meshMTLSOn(defaultMesh, "true"))(global)).To(Succeed())

Eventually(func() (map[string]int, error) {
return CollectResponsesByInstance(zone1, "demo-client", "test-server.mesh")
}, "30s", "500ms").Should(
And(
HaveLen(1),
HaveKeyWithValue(MatchRegexp(`.*echo-v1.*`), Not(BeNil())),
),
)
})
})
}