tvalentyn commented on code in PR #23931: URL: https://github.com/apache/beam/pull/23931#discussion_r1044833306
########## sdks/python/apache_beam/testing/analyzers/perf_analysis_utils.py: ########## @@ -0,0 +1,199 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +from dataclasses import asdict +from dataclasses import dataclass +import logging + +from typing import Any +from typing import Dict +from typing import List +from typing import Optional +from typing import Tuple +from typing import Union + +import pandas as pd +import yaml +from google.api_core import exceptions + +from apache_beam.testing.analyzers import constants +from apache_beam.testing.analyzers.github_issues_utils import get_issue_description +from apache_beam.testing.analyzers.github_issues_utils import report_change_point_on_issues +from apache_beam.testing.load_tests import load_test_metrics_utils +from apache_beam.testing.load_tests.load_test_metrics_utils import BigQueryMetricsFetcher +from apache_beam.testing.load_tests.load_test_metrics_utils import BigQueryMetricsPublisher +from signal_processing_algorithms.energy_statistics.energy_statistics import e_divisive + + +@dataclass +class GitHubIssueMetaData: + """ + This class holds metadata that needs to be published to the + BigQuery when a GitHub issue is created on a performance + alert. + """ + issue_timestamp: pd.Timestamp + change_point_timestamp: pd.Timestamp + test_name: str + metric_name: str + issue_number: int + issue_url: str + test_id: str + change_point: float + + +def is_change_point_in_valid_window( + num_runs_in_change_point_window: int, change_point_index: int) -> bool: + # If the change point is more than N runs behind the most recent run, + # Ignore the change point and don't raise an alert for it. + return num_runs_in_change_point_window >= change_point_index + + +def get_existing_issues_data( + test_name: str, big_query_metrics_fetcher: BigQueryMetricsFetcher +) -> Optional[pd.DataFrame]: + """ + Finds the most recent GitHub issue created for the test_name. + If no table found with name=test_name, return (None, None) + else return latest created issue_number along with + """ + query = f""" + SELECT * FROM {constants._BQ_PROJECT_NAME}.{constants._BQ_DATASET}.{test_name} + ORDER BY {constants._ISSUE_CREATION_TIMESTAMP_LABEL} DESC + LIMIT 10 + """ + try: + df = big_query_metrics_fetcher.fetch(query=query) + except exceptions.NotFound: + # If no table found, that means this is first performance regression + # on the current test+metric. + return None + return df + + +def is_perf_alert( + previous_change_point_timestamps: List[pd.Timestamp], + change_point_index: int, + timestamps: List[pd.Timestamp], Review Comment: Actually, I think I do have a strong opinion on this given the confusion in find_latest_change_point_index. It's easy to think that time is moving forward, and that timestamps would increase with increasing indices. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
