Skip to content

Commit

Permalink
Add common metric filtering logic for namespace and container exp types
Browse files Browse the repository at this point in the history
  • Loading branch information
shreyabiradar07 committed Oct 8, 2024
1 parent fa70cbe commit a2f7e12
Showing 1 changed file with 26 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1913,9 +1913,8 @@ private void fetchNamespaceMetricsBasedOnDataSourceAndProfile(KruizeObject kruiz
k8sObject.setNamespaceData(namespaceData);
}

List<Metric> namespaceMetricList = metricProfile.getSloInfo().getFunctionVariables().stream()
.filter(metricEntry -> metricEntry.getName().startsWith(AnalyzerConstants.NAMESPACE) && !metricEntry.getName().equals("namespaceMaxDate"))
.toList();
List<Metric> namespaceMetricList = filterMetricsBasedOnExpType(metricProfile,
AnalyzerConstants.MetricName.namespaceMaxDate.name(),AnalyzerConstants.ExperimentTypes.NAMESPACE_EXPERIMENT);

// Iterate over metrics and aggregation functions
for (Metric metricEntry : namespaceMetricList) {
Expand Down Expand Up @@ -2098,10 +2097,8 @@ private void fetchContainerMetricsBasedOnDataSourceAndProfile(KruizeObject kruiz
MetricResults metricResults = null;
MetricAggregationInfoResults metricAggregationInfoResults = null;

// Exclude maxDate and namespace queries to fetch container metric data
List<Metric> metricList = metricProfile.getSloInfo().getFunctionVariables().stream()
.filter(metricEntry -> !metricEntry.getName().startsWith(AnalyzerConstants.NAMESPACE) && !metricEntry.getName().equals(AnalyzerConstants.MetricName.maxDate.name()))
.toList();
List<Metric> metricList = filterMetricsBasedOnExpType(metricProfile,
AnalyzerConstants.MetricName.maxDate.name(),AnalyzerConstants.ExperimentTypes.CONTAINER_EXPERIMENT);

List<String> acceleratorFunctions = Arrays.asList(
AnalyzerConstants.MetricName.gpuCoreUsage.toString(),
Expand Down Expand Up @@ -2376,5 +2373,27 @@ private void prepareIntervalResults(Map<Timestamp, IntervalResults> dataResultsM
throw new Exception(AnalyzerErrorConstants.APIErrors.UpdateRecommendationsAPI.METRIC_EXCEPTION + e.getMessage());
}
}

/**
* Filters out maxDateQuery and namespace metrics based on the experiment type
* @param metricProfile Metric profile to be used
* @param maxDateQuery maxDateQuery metric to be filtered out
* @param experimentType experiment type
*/
public List<Metric> filterMetricsBasedOnExpType(PerformanceProfile metricProfile, String maxDateQuery, String experimentType) {
String namespace = AnalyzerConstants.NAMESPACE;
return metricProfile.getSloInfo().getFunctionVariables().stream()
.filter(Metric -> {
String name = Metric.getName();
if (experimentType.equals(AnalyzerConstants.ExperimentTypes.NAMESPACE_EXPERIMENT)) {
// Include metrics that start with namespace and exclude namespaceMaxDate metric
return name.startsWith(namespace) && !name.equals(maxDateQuery);
} else {
// Exclude metrics that start with namespace or maxDate metric
return !name.startsWith(namespace) && !name.equals(maxDateQuery);
}
})
.toList();
}
}

0 comments on commit a2f7e12

Please sign in to comment.