ApplicationInsights-dotnet-.../CONTRIBUTING.md

164 строки
12 KiB
Markdown
Исходник Постоянная ссылка Обычный вид История

# How to Contribute
2017-11-08 21:54:11 +03:00
If you're interested in contributing, take a look at the general [contributer's guide](https://github.com/Microsoft/ApplicationInsights-Home/blob/master/CONTRIBUTING.md) first and continue here.
## Build
To successfully build the sources on your machine, make sure you've installed the following prerequisites:
2017-11-02 20:44:35 +03:00
* Visual Studio 2017 Community or Enterprise
* .NET 4.6
2018-01-12 04:19:32 +03:00
* .NET Core SDK 1.1.7
* .NET Core SDK 2.0 or above.(https://www.microsoft.com/net/download/windows)
If using Azure VM, the following image from Microsoft contains the above pre-requisites already installed.
_Visual Studio Enterprise 2017 (latest release) on Windows Server 2016._
Once you've installed the prerequisites execute either ```buildDebug.cmd``` or ```buildRelease.cmd``` script in the repository root to build the project (excluding functional tests) locally.
2017-12-07 03:01:28 +03:00
```buildRelease.cmd``` also runs StlyeCop checks, and is required before merging any pull requests.
You can also open the solutions in Visual Studio and build directly from there.
The following solution contains the product code and unit tests
2017-12-07 03:01:28 +03:00
``` "\Src\Microsoft.ApplicationInsights.Web.sln" ```
## Unit Tests
Several tests require that you configure a strong name verification exception for Microsoft.WindowsAzure.ServiceRuntime.dll using the [Strong Name Tool](https://msdn.microsoft.com/en-us/library/k5b5tt23(v=vs.110).aspx).
Using the Developer Command Prompt as Administrator, run this command from the repository root to register the assembly for verification skipping. (after building Microsoft.ApplicationInsights.Web.sln)
2018-02-15 02:35:37 +03:00
"%ProgramFiles(x86)%\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.7.1 Tools\sn.exe" -Vr ..\bin\Debug\Src\WindowsServer\WindowsServer.Net45.Tests\Microsoft.WindowsAzure.ServiceRuntime.dll
(Depending on you OS version, the above exe may be located in different folder. Modify the path according to local path).
Once you've configured the strong name verification, execute the ```runUnitTests.cmd``` script in the repository root.
2018-02-15 02:35:37 +03:00
If the script fail with errors like unable to find path to Visual Studio Test runner, please edit the helper script to match you local installation of Visual Studio.
2017-11-08 21:54:11 +03:00
You can also run the tests within Visual Studio using the test explorer. If test explorer is not showing all the tests, please make sure you have installed all updates to Visual Studio.
You can remove the strong name verification exception by running this command as Administrator:
2018-02-15 02:35:37 +03:00
"%ProgramFiles(x86)%\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.7.1 Tools\sn.exe" -Vr ..\bin\Debug\Src\WindowsServer\WindowsServer.Net45.Tests\Microsoft.WindowsAzure.ServiceRuntime.dll
## Functional Tests
It is recommended to rely on unit tests to test functionalities wherever possible. For doing end-to-end validation, functional tests exists for all the modules. Unless doing significant changes,
it is not required to run func-tests locally. All the tests, including functional tests, are automatically run when a PR is submitted.
These tests works like described below:
2018-01-09 20:18:52 +03:00
Functional tests contain test apps which refers to the product dlls from the local build. Tests deploy the Test apps to IIS/Docker and http requests are fired against it to trigger various scenarios.
Tests apps are modified to send telemetry to a fake ingestion endpoint controlled by tests. Tests then validate the telemetry received by this endpoint.
Pre-requisites:
2017-12-07 03:01:28 +03:00
To execute the functional tests, you need to install some additional prerequisites:
2017-12-07 03:04:32 +03:00
For Web and PerformanceCollector tests IIS Express should be installed.
2017-12-07 03:01:28 +03:00
2017-12-07 03:09:49 +03:00
For Dependency Collector, you need to install Docker for windows as these tests need several additional dependencies to be deployed like SQL Server, Azure Emulator etc, and these are deployed as Docker containers.
Docker for Windows (https://docs.docker.com/docker-for-windows/install/).
After installation switch Docker engine to Windows Containers.(https://blogs.msdn.microsoft.com/webdev/2017/09/07/getting-started-with-windows-containers/)
2017-12-23 02:18:54 +03:00
And finally, make sure you can run ```docker run hello-world``` successfully to confirm that your machine is Docker ready.
Running functional tests:
Before running the functional tests, the product code should be built following 'Build' instructions above.
After building, open the respective solutions from locations given below, build the solution. Tests will appear in Visual Studio Test Explorer and can be run from there.
The following solutions contains the functional tests for various features.
2017-12-07 03:09:49 +03:00
2017-11-15 02:44:06 +03:00
"\Test\Web\FunctionalTests.sln" -- Functional tests using apps onboarded with the nuget Microsoft.ApplicationInsights.Web
Helper script to build product and run all tests in this solution - ```runFunctionalTestsWeb```
2017-12-07 03:09:49 +03:00
"..\bin\Debug\Test\Web\FunctionalTests" -- Binary location for Test and Test apps.
"\Test\PerformanceCollector\FunctionalTests.sln" -- Functional tests using apps onboarded with the nuget Microsoft.ApplicationInsights.PerfCounterCollector
Helper script to build product and run all tests in this solution - ```runFunctionalTestsPerfCollectorAndQuickPulse```
"..\bin\Debug\Test\PerformanceCollector\FunctionalTests" -- Binary location for Test and Test apps.
2017-12-07 03:09:49 +03:00
2017-11-15 02:44:06 +03:00
"\Test\E2ETests\DependencyCollectionTests.sln" -- Functional tests using apps onboarded with the nuget Microsoft.ApplicationInsights.DependencyCollector
Helper script to build product and run all tests in this solution - ```runFunctionalTestsDependencyCollector```
"..bin\Debug\Test\E2ETests" -- Binary location for Test and Test apps.
Special Notes regarding DependencyCollectionTests
1. All Docker images are downloaded from internet when ran for first time and this could take several minutes (depends on network speed as **around 20GB will be downloaded on first time on a machine**.). Tests may appear hung during this time.
2. If using Visual Studio Test Explorer to run tests, group the tests by namespace and run each namespaces separately to avoid test conflicts. ```runFunctionalTestsDependencyCollector``` does this automatically.
Edit the helper scripts to change between 'Release' and 'Debug' as per your build.
```runAllFunctionalTests.cmd``` script builds the product and runs all the above functional tests.
Its is important to note that functional tests do not trigger product code build, so explicit build of product code is required before running functional tests.
A typical work flow would be make-produce-change followed by build-product followed by build-functest-solution and finally run-func-tests. (This helpers scripts does this.)
## Known issues/workarounds with running functional tests.
2017-12-23 02:18:54 +03:00
If any tests fail, please retry first to see if it helps. If not, try one of the known issues below.
2018-01-12 04:24:22 +03:00
Tests fail with error like "It was not possible to find any compatible framework version The specified framework 'Microsoft.NETCore.App', version '1.0.4' was not found"
Workaround: Install .NET Core SDK 1.1.7.
Web and PerformanceCollector fails with error related to 'Port conflicts' - its possible that some prior tests has not released ports.
Workaround - Kill all running IISExpress processes and re-run tests.
All/many functional tests fail with error "Incorrect number of items. Expected: 1 Received: 0" when ran from Visual Studio IDE.
Look for warnings in Visual Studio output window which contains errors like 'Unable to copy dll file due to file being locked..' etc.
Workarounds:
1. Close all instances of Visual Studio/cmd windows where scripts were run and retry.
2. One can use advanced tools like 'process explorer' to find out which process is locking files. Kill the process and retry.
3. Delete bin folder from repository root and rebuild.
2018-01-09 20:18:52 +03:00
4. Restart machine if none of the above helps.
Dependency Collector functional tests fail with messages like "Assert.AreEqual failed. Expected:<1>. Actual<0>." or "All apps are not healthy", then its likely that Docker installation has some issues.
2017-12-07 03:10:34 +03:00
Workaround if you are trying first time - Make sure you can run ```docker run hello-world``` successfully to confirm that your machine is Docker ready. Also, the very first time DependencyCollector tests are run, all Docker images are downloaded from web and this could potentially take an hour or so. This is only one time per machine.
2017-12-07 03:12:56 +03:00
Alternate workaround if you have previously run the tests successfully atleast once - execute the ```dockercleanup.ps1``` from repository root to cleanup any containers from prior runs.
All DependencyCollectionTests fail at initialization stage itself with error 'All apps are not healthy'. In the logs you'll find that Docker container has exited with some error codes. Eg: "Exited (2147943452) 53 seconds ago".
If this error occurs execute ```dockercleanup.ps1``` from repository root, and re-run the tests.
The test code intentionally does not clean up the containers it spun up. This is to enable fast re-runs of the tests. If the Test App code is changed, then Docker-Compose will detect it, and re-build the container.
If you want to do clean up all the containers created by the test, execute the ```dockercleanup.ps1``` from repository root. This is typically required if tests were aborted in the middle of a run for some reason.
2017-11-10 19:53:08 +03:00
After retrying, it tests still fail, please clear the binaries folder and rebuild the product solution and test solution and run the tests again.
2017-12-23 02:18:54 +03:00
If none of the above helps, please open an issue in Github describing the problem.
## Debugging the functional tests.
2017-11-08 21:54:11 +03:00
It is important to note that since the test application is deployed as a separate process/container, debugging the tests itself will not help debug the application code. A debugger need to be attached
to the process hosting the Application, IISExpress or IIS, after deploying the application there.
2017-11-14 03:43:06 +03:00
The test apps refers to the Web SDK assemblies from your local build. After making the changes to product code, build locally (from Visual Studio or using ```buildDebug.cmd```). Then build and start the test application from its publish folder in either IISExpress or IIS, and attach debugger to it. Open the .cs file you want your breakpoint in and set it. Now triggering a request to the application will hit the breakpoint.
2017-11-08 21:54:11 +03:00
The exact request to be triggered depends on what you are doing. If investigating functional test failures locally, then the tests logs should contain the url it hit to trigger scenarios.
2017-11-10 19:53:08 +03:00
Dependency Collector tests deploy the test apps, along with dependencies (Fake Ingestion, SQL etc) to Docker containers inside same Docker virtual network, so that apps can access the dependencies with their names. However, if
2017-11-10 19:45:54 +03:00
the test apps are deployed to IIS or IISExpress, then they are outside the Docker virtual network of dependencies, and so it won't be able to access dependencies without using their IP Address. This is a Docker for windows limitation, and could be fixed in future.
Until then, the test app need to address the dependencies using their IP Address. Instead of manually finding IP Addresses and replacing containers names with IP Address, its easy to just run the following script.
This uses Docker commands to determine the IP Addresses, and replaces them in the necessary configs.
"<repo-root>\bin\Debug\Test\E2ETests\E2ETests\replacecontainernamewithip.ps1"
2017-11-09 03:43:44 +03:00
2017-11-08 21:54:11 +03:00
Following pre-requisite is needed to deploy to IIS locally.
* IIS (Make sure Internet Information Services > World Wide Web Services > Application Development Features > ASP.NET 4.6 is enabled)
2018-01-09 20:36:12 +03:00
## Debugging the SDK in general (How to test Application Insights from local build in any Test App)
* Build the project using ```buildDebug.cmd```
* If the build was successful, you'll find that it generated NuGet packages in <repository root>\..\bin\Debug\NuGet
* If your change is confined to one of the nuget packages (say Web sdk), and you are developing on one of VNext branches, you can get the rest of the compatible nuget packages from [myget feed](https://www.myget.org/F/applicationinsights/)
* Create a web application project to test the SDK on, and install the Microsoft.ApplicationInsights.Web NuGet package from the above directory
* In your web application, point your project references to Microsoft.AI.Web, Microsoft.AI.WindowsServer, Microsoft.AI.PerfCounterCollector and Microsoft.AI.DependencyCollector to those DLLs in the SDK debug output folder (this makes sure you get the symbol files and that your web application is updated when you recompile the SDK).
* From your web application, open the .cs file you want your breakpoint in and set it
* Run your web application.
Your breakpoints should be hit now when your web application triggers them.