summaryrefslogtreecommitdiffstats
path: root/clover/tools
diff options
context:
space:
mode:
Diffstat (limited to 'clover/tools')
-rw-r--r--clover/tools/__init__.py0
-rw-r--r--clover/tools/clover_validate_rr.py56
-rw-r--r--clover/tools/validate_rr.py88
3 files changed, 144 insertions, 0 deletions
diff --git a/clover/tools/__init__.py b/clover/tools/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/clover/tools/__init__.py
diff --git a/clover/tools/clover_validate_rr.py b/clover/tools/clover_validate_rr.py
new file mode 100644
index 0000000..ff1f8b4
--- /dev/null
+++ b/clover/tools/clover_validate_rr.py
@@ -0,0 +1,56 @@
+#!/usr/bin/env python
+
+# Copyright (c) Authors of Clover
+#
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Apache License, Version 2.0
+# which accompanies this distribution, and is available at
+# http://www.apache.org/licenses/LICENSE-2.0
+
+import getopt
+import sys
+
+sys.path.insert(0, '..')
+
+from orchestration import kube_client
+import servicemesh.route_rules as rr
+from tracing.tracing import Tracing
+from validate_rr import ValidateWRR
+
+def main(argv):
+ service_name = None
+ test_id = None
+ help_str = 'clover_validate_rr.py -t <test-id> -s <service name>'
+ try:
+ opts, args = getopt.getopt(argv,"hs:t:",["service-name", "test-id"])
+ except getopt.GetoptError:
+ print help_str
+ sys.exit(2)
+ for opt, arg in opts:
+ if opt == '-h':
+ print help_str
+ sys.exit()
+ elif opt in ("-t", "--test-id"):
+ test_id = str(arg)
+ elif opt in ("-s", "--service-name"):
+ service_name = str(arg)
+
+ if not service_name or not test_id:
+ print help_str
+ sys.exit(3)
+
+ validate_wrr = ValidateWRR(test_id)
+
+ istio_pods = ['istio-ingress', 'istio-mixer', 'istio-pilot']
+ jaeger_pods = ['jaeger-deployment']
+
+ if not validate_wrr.check_pods_up(istio_pods + jaeger_pods,
+ 'istio-system'):
+ sys.exit(4)
+
+ ret, errors = validate_wrr.validate(service_name)
+ for err in errors:
+ print err
+
+if __name__ == "__main__":
+ main(sys.argv[1:])
diff --git a/clover/tools/validate_rr.py b/clover/tools/validate_rr.py
new file mode 100644
index 0000000..0e7b9ed
--- /dev/null
+++ b/clover/tools/validate_rr.py
@@ -0,0 +1,88 @@
+#!/usr/bin/env python
+
+# Copyright (c) Authors of Clover
+#
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Apache License, Version 2.0
+# which accompanies this distribution, and is available at
+# http://www.apache.org/licenses/LICENSE-2.0
+import sys
+
+sys.path.insert(0, '..')
+
+from orchestration import kube_client
+import servicemesh.route_rules as rr
+from tracing.tracing import Tracing
+
+class ValidateWRR(object):
+
+ def __init__(self, test_id, tracing_ip='localhost', tracing_port='31298'):
+ self._k8s_client = kube_client.KubeClient()
+ self._test_id = test_id
+ self._tracing = Tracing(tracing_ip, tracing_port)
+
+ def check_pods_up(self, pod_list, namespace='default'):
+ for pod in pod_list:
+ up, name = self._k8s_client.check_pod_up(pod, namespace)
+ if not up:
+ print('pod %s in namespace %s not up' % (pod, namespace))
+ return False
+ return True
+
+ def set_test_id(self, test_id):
+ self._test_id = test_id
+
+ def validate(self, service_name):
+ total = 0
+ svc = self._k8s_client.find_svc_by_namespace(svc_name=service_name)
+ if not svc:
+ err_msg = 'Failed to locate service %s in default namespace' % service_name
+ print err_msg
+ return False, [err_msg]
+ pods = self._k8s_client.find_pod_by_namespace()
+ if not pods:
+ err_msg = 'No pod found in default namespace'
+ return False, [err_msg]
+ svc_pods = {}
+ for p,l in pods.items():
+ pod_labels = l.get('labels')
+ svc_selector_dict = svc[service_name].get('selector')
+ for svc_select_key in svc_selector_dict:
+ if svc_select_key in pod_labels:
+ if svc_selector_dict[svc_select_key] == pod_labels[svc_select_key]:
+ svc_pods[p] = l
+
+ trace_ids = self._tracing.getRedisTraceids(self._test_id)
+ rr_dict = {'service': service_name}
+ ver_count_dict = {}
+ for trace_id in trace_ids:
+ span_ids = self._tracing.getRedisSpanids(trace_id)
+ for span in span_ids:
+ # count only the received side --- i.e., messages sent TO
+ # service
+ node_id = self._tracing.getRedisTagsValue(span, trace_id, 'node_id')
+ direction = self._tracing.getRedisTagsValue(span, trace_id, 'upstream_cluster')
+ if direction.startswith('in.'):
+ for pod_name in svc_pods:
+ if pod_name in node_id:
+ total += 1
+ labels = svc_pods[pod_name]['labels']
+ print('node %s pod %s labels %s' % (node_id, pod_name, labels))
+ if 'version' in labels:
+ version = labels.get('version')
+ if version in ver_count_dict:
+ ver_count_dict[version] += 1
+ else:
+ ver_count_dict[version] = 1
+
+ print('total is %d, ver_count_dict is %s' % (total, ver_count_dict))
+ if ver_count_dict and total > 0:
+ for version in ver_count_dict:
+ rr_dict[version] = float(ver_count_dict[version]) / float(total) * 100
+
+ return(rr.validate_weighted_route_rules(rr_dict, self._test_id))
+ else:
+ err_msg = 'No version label found on any pod'
+ print(err_msg)
+ return False, [err_msg]
+