@sdc_min_version('3.15.0')
def test_runner_metrics_for_init_and_destroy(sdc_builder, sdc_executor):
    'Ensure that we properly update metrics when the runner is in starting phase.'
    builder = sdc_builder.get_pipeline_builder()
    SLEEP_SCRIPT = 'sleep(5*1000)'
    source = builder.add_stage('Dev Data Generator')
    groovy = builder.add_stage('Groovy Evaluator', type='processor')
    groovy.init_script = SLEEP_SCRIPT
    groovy.destroy_script = SLEEP_SCRIPT
    groovy.script = SLEEP_SCRIPT
    trash = builder.add_stage('Trash')
    ((source >> groovy) >> trash)
    pipeline = builder.build()
    sdc_executor.add_pipeline(pipeline)
    sdc_executor.start_pipeline(pipeline, wait=False)
    count = 0
    while True:
        metrics_json = sdc_executor.api_client.get_pipeline_metrics(pipeline.id)
        if metrics_json:
            metrics = Metrics(metrics_json)
            logger.info(f"Detected runtime gauge state {metrics.gauge('runner.0.gauge').value['state']}")
            if (metrics.gauge('runner.0.gauge').value['state'] == 'Starting'):
                count += 1
        status = sdc_executor.get_pipeline_status(pipeline).response.json()
        sleep(0.5)
        if (status.get('status') == 'RUNNING'):
            break
    assert (count > 0)
    sdc_executor.stop_pipeline(pipeline)
Ensure that we properly update metrics when the runner is in starting phase.
@sdc_min_version('3.15.0')
def test_runner_metrics_for_init_and_destroy(sdc_builder, sdc_executor):
    
    builder = sdc_builder.get_pipeline_builder()
    SLEEP_SCRIPT = 'sleep(5*1000)'
    source = builder.add_stage('Dev Data Generator')
    groovy = builder.add_stage('Groovy Evaluator', type='processor')
    groovy.init_script = SLEEP_SCRIPT
    groovy.destroy_script = SLEEP_SCRIPT
    groovy.script = SLEEP_SCRIPT
    trash = builder.add_stage('Trash')
    ((source >> groovy) >> trash)
    pipeline = builder.build()
    sdc_executor.add_pipeline(pipeline)
    sdc_executor.start_pipeline(pipeline, wait=False)
    count = 0
    while True:
        metrics_json = sdc_executor.api_client.get_pipeline_metrics(pipeline.id)
        if metrics_json:
            metrics = Metrics(metrics_json)
            logger.info(f"Detected runtime gauge state {metrics.gauge('runner.0.gauge').value['state']}")
            if (metrics.gauge('runner.0.gauge').value['state'] == 'Starting'):
                count += 1
        status = sdc_executor.get_pipeline_status(pipeline).response.json()
        sleep(0.5)
        if (status.get('status') == 'RUNNING'):
            break
    assert (count > 0)
    sdc_executor.stop_pipeline(pipeline)