Collecting Metrics for TCP Services automated test (#7826)

* TCP Metrics automated test

* Fix url and spelling

* More cleanup

* Cleanup - no browser tests

* More cleanup

* Updates - review comment, actually call Prometheus

* code review comments

* Add back second itstioctl kill
This commit is contained in:
Eric Van Norman 2020-08-10 12:22:07 -05:00 committed by GitHub
parent af7e232cea
commit b1f43215cd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 199 additions and 7 deletions

View File

@ -7,7 +7,7 @@ aliases:
- /docs/tasks/telemetry/tcp-metrics
- /docs/tasks/telemetry/metrics/tcp-metrics/
owner: istio/wg-policies-and-telemetry-maintainers
test: no
test: yes
---
This task shows how to configure Istio to automatically gather telemetry for TCP
@ -19,7 +19,7 @@ as the example throughout this task.
## Before you begin
* [Install Istio](/docs/setup) in your cluster and deploy an
application.
application. You must also install [Prometheus](/docs/ops/integrations/prometheus/).
* This task assumes that the Bookinfo sample will be deployed in the `default`
namespace. If you use a different namespace, update the
@ -36,6 +36,8 @@ example configuration and commands.
{{< text bash >}}
$ kubectl apply -f @samples/bookinfo/platform/kube/bookinfo-ratings-v2.yaml@
serviceaccount/bookinfo-ratings-v2 created
deployment.apps/ratings-v2 created
{{< /text >}}
If you are using manual sidecar injection, run the following command instead:
@ -52,6 +54,8 @@ example configuration and commands.
{{< text bash >}}
$ kubectl apply -f @samples/bookinfo/platform/kube/bookinfo-db.yaml@
service/mongodb created
deployment.apps/mongodb-v1 created
{{< /text >}}
If you are using manual sidecar injection, run the following command instead:
@ -87,8 +91,8 @@ example configuration and commands.
{{< text bash >}}
$ kubectl apply -f @samples/bookinfo/networking/virtual-service-ratings-db.yaml@
Created config virtual-service/default/reviews at revision 3003
Created config virtual-service/default/ratings at revision 3004
virtualservice.networking.istio.io/reviews created
virtualservice.networking.istio.io/ratings created
{{< /text >}}
1. Send traffic to the sample application.
@ -97,7 +101,7 @@ example configuration and commands.
browser or use the following command:
{{< text bash >}}
$ curl http://$GATEWAY_URL/productpage
$ curl http://"$GATEWAY_URL/productpage"
{{< /text >}}
{{< tip >}}
@ -110,7 +114,7 @@ example configuration and commands.
using the following command:
{{< text bash >}}
$ kubectl -n istio-system port-forward $(kubectl -n istio-system get pod -l app=prometheus -o jsonpath='{.items[0].metadata.name}') 9090:9090 &
$ istioctl dashboard prometheus
{{< /text >}}
View the values for the TCP metrics in the Prometheus browser window. Select **Graph**.
@ -171,7 +175,7 @@ This protocol extends TCP as follows:
* Remove the `port-forward` process:
{{< text bash >}}
$ killall kubectl
$ killall istioctl
{{< /text >}}
* If you are not planning to explore any follow-on tasks, refer to the

View File

@ -0,0 +1,107 @@
#!/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/metrics/tcp-metrics/index.md
####################################################################################################
snip_collecting_new_telemetry_data_1() {
kubectl apply -f samples/bookinfo/platform/kube/bookinfo-ratings-v2.yaml
}
! read -r -d '' snip_collecting_new_telemetry_data_1_out <<\ENDSNIP
serviceaccount/bookinfo-ratings-v2 created
deployment.apps/ratings-v2 created
ENDSNIP
snip_collecting_new_telemetry_data_2() {
kubectl apply -f <(istioctl kube-inject -f samples/bookinfo/platform/kube/bookinfo-ratings-v2.yaml)
}
! read -r -d '' snip_collecting_new_telemetry_data_2_out <<\ENDSNIP
deployment "ratings-v2" configured
ENDSNIP
snip_collecting_new_telemetry_data_3() {
kubectl apply -f samples/bookinfo/platform/kube/bookinfo-db.yaml
}
! read -r -d '' snip_collecting_new_telemetry_data_3_out <<\ENDSNIP
service/mongodb created
deployment.apps/mongodb-v1 created
ENDSNIP
snip_collecting_new_telemetry_data_4() {
kubectl apply -f <(istioctl kube-inject -f samples/bookinfo/platform/kube/bookinfo-db.yaml)
}
! read -r -d '' snip_collecting_new_telemetry_data_4_out <<\ENDSNIP
service "mongodb" configured
deployment "mongodb-v1" configured
ENDSNIP
snip_collecting_new_telemetry_data_5() {
kubectl apply -f samples/bookinfo/networking/destination-rule-all.yaml
}
snip_collecting_new_telemetry_data_6() {
kubectl apply -f samples/bookinfo/networking/destination-rule-all-mtls.yaml
}
snip_collecting_new_telemetry_data_7() {
kubectl get destinationrules -o yaml
}
snip_collecting_new_telemetry_data_8() {
kubectl apply -f samples/bookinfo/networking/virtual-service-ratings-db.yaml
}
! read -r -d '' snip_collecting_new_telemetry_data_8_out <<\ENDSNIP
virtualservice.networking.istio.io/reviews created
virtualservice.networking.istio.io/ratings created
ENDSNIP
snip_collecting_new_telemetry_data_9() {
curl http://"$GATEWAY_URL/productpage"
}
snip_collecting_new_telemetry_data_10() {
istioctl dashboard prometheus
}
! read -r -d '' snip_collecting_new_telemetry_data_11 <<\ENDSNIP
istio_tcp_connections_opened_total{
destination_version="v1",
instance="172.17.0.18:42422",
job="istio-mesh",
canonical_service_name="ratings-v2",
canonical_service_revision="v2"}
ENDSNIP
! read -r -d '' snip_collecting_new_telemetry_data_12 <<\ENDSNIP
istio_tcp_connections_closed_total{
destination_version="v1",
instance="172.17.0.18:42422",
job="istio-mesh",
canonical_service_name="ratings-v2",
canonical_service_revision="v2"}
ENDSNIP
snip_cleanup_1() {
killall istioctl
}

View File

@ -0,0 +1,81 @@
#!/usr/bin/env bash
# shellcheck disable=SC1090,SC2154,SC2155
# 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 "tests/util/samples.sh"
# @setup profile=demo
# Set to known setting of sidecar injection
kubectl label namespace default istio-injection=enabled --overwrite
# Install Bookinfo sample
startup_bookinfo_sample # from tests/util/samples.sh
# Install Prometheus
kubectl apply -f samples/addons/prometheus.yaml -n istio-system
_wait_for_deployment istio-system prometheus
# Setup bookinfo to use MongoDB
# Install Ratings v2
_verify_same snip_collecting_new_telemetry_data_1 "$snip_collecting_new_telemetry_data_1_out"
# Install the MongoDB service
_verify_same snip_collecting_new_telemetry_data_3 "$snip_collecting_new_telemetry_data_3_out"
# Apply the destination rules
snip_collecting_new_telemetry_data_5
_wait_for_istio destinationrule default ratings
_wait_for_istio destinationrule default reviews
# Create the virtual services
_verify_same snip_collecting_new_telemetry_data_8 "$snip_collecting_new_telemetry_data_8_out"
_wait_for_istio virtualservice default reviews
_wait_for_istio virtualservice default ratings
# Get GATEWAY_URL
# export the INGRESS_ environment variables
# TODO make this work more generally. Currently using snips for Kind.
_set_ingress_environment_variables
export GATEWAY_URL=$INGRESS_HOST:$INGRESS_PORT
# Next steps look at the Prometheus browser. Start redirection.
# snip_collecting_new_telemetry_data_10
istioctl dashboard prometheus &
# Hit the GATEWAY_URL and verify metrics exist
get_metrics_1() {
curl -s "http://${GATEWAY_URL}/productpage" | grep -o "<title>.*</title>"
curl -sg 'http://localhost:9090/api/v1/query?query=istio_tcp_connections_opened_total' | jq .data.result[0].metric.__name__
}
# Because of retries we can't validate values, but verify that metric exists.
_verify_contains get_metrics_1 '"istio_tcp_connections_opened_total"'
pgrep istioctl | xargs kill
# @cleanup
set +e # ignore cleanup errors
pgrep istioctl | xargs kill
kubectl delete -f samples/bookinfo/networking/virtual-service-ratings-db.yaml
kubectl delete -f samples/bookinfo/networking/destination-rule-all.yaml
kubectl delete -f samples/bookinfo/platform/kube/bookinfo-db.yaml
kubectl delete -f samples/bookinfo/platform/kube/bookinfo-ratings-v2.yaml
kubectl delete -f samples/addons/prometheus.yaml -n istio-system
cleanup_bookinfo_sample