forked from istio/istio
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adapter integration test framework [has-vendor-changes] (istio#4132)
**Utility for all adapters to write baseline based mixer integration tests.** Also added prometheus, redisquota and list adapter integration tests. This has been a common ask from adapter devs, so adding few adapter devs in the review for feedback and input. Features ====== * _Trigger parallel Mixer calls_ : Multiple async calls to adapter via Mixer. * _Initial setup/teardown_: Allow test to do adapter specific initial setup (eg. start fake backend server) and teardown (do backend server cleanup). (see redisquotatest) * _All purpose baseline section for adapter specific baseline data_: Test can specify any (interface{}) adapter specific data to be part of baseline. Example: for prometheus adapter, actual metric reported to backend can be embedded into the expected json baseline. (see prometheus test) * _manipulate config and input attrs_: Test can easily manipulate config or call attributes to create test variety (see redisquotatest, list adapter) Thanks @ozevren and @geeknoid for most of the ideas. * Adapter integration test framework * Cleanup * update lock file * Address feedback from Doug and Jeff * changes after rebase * Make linter happy * Address feedback from Oz * update vendor * update lock after rebase * update lock and vendor after rebase * fix the test * update vendor
- Loading branch information
Showing
6 changed files
with
696 additions
and
110 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
// Copyright 2018 Istio Authors | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package list | ||
|
||
import ( | ||
"testing" | ||
|
||
adapter_integration "istio.io/istio/mixer/pkg/adapter/test" | ||
) | ||
|
||
const ( | ||
h1OverrideSrc1Src2 = ` | ||
apiVersion: "config.istio.io/v1alpha2" | ||
kind: listchecker | ||
metadata: | ||
name: staticversion | ||
namespace: istio-system | ||
spec: | ||
overrides: ["src1", "src2"] | ||
blacklist: false | ||
` | ||
i1ValSrcNameAttr = ` | ||
apiVersion: "config.istio.io/v1alpha2" | ||
kind: listentry | ||
metadata: | ||
name: appversion | ||
namespace: istio-system | ||
spec: | ||
value: source.name | "" | ||
` | ||
r1H1I1 = ` | ||
apiVersion: "config.istio.io/v1alpha2" | ||
kind: rule | ||
metadata: | ||
name: checkwl | ||
namespace: istio-system | ||
spec: | ||
actions: | ||
- handler: staticversion.listchecker | ||
instances: | ||
- appversion.listentry | ||
` | ||
) | ||
|
||
func TestReport(t *testing.T) { | ||
adapter_integration.RunTest( | ||
t, | ||
GetInfo, | ||
adapter_integration.Scenario{ | ||
ParallelCalls: []adapter_integration.Call{ | ||
{ | ||
CallKind: adapter_integration.CHECK, | ||
Attrs: map[string]interface{}{"source.name": "src1"}, | ||
}, | ||
{ | ||
CallKind: adapter_integration.CHECK, | ||
}, | ||
}, | ||
Configs: []string{ | ||
h1OverrideSrc1Src2, | ||
r1H1I1, | ||
i1ValSrcNameAttr, | ||
}, | ||
Want: `{ | ||
"AdapterState": null, | ||
"Returns": [ | ||
{ | ||
"Check": { | ||
"Status": {}, | ||
"ValidDuration": 300000000000, | ||
"ValidUseCount": 10000 | ||
} | ||
}, | ||
{ | ||
"Check": { | ||
"Status": { | ||
"code": 5, | ||
"message": "staticversion.listchecker.istio-system: is not whitelisted" | ||
}, | ||
"ValidDuration": 300000000000, | ||
"ValidUseCount": 10000 | ||
} | ||
} | ||
] | ||
}`, | ||
}, | ||
) | ||
} |
134 changes: 134 additions & 0 deletions
134
mixer/adapter/prometheus/prometheus_integration_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
// Copyright 2018 Istio Authors | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package prometheus | ||
|
||
import ( | ||
"testing" | ||
|
||
dto "github.com/prometheus/client_model/go" | ||
"github.com/prometheus/prom2json" | ||
|
||
adapter_integration "istio.io/istio/mixer/pkg/adapter/test" | ||
) | ||
|
||
const ( | ||
prometheusMetricsURL = "http://localhost:42422/metrics" | ||
requestCountToPromCfg = ` | ||
apiVersion: "config.istio.io/v1alpha2" | ||
kind: prometheus | ||
metadata: | ||
name: handler | ||
namespace: istio-system | ||
spec: | ||
metrics: | ||
- name: request_count | ||
instance_name: requestcount.metric.istio-system | ||
kind: COUNTER | ||
label_names: | ||
- destination_service | ||
- response_code | ||
--- | ||
apiVersion: "config.istio.io/v1alpha2" | ||
kind: rule | ||
metadata: | ||
name: r1 | ||
namespace: istio-system | ||
spec: | ||
actions: | ||
- handler: handler.prometheus | ||
instances: | ||
- requestcount.metric | ||
--- | ||
apiVersion: "config.istio.io/v1alpha2" | ||
kind: metric | ||
metadata: | ||
name: requestcount | ||
namespace: istio-system | ||
spec: | ||
value: "1" | ||
dimensions: | ||
destination_service: "\"myservice\"" | ||
response_code: "200" | ||
` | ||
) | ||
|
||
func TestReport(t *testing.T) { | ||
adapter_integration.RunTest( | ||
t, | ||
GetInfo, | ||
adapter_integration.Scenario{ | ||
ParallelCalls: []adapter_integration.Call{ | ||
{ | ||
CallKind: adapter_integration.REPORT, | ||
}, | ||
{ | ||
CallKind: adapter_integration.REPORT, | ||
}, | ||
}, | ||
|
||
GetState: func(ctx interface{}) (interface{}, error) { | ||
mfChan := make(chan *dto.MetricFamily, 1) | ||
go prom2json.FetchMetricFamilies(prometheusMetricsURL, mfChan, "", "", true) | ||
result := []prom2json.Family{} | ||
for mf := range mfChan { | ||
result = append(result, *prom2json.NewFamily(mf)) | ||
} | ||
return result, nil | ||
}, | ||
|
||
Configs: []string{ | ||
requestCountToPromCfg, | ||
}, | ||
|
||
Want: ` | ||
{ | ||
"AdapterState": [ | ||
{ | ||
"help": "request_count", | ||
"metrics": [ | ||
{ | ||
"labels": { | ||
"destination_service": "myservice", | ||
"response_code": "200" | ||
}, | ||
"value": "2" | ||
} | ||
], | ||
"name": "istio_request_count", | ||
"type": "COUNTER" | ||
} | ||
], | ||
"Returns": [ | ||
{ | ||
"Check": { | ||
"Status": {}, | ||
"ValidDuration": 0, | ||
"ValidUseCount": 0 | ||
}, | ||
"Error": null | ||
}, | ||
{ | ||
"Check": { | ||
"Status": {}, | ||
"ValidDuration": 0, | ||
"ValidUseCount": 0 | ||
}, | ||
"Error": null | ||
} | ||
] | ||
}`, | ||
}, | ||
) | ||
} |
Oops, something went wrong.