add test for Access log (#7423)

* add test for access log

* fix k8s test

* fix k8s test
This commit is contained in:
Iris 2020-06-09 21:59:09 +08:00 committed by GitHub
parent c88cb628e1
commit 2bb1952f32
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 234 additions and 2 deletions

View File

@ -6,7 +6,7 @@ keywords: [telemetry]
aliases:
- /docs/tasks/telemetry/access-log
- /docs/tasks/telemetry/logs/access-log/
test: no
test: yes
---
The simplest kind of Istio logging is
@ -61,7 +61,8 @@ All three of these parameters may also be configured via [install options](https
1. Send a request from `sleep` to `httpbin`:
{{< text bash >}}
$ kubectl exec -it $(kubectl get pod -l app=sleep -o jsonpath='{.items[0].metadata.name}') -c sleep -- curl -v httpbin:8000/status/418
$ SLEEP_POD=$(kubectl get pod -l app=sleep -o jsonpath='{.items[0].metadata.name}')
$ kubectl exec -it "$SLEEP_POD" -c sleep -- curl -v httpbin:8000/status/418
* Trying 172.21.13.94...
* TCP_NODELAY set
* Connected to httpbin (172.21.13.94) port 8000 (#0)

View File

@ -0,0 +1,110 @@
#!/bin/bash
# shellcheck disable=SC2034,SC2153,SC2155,SC2164
# Copyright Istio Authors. All Rights Reserved.
#
# 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.
####################################################################################################
# WARNING: THIS IS AN AUTO-GENERATED FILE, DO NOT EDIT. PLEASE MODIFY THE ORIGINAL MARKDOWN FILE:
# docs/tasks/observability/logs/access-log/index.md
####################################################################################################
snip_enable_envoys_access_logging_1() {
istioctl install --set profile=demo --set meshConfig.accessLogFile="/dev/stdout"
}
! read -r -d '' snip_enable_envoys_access_logging_1_out <<\ENDSNIP
- Applying manifest for component Base...
✔ Finished applying manifest for component Base.
- Applying manifest for component Pilot...
✔ Finished applying manifest for component Pilot.
- Applying manifest for component EgressGateways...
- Applying manifest for component IngressGateways...
- Applying manifest for component AddonComponents...
✔ Finished applying manifest for component EgressGateways.
✔ Finished applying manifest for component IngressGateways.
✔ Finished applying manifest for component AddonComponents.
✔ Installation complete
ENDSNIP
snip_test_the_access_log_1() {
SLEEP_POD=$(kubectl get pod -l app=sleep -o jsonpath='{.items[0].metadata.name}')
kubectl exec -it "$SLEEP_POD" -c sleep -- curl -v httpbin:8000/status/418
}
! read -r -d '' snip_test_the_access_log_1_out <<\ENDSNIP
* Trying 172.21.13.94...
* TCP_NODELAY set
* Connected to httpbin (172.21.13.94) port 8000 (#0)
> GET /status/418 HTTP/1.1
...
< HTTP/1.1 418 Unknown
< server: envoy
...
-=[ teapot ]=-
_...._
.' _ _ `.
| ."` ^ `". _,
\_;`"---"`|//
| ;/
\_ _/
`"""`
* Connection #0 to host httpbin left intact
ENDSNIP
snip_test_the_access_log_2() {
kubectl logs -l app=sleep -c istio-proxy
}
! read -r -d '' snip_test_the_access_log_2_out <<\ENDSNIP
[2019-03-06T09:31:27.354Z] "GET /status/418 HTTP/1.1" 418 - "-" 0 135 11 10 "-" "curl/7.60.0" "d209e46f-9ed5-9b61-bbdd-43e22662702a" "httpbin:8000" "172.30.146.73:80" outbound|8000||httpbin.default.svc.cluster.local - 172.21.13.94:8000 172.30.146.82:60290 -
ENDSNIP
snip_test_the_access_log_3() {
kubectl logs -l app=httpbin -c istio-proxy
}
! read -r -d '' snip_test_the_access_log_3_out <<\ENDSNIP
[2019-03-06T09:31:27.360Z] "GET /status/418 HTTP/1.1" 418 - "-" 0 135 5 2 "-" "curl/7.60.0" "d209e46f-9ed5-9b61-bbdd-43e22662702a" "httpbin:8000" "127.0.0.1:80" inbound|8000|http|httpbin.default.svc.cluster.local - 172.30.146.73:80 172.30.146.82:38618 outbound_.8000_._.httpbin.default.svc.cluster.local
ENDSNIP
snip_cleanup_1() {
kubectl delete -f samples/sleep/sleep.yaml
kubectl delete -f samples/httpbin/httpbin.yaml
}
snip_disable_envoys_access_logging_1() {
istioctl install --set profile=demo
}
! read -r -d '' snip_disable_envoys_access_logging_1_out <<\ENDSNIP
- Applying manifest for component Base...
✔ Finished applying manifest for component Base.
- Applying manifest for component Pilot...
✔ Finished applying manifest for component Pilot.
- Applying manifest for component EgressGateways...
- Applying manifest for component IngressGateways...
- Applying manifest for component AddonComponents...
✔ Finished applying manifest for component EgressGateways.
✔ Finished applying manifest for component IngressGateways.
✔ Finished applying manifest for component AddonComponents.
✔ Installation complete
ENDSNIP

View File

@ -0,0 +1,43 @@
// Copyright 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 observability
import (
"testing"
"istio.io/istio/pkg/test/framework"
"istio.io/istio.io/pkg/test/istioio"
)
func TestAccessLog(t *testing.T) {
framework.
NewTest(t).
Run(istioio.NewBuilder("tasks__observability__logs__access-log").
Add(istioio.Script{
Input: istioio.Path("scripts/access_log.sh"),
}).
Defer(istioio.Script{
Input: istioio.Inline{
FileName: "cleanup.sh",
Value: `
set +e # ignore cleanup errors
source ${REPO_ROOT}/content/en/docs/tasks/observability/logs/access-log/snips.sh
source ${REPO_ROOT}/tests/util/samples.sh
snip_cleanup_1`,
},
}).
Build())
}

View File

@ -0,0 +1,29 @@
// Copyright 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 observability
import (
"testing"
"istio.io/istio/pkg/test/framework"
"istio.io/istio/pkg/test/framework/resource/environment"
)
func TestMain(m *testing.M) {
framework.
NewSuite("observability", m).
RequireEnvironment(environment.Kube).
Run()
}

View File

@ -0,0 +1,49 @@
#!/usr/bin/env bash
# shellcheck disable=SC1090,SC2154
# Copyright 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.
set -e
set -u
set -o pipefail
source "${REPO_ROOT}/content/en/docs/tasks/observability/logs/access-log/snips.sh"
source "${REPO_ROOT}/tests/util/samples.sh"
# Install Istio with access logging enabled
_verify_contains snip_enable_envoys_access_logging_1 "Installation complete"
# Wait for istiod pod to be ready
_wait_for_deployment istio-system istiod
kubectl label namespace default istio-injection=enabled --overwrite
# Start the sleep sample
startup_sleep_sample
startup_httpbin_sample
_wait_for_deployment default sleep
_wait_for_deployment default httpbin
# Make curl request to httpbin
_verify_contains snip_test_the_access_log_1 "-=[ teapot ]=-"
# Check the logs
_verify_contains snip_test_the_access_log_2 "outbound|8000||httpbin.default.svc.cluster.local"
_verify_contains snip_test_the_access_log_3 "inbound|8000|http|httpbin.default.svc.cluster.local"
snip_cleanup_1
_verify_contains snip_disable_envoys_access_logging_1 "Installation complete"