Skip to content

Commit

Permalink
Merge pull request kruize#1309 from shreyabiradar07/filter-namespace-…
Browse files Browse the repository at this point in the history
…queries

Exclude namespace queries to fetch container metric data
  • Loading branch information
dinogun authored Oct 8, 2024
2 parents 484b749 + 2ba6ef1 commit 236279c
Showing 1 changed file with 27 additions and 4 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 = filterMetricsBasedOnExpTypeAndK8sObject(metricProfile,
AnalyzerConstants.MetricName.namespaceMaxDate.name(), kruizeObject.getExperimentType());

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

List<Metric> metricList = metricProfile.getSloInfo().getFunctionVariables();
List<Metric> metricList = filterMetricsBasedOnExpTypeAndK8sObject(metricProfile,
AnalyzerConstants.MetricName.maxDate.name(), kruizeObject.getExperimentType());

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

/**
* Filters out maxDateQuery and includes metrics based on the experiment type and kubernetes_object
* @param metricProfile Metric profile to be used
* @param maxDateQuery maxDateQuery metric to be filtered out
* @param experimentType experiment type
*/
public List<Metric> filterMetricsBasedOnExpTypeAndK8sObject(PerformanceProfile metricProfile, String maxDateQuery, String experimentType) {
String namespace = KruizeConstants.JSONKeys.NAMESPACE;
String container = KruizeConstants.JSONKeys.CONTAINER;
return metricProfile.getSloInfo().getFunctionVariables().stream()
.filter(Metric -> {
String name = Metric.getName();
String kubernetes_object = Metric.getKubernetesObject();

// Include metrics based on experiment_type, kubernetes_object and exclude maxDate metric
return !name.equals(maxDateQuery) && (
(experimentType.equals(AnalyzerConstants.ExperimentTypes.NAMESPACE_EXPERIMENT) && kubernetes_object.equals(namespace)) ||
(experimentType.equals(AnalyzerConstants.ExperimentTypes.CONTAINER_EXPERIMENT) && kubernetes_object.equals(container))
);
})
.toList();
}
}

0 comments on commit 236279c

Please sign in to comment.