示例#1
0
def test__get_sink__returns_stdout_sink():
    # arrange
    env = LocalEnvironment()

    # act
    result = env.get_sink()

    # assert
    assert isinstance(result, StdoutSink)
示例#2
0
def test_get_type_returns_unknown_if_not_specified():
    # arrange
    env = LocalEnvironment()
    Config.service_type = None

    # act
    result = env.get_type()

    # assert
    assert result == "Unknown"
示例#3
0
def test__get_log_group_name__returns_log_group_if_configured():
    # arrange
    expected = fake.word()
    env = LocalEnvironment()
    Config.log_group_name = expected

    # act
    result = env.get_log_group_name()

    # assert
    assert result == expected
示例#4
0
def test__get_type__returns_type_if_configured():
    # arrange
    expected_type = fake.word()
    env = LocalEnvironment()
    Config.service_type = expected_type

    # act
    result = env.get_type()

    # assert
    assert result == expected_type
示例#5
0
def test__get_log_group_name__returns_service_name_metrics_if_not_configured():
    # arrange
    expected = fake.word()
    env = LocalEnvironment()
    Config.service_name = expected
    Config.log_group_name = None

    # act
    result = env.get_log_group_name()

    # assert
    assert result == f"{expected}-metrics"
示例#6
0
async def test_probe_always_returns_false():
    # arrange
    env = LocalEnvironment()

    # act
    result = await env.probe()

    # assert
    assert result is False
import logging
from aws_embedded_metrics import config
from aws_embedded_metrics.environment import Environment
from aws_embedded_metrics.environment.default_environment import DefaultEnvironment
from aws_embedded_metrics.environment.lambda_environment import LambdaEnvironment
from aws_embedded_metrics.environment.local_environment import LocalEnvironment
from aws_embedded_metrics.environment.ec2_environment import EC2Environment
from typing import Optional

log = logging.getLogger(__name__)

lambda_environment = LambdaEnvironment()
ec2_environment = EC2Environment()
default_environment = DefaultEnvironment()
local_environment = LocalEnvironment()
environments = [lambda_environment, ec2_environment]
Config = config.get_config()


class EnvironmentCache:
    environment: Optional[Environment] = None


async def resolve_environment() -> Environment:
    if EnvironmentCache.environment is not None:
        log.debug("Environment resolved from cache.")
        return EnvironmentCache.environment

    if Config.environment:
        lower_configured_enviroment = Config.environment.lower()