def run_prometheus_query_range(
    prometheus_params: PrometheusParams, promql_query: str, starts_at: datetime, ends_at: datetime, step: Optional[str]
) -> PrometheusQueryResult:
    """
    This calls the prometheus query_range api, which is what is used for graphs
    """
    if not starts_at or not ends_at:
        raise Exception("Invalid timerange specified for the prometheus query.")

    promql_query = __add_additional_labels(promql_query, prometheus_params)

    query_duration = ends_at - starts_at
    resolution = get_resolution_from_duration(query_duration)

    step = step if step else str(max(query_duration.total_seconds() / resolution, 1.0))

    prom = get_prometheus_connect(prometheus_params)
    params = {"timeout": PROMETHEUS_REQUEST_TIMEOUT_SECONDS}
    prom.check_prometheus_connection(params)
    result = prom.safe_custom_query_range(
        query=promql_query, start_time=starts_at, end_time=ends_at, step=step, params=params
    )

    return PrometheusQueryResult(data=result)

    This calls the prometheus query_range api, which is what is used for graphs
    
src/robusta/core/playbooks/prometheus_enrichment_utils.py