Esempio n. 1
0
def test_replay_window_w_replay_duration_of_1():
    defaults = {
        "apps_to_test": ["test-app1"],
        "test_params": {
            "rate": 100,
            "replay_start_time": "2018-08-30T00:00",
            "replay_end_time": "2018-08-30T00:00",
            "base_url": "http://shadowreader.example.com",
            "identifier": "qa",
        },
        "overrides": [],
        "timezone": "Japan",
    }

    apps, test_params = orchestrator.init_apps_from_test_params(defaults)
    app1 = apps[0]
    assert app1.loop_duration == 1

    defaults = {
        "apps_to_test": ["test-app1"],
        "test_params": {
            "rate": 100,
            "replay_start_time": "2018-08-30T00:00",
            "replay_end_time": "2018-08-30T00:01",
            "base_url": "http://shadowreader.example.com",
            "identifier": "qa",
        },
        "overrides": [],
        "timezone": "Japan",
    }

    apps, test_params = orchestrator.init_apps_from_test_params(defaults)
    app1 = apps[0]
    assert app1.loop_duration == 1
Esempio n. 2
0
def test_init_apps_from_test_params_w_isoformat():
    defaults = {
        "apps_to_test": ["test-app1", "test-app2", "test-app3"],
        "test_params": {
            "rate": 100,
            "loop_duration": 60,
            "replay_start_time": "2018-08-02T00:30",
            "base_url": "http://shadowreader.example.com",
            "identifier": "qa",
        },
        "overrides": [],
        "timezone": "US/Pacific",
    }

    apps, test_params = orchestrator.init_apps_from_test_params(defaults)
    app1 = apps[0]
    app2 = App(
        name="test-app1",
        replay_start_time=MyTime().from_epoch(epoch=1533195000,
                                              tzinfo="US/Pacific"),
        rate=100,
        base_url="http://shadowreader.example.com",
        identifier="qa",
        loop_duration=60,
        baseline=0,
    )
    assert app1 == app2 and len(apps) == 3
    assert app2.replay_start_time == app1.replay_start_time
Esempio n. 3
0
def test_init_apps_from_test_params_w_replay_end_time():
    defaults = {
        "apps_to_test": ["test-app1", "test-app2", "test-app3"],
        "test_params": {
            "rate": 100,
            "replay_start_time": "2018-08-29T10:30",
            "replay_end_time": "2018-08-30T12:31",
            "base_url": "http://shadowreader.example.com",
            "identifier": "qa",
        },
        "overrides": [],
        "timezone": "Japan",
    }

    apps, test_params = orchestrator.init_apps_from_test_params(defaults)
    app1 = apps[0]
    app2 = App(
        name="test-app1",
        replay_start_time=MyTime(year=2018,
                                 month=8,
                                 day=29,
                                 hour=10,
                                 minute=30,
                                 tzinfo="Japan"),
        rate=100,
        base_url="http://shadowreader.example.com",
        identifier="qa",
        loop_duration=1561,
        baseline=0,
    )

    assert app1 == app2
    assert len(apps) == 3
    assert app2.replay_start_time == app1.replay_start_time
Esempio n. 4
0
def test_init_apps_from_test_params():
    defaults = {
        'apps_to_test': ['test-app1', 'test-app2', 'test-app3'],
        'test_params': {
            "rate": 100,
            "loop_duration": 60,
            "replay_start_time": "2018-3-20-16-00",
            "base_url": "http://shadowreader.example.com",
            "identifier": "qa",
        },
        "overrides": [],
        'timezone': 'US/Pacific'
    }

    apps, test_params = orchestrator.init_apps_from_test_params(defaults)
    app1 = apps[0]
    app2 = App(name='test-app1',
               replay_start_time=MyTime().from_epoch(epoch=1521586800,
                                                     tzinfo='US/Pacific'),
               rate=100,
               base_url='http://shadowreader.example.com',
               identifier='qa',
               loop_duration=60,
               baseline=0)

    assert app1 == app2 and len(apps) == 3
Esempio n. 5
0
def test_init_apps_from_test_params_w_override():
    defaults = {
        "apps_to_test": ["test-app1", "test-app2"],
        "test_params": {
            "rate": 100,
            "loop_duration": 60,
            "replay_start_time": "2018-3-20-16-00",
            "base_url": "http://shadowreader.example.com",
            "identifier": "qa",
        },
        "overrides": [
            {
                "app": "test-app1",
                "rate": 50,
                "loop_duration": 30,
                "replay_start_time": "2018-3-20-17-00",
                "base_url": "http://shadowreader.example.com",
                "identifier": "qa",
            },
            {
                "app": "test-app2",
                "rate": 0,
                "loop_duration": 30,
                "replay_start_time": "2018-3-20-17-00",
                "base_url": "http://shadowreader.example.com",
                "identifier": "qa",
            },
        ],
        "timezone":
        "US/Pacific",
    }

    apps, test_params = orchestrator.init_apps_from_test_params(defaults)
    app1 = apps[0]
    app1_copy = App(
        name="test-app1",
        replay_start_time=MyTime(epoch=1521590400),
        rate=50,
        base_url="http://shadowreader.example.com",
        identifier="qa",
        loop_duration=30,
        baseline=0,
    )

    assert app1 == app1_copy and len(apps) == 1
def lambda_handler(event, context):
    try:
        """
        First gather the necessary test params, init App objects, filters and compute the current step
        After,
        then send (app, env_to_test, cur_timestamp, rate) to consumer-master
        consumer-master will then fetch data set (set of URLs) from S3, then pass it to multiple consumer-workers
        each consumer-worker will then send out requests to test environment (each worker handles up to 100 requests)
        """

        mytime, lambda_name, env_vars = lambda_init.init_lambda(context)
        stage = env_vars["stage"]
        consumer_master_past_lambda = env_vars["consumer_master_past_name"]

        apps, test_params = init_apps_from_test_params(event)
        filters = init_filters()

        step = generate_step_from_mytime(mytime)

        print("step:", step)
        for app in apps:
            advance_app_timestamp(app, step)

        consumer_event = {}

        # Invoke the consumer-master lambda for each app in apps
        for app in apps:
            headers = Headers(
                shadowreader_type="past", stage=stage, app=app, step=step
            ).headers

            consumer_event = {
                "app": app.name,
                "identifier": app.identifier,
                "base_url": app.base_url,
                "cur_timestamp": app.cur_timestamp,
                "rate": app.rate,
                "baseline": app.baseline,
                "parent_lambda": lambda_name,
                "child_lambda": consumer_master_past_lambda,
                "headers": headers,
                "filters": filters,
            }
            invoke_func(consumer_event, func=consumer_master_past_lambda)

        if apps and consumer_event:
            print_to_logs(consumer_event, apps)

        # Collect metrics and put metrics into CW
        metrics = []
        for app in apps:
            # This is the timestamp (in epoch time) that is being replayed
            # by the load test.
            metric = {
                "name": "replayed_timestamp",
                "stage": stage,
                "lambda_name": lambda_name,
                "app": app.name,
                "identifier": app.identifier,
                "mytime": mytime,
                "val": app.cur_timestamp,
            }
            metrics.append(metric)

        if sr_plugins.exists("metrics"):
            metric_emitter = sr_plugins.load("metrics")
            for metric in metrics:
                metric_emitter.main(metric)

        cur_params = {"apps": apps, "filters": filters, "test_params": test_params}

        if sr_plugins.exists("test_params_emitter"):
            params_emitter = sr_plugins.load("test_params_emitter")
            params_emitter.main(
                cur_params,
                lambda_name,
                mytime,
                stage,
                env_vars,
                sr_config,
                sr_plugins._sr_plugins,
            )

    except Exception as e:
        trace = traceback.format_exc()
        raise Exception(trace)

    return json.dumps(cur_params, default=str), json.dumps(consumer_event, default=str)