-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: tvalentyn <[email protected]> Fixes #23930
- Loading branch information
1 parent
eb23b0a
commit 94c6212
Showing
12 changed files
with
1,269 additions
and
5 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
# 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. | ||
|
||
# To learn more about GitHub Actions in Apache Beam check the CI.md | ||
|
||
name: Run performance alerting tool on Python load/performance/benchmark tests. | ||
|
||
on: | ||
schedule: | ||
- cron: '5 22 * * *' | ||
|
||
jobs: | ||
python_run_change_point_analysis: | ||
name: Run Change Point Analysis. | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v3 | ||
- name: Install python | ||
uses: actions/setup-python@v4 | ||
with: | ||
python-version: 3.8 | ||
- name: Get Apache Beam Build dependencies | ||
working-directory: ./sdks/python | ||
run: pip install pip setuptools --upgrade && pip install -r build-requirements.txt | ||
- name: Install Apache Beam | ||
working-directory: ./sdks/python | ||
run: pip install -e .[gcp,test] | ||
- name: Install signal-processing-algorithms | ||
run: pip install signal-processing-algorithms | ||
- name: Install pandas, yaml, requests | ||
run: pip install pandas PyYAML requests | ||
# - name: Run Change Point Analysis. | ||
# working-directory: ./sdks/python/apache_beam/testing/analyzers | ||
# shell: bash | ||
# run: python analysis.py | ||
# env: | ||
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
- name: Run change point analysis tests. | ||
working-directory: ./sdks/python/apache_beam/testing/analyzers | ||
shell: bash | ||
run: pytest perf_analysis_test.py | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
|
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,97 @@ | ||
<!-- | ||
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. | ||
--> | ||
|
||
# Performance alerts for Beam Python performance and load tests | ||
|
||
## Alerts | ||
Performance regressions or improvements detected with the [Change Point Analysis](https://en.wikipedia.org/wiki/Change_detection) using [edivisive](https://github.com/apache/beam/blob/0a91d139dea4276dc46176c4cdcdfce210fc50c4/.test-infra/jenkins/job_InferenceBenchmarkTests_Python.groovy#L30) | ||
analyzer are automatically filed as Beam GitHub issues with a label `perf-alert`. | ||
|
||
The GitHub issue description will contain the information on the affected test and metric by providing the metric values for N consecutive runs with timestamps | ||
before and after the observed change point. Observed change point is pointed as `Anomaly` in the issue description. | ||
|
||
Example: [sample perf alert GitHub issue](https://github.com/AnandInguva/beam/issues/83). | ||
|
||
If a performance alert is created on a test, a GitHub issue will be created and the GitHub issue metadata such as GitHub issue | ||
URL, issue number along with the change point value and timestamp are exported to BigQuery. This data will be used to analyze the next change point observed on the same test to | ||
update already created GitHub issue or ignore performance alert by not creating GitHub issue to avoid duplicate issue creation. | ||
|
||
## Config file structure | ||
The config file defines the structure to run change point analysis on a given test. To add a test to the config file, | ||
please follow the below structure. | ||
|
||
**NOTE**: The Change point analysis only supports reading the metric data from Big Query for now. | ||
|
||
``` | ||
# the test_1 must be a unique id. | ||
test_1: | ||
test_name: apache_beam.testing.benchmarks.inference.pytorch_image_classification_benchmarks | ||
source: big_query | ||
metrics_dataset: beam_run_inference | ||
metrics_table: torch_inference_imagenet_results_resnet152 | ||
project: apache-beam-testing | ||
metric_name: mean_load_model_latency_milli_secs | ||
labels: | ||
- run-inference | ||
min_runs_between_change_points: 3 # optional parameter | ||
num_runs_in_change_point_window: 30 # optional parameter | ||
``` | ||
|
||
**NOTE**: `test_name` should be in the format `apache_beam.foo.bar`. It should point to a single test target. | ||
|
||
**Note**: If the source is **BigQuery**, the metrics_dataset, metrics_table, project and metric_name should match with the values defined for performance/load tests. | ||
The above example uses this [test configuration](https://github.com/apache/beam/blob/0a91d139dea4276dc46176c4cdcdfce210fc50c4/.test-infra/jenkins/job_InferenceBenchmarkTests_Python.groovy#L30) | ||
to fill up the values required to fetch the data from source. | ||
|
||
### Different ways to avoid false positive change points | ||
|
||
**min_runs_between_change_points**: As the metric data moves across the runs, the change point analysis can place the | ||
change point in a slightly different place. These change points refer to the same regression and are just noise. | ||
When we find a new change point, we will search up to the `min_runs_between_change_points` in both directions from the | ||
current change point. If an existing change point is found within the distance, then the current change point will be | ||
suppressed. | ||
|
||
**num_runs_in_change_point_window**: This defines how many runs to consider from the most recent run to be in change point window. | ||
Sometimes, the change point found might be way back in time and could be irrelevant. For a test, if a change point needs to be | ||
reported only when it was observed in the last 7 runs from the current run, | ||
setting `num_runs_in_change_point_window=7` will achieve it. | ||
|
||
## Register a test for performance alerts | ||
|
||
If a new test needs to be registered for the performance alerting tool, please add the required test parameters to the | ||
config file. | ||
|
||
## Triage performance alert issues | ||
|
||
All the performance/load tests metrics defined at [beam/.test-infra/jenkins](https://github.com/apache/beam/tree/master/.test-infra/jenkins) are imported to [Grafana dashboards](http://104.154.241.245/d/1/getting-started?orgId=1) for visualization. Please | ||
find the alerted test dashboard to find a spike in the metric values. | ||
|
||
For example, for the below configuration, | ||
* test: `apache_beam.testing.benchmarks.inference.pytorch_image_classification_benchmarks` | ||
* metric_name: `mean_load_model_latency_milli_secs` | ||
|
||
Grafana dashboard can be found at http://104.154.241.245/d/ZpS8Uf44z/python-ml-runinference-benchmarks?orgId=1&viewPanel=7 | ||
|
||
If the dashboard for a test is not found, you can use the | ||
notebook `analyze_metric_data.ipynb` to generate a plot for the given test, metric_name. | ||
|
||
If you confirm there is a change in the pattern of the values for a test, find the timestamp of when that change happened | ||
and use that timestamp to find possible culprit commit. | ||
|
||
If the performance alert is a `false positive`, close the issue as `Close as not planned`. |
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,16 @@ | ||
# | ||
# 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. | ||
# |
172 changes: 172 additions & 0 deletions
172
sdks/python/apache_beam/testing/analyzers/analyze_metric_data.ipynb
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,172 @@ | ||
{ | ||
"nbformat": 4, | ||
"nbformat_minor": 0, | ||
"metadata": { | ||
"colab": { | ||
"provenance": [] | ||
}, | ||
"kernelspec": { | ||
"name": "python3", | ||
"display_name": "Python 3" | ||
}, | ||
"language_info": { | ||
"name": "python" | ||
} | ||
}, | ||
"cells": [ | ||
{ | ||
"cell_type": "code", | ||
"source": [ | ||
"# Licensed to the Apache Software Foundation (ASF) under one\n", | ||
"# or more contributor license agreements. See the NOTICE file\n", | ||
"# distributed with this work for additional information\n", | ||
"# regarding copyright ownership. The ASF licenses this file\n", | ||
"# to you under the Apache License, Version 2.0 (the\n", | ||
"# \"License\"); you may not use this file except in compliance\n", | ||
"# with the License. You may obtain a copy of the License at\n", | ||
"#\n", | ||
"# http://www.apache.org/licenses/LICENSE-2.0\n", | ||
"#\n", | ||
"# Unless required by applicable law or agreed to in writing,\n", | ||
"# software distributed under the License is distributed on an\n", | ||
"# \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY\n", | ||
"# KIND, either express or implied. See the License for the\n", | ||
"# specific language governing permissions and limitations\n", | ||
"# under the License." | ||
], | ||
"metadata": { | ||
"id": "fCjymAKWJiTh" | ||
}, | ||
"execution_count": null, | ||
"outputs": [] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"source": [ | ||
"# this notebook intended for internal testing purpose." | ||
], | ||
"metadata": { | ||
"id": "CCAvj4mQFR5x" | ||
}, | ||
"execution_count": null, | ||
"outputs": [] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"source": [ | ||
"Apache Beam can be installed directly from the main branch of https://github.com/apache/beam or can be installed via `pip install apache_beam>=2.45.0`" | ||
], | ||
"metadata": { | ||
"id": "IL7coD4DJqzG" | ||
} | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"source": [ | ||
"!git clone https://github.com/apache/beam.git\n", | ||
"!pip install -r beam/sdks/python/build-requirements.txt\n", | ||
"!pip install -e beam/sdks/python[gcp]\n", | ||
"!pip install matplotlib\n", | ||
"!pip install pandas" | ||
], | ||
"metadata": { | ||
"id": "yW4okqmpECqY" | ||
}, | ||
"execution_count": null, | ||
"outputs": [] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"source": [ | ||
"Import necessary dependencies" | ||
], | ||
"metadata": { | ||
"id": "ZPt3DbZcL-Ki" | ||
} | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"source": [ | ||
"import pandas as pd\n", | ||
"import matplotlib.pyplot as plt\n", | ||
"from apache_beam.testing.load_tests import load_test_metrics_utils\n", | ||
"from apache_beam.testing.load_tests.load_test_metrics_utils import BigQueryMetricsFetcher" | ||
], | ||
"metadata": { | ||
"id": "xYGgc-tpE9qY" | ||
}, | ||
"execution_count": null, | ||
"outputs": [] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"source": [ | ||
"bq_project = 'apache-beam-testing'\n", | ||
"bq_dataset = '<bq-dataset-name>' # sample value: beam_run_inference\n", | ||
"bq_table = '<bq-table>' # sample value: torch_inference_imagenet_results_resnet152\n", | ||
"metric_name = '<perf-alerted-metric-name>' # sample value: mean_load_model_latency_milli_secs\n", | ||
"\n", | ||
"query = f\"\"\"\n", | ||
" SELECT *\n", | ||
" FROM {bq_project}.{bq_dataset}.{bq_table}\n", | ||
" WHERE CONTAINS_SUBSTR(({load_test_metrics_utils.METRICS_TYPE_LABEL}), '{metric_name}')\n", | ||
" ORDER BY {load_test_metrics_utils.SUBMIT_TIMESTAMP_LABEL} DESC\n", | ||
" LIMIT 30\n", | ||
" \"\"\"\n" | ||
], | ||
"metadata": { | ||
"id": "nyMmUpRrD_zV" | ||
}, | ||
"execution_count": null, | ||
"outputs": [] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"source": [ | ||
"If the performance/load test store the results in BigQuery using this [schema](https://github.com/apache/beam/blob/83679216cce2d52dbeb7e837f06ca1d57b31d509/sdks/python/apache_beam/testing/load_tests/load_test_metrics_utils.py#L66),\n", | ||
"then fetch the metric_values for a `metric_name` for the last `30` runs and display a plot using matplotlib.\n" | ||
], | ||
"metadata": { | ||
"id": "RwlsXCLbVs_2" | ||
} | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"source": [ | ||
"big_query_metrics_fetcher = BigQueryMetricsFetcher()\n", | ||
"metric_data: pd.DataFrame = big_query_metrics_fetcher.fetch(query=query)" | ||
], | ||
"metadata": { | ||
"id": "rmOE_odNEBFK" | ||
}, | ||
"execution_count": null, | ||
"outputs": [] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"source": [ | ||
"# sort the data to view it in chronological order.\n", | ||
"metric_data.sort_values(\n", | ||
" by=[load_test_metrics_utils.SUBMIT_TIMESTAMP_LABEL], inplace=True)" | ||
], | ||
"metadata": { | ||
"id": "q-i3qLpGV5Ly" | ||
}, | ||
"execution_count": null, | ||
"outputs": [] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"source": [ | ||
"metric_data.plot(x=load_test_metrics_utils.SUBMIT_TIMESTAMP_LABEL,\n", | ||
" y=load_test_metrics_utils.VALUE_LABEL)\n", | ||
"plt.show()" | ||
], | ||
"metadata": { | ||
"id": "vbFoxdxHVvtQ" | ||
}, | ||
"execution_count": null, | ||
"outputs": [] | ||
} | ||
] | ||
} |
Oops, something went wrong.