Exemplo n.º 1
0
def main(
    data_path,
    codespeed_url,
    codespeed_auth,
    codespeed_project,
    codespeed_executable,
    codespeed_environment,
    dry_run=False,
):
    data_paths = glob.glob(data_path)

    for data_path in data_paths:
        LOG.info("Processing file: %s" % (data_path))
        data = parse_data_file(data_path)

        payload = format_benchmark_data_for_codespeed(
            data=data,
            codespeed_project=codespeed_project,
            codespeed_executable=codespeed_executable,
            codespeed_environment=codespeed_environment,
        )

        if not payload:
            continue

        commit_id = payload[0].get("commitid", "unknown")

        send_payload_to_codespeed(
            codespeed_url=codespeed_url,
            codespeed_auth=codespeed_auth,
            commit_id=commit_id,
            payload=payload,
            dry_run=dry_run,
        )
def send_value_to_codespeed(
    codespeed_url,
    codespeed_auth,
    codespeed_project,
    codespeed_executable,
    codespeed_environment,
    codespeed_benchmark,
    branch,
    commit_id,
    value,
    commit_date=None,
):
    # type: (str, Optional[Tuple[str, str]], str, str, str, str, str, str, int, Optional[datetime]) -> None
    payload = [{
        "commitid": commit_id,
        "branch": branch,
        "project": codespeed_project,
        "executable": codespeed_executable,
        "benchmark": codespeed_benchmark,
        "environment": codespeed_environment,
        "result_value": value,
    }]

    if commit_date:
        payload[0]["revision_date"] = commit_date.strftime("%Y-%m-%d %H:%M:%S")

    send_payload_to_codespeed(
        codespeed_url=codespeed_url,
        codespeed_auth=codespeed_auth,
        commit_id=commit_id,
        payload=payload,
    )
Exemplo n.º 3
0
def send_data_to_codespeed(
    codespeed_url,
    codespeed_auth,
    codespeed_project,
    codespeed_executable,
    codespeed_environment,
    branch,
    commit_id,
    result,
    commit_date=None,
    dry_run=False,
):
    # type: (str, Optional[Tuple[str, str]], str, str, str, str, str, dict, Optional[datetime], bool) -> None
    """
    Submit captured data to CodeSpeed instance.
    """
    payload = []
    for metric_name, metric_result in result.items():
        benchmark = metric_name

        item = {
            "commitid": commit_id,
            "branch": branch,
            "project": codespeed_project,
            "executable": codespeed_executable,
            "benchmark": benchmark,
            "environment": codespeed_environment,
            "result_value": metric_result["value"],
        }

        if commit_date:
            item["revision_date"] = commit_date.strftime("%Y-%m-%d %H:%M:%S")

        # Include optional pre-computed data for gauge metrics
        for key in ["min", "max", "std_dev"]:
            if metric_result.get(key, None) is not None:
                item[key] = metric_result[key]

        payload.append(item)

    send_payload_to_codespeed(
        codespeed_url=codespeed_url,
        codespeed_auth=codespeed_auth,
        commit_id=commit_id,
        payload=payload,
        dry_run=dry_run,
    )