(
    cluster: str,
    pool: str,
    scheduler: str,
    app: str,
    metrics_client: ClustermanMetricsBotoClient,
    required_metrics: List[MetricsConfigDict],
    end_time: arrow.Arrow,
)
return metrics
Get the metrics required for a signal
Get the metrics required for a signal
Get the metrics required for a signal
def get_metrics_for_signal(
    cluster: str,
    pool: str,
    scheduler: str,
    app: str,
    metrics_client: ClustermanMetricsBotoClient,
    required_metrics: List[MetricsConfigDict],
    end_time: arrow.Arrow,
) -> MetricsValuesDict:
    """ Get the metrics required for a signal """

    metrics: MetricsValuesDict = defaultdict(list)
    for metric_dict in required_metrics:
        if metric_dict["type"] not in (SYSTEM_METRICS, APP_METRICS):
            raise MetricsError(f"Metrics of type {metric_dict['type']} cannot be queried by signals.")

        # Need to add the cluster/pool to get the right system metrics
        # TODO (CLUSTERMAN-126) this should probably be cluster/pool/app eventually
        # TODO (CLUSTERMAN-446) if a mesos pool and a k8s pool share the same app_name,
        #      APP_METRICS will be used for both
        if metric_dict["type"] == SYSTEM_METRICS:
            dims_list = [get_cluster_dimensions(cluster, pool, scheduler)]
            if scheduler == "mesos":  # handle old (non-scheduler-aware) metrics
                dims_list.insert(0, get_cluster_dimensions(cluster, pool, None))
        else:
            dims_list = [{}]

        # We only support regex expressions for APP_METRICS
        if "regex" not in metric_dict:
            metric_dict["regex"] = False

        start_time = end_time.shift(minutes=-metric_dict["minute_range"])
        for dims in dims_list:
            query_results = metrics_client.get_metric_values(
                metric_dict["name"],
                metric_dict["type"],
                start_time.timestamp,
                end_time.timestamp,
                is_regex=metric_dict["regex"],
                extra_dimensions=dims,
                app_identifier=app,
            )
            for metric_name, timeseries in query_results.items():
                metrics[metric_name].extend(timeseries)
                # safeguard; the metrics _should_ already be sorted since we inserted the old
                # (non-scheduler-aware) metrics before the new metrics above, so this should be fast
                metrics[metric_name].sort()
    return metrics
def get_metrics_for_signal ( cluster : str , pool : str , scheduler : str , app : str , metrics_client : ClustermanMetricsBotoClient , required_metrics : List [ MetricsConfigDict ] , end_time : arrow . Arrow , ) -> MetricsValuesDict : metrics : MetricsValuesDict = defaultdict ( list ) for metric_dict in required_metrics : if metric_dict [ "type" ] not in ( SYSTEM_METRICS , APP_METRICS ) : raise MetricsError ( f"Metrics of type {metric_dict['type']} cannot be queried by signals." ) # Need to add the cluster/pool to get the right system metrics # TODO (CLUSTERMAN-126) this should probably be cluster/pool/app eventually # TODO (CLUSTERMAN-446) if a mesos pool and a k8s pool share the same app_name, #      APP_METRICS will be used for both if metric_dict [ "type" ] == SYSTEM_METRICS : dims_list = [ get_cluster_dimensions ( cluster , pool , scheduler ) ] if scheduler == "mesos" : # handle old (non-scheduler-aware) metrics dims_list . insert ( 0 , get_cluster_dimensions ( cluster , pool , None ) ) else : dims_list = [ { } ] # We only support regex expressions for APP_METRICS if "regex" not in metric_dict : metric_dict [ "regex" ] = False start_time = end_time . shift ( minutes = - metric_dict [ "minute_range" ] ) for dims in dims_list : query_results = metrics_client . get_metric_values ( metric_dict [ "name" ] , metric_dict [ "type" ] , start_time . timestamp , end_time . timestamp , is_regex = metric_dict [ "regex" ] , extra_dimensions = dims , app_identifier = app , ) for metric_name , timeseries in query_results . items ( ) : metrics [ metric_name ] . extend ( timeseries ) # safeguard; the metrics _should_ already be sorted since we inserted the old # (non-scheduler-aware) metrics before the new metrics above, so this should be fast metrics [ metric_name ] . sort ( ) return metrics