-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
CMR #66
Merged
Merged
CMR #66
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
""" | ||
Init for CMR Algorithm | ||
""" | ||
from .cmr import CMR |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
"""CMR - Comparing Mean Responses Algorithm""" | ||
|
||
# pylint: disable = line-too-long | ||
import pandas as pd | ||
import numpy | ||
|
||
from fmatch.logrus import SingletonLogger | ||
from hunter.series import ChangePoint, ComparativeStats | ||
from pkg.algorithms.algorithm import Algorithm | ||
|
||
|
||
class CMR(Algorithm): | ||
"""Implementation of the CMR algorithm | ||
Will Combine metrics into 2 lines and compare with a tolerancy to set pass fail | ||
|
||
Args: | ||
Algorithm (Algorithm): Inherits | ||
""" | ||
|
||
|
||
def _analyze(self): | ||
"""Analyze the dataframe with meaning any previous data and generate percent change with a current uuid | ||
|
||
Returns: | ||
series: data series that contains attributes and full dataframe | ||
change_points_by_metric: list of ChangePoints | ||
""" | ||
logger_instance = SingletonLogger.getLogger("Orion") | ||
logger_instance.info("Starting analysis using CMR") | ||
self.dataframe["timestamp"] = pd.to_datetime(self.dataframe["timestamp"]) | ||
self.dataframe["timestamp"] = self.dataframe["timestamp"].astype(int) // 10**9 | ||
|
||
if len(self.dataframe.index) == 1: | ||
series= self.setup_series() | ||
series.data = self.dataframe | ||
return series, {} | ||
# if larger than 2 rows, need to get the mean of 0 through -2 | ||
self.dataframe = self.combine_and_average_runs(self.dataframe) | ||
|
||
series= self.setup_series() | ||
|
||
df, change_points_by_metric = self.run_cmr(self.dataframe) | ||
series.data= df | ||
return series, change_points_by_metric | ||
|
||
|
||
def run_cmr(self, dataframe_list: pd.DataFrame): | ||
""" | ||
Generate the percent difference in a 2 row dataframe | ||
|
||
Args: | ||
dataframe_list (pd.DataFrame): data frame of all data to compare on | ||
|
||
Returns: | ||
pd.Dataframe, dict[metric_name, ChangePoint]: Returned data frame and change points | ||
""" | ||
metric_columns = self.metrics_config.keys() | ||
change_points_by_metric={ k:[] for k in metric_columns } | ||
|
||
for column in metric_columns: | ||
|
||
change_point = ChangePoint(metric=column, | ||
index=1, | ||
time=0, | ||
stats=ComparativeStats( | ||
mean_1=dataframe_list[column][0], | ||
mean_2=dataframe_list[column][1], | ||
std_1=0, | ||
std_2=0, | ||
pvalue=1 | ||
)) | ||
change_points_by_metric[column].append(change_point) | ||
|
||
# based on change point generate pass/fail | ||
return dataframe_list, change_points_by_metric | ||
|
||
def combine_and_average_runs(self, dataFrame: pd.DataFrame): | ||
""" | ||
If more than 1 previous run, mean data together into 1 single row | ||
Combine with current run into 1 data frame (current run being -1 index) | ||
|
||
Args: | ||
dataFrame (pd.DataFrame): data to combine into 2 rows | ||
|
||
Returns: | ||
pd.Dataframe: data frame of most recent run and averaged previous runs | ||
""" | ||
i = 0 | ||
|
||
last_row = dataFrame.tail(1) | ||
dF = dataFrame[:-1] | ||
data2 = {} | ||
|
||
metric_columns = list(dataFrame.columns) | ||
for column in metric_columns: | ||
|
||
if isinstance(dF.loc[0, column], (numpy.float64, numpy.int64)): | ||
mean = dF[column].mean() | ||
data2[column] = [mean] | ||
else: | ||
column_list = dF[column].tolist() | ||
non_numeric_joined_list = ','.join(column_list) | ||
data2[column] = [non_numeric_joined_list] | ||
i += 1 | ||
df2 = pd.DataFrame(data2) | ||
|
||
result = pd.concat([df2, last_row], ignore_index=True) | ||
return result |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,3 +6,4 @@ | |
JSON="json" | ||
TEXT="text" | ||
JUNIT="junit" | ||
CMR="cmr" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Our factory seems to be growing, can we have switch-case here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In prow we are using python3.9, from what I read online switch-case doesn't work with that python version
https://gcsweb-ci.apps.ci.l2s4.p1.openshiftapps.com/gcs/test-platform-results/pr-logs/pull/openshift_release/56698/rehearse-56698-periodic-ci-openshift-qe-ocp-qe-perfscale-ci-main-aws-4.18-nightly-x86-payload-control-plane-6nodes/1836716469891633152/artifacts/payload-control-plane-6nodes/openshift-qe-orion-cluster-density/build-log.txt
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need not necessarily be a switch case. Even a dictionary to map those constants with functions should work so that we can have all the mappings at one place. I am okay if we want to take that in a different PR