Skip to content

Commit 955d54a

Browse files
authored
Add mixer client end to end integration test. (istio#177)
* Add mixer client end to end integration test. * Split some repositories into a separate file. * use real mixer for fake mixer_server. * Test repository * use mixer bzl file. * Use mixer repositories * Not to use mixer repository. * Add return line at the end of WORKSPACE.
1 parent 978b967 commit 955d54a

File tree

13 files changed

+1430
-5
lines changed

13 files changed

+1430
-5
lines changed

BUILD

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,7 @@ config_setting(
2424
},
2525
visibility = ["//visibility:public"],
2626
)
27+
28+
load("@io_bazel_rules_go//go:def.bzl", "go_prefix")
29+
30+
go_prefix("istio.io/proxy")

WORKSPACE

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,3 +96,19 @@ http_file(
9696
url = "https://storage.googleapis.com/istio-build/manager/ubuntu_xenial_debug-" + DEBUG_BASE_IMAGE_SHA + ".tar.gz",
9797
sha256 = DEBUG_BASE_IMAGE_SHA,
9898
)
99+
100+
# Following go repositories are for building go integration test for mixer filter.
101+
git_repository(
102+
name = "io_bazel_rules_go",
103+
commit = "9496d79880a7d55b8e4a96f04688d70a374eaaf4", # Mar 3, 2017 (v0.4.1)
104+
remote = "https://github.com/bazelbuild/rules_go.git",
105+
)
106+
107+
git_repository(
108+
name = "org_pubref_rules_protobuf",
109+
commit = "d42e895387c658eda90276aea018056fcdcb30e4", # Mar 07 2017 (gogo* support)
110+
remote = "https://github.com/pubref/rules_protobuf",
111+
)
112+
113+
load("//src/envoy/mixer/integration_test:repositories.bzl", "go_mixer_repositories")
114+
go_mixer_repositories()

src/envoy/mixer/BUILD

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
################################################################################
1616
#
1717

18-
1918
load("@bazel_tools//tools/build_defs/pkg:pkg.bzl", "pkg_tar")
2019
load("//src/envoy/mixer:proxy_docker.bzl", "proxy_docker_build")
2120
load("@protobuf_git//:protobuf.bzl", "cc_proto_library")
@@ -48,6 +47,7 @@ cc_library(
4847
cc_binary(
4948
name = "envoy",
5049
linkstatic = 1,
50+
visibility = [":__subpackages__"],
5151
deps = [
5252
":filter_lib",
5353
"@envoy_git//:envoy-main",
@@ -80,10 +80,6 @@ pkg_tar(
8080
)
8181

8282
proxy_docker_build(
83-
images = [
84-
{"name": "proxy", "base": "@docker_ubuntu//:xenial"},
85-
{"name": "proxy_debug", "base": "@ubuntu_xenial_debug//file"},
86-
],
8783
entrypoint = [
8884
"/usr/local/bin/start_envoy",
8985
"-e",
@@ -93,6 +89,16 @@ proxy_docker_build(
9389
"-t",
9490
"/etc/opt/proxy/envoy.conf.template",
9591
],
92+
images = [
93+
{
94+
"name": "proxy",
95+
"base": "@docker_ubuntu//:xenial",
96+
},
97+
{
98+
"name": "proxy_debug",
99+
"base": "@ubuntu_xenial_debug//file",
100+
},
101+
],
96102
ports = ["9090"],
97103
repository = "istio",
98104
tags = ["manual"],
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# Copyright 2016 Google Inc. 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+
################################################################################
16+
#
17+
18+
load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test")
19+
20+
go_library(
21+
name = "go_default_library",
22+
srcs = [
23+
"attributes.go",
24+
"envoy.go",
25+
"http_client.go",
26+
"http_server.go",
27+
"mixer_server.go",
28+
"setup.go",
29+
],
30+
deps = [
31+
"@com_github_gogo_protobuf//types:go_default_library",
32+
"@com_github_golang_glog//:go_default_library",
33+
"@com_github_golang_protobuf//proto:go_default_library",
34+
"@com_github_googleapis_googleapis//:google/rpc",
35+
"@com_github_istio_api//:mixer/v1",
36+
"@com_github_istio_mixer//pkg/api:go_default_library",
37+
"@com_github_istio_mixer//pkg/attribute:go_default_library",
38+
"@com_github_istio_mixer//pkg/pool:go_default_library",
39+
"@com_github_istio_mixer//pkg/tracing:go_default_library",
40+
"@org_golang_google_grpc//:go_default_library",
41+
],
42+
)
43+
44+
go_test(
45+
name = "mixer_test",
46+
size = "small",
47+
srcs = [
48+
"mixer_test.go",
49+
],
50+
data = [
51+
"envoy.conf",
52+
"//src/envoy/mixer:envoy",
53+
],
54+
library = ":go_default_library",
55+
# shared memory path /envoy_shared_memory_0 used by Envoy
56+
# hot start is not working in sandbox mode.
57+
local = True,
58+
)
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
// Copyright 2017 Istio Authors
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+
"encoding/json"
19+
"fmt"
20+
"reflect"
21+
22+
"istio.io/mixer/pkg/attribute"
23+
)
24+
25+
func verifyStringMap(actual map[string]string, expected map[string]interface{}) error {
26+
for k, v := range expected {
27+
vstring := v.(string)
28+
// "-" make sure the key does not exist.
29+
if vstring == "-" {
30+
if _, ok := actual[k]; ok {
31+
return fmt.Errorf("key %+v is NOT expected", k)
32+
}
33+
} else {
34+
if val, ok := actual[k]; ok {
35+
// "*" only check key exist
36+
if val != vstring && vstring != "*" {
37+
return fmt.Errorf("key %+v value doesn't match. Actual %+v, expected %+v",
38+
k, val, vstring)
39+
}
40+
} else {
41+
return fmt.Errorf("key %+v is expected", k)
42+
}
43+
}
44+
}
45+
return nil
46+
}
47+
48+
// Please see the comment at top of mixer_test.go for verification rules
49+
func Verify(b *attribute.MutableBag, json_results string) error {
50+
var r map[string]interface{}
51+
if err := json.Unmarshal([]byte(json_results), &r); err != nil {
52+
return fmt.Errorf("unable to decode json %v", err)
53+
}
54+
55+
all_keys := make(map[string]bool)
56+
for _, k := range b.Names() {
57+
all_keys[k] = true
58+
}
59+
60+
for k, v := range r {
61+
switch vv := v.(type) {
62+
case string:
63+
// "*" means only checking key.
64+
if vv == "*" {
65+
if _, ok := b.Get(k); !ok {
66+
return fmt.Errorf("attribute %+v is expected", k)
67+
}
68+
} else {
69+
if val, ok := b.Get(k); ok {
70+
if val.(string) != v.(string) {
71+
return fmt.Errorf("attribute %+v value doesn't match. Actual %+v, expected %+v",
72+
k, val.(string), v.(string))
73+
}
74+
} else {
75+
return fmt.Errorf("attribute %+v is expected", k)
76+
}
77+
}
78+
case float64:
79+
// Json converts all integers to float64,
80+
// Our tests only verify size related attributes which are int64 type
81+
if val, ok := b.Get(k); ok {
82+
vint64 := int64(vv)
83+
if val.(int64) != vint64 {
84+
return fmt.Errorf("attribute %+v value doesn't match. Actual %+v, expected %+v",
85+
k, val.(int64), vint64)
86+
}
87+
} else {
88+
return fmt.Errorf("attribute %+v is expected", k)
89+
}
90+
case map[string]interface{}:
91+
if val, ok := b.Get(k); ok {
92+
if err := verifyStringMap(val.(map[string]string), v.(map[string]interface{})); err != nil {
93+
return fmt.Errorf("attribute %+v StringMap doesn't match: %+v", k, err)
94+
}
95+
} else {
96+
return fmt.Errorf("attribute %+v is expected", k)
97+
}
98+
default:
99+
return fmt.Errorf("attribute %+v is of a type %+v that I don't know how to handle ",
100+
k, reflect.TypeOf(v))
101+
}
102+
delete(all_keys, k)
103+
104+
}
105+
106+
if len(all_keys) > 0 {
107+
var s string
108+
for k, _ := range all_keys {
109+
s += k + ", "
110+
}
111+
return fmt.Errorf("Following attributes are not expected: %s", s)
112+
}
113+
return nil
114+
}
Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
{
2+
"listeners": [
3+
{
4+
"port": 29090,
5+
"bind_to_port": true,
6+
"filters": [
7+
{
8+
"type": "read",
9+
"name": "http_connection_manager",
10+
"config": {
11+
"codec_type": "auto",
12+
"stat_prefix": "ingress_http",
13+
"route_config": {
14+
"virtual_hosts": [
15+
{
16+
"name": "backend",
17+
"domains": ["*"],
18+
"routes": [
19+
{
20+
"timeout_ms": 0,
21+
"prefix": "/",
22+
"cluster": "service1",
23+
"opaque_config": {
24+
"mixer_control": "on",
25+
"mixer_forward": "off"
26+
}
27+
}
28+
]
29+
}
30+
]
31+
},
32+
"access_log": [
33+
{
34+
"path": "/dev/stdout"
35+
}
36+
],
37+
"filters": [
38+
{
39+
"type": "decoder",
40+
"name": "mixer",
41+
"config": {
42+
"mixer_server": "localhost:29091",
43+
"mixer_attributes": {
44+
"target.uid": "POD222",
45+
"target.namespace": "XYZ222"
46+
}
47+
}
48+
},
49+
{
50+
"type": "decoder",
51+
"name": "router",
52+
"config": {}
53+
}
54+
]
55+
}
56+
}
57+
]
58+
},
59+
{
60+
"port": 27070,
61+
"bind_to_port": true,
62+
"filters": [
63+
{
64+
"type": "read",
65+
"name": "http_connection_manager",
66+
"config": {
67+
"codec_type": "auto",
68+
"stat_prefix": "ingress_http",
69+
"route_config": {
70+
"virtual_hosts": [
71+
{
72+
"name": "backend",
73+
"domains": ["*"],
74+
"routes": [
75+
{
76+
"timeout_ms": 0,
77+
"prefix": "/",
78+
"cluster": "service2"
79+
}
80+
]
81+
}
82+
]
83+
},
84+
"access_log": [
85+
{
86+
"path": "/dev/stdout"
87+
}
88+
],
89+
"filters": [
90+
{
91+
"type": "decoder",
92+
"name": "mixer",
93+
"config": {
94+
"mixer_server": "localhost:29091",
95+
"forward_attributes": {
96+
"source.uid": "POD11",
97+
"source.namespace": "XYZ11"
98+
}
99+
}
100+
},
101+
{
102+
"type": "decoder",
103+
"name": "router",
104+
"config": {}
105+
}
106+
]
107+
}
108+
}
109+
]
110+
}
111+
],
112+
"admin": {
113+
"access_log_path": "/dev/stdout",
114+
"port": 29001
115+
},
116+
"cluster_manager": {
117+
"clusters": [
118+
{
119+
"name": "service1",
120+
"connect_timeout_ms": 5000,
121+
"type": "strict_dns",
122+
"lb_type": "round_robin",
123+
"hosts": [
124+
{
125+
"url": "tcp://localhost:28080"
126+
}
127+
]
128+
},
129+
{
130+
"name": "service2",
131+
"connect_timeout_ms": 5000,
132+
"type": "strict_dns",
133+
"lb_type": "round_robin",
134+
"hosts": [
135+
{
136+
"url": "tcp://localhost:29090"
137+
}
138+
]
139+
}
140+
]
141+
}
142+
}

0 commit comments

Comments
 (0)