Skip to content

Commit

Permalink
chore(): api retries and logging
Browse files Browse the repository at this point in the history
  • Loading branch information
Siddharth Singha Roy committed Oct 16, 2024
1 parent 1d5a12f commit f64347a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,12 @@ internal enum TestErrorType
Scalable
}

internal class ServiceClientConstants
{
internal static readonly int s_mAX_RETRIES = 3;
internal static readonly int s_mAX_RETRY_DELAY_IN_SECONDS = 2000;
}

internal static class TestResultErrorConstants
{
public static List<TestResultError> ErrorConstants = new()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
using Azure.Developer.MicrosoftPlaywrightTesting.TestLogger.Interface;
using Azure.Developer.MicrosoftPlaywrightTesting.TestLogger.Model;
using System.Text.Json;
using Azure.Core.Diagnostics;
using System.Diagnostics.Tracing;

namespace Azure.Developer.MicrosoftPlaywrightTesting.TestLogger.Implementation
{
Expand All @@ -15,14 +17,25 @@ internal class ServiceClient : IServiceClient
private readonly ReportingTestResultsClient _reportingTestResultsClient;
private readonly ReportingTestRunsClient _reportingTestRunsClient;
private readonly CloudRunMetadata _cloudRunMetadata;
private readonly ILogger _logger;
private static string AccessToken { get => $"Bearer {Environment.GetEnvironmentVariable(ServiceEnvironmentVariable.PlaywrightServiceAccessToken)}"; set { } }
private static string CorrelationId { get => Guid.NewGuid().ToString(); set { } }

public ServiceClient(CloudRunMetadata cloudRunMetadata, ReportingTestResultsClient? reportingTestResultsClient = null, ReportingTestRunsClient? reportingTestRunsClient = null)
public ServiceClient(CloudRunMetadata cloudRunMetadata, ReportingTestResultsClient? reportingTestResultsClient = null, ReportingTestRunsClient? reportingTestRunsClient = null, ILogger? logger = null)
{
_cloudRunMetadata = cloudRunMetadata;
_reportingTestResultsClient = reportingTestResultsClient ?? new ReportingTestResultsClient(_cloudRunMetadata.BaseUri);
_reportingTestRunsClient = reportingTestRunsClient ?? new ReportingTestRunsClient(_cloudRunMetadata.BaseUri);
_logger = logger ?? new Logger();
AzureEventSourceListener listener = new(delegate (EventWrittenEventArgs eventData, string text)
{
_logger.Info($"[{eventData.Level}] {eventData.EventSource.Name}: {text}");
}, EventLevel.Informational);
var clientOptions = new TestReportingClientOptions();
clientOptions.Diagnostics.IsLoggingEnabled = true;
clientOptions.Diagnostics.IsTelemetryEnabled = true;
clientOptions.Retry.MaxRetries = ServiceClientConstants.s_mAX_RETRIES;
clientOptions.Retry.MaxDelay = TimeSpan.FromSeconds(ServiceClientConstants.s_mAX_RETRY_DELAY_IN_SECONDS);
_reportingTestResultsClient = reportingTestResultsClient ?? new ReportingTestResultsClient(_cloudRunMetadata.BaseUri, clientOptions);
_reportingTestRunsClient = reportingTestRunsClient ?? new ReportingTestRunsClient(_cloudRunMetadata.BaseUri, clientOptions);
}

public TestRunDtoV2? PatchTestRunInfo(TestRunDtoV2 run)
Expand Down

0 comments on commit f64347a

Please sign in to comment.