예제 #1
0
"""
import json
import os
import socket
import string
import threading
import time
import uuid
from collections import namedtuple

import wrapt
from botocore.exceptions import ClientError

from fleece import log

LOGGER = log.get_logger("fleece.xray")

XRAY_DAEMON_HEADER = {"format": "json", "version": 1}

XRayDaemon = namedtuple("XRayDaemon", ["ip_address", "port"])
XRayTraceID = namedtuple("XRayTraceID", ["trace_id", "parent_id", "sampled"])

ERROR_HANDLING_GENERIC = "generic"
ERROR_HANDLING_BOTOCORE = "botocore"

# Thread-local storage for parent IDs
threadlocal = threading.local()


class XRayDaemonNotFoundError(Exception):
    pass
예제 #2
0
파일: xray.py 프로젝트: ranman/fleece
main handler module where the Lambda entry point is defined.
"""
from collections import namedtuple
import json
import os
import socket
import threading
import time
import uuid

from botocore.exceptions import ClientError
import wrapt

from fleece import log

LOGGER = log.get_logger('fleece.xray')

XRAY_DAEMON_HEADER = {'format': 'json', 'version': 1}

XRayDaemon = namedtuple('XRayDaemon', ['ip_address', 'port'])
XRayTraceID = namedtuple('XRayTraceID', ['trace_id', 'parent_id', 'sampled'])

ERROR_HANDLING_GENERIC = 'generic'
ERROR_HANDLING_BOTOCORE = 'botocore'

# Thread-local storage for parent IDs
threadlocal = threading.local()


class XRayDaemonNotFoundError(Exception):
    pass
예제 #3
0
 def setUp(self):
     self.logger = get_logger(uuid.uuid4().hex)
예제 #4
0
import os

import boto3
from fleece import log

logger = log.get_logger(__name__)


def load_config():
    ssm = boto3.client('ssm')
    ssm_config_version = os.environ['SSM_CONFIG_VERSION']
    response = ssm.get_parameters_by_path(
        Path=ssm_config_version,
        WithDecryption=True,
    )
    config = {
        # The parameter name contains the full path, so we have to strip the
        # prefix.
        p['Name'].replace(ssm_config_version, ''): p['Value']
        for p in response['Parameters']
    }
    logger.info('Got config from SSM')
    return config


CONFIG = load_config()
예제 #5
0
import random

from connexion import request
from fleece.log import get_logger

from .models import Place

logger = get_logger(__name__)


def get_random_place():
    # TODO(szilveszter): This solution doesn't scale, but should be good enough
    # for now.
    all_places = Place.get_all()
    random_place = random.choice(all_places)
    return random_place.to_dict(), 200, {}


def get_all_places():
    all_places = [place.to_dict() for place in Place.get_all()]
    return {'items': all_places}, 200, {}


def add_new_place():
    req = request.get_json()
    new_place = Place.create(req['title'])
    return new_place.to_dict(), 201, {}
예제 #6
0
파일: test_log.py 프로젝트: racker/fleece
 def setUp(self):
     self.logger = get_logger(uuid.uuid4().hex)