Skip to content

Commit

Permalink
test(e2e): add JSON to MeshAccessLog tests
Browse files Browse the repository at this point in the history
Signed-off-by: Mike Beaumont <mjboamail@gmail.com>
  • Loading branch information
michaelbeaumont committed Oct 18, 2022
1 parent d26e2eb commit edfd451
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions test/e2e_env/universal/meshaccesslog/meshaccesslog.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package meshaccesslog

import (
"encoding/json"
"fmt"
"net"
"strconv"
Expand Down Expand Up @@ -120,6 +121,59 @@ spec:
Expect(dst).To(Equal("test-server"))
})

It("should log outgoing traffic with JSON formatting", func() {
yaml := fmt.Sprintf(`
type: MeshAccessLog
name: client-outgoing
mesh: meshaccesslog
spec:
targetRef:
kind: MeshService
name: demo-client
to:
- targetRef:
kind: Mesh
default:
backends:
- tcp:
format:
json:
- key: Source
value: '%%KUMA_SOURCE_SERVICE%%'
- key: Destination
value: '%%KUMA_DESTINATION_SERVICE%%'
- key: Start
value: '%%START_TIME(%%s)%%'
address: "%s_%s:9999"
`, env.Cluster.Name(), externalServiceDeployment)
Expect(YamlUniversal(yaml)(env.Cluster)).To(Succeed())

var src, dst string
sinkDeployment := env.Cluster.Deployment(externalServiceDeployment).(*externalservice.UniversalDeployment)
Eventually(func(g Gomega) {
_, _, err := env.Cluster.Exec("", "", AppModeDemoClient,
"curl", "-v", "--fail", "test-server.mesh")
g.Expect(err).ToNot(HaveOccurred())

stdout, _, err := sinkDeployment.Exec("", "", "head", "-1", "/nc.out")
g.Expect(err).ToNot(HaveOccurred())

type log struct {
Source string
Destination string
Start string
}
var line log
g.Expect(json.Unmarshal([]byte(stdout), &line)).To(Succeed())

src = line.Source
dst = line.Destination
}, "30s", "1s").Should(Succeed())

Expect(src).To(Equal(AppModeDemoClient))
Expect(dst).To(Equal("test-server"))
})

// This is flaky if we don't redeploy demo-client in BeforeEach/E2EAfterEach
// This may have something to do with access-log-streamer
It("should log outgoing passthrough traffic", func() {
Expand Down

0 comments on commit edfd451

Please sign in to comment.