Skip to content

Commit

Permalink
Log AcceptHeaders for diagnosis convenience (#356)
Browse files Browse the repository at this point in the history
Example Log:
Getting transfer syntax for retrieving 'Frames' with accept headers 'MediaType:'application/octet-stream', PayloadType:'MultipartRelated', TransferSyntax:'', Quality:'''.
  • Loading branch information
pengchen0692 committed Sep 28, 2020
1 parent 9786fb8 commit 98f25e3
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public RetrieveResourceServiceTests()
_fileStore = Substitute.For<IFileStore>();
_retrieveTranscoder = Substitute.For<ITranscoder>();
_dicomFrameHandler = Substitute.For<IFrameHandler>();
_retrieveTransferSyntaxHandler = new RetrieveTransferSyntaxHandler();
_retrieveTransferSyntaxHandler = new RetrieveTransferSyntaxHandler(NullLogger<RetrieveTransferSyntaxHandler>.Instance);
_logger = NullLogger<RetrieveResourceService>.Instance;
_recyclableMemoryStreamManager = new RecyclableMemoryStreamManager();
_retrieveResourceService = new RetrieveResourceService(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
// -------------------------------------------------------------------------------------------------

using Dicom;
using Microsoft.Extensions.Logging.Abstractions;
using Microsoft.Health.Dicom.Core.Exceptions;
using Microsoft.Health.Dicom.Core.Features.Retrieve;
using Microsoft.Health.Dicom.Core.Messages;
Expand All @@ -20,7 +21,7 @@ public class RetrieveTransferSyntaxHandlerTests

public RetrieveTransferSyntaxHandlerTests()
{
_handler = new RetrieveTransferSyntaxHandler();
_handler = new RetrieveTransferSyntaxHandler(NullLogger<RetrieveTransferSyntaxHandler>.Instance);
}

[Fact(Skip = "Will be enabled later as https://microsofthealth.visualstudio.com/Health/_workitems/edit/75782")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,17 @@ public void GivenValidInput_WhenConstructAcceptHeader_ThenShouldSucceed()
Assert.Equal(transferSytnax, header.TransferSyntax);
Assert.Equal(quality, header.Quality);
}

[Fact]
public void GivenValidInput_WhenToString_ThenShouldReturnExpectedContent()
{
StringSegment mediaType = KnownContentTypes.ApplicationDicom;
PayloadTypes payloadType = PayloadTypes.MultipartRelated;
StringSegment transferSytnax = DicomTransferSyntax.ExplicitVRLittleEndian.UID.UID;
double quality = 0.5;
AcceptHeader header = new AcceptHeader(mediaType, payloadType, transferSytnax, quality);

Assert.Equal($"MediaType:'{mediaType}', PayloadType:'{payloadType}', TransferSyntax:'{transferSytnax}', Quality:'{quality}'", header.ToString());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using System.Linq;
using Dicom;
using EnsureThat;
using Microsoft.Extensions.Logging;
using Microsoft.Health.Dicom.Core.Exceptions;
using Microsoft.Health.Dicom.Core.Messages;
using Microsoft.Health.Dicom.Core.Messages.Retrieve;
Expand All @@ -28,17 +29,28 @@ public class RetrieveTransferSyntaxHandler : IRetrieveTransferSyntaxHandler

private readonly IReadOnlyDictionary<ResourceType, AcceptHeaderDescriptors> _acceptableDescriptors;

public RetrieveTransferSyntaxHandler()
: this(AcceptableDescriptors)
private readonly ILogger<RetrieveTransferSyntaxHandler> _logger;

public RetrieveTransferSyntaxHandler(ILogger<RetrieveTransferSyntaxHandler> logger)
: this(AcceptableDescriptors, logger)
{
}

public RetrieveTransferSyntaxHandler(IReadOnlyDictionary<ResourceType, AcceptHeaderDescriptors> acceptableDescriptors) => _acceptableDescriptors = acceptableDescriptors;
public RetrieveTransferSyntaxHandler(IReadOnlyDictionary<ResourceType, AcceptHeaderDescriptors> acceptableDescriptors, ILogger<RetrieveTransferSyntaxHandler> logger)
{
EnsureArg.IsNotNull(logger, nameof(logger));
EnsureArg.IsNotNull(acceptableDescriptors, nameof(acceptableDescriptors));

_acceptableDescriptors = acceptableDescriptors;
_logger = logger;
}

public string GetTransferSyntax(ResourceType resourceType, IEnumerable<AcceptHeader> acceptHeaders, out AcceptHeaderDescriptor acceptableHeaderDescriptor)
{
EnsureArg.IsNotNull(acceptHeaders, nameof(acceptHeaders));

_logger.LogInformation($"Getting transfer syntax for retrieving '{resourceType}' with accept headers '{string.Join(";", acceptHeaders)}'.");

// TODO: disable multiple accept headers, will fully implement it later (https://microsofthealth.visualstudio.com/Health/_workitems/edit/75782)
if (acceptHeaders.Count() > 1)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,10 @@ public AcceptHeader(StringSegment mediaType, PayloadTypes payloadType, StringSeg
public StringSegment TransferSyntax { get; }

public double? Quality { get; }

public override string ToString()
{
return $"MediaType:'{MediaType}', PayloadType:'{PayloadType}', TransferSyntax:'{TransferSyntax}', Quality:'{Quality}'";
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public RetrieveResourceServiceTests(DataStoreTestsFixture blobStorageFixture, Sq
_fileStore = blobStorageFixture.FileStore;
_retrieveTranscoder = Substitute.For<ITranscoder>();
_frameHandler = Substitute.For<IFrameHandler>();
_retrieveTransferSyntaxHandler = new RetrieveTransferSyntaxHandler();
_retrieveTransferSyntaxHandler = new RetrieveTransferSyntaxHandler(NullLogger<RetrieveTransferSyntaxHandler>.Instance);
_recyclableMemoryStreamManager = blobStorageFixture.RecyclableMemoryStreamManager;
_retrieveResourceService = new RetrieveResourceService(
_instanceStore, _fileStore, _retrieveTranscoder, _frameHandler, _retrieveTransferSyntaxHandler, blobStorageFixture.RecyclableMemoryStreamManager, NullLogger<RetrieveResourceService>.Instance);
Expand Down

0 comments on commit 98f25e3

Please sign in to comment.