Skip to content

Commit

Permalink
Filter metrics based on expType and kubernetes_object
Browse files Browse the repository at this point in the history
  • Loading branch information
shreyabiradar07 committed Oct 8, 2024
1 parent 1cb8a69 commit 2ba6ef1
Showing 1 changed file with 13 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1913,7 +1913,7 @@ private void fetchNamespaceMetricsBasedOnDataSourceAndProfile(KruizeObject kruiz
k8sObject.setNamespaceData(namespaceData);
}

List<Metric> namespaceMetricList = filterMetricsBasedOnExpType(metricProfile,
List<Metric> namespaceMetricList = filterMetricsBasedOnExpTypeAndK8sObject(metricProfile,
AnalyzerConstants.MetricName.namespaceMaxDate.name(), kruizeObject.getExperimentType());

// Iterate over metrics and aggregation functions
Expand Down Expand Up @@ -2097,7 +2097,7 @@ private void fetchContainerMetricsBasedOnDataSourceAndProfile(KruizeObject kruiz
MetricResults metricResults = null;
MetricAggregationInfoResults metricAggregationInfoResults = null;

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

List<String> acceleratorFunctions = Arrays.asList(
Expand Down Expand Up @@ -2375,23 +2375,24 @@ private void prepareIntervalResults(Map<Timestamp, IntervalResults> dataResultsM
}

/**
* Filters out maxDateQuery and namespace metrics based on the experiment type
* 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> filterMetricsBasedOnExpType(PerformanceProfile metricProfile, String maxDateQuery, String experimentType) {
String namespace = AnalyzerConstants.NAMESPACE;
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();
if (experimentType.equals(AnalyzerConstants.ExperimentTypes.NAMESPACE_EXPERIMENT)) {
// Include metrics that start with prefix "namespace" and exclude namespaceMaxDate metric
return name.startsWith(namespace) && !name.equals(maxDateQuery);
} else {
// Exclude metrics that start with prefix "namespace" and maxDate metric
return !name.startsWith(namespace) && !name.equals(maxDateQuery);
}
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();
}
Expand Down

0 comments on commit 2ba6ef1

Please sign in to comment.