/** * Determine if this API Metric Name is valid for the given time grain. * This capability is provided as a convenience for configurers to filter metrics from a TableGroup onto a set of * LogicalTable instances at configuration time. This version allows the logical metric itself to be used for * filtering. * <p> * An example of this is a DailyAverage metric that doesn't make sense to query by the HOUR grain, but does at WEEK. * * @param granularity TimeGrain to determine validity for * @param logicalMetric The metric whose validity is being tested. * * @return True if the ApiMetricName is valid for the time grain */ default boolean isValidFor(Granularity granularity, LogicalMetric logicalMetric) { return isValidFor(granularity); }
/** * Determine if this API Metric Name is valid for the given time grain. * This capability is provided as a convenience for configurers to filter metrics from a TableGroup onto a set of * LogicalTable instances at configuration time. * <p> * This version only takes the time grain into account. The default implementation simply sets a required minimum * grain for the metric. * <p> * An example of this is a DailyAverage metric that doesn't make sense to query by the HOUR grain, but does at WEEK. * * @param granularity TimeGrain to determine validity for * * @return True if the ApiMetricName is valid for the time grain */ default boolean isValidFor(Granularity granularity) { if (granularity instanceof TimeGrain) { return isValidFor(((TimeGrain) granularity)); } else { return granularity instanceof AllGranularity; } }
/** * Buid a stream of metric columns by filtering the table group's collection of ApiMetricNames. * Metric names are resolved and then filtered considering the table granularity and the metric referenced. * * @param apiMetricNames The names of the apiMetrics being bound and filtered * @param granularity The grain used to filter those metric names * @param metricDictionary The dictionary to resolve the logical metric instances from * * @return A stream of metric columns, filtered for compatibility with the grain. */ private static Stream<LogicalMetricColumn> buildMetricColumns( Collection<ApiMetricName> apiMetricNames, Granularity granularity, MetricDictionary metricDictionary ) { return apiMetricNames.stream() .filter(name -> name.isValidFor(granularity, metricDictionary.get(name.asName()))) .map(ApiMetricName::asName) .map(metricDictionary::get) .map(LogicalMetricColumn::new); } }