Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove failure analysis and apply code cleanup #8153

Merged
merged 4 commits into from
Apr 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,9 @@ dotnet_naming_style.prefix_underscore.capitalization = camel_case
###############################
[*.cs]
# var preferences
csharp_style_var_for_built_in_types = true:silent
csharp_style_var_when_type_is_apparent = true:silent
csharp_style_var_elsewhere = true:silent
csharp_style_var_for_built_in_types = false:silent
csharp_style_var_when_type_is_apparent = false:silent
csharp_style_var_elsewhere = false:silent
# Expression-bodied members
csharp_style_expression_bodied_methods = false:silent
csharp_style_expression_bodied_constructors = false:silent
Expand All @@ -105,6 +105,8 @@ csharp_style_deconstructed_variable_declaration = true:suggestion
csharp_prefer_simple_default_expression = true:suggestion
csharp_style_pattern_local_over_anonymous_function = true:suggestion
csharp_style_inlined_variable_declaration = true:suggestion
# one class per file
csharp_style_single_file_classes = true:suggestion

###############################
# C# Formatting Rules #
Expand Down Expand Up @@ -136,3 +138,4 @@ csharp_space_between_method_call_empty_parameter_list_parentheses = false
# Wrapping preferences
csharp_preserve_single_line_statements = true
csharp_preserve_single_line_blocks = true

Original file line number Diff line number Diff line change
Expand Up @@ -17,53 +17,53 @@ namespace Azure.Sdk.Tools.PipelineWitness.Tests
{
public class BlobUploadProcessorIntegrationTests
{
private VssCredentials VisualStudioCredentials;
private VssConnection VisualStudioConnection;
private string TARGET_ACCOUNT_ID = "azure-sdk";
private Guid TARGET_PROJECT_ID = new Guid("29ec6040-b234-4e31-b139-33dc4287b756");
private int TARGET_DEFINITION_ID = 297;
private string DEVOPS_PATH = "https://dev.azure.com/azure-sdk";
private PipelineWitnessSettings TestSettings = new PipelineWitnessSettings()
private const string TARGET_ACCOUNT_ID = "azure-sdk";
private const string TARGET_PROJECT_ID = "29ec6040-b234-4e31-b139-33dc4287b756";
private const int TARGET_DEFINITION_ID = 297;
private const string DEVOPS_PATH = "https://dev.azure.com/azure-sdk";

private readonly VssCredentials visualStudioCredentials;
private readonly VssConnection visualStudioConnection;
private readonly PipelineWitnessSettings testSettings = new()
{
PipelineOwnersDefinitionId = 5112,
PipelineOwnersFilePath = "pipelineOwners/pipelineOwners.json",
PipelineOwnersArtifactName = "pipelineOwners"
};
PipelineOwnersFilePath = "pipelineOwners/pipelineOwners.json",
PipelineOwnersArtifactName = "pipelineOwners"
};


public BlobUploadProcessorIntegrationTests()
{
var pat = Environment.GetEnvironmentVariable("AZURESDK_DEVOPS_TOKEN");
var blobUri = Environment.GetEnvironmentVariable("AZURESDK_BLOB_CS");
string pat = Environment.GetEnvironmentVariable("AZURESDK_DEVOPS_TOKEN");
string blobUri = Environment.GetEnvironmentVariable("AZURESDK_BLOB_CS");

if (!string.IsNullOrWhiteSpace(pat) && !string.IsNullOrWhiteSpace(blobUri) )
if (!string.IsNullOrWhiteSpace(pat) && !string.IsNullOrWhiteSpace(blobUri))
{
VisualStudioCredentials = new VssBasicCredential("nobody", pat);
VisualStudioConnection = new VssConnection(new Uri(DEVOPS_PATH), VisualStudioCredentials);
this.visualStudioCredentials = new VssBasicCredential("nobody", pat);
this.visualStudioConnection = new VssConnection(new Uri(DEVOPS_PATH), this.visualStudioCredentials);
}
}

[EnvironmentConditionalSkipFact]
public async Task BasicBlobProcessInvokesSuccessfully()
{
var buildLogProvider = new BuildLogProvider(logger: new NullLogger<BuildLogProvider>(), VisualStudioConnection);
var blobServiceClient = new BlobServiceClient(Environment.GetEnvironmentVariable("AZURESDK_BLOB_CS"));
var buildHttpClient = VisualStudioConnection.GetClient<BuildHttpClient>();
var testResultsBuiltClient = VisualStudioConnection.GetClient<TestResultsHttpClient>();
BuildLogProvider buildLogProvider = new(logger: new NullLogger<BuildLogProvider>(), this.visualStudioConnection);
BlobServiceClient blobServiceClient = new(Environment.GetEnvironmentVariable("AZURESDK_BLOB_CS"));
BuildHttpClient buildHttpClient = this.visualStudioConnection.GetClient<BuildHttpClient>();
TestResultsHttpClient testResultsBuiltClient = this.visualStudioConnection.GetClient<TestResultsHttpClient>();

List<Build> recentBuilds = await buildHttpClient.GetBuildsAsync(TARGET_PROJECT_ID, definitions: new[] { TARGET_DEFINITION_ID }, resultFilter: BuildResult.Succeeded, statusFilter: BuildStatus.Completed, top: 1, queryOrder: BuildQueryOrder.FinishTimeDescending);
Assert.True(recentBuilds.Count > 0);
var targetBuildId = recentBuilds.First().Id;
int targetBuildId = recentBuilds.First().Id;

BlobUploadProcessor processor = new BlobUploadProcessor(logger: new NullLogger<BlobUploadProcessor>(),
BlobUploadProcessor processor = new(logger: new NullLogger<BlobUploadProcessor>(),
logProvider: buildLogProvider,
blobServiceClient: blobServiceClient,
buildClient: buildHttpClient,
testResultsClient: testResultsBuiltClient,
options: Options.Create<PipelineWitnessSettings>(TestSettings),
failureAnalyzer: new PassThroughFailureAnalyzer());
options: Options.Create<PipelineWitnessSettings>(this.testSettings));

await processor.UploadBuildBlobsAsync(TARGET_ACCOUNT_ID, TARGET_PROJECT_ID, targetBuildId);
await processor.UploadBuildBlobsAsync(TARGET_ACCOUNT_ID, new Guid(TARGET_PROJECT_ID), targetBuildId);
}

[Theory]
Expand All @@ -73,7 +73,7 @@ public async Task BasicBlobProcessInvokesSuccessfully()
[InlineData(0, 10000, 0)]
public void TestBatching(int startingNumber, int batchSize, int expectedBatchNumber)
{
var numberOfBatches = BlobUploadProcessor.CalculateBatches(startingNumber, batchSize);
int numberOfBatches = BlobUploadProcessor.CalculateBatches(startingNumber, batchSize);

Assert.Equal(expectedBatchNumber, numberOfBatches);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ public sealed class EnvironmentConditionalSkipFact : FactAttribute
{
public EnvironmentConditionalSkipFact()
{
var devopsPat = Environment.GetEnvironmentVariable("AZURESDK_DEVOPS_TOKEN");
var blobToken = Environment.GetEnvironmentVariable("AZURESDK_BLOB_CS");
string devopsPat = Environment.GetEnvironmentVariable("AZURESDK_DEVOPS_TOKEN");
string blobToken = Environment.GetEnvironmentVariable("AZURESDK_BLOB_CS");

// and if we don't, skip this test
if (string.IsNullOrWhiteSpace(devopsPat) || string.IsNullOrWhiteSpace(blobToken))
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -24,29 +24,4 @@ public void Log<TState>(LogLevel logLevel, EventId eventId, TState state, Except
Logs.Add(state);
}
}

public class TestLoggingFactory : ILoggerFactory
{
private readonly TestLogger _logger;

public TestLoggingFactory(TestLogger logger)
{
_logger = logger;
}

public void Dispose()
{
throw new NotImplementedException();
}

public void AddProvider(ILoggerProvider provider)
{
throw new NotImplementedException();
}

public ILogger CreateLogger(string categoryName)
{
return _logger;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,31 +1,32 @@
using System.Reflection;
using System.Reflection;
using Microsoft.ApplicationInsights.Channel;
using Microsoft.ApplicationInsights.Extensibility;
using Microsoft.ApplicationInsights.Extensibility.Implementation;

namespace Azure.Sdk.Tools.PipelineWitness.ApplicationInsights
{
public class ApplicationVersionTelemetryInitializer : ITelemetryInitializer
{
private static string _version = GetVersion();
private static readonly string version = GetVersion();

public void Initialize(ITelemetry telemetry)
{
if (!string.IsNullOrEmpty(_version))
if (!string.IsNullOrEmpty(version))
{
var component = telemetry.Context?.Component;
ComponentContext component = telemetry.Context?.Component;

if (component != null)
{
component.Version = _version;
component.Version = version;
}
}
}

private static string GetVersion()
{
var assembly = typeof(ApplicationVersionTelemetryInitializer).Assembly;
var version = assembly.GetCustomAttribute<AssemblyInformationalVersionAttribute>()?.InformationalVersion
Assembly assembly = typeof(ApplicationVersionTelemetryInitializer).Assembly;

string version = assembly.GetCustomAttribute<AssemblyInformationalVersionAttribute>()?.InformationalVersion
?? assembly.GetName().Version?.ToString();

return version;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ public BlobNotFoundTelemetryProcessor(ITelemetryProcessor next)
{
this.next = next;
}

public void Process(ITelemetry telemetry)
{
if (telemetry is DependencyTelemetry { Success: false, Type: "Azure blob" or "Microsoft.Storage" } blobRequestTelemetry)
{
blobRequestTelemetry.Properties.TryGetValue("Error", out var errorProperty);
var isNotFound = blobRequestTelemetry.ResultCode is "404" or "409"
blobRequestTelemetry.Properties.TryGetValue("Error", out string errorProperty);

bool isNotFound = blobRequestTelemetry.ResultCode is "404" or "409"
|| (blobRequestTelemetry.ResultCode == "" && errorProperty?.Contains("Status: 404") == true);

if (isNotFound)
Expand Down
Loading