Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/Azure/azure-sdk-for-python
Browse files Browse the repository at this point in the history
…into link_om_sample

* 'master' of https://github.com/Azure/azure-sdk-for-python: (23 commits)
  Int32 serialization (Azure#13452)
  add output to opinion mining sample (Azure#13494)
  Add Document w/ Eng Sys Checks (Azure#13492)
  update version (Azure#13495)
  Remove resources post test (Azure#13379)
  bing_id -> bing_entity_search_api_id (Azure#13491)
  [EventGrid] Read me + improve docstrings (Azure#13484)
  Build AuthenticationRecords from ADFS identity tokens (Azure#13341)
  Support Subject Name/Issuer authentication (Azure#13350)
  Add KeyVaultAccessControlClient for data plane RBAC (Azure#13372)
  [text analytics] Add redacted_text (Azure#13449)
  add python sdk sample (Azure#13338)
  [text analytics] add versionadded sphinx documentation (Azure#13450)
  [text analytics] add bing_id property to LinkedEntity class (Azure#13446)
  fix typing for paging methods (Azure#13410)
  [text analytics] add domain_filter param (Azure#13451)
  fix issue Azure#11658 for is_valid_resource_id (Azure#11709)
  added create_table_if_not_exists method to table service client (Azure#13385)
  [ServiceBus] Test and failure improvements (Azure#13345)
  Proper encoding and decoding of source URLs - Fixes special characters in source URL issue (Azure#13275)
  ...
  • Loading branch information
iscai-msft committed Sep 1, 2020
2 parents 7a77de0 + 6e8656d commit f7625ea
Show file tree
Hide file tree
Showing 126 changed files with 5,335 additions and 593 deletions.
4 changes: 4 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,10 @@ Mypy install and run.
**Example: Invoke tox, breaking into the debugger on failure**
`tox -e whl -c ../../../eng/tox/tox.ini -- --pdb`

### More Reading

We maintain an [additional document](doc/eng_sys_checks.md) that has a ton of detail as to what is actually _happening_ in these executions.

### Dev Feed
Daily dev build version of Azure sdk packages for python are available and are uploaded to Azure devops feed daily. We have also created a tox environment to test a package against dev built version of dependent packages. Below is the link to Azure devops feed.
[`https://dev.azure.com/azure-sdk/public/_packaging?_a=feed&feed=azure-sdk-for-python`](https://dev.azure.com/azure-sdk/public/_packaging?_a=feed&feed=azure-sdk-for-python)
Expand Down
4 changes: 3 additions & 1 deletion doc/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@ This folder contains some documentations for this repository:

The folder structure is the following
- [sphinx](./sphinx) : contains the documentation source code for https://azure.github.io/azure-sdk-for-python/
- [dev](./dev) : contains advanced documentation for _developers_ of SDK (not _consumers_ of SDK)
- [dev](./dev) : contains advanced documentation for _developers_ of SDK (not _consumers_ of SDK)

The file [eng_sys_checks](eng_sys_checks.md) is a read up as to what a standard `ci.yml` will actually execute.
196 changes: 196 additions & 0 deletions doc/eng_sys_checks.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,196 @@
# Azure SDK for Python - Engineering System

There are various tests currently enabled in Azure pipeline for Python SDK and some of them are enabled only for nightly CI checks. We also run some static analysis tool to verify code completeness, security and lint check.

Check the [contributing guide](../CONTRIBUTING.md#building-and-testing) for an intro to `tox`.

As a contributor, you will see the build jobs run in two modes: `Nightly Scheduled` and `Pull Request`.

These utilize the _same build definition_, except that the `nightly` builds run additional, deeper checks that run for a bit longer.

Example PR build:

![res/job_snippet.png](res/job_snippet.png)

- `Analyze` tox envs run during the `Analyze job.
- `Test <platform>_<pyversion>` runs PR/Nightly tox envs, depending on context.

## Analyze Checks
Analyze job in both nightly CI and pull request validation pipeline runs a set of static analysis using external and internal tools. Following are the list of these static analysis.

#### MyPy
`Mypy` is a static analysis tool that runs type checking of python package. Following are the steps to run `MyPy` locally for a specific package
1. Go to root of the package
2. Execute following command
```tox -e mypy -c ../../../eng/tox/tox.ini ```

#### Pylint
`Pylint` is a static analysis tool to run lint checking. Following are the steps to run `pylint` locally for a specific package.

1. Go to root of the package.
2. Execute following command
```tox -e pylint -c ../../../eng/tox/tox.ini```


#### Bandit
`Bandit` is static security analysis tool. This check is triggered for all Azure SDK package as part of analyze job. Following are the steps to `Bandit` tool locally for a specific package.

1. Got to package root directory.
2. Execute following command
```tox -e bandit -c ../../../eng/tox/tox.ini```


#### ApiStubGen
`ApiStubGen` is an internal tool used to create API stub to help reviewing public APIs in our SDK package using [`APIViewTool`.](https://apiview.dev/) This tool also has some built in lint checks available and purpose of having this step in analyze job is to ensure any change in code is not impacting stubbing process and also to have more and more custom lint checks added in future.

#### Change log verification

Change log verification is added to ensure package has valid change log for current version. Guidelines to properly maintain the change log is documented [here]()

## PR Validation Checks
Each pull request runs various tests using `pytest` in addition to all the tests mentioned above in analyze check. Pull request validation performs 3 different types of test: `whl, sdist and depends`. Following section explains the purpose of each of these tests and how to execute them locally. All pull requests are validated on multiple python versions across different platforms and below is the test matrix for pull request.


|`Python Version`|`Platform` |
|--|--|
|2.7|Linux|
|3.5|Windows|
|3.8|Linux|

### PR validation tox test environments
Tests are executed using tox environment and following are the tox test names that are part of pull request validation
#### whl
This test installs wheel of the package being tested and runs all tests cases in the package using `pytest`. Following is the command to run this test environment locally.

1. Go to package root folder on a command line
2. Run following command
``tox -e whl -c ../../../eng/tox/tox.ini``

#### sdist
This test installs sdist of the package being tested and runs all tests cases in the package using `pytest`. Following is the command to run this test environment locally.

1. Go to package root folder on a command line
2. Run following command
``tox -e sdist -c ../../../eng/tox/tox.ini``

####depends
This test is to ensure all modules in the package being tested can be successfully imported. This is to ensure all package requirement is properly set in setup.py as well as to ensure modules are imported using valid namespace. This test install the package and it's required packages and executes `from <package-root-namespace> import *`. For e.g. `from azure.core import *`.

Following is the command to run this test environment locally.

1. Go to package root folder on a command line
2. Run following command
``tox -e sdist -c ../../../eng/tox/tox.ini``


## Nightly CI Checks

Nightly continuous integration checks run all tests mentioned above in Analyze and Pull request checks in addition to multiple other tests. Nightly CI checks run on all python versions that are supported by Azure SDK packages across multiple platforms.

![res/full_matrix.png](res/full_matrix.png)

Regression also executes:
![res/regression.png](res/regression.png)

Nightly CI check runs following additional tests to ensure the dependency between a package being developed against released packages to ensure backward compatibility. Following is the explanation of why we need dependency tests to ensure backward compatibility.

Imagine a situation where package `XYZ` requires another package `ABC` and as per the package requirement of `XYZ`, It should work with any version between 1.0 and 2.0 of package `ABC`.

Package `XYZ` requires package `ABC`

As a developer of package `XYZ`, we need to ensure that our package works fine with all versions of ABC as long as it is within package requirement specification.

Another scenario where regression test( reverse dependency) is required. Let's take same example above and assume we are developers of package `ABC` which is taken as required package by another package `XYZ`

Package `ABC is required by package `XYZ`


As a developer of `ABC`, we need to ensure that any new change in `ABC` is not breaking the use of `XYZ` and hence ensures backward compatibility.

Let's take few Azure SDK packages instead of dummy names to explain this in a context we are more familiar of.

Most of the Azure SDK packages require `azure-core` and this requirement is within a range for e.g. `azure-storage-blob` that requires `azure-core >1.0.0, <2.0.0`. So any new change in azure-storage-blob needs to make sure it works fine with all versions of azure-core between 1.0.0 and 2.0.0(Both included).
Similarly any new version of azure-core needs to ensure that it is still compatible with all released package versions which takes azure-core as required package.

It is lot of combinations if we need to run tests for all released versions within the range of requirement specification. In order to reduce the test matrix and at the same time ensures the quality, we currently run the test using oldest released and latest released packages and skips any version in between.

Following are the additional tests we run during nightly CI checks.

####Latest Dependency Test

This test makes sure that a package being developed works absolutely fine using latest released version of required Azure SDK package as long as there is a released version which satisfies the requirement specification. Workflow of this test is as follows:

1. Identify if any azure SDK package is marked as required package in setup.py of current package being tested.
Note: Any dependency mentioned only in dev_requirements are not considered to identify dependency.
2. Identify latest released version of required azure sdk package on PyPI
3. Install latest released version of required package instead of dev dependency to package in code repo
4. Install current package that is being tested
5. Run pytest of all test cases in current package

Tox name of this test is `latestdependency` and steps to manually run this test locally is as follows.
1. Go to package root. For e.g azure-storage-blob or azure-identity
2. Run following command
`Tox –e latestdependency –c ../../../tox/tox.ini`


####Oldest Dependency Test

This test makes sure that a package being developed works absolutely fine using oldest released version of required Azure SDK package as long as there is a released version which satisfies the requirement specification. Workflow of this test is as follows:

1. Identify if any azure SDK package is marked as required package in setup.py of current package being tested.
Note: Any dependency mentioned only in dev_requirements are not considered to identify dependency.
2. Identify oldest released version of required azure sdk package on PyPI
3. Install oldest released version of required package instead of dev dependency to package in code repo
4. Install current package that is being tested
5. Run pytest of all test cases in current package

Tox name of this test is `mindependency` and steps to manually run this test locally is as follows.
1. Go to package root. For e.g azure-storage-blob or azure-identity
2. Run following command
`Tox –e mindependency –c ../../../tox/tox.ini`


####Regression Test

As mentioned earlier, regression test or reverse dependency test is added to avoid a regression scenario for customers when any new change is made in a package that is required by other packages. Currently we have only very few Azure SDK packages that are added as required package by other Azure SDK package. As of now, list of these required packages are:
`azure-core`
`azure-eventhub`
`azure-storage-blob`

Our regression framework automatically finds any such package that is added as required package so this list is not hardcoded.

We have two different set of regression tests to verify regression scenarios against oldest and latest released dependent packages.
• Regression using latest released dependent package
• Regression using oldest released dependent package

One main difference between regression tests and forward dependency test( latest and mindependency) is in terms of what test cases are executed as part of the tests. While forward dependency tests executes the test cases in current code repo, regression tests execute the tests that were part of repo at the time of dependent package release. To make it more clear, let's look at an example here.

Let's assume that we are testing regression for azure-core and this test is for regression against latest released dependent packages. Test will identify all packages that takes azure-core as required package and finds latest released version of those packages. Test framework install currently being developed azure-core and latest released dependent package and runs the test cases in dependent package, for e.g. azure-identity, that were part of repo at the time of releasing depending package.

Workflow of this test is as follows when running regression for an SDK package.
1. Identify any packages that takes currently being tested package as required package
2. Find latest and oldest released versions of dependent package from PyPI
3. Install currently being developed version of package we are testing regression for. E.g. azure-core
4. Checkout the release tag of dependent package from github
5. Install latest/oldest version of dependent package. For e.g. azure-identity
6. Run test cases within dependent package from checked out branch.


Steps to manually run regression test locally:
1. Run below command from your git code repo to generate the wheel of package being developed. Currently we have restricted to have prebuilt wheel.
`./scripts/devops_tasks/build_packages.py --service= <service-name> -d <out-folder>`
2. Run below command to start regression test locally
`./scripts/devops_tasks/test_regression.py azure-* --service=<service-name> --whl-dir=<out-folder given above in step 2>`


How to run these additional tests on azure pipelines manually

Following variables can be set at queueing time in order to run these additional tests which are by default run only for scheduled runs.

• Latest and oldest dependency test in addition to basic testing
Variable name: `Run.DependencyTest`
Value: true

• Regression test
Variable name: `Run.Regression`
Value: true
Binary file added doc/res/full_matrix.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/res/job_snippet.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/res/regression.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions sdk/anomalydetector/azure-ai-anomalydetector/MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
recursive-include tests *.py *.yaml
recursive-include samples *.py *.md
include *.md
include azure/__init__.py
include azure/ai/__init__.py
Expand Down
59 changes: 59 additions & 0 deletions sdk/anomalydetector/azure-ai-anomalydetector/samples/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
---
page_type: sample
languages:
- python
products:
- azure
- azure-cognitive-services
- azure-anomaly-detector
urlFragment: anomalydetector-samples
---

# Samples for Azure Anomaly Detector client library for Python

These code samples show common scenario operations with the Anomaly Detector client library.

These sample programs show common scenarios for the Anomaly Detector client's offerings.

|**File Name**|**Description**|
|----------------|-------------|
|[sample_detect_entire_series_anomaly.py][sample_detect_entire_series_anomaly] |Detecting anomalies in the entire time series.|
|[sample_detect_last_point_anomaly.py][sample_detect_last_point_anomaly] |Detecting the anomaly status of the latest data point.|
|[sample_detect_change_point.py][sample_detect_change_point] |Detecting change points in the entire time series.|

## Prerequisites
* Python 2.7 or 3.5 or higher is required to use this package.
* The Pandas data analysis library.
* You must have an [Azure subscription][azure_subscription] and an
[Azure Anomaly Detector account][azure_anomaly_detector_account] to run these samples.

## Setup

1. Install the Azure Anomaly Detector client library for Python with [pip][pip]:

```bash
pip install azure-ai-anomalydetector
```

2. Clone or download this sample repository
3. Open the sample folder in Visual Studio Code or your IDE of choice.

## Running the samples

1. Open a terminal window and `cd` to the directory that the samples are saved in.
2. Set the environment variables specified in the sample file you wish to run.
3. Follow the usage described in the file, e.g. `python sample_detect_entire_series_anomaly.py`

## Next steps

Check out the [API reference documentation][python-fr-ref-docs] to learn more about
what you can do with the Azure Anomaly Detector client library.

[pip]: https://pypi.org/project/pip/
[azure_subscription]: https://azure.microsoft.com/free/cognitive-services
[azure_anomaly_detector_account]: https://ms.portal.azure.com/#create/Microsoft.CognitiveServicesAnomalyDetector
[python-fr-ref-docs]: https://azuresdkdocs.blob.core.windows.net/$web/python/azure-cognitiveservices-anomalydetector/0.3.0/index.html

[sample_detect_entire_series_anomaly]: ./sample_detect_entire_series_anomaly.py
[sample_detect_last_point_anomaly]: ./sample_detect_last_point_anomaly.py
[sample_detect_change_point]: ./sample_detect_change_point.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
2018-03-01T00:00:00Z,32858923
2018-03-02T00:00:00Z,29615278
2018-03-03T00:00:00Z,22839355
2018-03-04T00:00:00Z,25948736
2018-03-05T00:00:00Z,34139159
2018-03-06T00:00:00Z,33843985
2018-03-07T00:00:00Z,33637661
2018-03-08T00:00:00Z,32627350
2018-03-09T00:00:00Z,29881076
2018-03-10T00:00:00Z,22681575
2018-03-11T00:00:00Z,24629393
2018-03-12T00:00:00Z,34010679
2018-03-13T00:00:00Z,33893888
2018-03-14T00:00:00Z,33760076
2018-03-15T00:00:00Z,33093515
2018-03-16T00:00:00Z,29945555
2018-03-17T00:00:00Z,22676212
2018-03-18T00:00:00Z,25262514
2018-03-19T00:00:00Z,33631649
2018-03-20T00:00:00Z,34468310
2018-03-21T00:00:00Z,34212281
2018-03-22T00:00:00Z,38144434
2018-03-23T00:00:00Z,34662949
2018-03-24T00:00:00Z,24623684
2018-03-25T00:00:00Z,26530491
2018-03-26T00:00:00Z,35445003
2018-03-27T00:00:00Z,34250789
2018-03-28T00:00:00Z,33423012
2018-03-29T00:00:00Z,30744783
2018-03-30T00:00:00Z,25825128
2018-03-31T00:00:00Z,21244209
2018-04-01T00:00:00Z,22576956
2018-04-02T00:00:00Z,31957221
2018-04-03T00:00:00Z,33841228
2018-04-04T00:00:00Z,33554483
2018-04-05T00:00:00Z,32383350
2018-04-06T00:00:00Z,29494850
2018-04-07T00:00:00Z,22815534
2018-04-08T00:00:00Z,25557267
2018-04-09T00:00:00Z,34858252
2018-04-10T00:00:00Z,34750597
2018-04-11T00:00:00Z,34717956
2018-04-12T00:00:00Z,34132534
2018-04-13T00:00:00Z,30762236
2018-04-14T00:00:00Z,22504059
2018-04-15T00:00:00Z,26149060
2018-04-16T00:00:00Z,35250105
Loading

0 comments on commit f7625ea

Please sign in to comment.