コード例 #1
0
import arrow
import requests
from changelog.gerrit import GerritServer, GerritJSONEncoder
from changelog import get_changes
from config import Config
from custom_exceptions import DeviceNotFoundException, UpstreamApiException
from flask import Flask, jsonify, request, render_template, Response
from flask_caching import Cache
from prometheus_client import multiprocess, generate_latest, CollectorRegistry, CONTENT_TYPE_LATEST, Counter, Histogram

app = Flask(__name__)
app.config.from_object("config.Config")
app.json_encoder = GerritJSONEncoder

cache = Cache(app)
gerrit = GerritServer(app.config['GERRIT_URL'])

##########################
# Metrics!
##########################
REQUEST_LATENCY = Histogram("flask_request_latency_seconds", "Request Latency",
                            ['method', 'endpoint'])
REQUEST_COUNT = Counter("flask_request_count", "Request Count",
                        ["method", "endpoint", "status"])


@app.before_request
def start_timer():
    request.stats_start = time()

コード例 #2
0
from flask import Blueprint, jsonify, request

from api_common import get_builds, get_device_version, get_build_types, get_device_builds
from caching import cache
from changelog.gerrit import GerritServer, GerritJSONEncoder
from changelog import get_changes, get_timestamp
from config import Config

api = Blueprint('api_v1', __name__)
api.json_encoder = GerritJSONEncoder

gerrit = GerritServer(Config.GERRIT_URL)


@api.route('/<string:device>/<string:romtype>/<string:incrementalversion>')
def api_v1_index(device, romtype, incrementalversion):
    after = request.args.get('after')
    version = request.args.get('version')

    return get_build_types(device, romtype, after, version)


@api.route('/types/<string:device>/')
@cache.cached()
def api_v1_get_types(device):
    data = get_device_builds(device)
    types = {'nightly'}
    for build in data:
        types.add(build['type'])
    return jsonify({'response': list(types)})