Skip to content

Commit 7aa227b

Browse files
authored
Add report batch integration test. (istio#358)
1 parent a2009dd commit 7aa227b

File tree

5 files changed

+172
-13
lines changed

5 files changed

+172
-13
lines changed

src/envoy/mixer/integration_test/BUILD

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ go_test_suite(
6969
"check_fail_open_test.go",
7070
"check_fail_close_test.go",
7171
"failed_request_test.go",
72+
"report_batch_test.go",
7273
"quota_cache_test.go",
7374
"quota_test.go",
7475
"stress_test.go",

src/envoy/mixer/integration_test/mixer_server.go

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,29 +34,26 @@ import (
3434

3535
type Handler struct {
3636
stress bool
37-
bag *attribute.MutableBag
38-
ch chan int
37+
ch chan *attribute.MutableBag
3938
count int
4039
r_status rpc.Status
4140
}
4241

4342
func newHandler(stress bool) *Handler {
4443
h := &Handler{
4544
stress: stress,
46-
bag: nil,
4745
count: 0,
4846
r_status: rpc.Status{},
4947
}
5048
if !stress {
51-
h.ch = make(chan int, 10) // Allow maximum 10 requests
49+
h.ch = make(chan *attribute.MutableBag, 10) // Allow maximum 10 requests
5250
}
5351
return h
5452
}
5553

5654
func (h *Handler) run(bag *attribute.MutableBag) rpc.Status {
5755
if !h.stress {
58-
h.bag = attribute.CopyBag(bag)
59-
h.ch <- 1
56+
h.ch <- attribute.CopyBag(bag)
6057
}
6158
h.count++
6259
return h.r_status
Lines changed: 161 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,161 @@
1+
// Copyright 2017 Istio Authors. All Rights Reserved.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package test
16+
17+
import (
18+
"fmt"
19+
"testing"
20+
)
21+
22+
// Report attributes from a good GET request
23+
const reportAttributesOkGet = `
24+
{
25+
"request.host": "localhost:27070",
26+
"request.path": "/echo",
27+
"request.time": "*",
28+
"request.useragent": "Go-http-client/1.1",
29+
"request.method": "GET",
30+
"request.scheme": "http",
31+
"source.uid": "POD11",
32+
"source.namespace": "XYZ11",
33+
"target.uid": "POD222",
34+
"target.namespace": "XYZ222",
35+
"request.headers": {
36+
":method": "GET",
37+
":path": "/echo",
38+
":authority": "localhost:27070",
39+
"x-forwarded-proto": "http",
40+
"x-istio-attributes": "-",
41+
"x-request-id": "*"
42+
},
43+
"request.size": 0,
44+
"response.time": "*",
45+
"response.size": 0,
46+
"response.duration": "*",
47+
"response.code": 200,
48+
"response.headers": {
49+
"date": "*",
50+
"content-type": "text/plain; charset=utf-8",
51+
"content-length": "0",
52+
":status": "200",
53+
"server": "envoy"
54+
}
55+
}
56+
`
57+
58+
// Report attributes from a good POST request
59+
const reportAttributesOkPost1 = `
60+
{
61+
"request.host": "localhost:27070",
62+
"request.path": "/echo",
63+
"request.time": "*",
64+
"request.useragent": "Go-http-client/1.1",
65+
"request.method": "POST",
66+
"request.scheme": "http",
67+
"source.uid": "POD11",
68+
"source.namespace": "XYZ11",
69+
"target.uid": "POD222",
70+
"target.namespace": "XYZ222",
71+
"request.headers": {
72+
":method": "POST",
73+
":path": "/echo",
74+
":authority": "localhost:27070",
75+
"x-forwarded-proto": "http",
76+
"x-istio-attributes": "-",
77+
"x-request-id": "*"
78+
},
79+
"request.size": 12,
80+
"response.time": "*",
81+
"response.size": 12,
82+
"response.duration": "*",
83+
"response.code": 200,
84+
"response.headers": {
85+
"date": "*",
86+
"content-type": "text/plain",
87+
"content-length": "12",
88+
":status": "200",
89+
"server": "envoy"
90+
}
91+
}
92+
`
93+
94+
// Report attributes from a good POST request
95+
const reportAttributesOkPost2 = `
96+
{
97+
"request.host": "localhost:27070",
98+
"request.path": "/echo",
99+
"request.time": "*",
100+
"request.useragent": "Go-http-client/1.1",
101+
"request.method": "POST",
102+
"request.scheme": "http",
103+
"source.uid": "POD11",
104+
"source.namespace": "XYZ11",
105+
"target.uid": "POD222",
106+
"target.namespace": "XYZ222",
107+
"request.headers": {
108+
":method": "POST",
109+
":path": "/echo",
110+
":authority": "localhost:27070",
111+
"x-forwarded-proto": "http",
112+
"x-istio-attributes": "-",
113+
"x-request-id": "*"
114+
},
115+
"request.size": 18,
116+
"response.time": "*",
117+
"response.size": 18,
118+
"response.duration": "*",
119+
"response.code": 200,
120+
"response.headers": {
121+
"date": "*",
122+
"content-type": "text/plain",
123+
"content-length": "18",
124+
":status": "200",
125+
"server": "envoy"
126+
}
127+
}
128+
`
129+
130+
func TestReportBatch(t *testing.T) {
131+
s := &TestSetup{
132+
t: t,
133+
conf: basicConfig,
134+
}
135+
if err := s.SetUp(); err != nil {
136+
t.Fatalf("Failed to setup test: %v", err)
137+
}
138+
defer s.TearDown()
139+
140+
url := fmt.Sprintf("http://localhost:%d/echo", ClientProxyPort)
141+
142+
// Issues a GET echo request with 0 size body
143+
tag := "OKGet"
144+
if _, _, err := HTTPGet(url); err != nil {
145+
t.Errorf("Failed in request %s: %v", tag, err)
146+
}
147+
// Issues a POST request.
148+
tag = "OKPost1"
149+
if _, _, err := HTTPPost(url, "text/plain", "Hello World!"); err != nil {
150+
t.Errorf("Failed in request %s: %v", tag, err)
151+
}
152+
// Issues a POST request again.
153+
tag = "OKPost2"
154+
if _, _, err := HTTPPost(url, "text/plain", "Hello World Again!"); err != nil {
155+
t.Errorf("Failed in request %s: %v", tag, err)
156+
}
157+
tag = "Batch"
158+
s.VerifyReport(tag, reportAttributesOkGet)
159+
s.VerifyReport(tag, reportAttributesOkPost1)
160+
s.VerifyReport(tag, reportAttributesOkPost2)
161+
}

src/envoy/mixer/integration_test/repositories.bzl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,6 @@ def go_mixer_repositories(use_local_api=False):
211211

212212
go_repository(
213213
name = "com_github_istio_mixer",
214-
commit = "233d6ba56b07ab647629bf71c0c5274216ba4da7",
214+
commit = "c685be4eb9578cb8edb3d8164b9b56f70b813c77",
215215
importpath = "github.com/istio/mixer",
216216
)

src/envoy/mixer/integration_test/setup.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -73,18 +73,18 @@ func (s *TestSetup) VerifyCheckCount(tag string, expected int) {
7373
}
7474

7575
func (s *TestSetup) VerifyCheck(tag string, result string) {
76-
_ = <-s.mixer.check.ch
77-
if err := Verify(s.mixer.check.bag, result); err != nil {
76+
bag := <-s.mixer.check.ch
77+
if err := Verify(bag, result); err != nil {
7878
s.t.Fatalf("Failed to verify %s check: %v\n, Attributes: %+v",
79-
tag, err, s.mixer.check.bag)
79+
tag, err, bag)
8080
}
8181
}
8282

8383
func (s *TestSetup) VerifyReport(tag string, result string) {
84-
_ = <-s.mixer.report.ch
85-
if err := Verify(s.mixer.report.bag, result); err != nil {
84+
bag := <-s.mixer.report.ch
85+
if err := Verify(bag, result); err != nil {
8686
s.t.Fatalf("Failed to verify %s report: %v\n, Attributes: %+v",
87-
tag, err, s.mixer.report.bag)
87+
tag, err, bag)
8888
}
8989
}
9090

0 commit comments

Comments
 (0)