Esempio n. 1
0
def predict():
    project_id = os.environ['GCLOUD_PROJECT']

    tracer = initialize_tracer()

    tracer = app.config['TRACER']
    tracer.start_span(name='summarize')

    text = request.get_data()
    topic = request.args.get('topic')

    # if not topic:
    #     return jsonify({"error": "no topic present"}), 400
    if not text.strip():
        return jsonify({"error": "empty text"}), 400

    summary, accuracy = model.summarize(text, topic)
    health()
    log(str(summary), "summary")
    js = json.dumps({
        "summary": summary,
        "accuracy": accuracy,
        "text": str(text)
    })

    result = "Tracing requests"
    tracer.end_span()

    return jsonify(js)
Esempio n. 2
0
def home():
    logtracer = app.config['TRACER']
    tracer.start_span(name='home')
    log("home dir", "root")
    result = "Tracing requests"
    tracer.end_span()
    return 'Text summarizer service. Please use /summarize'
Esempio n. 3
0
def health():
    tracer = app.config['TRACER']
    tracer.start_span(name='health')
    log("alive", "health_check")
    result = "Tracing requests"
    tracer.end_span()
    return 'alive', 200  #,  requests
    async def middleware(request, handler):
        if handler.__name__ == "health_check":
            return await handler(request)
        span = None
        tracer = None
        try:
            propagator = google_cloud_format.GoogleCloudFormatPropagator()
            span_context = propagator.from_headers(request.headers)
            tracer = initialize_tracer(project_id, span_context, propagator)
            span = tracer.start_span()
            span.name = handler.__name__
            tracer.add_attribute_to_current_span(HTTP_HOST, request.host)
            tracer.add_attribute_to_current_span(HTTP_METHOD, request.method)
            tracer.add_attribute_to_current_span(HTTP_PATH, request.path)
            tracer.add_attribute_to_current_span(HTTP_URL, str(request.url))
            request["trace_header"] = propagator.to_headers(span_context)
        except:  # NOQA
            logging.exception("Could not initialize the tracer")

        try:
            response = await handler(request)
            if tracer:
                tracer.add_attribute_to_current_span(HTTP_STATUS_CODE,
                                                     response.status)
            return response
        finally:
            if tracer:
                tracer.end_span()
Esempio n. 5
0
def index():
    tracer = app.config['TRACER']
    tracer.start_span(name='index')

    result = "Tracing requests"

    tracer.end_span()
    return result
Esempio n. 6
0
def write():
    tracer = app.config['TRACER']
    tracer.start_span(name='write')
    url = "http://db-write/write/" + trace_id
    result = requests.get(url)
    tracer.end_span()
    
    return result.content
Esempio n. 7
0
def read(name):
    tracer = app.config['TRACER']
    tracer.start_span(name='read')
    url = "http://db-read/read/" + trace_id + "/" + name
    result = requests.get(url)
    tracer.end_span()
    
    return result.content
Esempio n. 8
0
def dump():
    tracer = app.config['TRACER']
    tracer.start_span(name='dump')
    url = "http://db-dump/dump/" + trace_id
    result = requests.get(url)
    tracer.end_span()
    
    return result.content
Esempio n. 9
0
def index():
    tracer.start_span(name='index')

    # Add up to 1 sec delay, weighted toward zero
    time.sleep(random.random()**2)
    result = "Tracing requests"

    tracer.end_span()
    return result
Esempio n. 10
0
def dump(trace_id):
    conn = connect()
    tracer = initialize_tracer(project_id, trace_id)
    app.config['TRACER'] = tracer
    tracer.start_span(name='database')
    db_content = select(conn)
    tracer.end_span()
    db_content_to_print = format(db_content)

    return render_page(db_content_to_print)
def index():
    tracer = app.config['TRACER']
    tracer.start_span(name='index')

    # Add up to 1 sec delay, weighted toward zero
    time.sleep(random.random() ** 2)
    result = "Tracing requests"

    tracer.end_span()
    return result
Esempio n. 12
0
def insert(trace_id):
    conn = connect()
    tracer = initialize_tracer(project_id, trace_id)
    app.config['TRACER'] = tracer
    table = os.environ['TABLE']
    name = names[randint(0, 14)]
    surname = surnames[randint(0, 14)]
    tracer = app.config['TRACER']
    tracer.start_span(name='database')
    db_content = write(conn, table, name, surname)
    tracer.end_span()
    db_content_to_print = format(db_content)

    return render_page(db_content_to_print)
Esempio n. 13
0
def trace(service_color):
    tracer = app.config['TRACER']
    tracer.start_span(name='trace')
    headers = {}
    ## For Propagation test ##
    # Call service 'green' from service 'blue'
    if (os.environ['SERVICE_NAME']) == 'blue':
        for header in TRACE_HEADERS_TO_PROPAGATE:
            if header in request.headers:
                headers[header] = request.headers[header]
        ret = requests.get("http://localhost:9000/trace/green",
                           headers=headers)
    # Call service 'red' from service 'green'
    elif (os.environ['SERVICE_NAME']) == 'green':
        for header in TRACE_HEADERS_TO_PROPAGATE:
            if header in request.headers:
                headers[header] = request.headers[header]
        ret = requests.get("http://localhost:9000/trace/red", headers=headers)
    result = render_page()
    tracer.end_span()
    return result
Esempio n. 14
0
def log(message, log_name):
    # [START logging_quickstart]
    # Imports the Google Cloud client library
    logtracer = app.config['TRACER']
    tracer.start_span(name='log')
    from google.cloud import logging

    # Instantiates a client
    logging_client = logging.Client()

    # The name of the log to write to
    # Selects the log to write to
    logger = logging_client.logger(str(log_name))

    # The data to log

    # Writes the log entry
    logger.log_text(message)

    print('Logged: {}'.format(message))
    # [END logging_quickstart]
    result = "Tracing requests"
    tracer.end_span()
Esempio n. 15
0
def service(service_color):
    tracer = app.config['TRACER']
    tracer.start_span(name='service')
    result = render_page()
    tracer.end_span()
    return result