service.py 873 Bytes
Newer Older
Nane Kratzke's avatar
Nane Kratzke committed
1
from flask import Flask, redirect
2
3
4
from jaeger_client import Config
from flask_opentracing import FlaskTracing
import requests
Nane Kratzke's avatar
Nane Kratzke committed
5
import os
6

Nane Kratzke's avatar
Nane Kratzke committed
7
8
9
# A very boring and basic hip-hop-service to demonstrate 
# observalability and tracing.

10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
service = os.environ.get('HIPHOP', 'hiphop')
tier = int(os.environ.get('TIER', '1'))
app = Flask(__name__)

config = Config(config = {
    'sampler': { 
        'type': 'const', 
        'param': 1
    },
    'logging': True,
    'reporter_batch_size': 1
}, service_name=service)

jaeger_tracer = config.initialize_tracer()
tracing = FlaskTracing(jaeger_tracer, True, app)


@app.route('/')
def index():
    return redirect('/hip')

@app.route('/hip')
def hip():
    r = ""
    try:
        r = requests.get(f"http://{service}-{tier + 1}").content
        r = f"-{r}"
    except Exception as ex:
        print(ex)
    return f"hop-{ tier }{ r }"