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
15package perftests
16
17import (
18	"strings"
19
20	"istio.io/istio/mixer/adapter"
21	"istio.io/istio/mixer/pkg/perf"
22	generatedTmplRepo "istio.io/istio/mixer/template"
23)
24
25// ExecutableSearchSuffix is used to find the co-process executable that hosts the driver Mixer client.
26const ExecutableSearchSuffix = "bazel-bin/mixer/test/perf/perfclient/perfclient"
27
28var baseSettings = perf.Settings{
29	Templates:            generatedTmplRepo.SupportedTmplInfo,
30	Adapters:             adapter.Inventory(),
31	ExecutablePathSuffix: ExecutableSearchSuffix,
32}
33
34// A minimal service config that can be used by other systems.
35var minimalServiceConfig = `
36apiVersion: "config.istio.io/v1alpha2"
37kind: attributemanifest
38metadata:
39  name: istio-proxy
40  namespace: default
41spec:
42    attributes:
43      source.name:
44        value_type: STRING
45      source.service:
46        value_type: STRING
47      source.labels:
48        value_type: STRING_MAP
49      destination.service:
50        value_type: STRING
51      destination.labels:
52        value_type: STRING_MAP
53      target.name:
54        value_type: STRING
55      response.code:
56        value_type: INT64
57      request.size:
58        value_type: INT64
59      response_code:
60        value_type: INT64
61
62      attr.bool:
63        value_type: BOOL
64      attr.string:
65        value_type: STRING
66      attr.double:
67        value_type: DOUBLE
68      attr.int64:
69        value_type: INT64
70---`
71
72// h1Noop is the handler configuration using the noop adapter.
73var h1Noop = `
74apiVersion: "config.istio.io/v1alpha2"
75kind: noop
76metadata:
77  name: h1
78  namespace: istio-system
79`
80
81// i1ReportNothing is an instance that uses the reportnothing template.
82var i1ReportNothing = `
83apiVersion: "config.istio.io/v1alpha2"
84kind: reportnothing
85metadata:
86  name: i1
87  namespace: istio-system
88spec:
89`
90
91// i2CheckNothing is an instance that uses the checknothing template.
92var i2CheckNothing = `
93apiVersion: "config.istio.io/v1alpha2"
94kind: checknothing
95metadata:
96  name: i2
97  namespace: istio-system
98spec:
99`
100
101// i3Metric is an instance that uses the metric template.
102var i3Metric = `
103apiVersion: "config.istio.io/v1alpha2"
104kind: metric
105metadata:
106  name: i3
107  namespace: istio-system
108spec:
109   value: request.size | 0
110   dimensions:
111     source_service: source.service | "unknown"
112     source_version: source.labels["version"] | "unknown"
113     destination_service: destination.service | "unknown"
114     destination_version: destination.labels["version"] | "unknown"
115     response_code: response.code | 200
116   monitored_resource_type: '"UNSPECIFIED"'
117`
118
119// i4Metric is an instance that uses the metric template.
120var i4Metric = `
121apiVersion: "config.istio.io/v1alpha2"
122kind: metric
123metadata:
124  name: i4
125  namespace: istio-system
126spec:
127   value: request.size | 0
128   dimensions:
129     source_service: source.service | "unknown"
130     source_version: source.labels["version"] | "unknown"
131     destination_service: destination.service | "unknown"
132     destination_version: destination.labels["version"] | "unknown"
133     response_code: response.code | 200
134   monitored_resource_type: '"UNSPECIFIED"'
135`
136
137// i5Metric is an instance that uses the metric template.
138var i5Metric = `
139apiVersion: "config.istio.io/v1alpha2"
140kind: metric
141metadata:
142  name: i5
143  namespace: istio-system
144spec:
145   value: request.size | 0
146   dimensions:
147     source_service: source.service | "unknown"
148     source_version: source.labels["version"] | "unknown"
149     destination_service: destination.service | "unknown"
150     destination_version: destination.labels["version"] | "unknown"
151     response_code: response.code | 200
152   monitored_resource_type: '"UNSPECIFIED"'
153`
154
155// i6Metric is an instance that uses the metric template.
156var i6Metric = `
157apiVersion: "config.istio.io/v1alpha2"
158kind: metric
159metadata:
160  name: i6
161  namespace: istio-system
162spec:
163   value: request.size | 0
164   dimensions:
165     source_service: source.service | "unknown"
166     source_version: source.labels["version"] | "unknown"
167     destination_service: destination.service | "unknown"
168     destination_version: destination.labels["version"] | "unknown"
169     response_code: response.code | 200
170   monitored_resource_type: '"UNSPECIFIED"'
171`
172
173// i7Metric is an instance that uses the metric template.
174var i7Metric = `
175apiVersion: "config.istio.io/v1alpha2"
176kind: metric
177metadata:
178  name: i7
179  namespace: istio-system
180spec:
181   value: request.size | 0
182   dimensions:
183     source_service: source.service | "unknown"
184     source_version: source.labels["version"] | "unknown"
185     destination_service: destination.service | "unknown"
186     destination_version: destination.labels["version"] | "unknown"
187     response_code: response.code | 200
188   monitored_resource_type: '"UNSPECIFIED"'
189`
190
191// r1UsingH1AndI1 is a simple no-condition rule that calls into the noop adapter with reportnothing template.
192var r1UsingH1AndI1 = `
193apiVersion: "config.istio.io/v1alpha2"
194kind: rule
195metadata:
196  name: r1-h1-i1
197  namespace: istio-system
198spec:
199  actions:
200  - handler: h1.noop
201    instances:
202    - i1.reportnothing.istio-system
203`
204
205// r2UsingH1AndI2 is a simple no-condition rule that calls into the noop adapter with checknothing template.
206var r2UsingH1AndI2 = `
207apiVersion: "config.istio.io/v1alpha2"
208kind: rule
209metadata:
210  name: r2-h1-i2
211  namespace: istio-system
212spec:
213  actions:
214  - handler: h1.noop
215    instances:
216    - i2.checknothing.istio-system
217`
218
219// r3UsingH1AndI1Conditional is a simple conditional rule that calls into the noop adapter with reportnothing template.
220var r3UsingH1AndI1Conditional = `
221apiVersion: "config.istio.io/v1alpha2"
222kind: rule
223metadata:
224  name: r1-h1-i1
225  namespace: istio-system
226spec:
227  match: attr.int64 == 42
228  actions:
229  - handler: h1.noop
230    instances:
231    - i1.reportnothing.istio-system
232`
233
234var r5UsingH1AndI3 = `
235apiVersion: "config.istio.io/v1alpha2"
236kind: rule
237metadata:
238  name: r5-h1-i3
239  namespace: istio-system
240spec:
241  actions:
242  - handler: h1.noop
243    instances:
244    - i3.metric.istio-system
245`
246
247var r6UsingH1AndI3To7 = `
248apiVersion: "config.istio.io/v1alpha2"
249kind: rule
250metadata:
251  name: r6-h1-i3to7
252  namespace: istio-system
253spec:
254  actions:
255  - handler: h1.noop
256    instances:
257    - i3.metric.istio-system
258    - i4.metric.istio-system
259    - i5.metric.istio-system
260    - i6.metric.istio-system
261    - i7.metric.istio-system
262`
263
264func joinConfigs(configs ...string) string {
265	return strings.Join(configs, "\n---\n")
266}
267