Skip to content

Commit 4d5dfb9

Browse files
Additional logs added (#3710)
* Additional logs added * Fixed printing Object
1 parent cc5576f commit 4d5dfb9

File tree

3 files changed

+18
-4
lines changed

3 files changed

+18
-4
lines changed

src/Microsoft.Health.Fhir.Core/Features/Operations/Reindex/ReindexJobTask.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ public async Task ExecuteAsync(ReindexJobRecord reindexJobRecord, WeakETag weakE
139139
// If no queries have been added to the progress then this is a new job
140140
if (_reindexJobRecord.QueryList?.Count == 0)
141141
{
142+
_logger.LogInformation("Picked up a new job");
142143
if (!await TryPopulateNewJobFields(cancellationToken))
143144
{
144145
return;
@@ -375,6 +376,7 @@ private async Task ProcessJob()
375376
// if this query has a created task, cancel it
376377
if (queryCancellationTokens.TryGetValue(staleQuery, out var tokenSource))
377378
{
379+
_logger.LogInformation("Stale Query that is being reset to queued. Status : {StaleQueryStatus}, StartResourceSurrogateId : {StaleQueryStartSurrogateId}, ResourceType : {StaleQueryResourceType}", staleQuery.Status, staleQuery.StartResourceSurrogateId, staleQuery.ResourceType);
378380
try
379381
{
380382
tokenSource.Cancel(false);
@@ -409,6 +411,7 @@ private async Task ProcessJob()
409411
var finishedTasks = queryTasks.Where(t => t.IsCompleted).ToArray();
410412
foreach (var finishedTask in finishedTasks)
411413
{
414+
_logger.LogInformation("Details of Reindex Task completed LastModified : {LastModified} ResourceType: {ResourceType} StartResourceSurrogateId: {StartResourceSurrogateId}", finishedTask.Result.LastModified, finishedTask.Result.ResourceType, finishedTask.Result.StartResourceSurrogateId);
412415
queryTasks.Remove(finishedTask);
413416
queryCancellationTokens.Remove(await finishedTask);
414417
}
@@ -428,9 +431,10 @@ private async Task ProcessJob()
428431
_reindexJobRecord.Status = wrapper.JobRecord.Status;
429432
}
430433
}
431-
catch (Exception)
434+
catch (Exception ex)
432435
{
433436
// if something went wrong with fetching job status, we shouldn't fail process loop.
437+
_logger.LogWarning(ex, "Reindex error occurred while fetching job status.");
434438
}
435439
finally
436440
{
@@ -543,6 +547,7 @@ private async Task<ReindexJobQueryStatus> ProcessQueryAsync(ReindexJobQueryStatu
543547
if (_reindexJobRecord.QueryList.Count > 10)
544548
{
545549
var queryStatusToRemove = _reindexJobRecord.QueryList.Keys.Where(q => q.Status == OperationStatus.Completed).OrderBy(q => q.LastModified).FirstOrDefault();
550+
_logger.LogInformation("Reindex job that is being removed from query list StartResourceSurrogateId: {StartResourceSurrogateId}, ResourceType: {ResourceType}, FailureCount: {FailureCount}, Status: {Status}", queryStatusToRemove?.StartResourceSurrogateId, queryStatusToRemove?.ResourceType, queryStatusToRemove?.FailureCount, queryStatusToRemove?.Status);
546551
_reindexJobRecord.QueryList.TryRemove(queryStatusToRemove, out var removedByte);
547552
}
548553

src/Microsoft.Health.Fhir.Core/Features/Operations/Reindex/ReindexJobWorker.cs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,29 +78,34 @@ public async Task ExecuteAsync(CancellationToken cancellationToken)
7878
// Check for any new Reindex Jobs
7979
try
8080
{
81-
// Remove all completed tasks.
81+
_logger.LogInformation("Number of Tasks in the list {RunningTasksCount}.", runningTasks.Count);
82+
8283
// Remove all completed tasks.
8384
foreach (var task in runningTasks.Where(task => task.Task.IsCompleted).ToList())
8485
{
8586
task.Scope.Dispose();
8687
runningTasks.Remove(task);
8788
}
8889

90+
_logger.LogInformation("Number of running Tasks after removing completed tasks {RunningTasksCount}.", runningTasks.Count);
91+
8992
// Get list of available jobs.
9093
if (runningTasks.Count < _reindexJobConfiguration.MaximumNumberOfConcurrentJobsAllowed)
9194
{
9295
using IScoped<IFhirOperationDataStore> store = _fhirOperationDataStoreFactory.Invoke();
9396

94-
_logger.LogTrace("Querying datastore for reindex jobs.");
97+
_logger.LogInformation("Querying datastore for reindex jobs.");
9598

9699
IReadOnlyCollection<ReindexJobWrapper> jobs = await store.Value.AcquireReindexJobsAsync(
97100
_reindexJobConfiguration.MaximumNumberOfConcurrentJobsAllowed,
98101
_reindexJobConfiguration.JobHeartbeatTimeoutThreshold,
99102
cancellationToken);
100103

104+
_logger.LogInformation("No.of reindex jobs picked.{JobsPicked} ", jobs.Count);
105+
101106
foreach (ReindexJobWrapper job in jobs)
102107
{
103-
_logger.LogTrace("Picked up reindex job: {JobId}.", job.JobRecord.Id);
108+
_logger.LogInformation("Picked up reindex job: {JobId}.", job.JobRecord.Id);
104109

105110
IScoped<IReindexJobTask> reindexJobScope = _reindexJobTaskFactory.Invoke();
106111
runningTasks.Add(
@@ -112,6 +117,7 @@ public async Task ExecuteAsync(CancellationToken cancellationToken)
112117
catch (OperationCanceledException) when (cancellationToken.IsCancellationRequested)
113118
{
114119
// End the execution of the task
120+
_logger.LogDebug("Polling Reindex jobs canceled.");
115121
}
116122
catch (Exception ex)
117123
{
@@ -127,6 +133,7 @@ public async Task ExecuteAsync(CancellationToken cancellationToken)
127133
catch (OperationCanceledException) when (cancellationToken.IsCancellationRequested)
128134
{
129135
// End the execution of the task
136+
_logger.LogDebug("Reindex job worker canceled.");
130137
}
131138
}
132139
}

src/Microsoft.Health.Fhir.SqlServer/Features/Search/SqlServerSearchService.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
using System.Threading;
1717
using System.Threading.Tasks;
1818
using EnsureThat;
19+
using Hl7.Fhir.Rest;
1920
using Microsoft.Data.SqlClient;
2021
using Microsoft.Extensions.Logging;
2122
using Microsoft.Extensions.Options;
@@ -920,6 +921,7 @@ protected async override Task<SearchResult> SearchForReindexInternalAsync(Search
920921
results = new SearchResult(0, new List<Tuple<string, string>>());
921922
}
922923

924+
_logger.LogInformation("For Reindex, Resource Type={ResourceType} Count={Count} MaxResourceSurrogateId={MaxResourceSurrogateId}", resourceType, results.TotalCount, results.MaxResourceSurrogateId);
923925
return results;
924926
}
925927

0 commit comments

Comments
 (0)