[Internal] Client Telemetry: Adds Client Telemetry pipeline sending data to service (#3900)

* first draft

* comment other pipelines

* pint variables

* commnet other pipelines

* added env variable

* minor changes

* update env variable

* print env variable

* add space in end

* fix test

* fix tests

* fix test

* fix tests

* remove response interceptor

* logs

* debuug mode

* 3failing test to print llgs

* minor refactoring

* 2nd windows-2019

* fix ct tests

* 2remove debugging

* fix tests

* revert

* ncomment pipelines

* fix test

* minor changes

* release and emulator pipeline

* update pipelines

* ignore abstract class test

* fixing pipeline

* refactor code

* change it to class name to run tests

* added emulator setup

* 1 temp commit

* env variable

* renames env variable

* fix tests

* add condition

* fix tests

* reorder env variable

* revert pipeline

* did some clean up

* change to revert

* Revert "change to revert"

This reverts commit 03db3c104505dc7b8f3cea267835c92ca530f8f4.

* fix typos

* throw if exception intercepter is null

* remove modelling changes

* removed virtaul

* Update Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/Utils/HttpHandlerHelper.cs

Co-authored-by: Matias Quaranta <ealsur@users.noreply.github.com>

* added condition for pipelines

* Revert "added condition for pipelines"

This reverts commit f9a208cd28e01badee97a2eb770a486cea67c1f0.

* changed cond

* fix codn

* more enhancement

* testing for release pipeline

* refactore code and using test category

* added comments on test

* refactor pipeline code

* fix variables

* fix pipeline

---------

Co-authored-by: Matias Quaranta <ealsur@users.noreply.github.com>
This commit is contained in:
Sourabh Jain 2023-08-22 16:26:27 +05:30 коммит произвёл GitHub
Родитель ce38cc1b22
Коммит 2257ca2fbe
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
6 изменённых файлов: 1364 добавлений и 1032 удалений

Просмотреть файл

@ -0,0 +1,164 @@
//------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//------------------------------------------------------------
namespace Microsoft.Azure.Cosmos.SDK.EmulatorTests
{
using System;
using System.Net.Http;
using System.Threading.Tasks;
using Microsoft.Azure.Cosmos.Fluent;
using Microsoft.Azure.Cosmos.Telemetry;
using Microsoft.VisualStudio.TestTools.UnitTesting;
/// <summary>
/// In Release pipeline, no need to mock Client Telemetry Service Call and Test will talk to the real database account.
/// If you are making changes in this file please make sure you are adding similar test in <see cref="ClientTelemetryTests"/> also.
/// </summary>
[TestClass]
[TestCategory("ClientTelemetryRelease")]
public class ClientTelemetryReleaseTests : ClientTelemetryTestsBase
{
public override CosmosClientBuilder GetBuilder()
{
string connectionString = ConfigurationManager.GetEnvironmentVariable<string>("COSMOSDB_ACCOUNT_CONNECTION_STRING", null);
return new CosmosClientBuilder(connectionString: connectionString);
}
/// <summary>
/// Returing null means do not return any hard codd response for any HTTP call.
/// </summary>
/// <param name="request"></param>
/// <returns></returns>
public override Task<HttpResponseMessage> HttpHandlerRequestCallbackChecks(HttpRequestMessage request)
{
return null;
}
[ClassInitialize]
public static new void ClassInitialize(TestContext context)
{
ClientTelemetryTestsBase.ClassInitialize(context);
// It will go away in next PR
Environment.SetEnvironmentVariable(ClientTelemetryOptions.EnvPropsClientTelemetryEnabled, "true");
Environment.SetEnvironmentVariable(ClientTelemetryOptions.EnvPropsClientTelemetrySchedulingInSeconds, "1");
Environment.SetEnvironmentVariable(ClientTelemetryOptions.EnvPropsClientTelemetryEndpoint, "https://tools.cosmos.azure.com/api/clienttelemetry/trace");
}
[ClassCleanup]
public static new void FinalCleanup()
{
ClientTelemetryTestsBase.FinalCleanup();
}
[TestInitialize]
public override void TestInitialize()
{
base.TestInitialize();
}
[TestCleanup]
public override async Task Cleanup()
{
await base.Cleanup();
}
[TestMethod]
[DataRow(ConnectionMode.Direct, true)]
[DataRow(ConnectionMode.Gateway, true)]
[DataRow(ConnectionMode.Direct, false)]
[DataRow(ConnectionMode.Gateway, false)]
public override async Task PointSuccessOperationsTest(ConnectionMode mode, bool isAzureInstance)
{
await base.PointSuccessOperationsTest(mode, isAzureInstance);
}
[TestMethod]
[DataRow(ConnectionMode.Direct)]
[DataRow(ConnectionMode.Gateway)]
public override async Task PointReadFailureOperationsTest(ConnectionMode mode)
{
await base.PointReadFailureOperationsTest(mode);
}
[TestMethod]
[DataRow(ConnectionMode.Direct)]
[DataRow(ConnectionMode.Gateway)]
public override async Task StreamReadFailureOperationsTest(ConnectionMode mode)
{
await base.StreamReadFailureOperationsTest(mode);
}
[TestMethod]
[DataRow(ConnectionMode.Direct)]
[DataRow(ConnectionMode.Gateway)]
public override async Task StreamOperationsTest(ConnectionMode mode)
{
await base.StreamOperationsTest(mode);
}
[TestMethod]
[DataRow(ConnectionMode.Direct)]
[DataRow(ConnectionMode.Gateway)]
public override async Task BatchOperationsTest(ConnectionMode mode)
{
await base.BatchOperationsTest(mode);
}
[TestMethod]
[DataRow(ConnectionMode.Direct)]
[DataRow(ConnectionMode.Gateway)]
public override async Task SingleOperationMultipleTimesTest(ConnectionMode mode)
{
await base.SingleOperationMultipleTimesTest(mode);
}
[TestMethod]
[DataRow(ConnectionMode.Direct)]
[DataRow(ConnectionMode.Gateway)]
public override async Task QueryOperationSinglePartitionTest(ConnectionMode mode)
{
await base.QueryOperationSinglePartitionTest(mode);
}
[TestMethod]
[DataRow(ConnectionMode.Direct)]
[DataRow(ConnectionMode.Gateway)]
public override async Task QueryMultiPageSinglePartitionOperationTest(ConnectionMode mode)
{
await base.QueryMultiPageSinglePartitionOperationTest(mode);
}
[TestMethod]
[DataRow(ConnectionMode.Direct)]
[DataRow(ConnectionMode.Gateway)]
public override async Task QueryOperationCrossPartitionTest(ConnectionMode mode)
{
await base.QueryOperationCrossPartitionTest(mode);
}
[TestMethod]
[DataRow(ConnectionMode.Direct)]
[DataRow(ConnectionMode.Gateway)]
public override async Task QueryOperationMutiplePageCrossPartitionTest(ConnectionMode mode)
{
await base.QueryOperationMutiplePageCrossPartitionTest(mode);
}
[TestMethod]
[DataRow(ConnectionMode.Direct)]
[DataRow(ConnectionMode.Gateway)]
public override async Task QueryOperationInvalidContinuationTokenTest(ConnectionMode mode)
{
await base.QueryOperationInvalidContinuationTokenTest(mode);
}
[TestMethod]
[DataRow(ConnectionMode.Direct)]
public override async Task CreateItemWithSubStatusCodeTest(ConnectionMode mode)
{
await base.CreateItemWithSubStatusCodeTest(mode);
}
}
}

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Просмотреть файл

@ -19,6 +19,8 @@ namespace Microsoft.Azure.Cosmos.SDK.EmulatorTests
public Func<HttpResponseMessage, Task<HttpResponseMessage>> ResponseIntercepter { get; set; }
public Action<HttpRequestMessage, Exception> ExceptionIntercepter { get; set; }
protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
{
HttpResponseMessage httpResponse = null;
@ -39,7 +41,19 @@ namespace Microsoft.Azure.Cosmos.SDK.EmulatorTests
}
}
httpResponse = await base.SendAsync(request, cancellationToken);
try
{
httpResponse = await base.SendAsync(request, cancellationToken);
}
catch (Exception ex) {
if (this.ExceptionIntercepter == null)
{
throw;
}
this.ExceptionIntercepter.Invoke(request, ex);
}
if (this.ResponseIntercepter != null)
{
httpResponse = await this.ResponseIntercepter(httpResponse);

Просмотреть файл

@ -7,6 +7,8 @@ variables:
VmImage: windows-latest # https://docs.microsoft.com/en-us/azure/devops/pipelines/agents/hosted?view=azure-devops
BuildConfiguration: Release
Packaging.EnableSBOMSigning: true
ReleasePackage: true
OS: 'Windows'
stages:
- stage:
@ -22,14 +24,45 @@ stages:
BuildConfiguration: $(BuildConfiguration)
Arguments: $(ReleaseArguments)
VmImage: $(VmImage)
- job:
displayName: TelemetryToService $(BuildConfiguration)
timeoutInMinutes: 120
condition: and(succeeded(), eq('$(OS)', 'Windows'))
pool:
vmImage: windows-2019
steps:
- checkout: self # self represents the repo where the initial Pipelines YAML file was found
clean: true # if true, execute `execute git clean -ffdx && git reset --hard HEAD` before fetching
# Add this Command to Include the .NET 6 SDK
- task: UseDotNet@2
displayName: Use .NET 6.0
inputs:
packageType: 'sdk'
version: '6.x'
- task: DotNetCoreCLI@2
displayName: Integration Test With Client Telemetry Service
condition: succeeded()
inputs:
command: test
projects: 'Microsoft.Azure.Cosmos/tests/Microsoft.Azure.Cosmos.EmulatorTests/*.csproj'
arguments: --filter "TestCategory=ClientTelemetryRelease" --verbosity normal --configuration $(BuildConfiguration) /p:OS=$(OS)
nugetConfigPath: NuGet.config
publishTestResults: true
testRunTitle: Microsoft.Azure.Cosmos.EmulatorTests
env:
COSMOSDB_ACCOUNT_CONNECTION_STRING: $(COSMOSDB_ACCOUNT_CONNECTION_STRING) # Real Account Connection String used by Integration Tests while running as part of release pipeline
- stage:
displayName: Publish
jobs:
- template: templates/nuget-pack.yml
parameters:
BuildConfiguration: Release
BuildConfiguration: $(BuildConfiguration)
VmImage: $(VmImage)
ReleasePackage: true
ReleasePackage: $(ReleasePackage)
OutputPath: '$(Build.ArtifactStagingDirectory)/bin/AnyCPU/$(BuildConfiguration)/Microsoft.Azure.Cosmos'
BlobVersion: $(BlobVersion)

Просмотреть файл

@ -5,9 +5,9 @@ parameters:
Arguments: ''
VmImage: '' # https://docs.microsoft.com/en-us/azure/devops/pipelines/agents/hosted?view=azure-devops
OS: 'Windows'
EmulatorPipeline1Arguments: ' --filter "TestCategory!=Quarantine & TestCategory!=Functional & (TestCategory=Query|TestCategory=ReadFeed|TestCategory=Batch|TestCategory=ChangeFeed)" --verbosity normal '
EmulatorPipeline2Arguments: ' --filter "TestCategory!=Quarantine & TestCategory!=Functional & TestCategory!=Query & TestCategory!=ReadFeed & TestCategory!=Batch & TestCategory!=ChangeFeed" --verbosity normal '
EmulatorPipeline1CategoryListName: ' Query, ChangeFeed, ReadFeed, Batch ' # Divided in 2 categories to run them in parallel and reduce the PR feedback time
EmulatorPipeline1Arguments: ' --filter "TestCategory!=Quarantine & TestCategory!=Functional & TestCategory!=ClientTelemetryRelease & (TestCategory=ClientTelemetryEmulator|TestCategory=Query|TestCategory=ReadFeed|TestCategory=Batch|TestCategory=ChangeFeed)" --verbosity normal '
EmulatorPipeline2Arguments: ' --filter "TestCategory!=Quarantine & TestCategory!=Functional & TestCategory!=ClientTelemetryRelease & TestCategory!=ClientTelemetryEmulator & TestCategory!=Query & TestCategory!=ReadFeed & TestCategory!=Batch & TestCategory!=ChangeFeed" --verbosity normal '
EmulatorPipeline1CategoryListName: ' Client Telemetry, Query, ChangeFeed, ReadFeed, Batch ' # Divided in 2 categories to run them in parallel and reduce the PR feedback time
EmulatorPipeline2CategoryListName: ' Others '
jobs: