From df58e390a7e9e7950cac5d24197c19ae19e8062b Mon Sep 17 00:00:00 2001 From: earrage Date: Mon, 15 Oct 2018 17:30:20 -0700 Subject: Add visibility API in controller and CLI - Modify get visibility to retrieve config and stats - Add visibility REST API in controller to clear, set, and get from redis - Add example yaml to set visibility (service list by name, metric suffixes/prefixes, and custom metrics) from CLI - Modify example yaml to start visibility (collector) for Istio 1.0 from CLI Change-Id: I43304ff6d70bb4b817b345b9c383ce3621fb06c7 Signed-off-by: earrage --- clover/controller/control/api/collector.py | 51 ++++++++++++++++++------------ 1 file changed, 30 insertions(+), 21 deletions(-) (limited to 'clover/controller/control/api/collector.py') diff --git a/clover/controller/control/api/collector.py b/clover/controller/control/api/collector.py index c82c543..3abcba7 100644 --- a/clover/controller/control/api/collector.py +++ b/clover/controller/control/api/collector.py @@ -5,7 +5,7 @@ # which accompanies this distribution, and is available at # http://www.apache.org/licenses/LICENSE-2.0 -from flask import Blueprint, request, jsonify, Response +from flask import Blueprint, request, Response import grpc import pickle import collector_pb2 @@ -17,13 +17,13 @@ import logging collector = Blueprint('collector', __name__) grpc_port = '50054' -pod_name = 'clover-collector' +pod_name = 'clover-collector.clover-system' collector_grpc = pod_name + ':' + grpc_port channel = grpc.insecure_channel(collector_grpc) stub = collector_pb2_grpc.ControllerStub(channel) -CASSANDRA_HOSTS = pickle.dumps(['cassandra.default']) +CASSANDRA_HOSTS = pickle.dumps(['cassandra.clover-system']) -HOST_IP = 'redis' +HOST_IP = 'redis.default' @collector.route("/collector/init") @@ -62,7 +62,7 @@ def start(): p = request.json if not p: sample_interval = '5' - t_host = 'jaeger-deployment.istio-system' + t_host = 'tracing.istio-system' t_port = '16686' m_host = 'prometheus.istio-system' m_port = '9090' @@ -103,27 +103,36 @@ def stop(): return response.message -@collector.route("/collector/stats", methods=['GET', 'POST']) -def stats(): +@collector.route("/collector/set", methods=['GET', 'POST']) +def set_collector(): try: p = request.json - if not p: - stat_type = 'toplevel' - else: - stat_type = p['stat_type'] r = redis.StrictRedis(host=HOST_IP, port=6379, db=0) - content = {} - content['proxy_rt'] = r.get('proxy_rt') - content['trace_count'] = r.get('trace_count') - content['span_urls'] = list(r.smembers('span_urls')) - response = jsonify(content) + del_keys = ['visibility_services', 'metric_prefixes', + 'metric_suffixes', 'custom_metrics'] + for dk in del_keys: + r.delete(dk) + + try: + for service in p['services']: + r.sadd('visibility_services', service['name']) + except (KeyError, ValueError) as e: + logging.debug(e) + return Response( + "Specify at least one service to track", status=400) + if p['metric_prefixes'] and p['metric_suffixes']: + for prefix in p['metric_prefixes']: + r.sadd('metric_prefixes', prefix['prefix']) + for suffix in p['metric_suffixes']: + r.sadd('metric_suffixes', suffix['suffix']) + if p['custom_metrics']: + for metric in p['custom_metrics']: + r.sadd('custom_metrics', metric['metric']) + except Exception as e: logging.debug(e) - if e.__class__.__name__ == "_Rendezvous": - return Response("Error connecting via gRPC", status=400) - else: - return Response("Error getting visibility stats", status=400) - return response + return Response("Error setting visibility config", status=400) + return Response("Updated visibility config", status=200) @collector.route("/collector/test") -- cgit 1.2.3-korg