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

track total egress bytes on stow #3337

Merged
merged 2 commits into from
Feb 3, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,9 @@ public class DefaultDicomRequestContext : IDicomRequestContext
public IDictionary<string, StringValues> ResponseHeaders { get; set; }

public int Version { get; set; }

/// <summary>
/// Egress bytes from Dicom server to other resources
/// </summary>
public long TotalEgressBytes { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -155,12 +155,15 @@ public async Task GivenAValidDicomInstanceEntry_WhenProcessed_ThenSuccessfulEntr
IDicomInstanceEntry dicomInstanceEntry = Substitute.For<IDicomInstanceEntry>();

dicomInstanceEntry.GetDicomDatasetAsync(DefaultCancellationToken).Returns(_dicomDataset1);
long bytesStored = 100L;
_storeOrchestrator.StoreDicomInstanceEntryAsync(dicomInstanceEntry, DefaultCancellationToken).Returns(bytesStored);

await ExecuteAndValidateAsync(dicomInstanceEntry);

_storeResponseBuilder.Received(1).AddSuccess(_dicomDataset1, DefaultStoreValidationResult, _dicomRequestContext.DataPartition);
_storeResponseBuilder.DidNotReceiveWithAnyArgs().AddFailure(default);
Assert.Equal(1, _dicomRequestContextAccessor.RequestContext.PartCount);
Assert.Equal(bytesStored, _dicomRequestContextAccessor.RequestContext.TotalEgressBytes);
}

[Fact]
Expand All @@ -174,6 +177,8 @@ public async Task GiveAnInvalidDicomDataset_WhenProcessed_ThenFailedEntryShouldB

_storeResponseBuilder.DidNotReceiveWithAnyArgs().AddSuccess(default, DefaultStoreValidationResult, Partition.Default);
_storeResponseBuilder.Received(1).AddFailure(null, TestConstants.ProcessingFailureReasonCode);
Assert.Equal(0, _dicomRequestContextAccessor.RequestContext.TotalEgressBytes);
await _storeOrchestrator.DidNotReceiveWithAnyArgs().StoreDicomInstanceEntryAsync(Arg.Any<IDicomInstanceEntry>(), Arg.Any<CancellationToken>());
}

[Fact]
Expand All @@ -187,6 +192,8 @@ public async Task GivenADicomDatasetFailsToOpenDueToDicomValidationException_Whe

_storeResponseBuilder.DidNotReceiveWithAnyArgs().AddSuccess(default, DefaultStoreValidationResult, Partition.Default);
_storeResponseBuilder.Received(1).AddFailure(null, TestConstants.ValidationFailureReasonCode);
Assert.Equal(0, _dicomRequestContextAccessor.RequestContext.TotalEgressBytes);
await _storeOrchestrator.DidNotReceiveWithAnyArgs().StoreDicomInstanceEntryAsync(Arg.Any<IDicomInstanceEntry>(), Arg.Any<CancellationToken>());
}

[Fact]
Expand All @@ -199,6 +206,8 @@ public async Task GivenAValidationError_WhenDropDataEnabled_ThenSucceedsWithErro
dicomDataset.Add(DicomTag.StudyDate, "NotAValidStudyDate");

dicomInstanceEntry.GetDicomDatasetAsync(DefaultCancellationToken).Returns(dicomDataset);
long bytesStored = 100L;
_storeOrchestrator.StoreDicomInstanceEntryAsync(dicomInstanceEntry, DefaultCancellationToken).Returns(bytesStored);

// call
StoreResponse response = await _storeServiceDropData.ProcessAsync(
Expand Down Expand Up @@ -235,6 +244,8 @@ await _storeOrchestrator
dicomInstanceEntry,
DefaultCancellationToken
);

Assert.Equal(bytesStored, _dicomRequestContextAccessorLatestApi.RequestContext.TotalEgressBytes);
}

[Fact]
Expand All @@ -247,6 +258,8 @@ public async Task GivenAValidationErrorOnNonCoreTag_WhenDropDataEnabledAndFullDi
dicomDataset.Add(DicomTag.StudyDate, "NotAValidStudyDate");

dicomInstanceEntry.GetDicomDatasetAsync(DefaultCancellationToken).Returns(dicomDataset);
long bytesStored = 100L;
_storeOrchestrator.StoreDicomInstanceEntryAsync(dicomInstanceEntry, DefaultCancellationToken).Returns(bytesStored);

// call
StoreResponse response = await _storeServiceDropData.ProcessAsync(
Expand Down Expand Up @@ -283,6 +296,8 @@ await _storeOrchestrator
dicomInstanceEntry,
DefaultCancellationToken
);

Assert.Equal(bytesStored, _dicomRequestContextAccessorLatestApi.RequestContext.TotalEgressBytes);
}

[Fact]
Expand Down Expand Up @@ -515,10 +530,12 @@ public async Task GivenAnExternalStoreExceptionWhenStoring_WhenProcessed_ThenExp
}

[Fact]
public async Task GivenMultipleDicomInstanceEntries_WhenProcessed_ThenCorrespondingEntryShouldBeAdded()
public async Task GivenMultipleDicomInstanceEntriesWithFailure_WhenProcessed_ThenCorrespondingEntryShouldBeAdded()
{
IDicomInstanceEntry dicomInstanceEntryToSucceed = Substitute.For<IDicomInstanceEntry>();
IDicomInstanceEntry dicomInstanceEntryToFail = Substitute.For<IDicomInstanceEntry>();
long bytesStored = 100L;
_storeOrchestrator.StoreDicomInstanceEntryAsync(Arg.Any<IDicomInstanceEntry>(), DefaultCancellationToken).Returns(bytesStored);

dicomInstanceEntryToSucceed.GetDicomDatasetAsync(DefaultCancellationToken).Returns(_dicomDataset1);
dicomInstanceEntryToFail.GetDicomDatasetAsync(DefaultCancellationToken).Returns(_dicomDataset2);
Expand All @@ -535,6 +552,56 @@ public async Task GivenMultipleDicomInstanceEntries_WhenProcessed_ThenCorrespond
_storeResponseBuilder.Received(1).AddSuccess(_dicomDataset1, DefaultStoreValidationResult, _dicomRequestContext.DataPartition);
_storeResponseBuilder.Received(1).AddFailure(_dicomDataset2, TestConstants.ProcessingFailureReasonCode);
Assert.Equal(2, _dicomRequestContextAccessor.RequestContext.PartCount);

await _storeOrchestrator
.Received(1)
.StoreDicomInstanceEntryAsync(
dicomInstanceEntryToSucceed,
DefaultCancellationToken
);

await _storeOrchestrator
.DidNotReceive()
.StoreDicomInstanceEntryAsync(
dicomInstanceEntryToFail,
DefaultCancellationToken
);

Assert.Equal(bytesStored, _dicomRequestContextAccessor.RequestContext.TotalEgressBytes);
}

[Fact]
public async Task GivenMultipleDicomInstanceEntries_WhenProcessed_ThenTotalBytesTracked()
{
IDicomInstanceEntry dicomInstanceEntryToSucceed = Substitute.For<IDicomInstanceEntry>();
IDicomInstanceEntry dicomInstanceEntryToSucceed2 = Substitute.For<IDicomInstanceEntry>();
long bytesStored = 100L;
long totalExpectedBytesStored = bytesStored * 2;
_storeOrchestrator.StoreDicomInstanceEntryAsync(Arg.Any<IDicomInstanceEntry>(), DefaultCancellationToken).Returns(bytesStored);

dicomInstanceEntryToSucceed.GetDicomDatasetAsync(DefaultCancellationToken).Returns(_dicomDataset1);
dicomInstanceEntryToSucceed2.GetDicomDatasetAsync(DefaultCancellationToken).Returns(_dicomDataset2);

await ExecuteAndValidateAsync(dicomInstanceEntryToSucceed, dicomInstanceEntryToSucceed2);

_storeResponseBuilder.Received(1).AddSuccess(_dicomDataset1, DefaultStoreValidationResult, _dicomRequestContext.DataPartition);
_storeResponseBuilder.Received(1).AddSuccess(_dicomDataset2, DefaultStoreValidationResult, _dicomRequestContext.DataPartition);

await _storeOrchestrator
.Received(1)
.StoreDicomInstanceEntryAsync(
dicomInstanceEntryToSucceed,
DefaultCancellationToken
);

await _storeOrchestrator
.Received(1)
.StoreDicomInstanceEntryAsync(
dicomInstanceEntryToSucceed2,
DefaultCancellationToken
);

Assert.Equal(totalExpectedBytesStored, _dicomRequestContextAccessor.RequestContext.TotalEgressBytes);
}

[Fact]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,9 @@ public DicomRequestContext(
public IDictionary<string, StringValues> RequestHeaders { get; }

public IDictionary<string, StringValues> ResponseHeaders { get; }

/// <summary>
/// Egress bytes from Dicom server to other resources
/// </summary>
public long TotalEgressBytes { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,9 @@ public interface IDicomRequestContext : IRequestContext

// Opportunity for the core to change based on the caller version
int Version { get; set; }

/// <summary>
/// Egress bytes from Dicom server to other resources
/// </summary>
long TotalEgressBytes { get; set; }
esmadau marked this conversation as resolved.
Show resolved Hide resolved
}
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ public async Task<StoreResponse> ProcessAsync(
_dicomRequestContextAccessor.RequestContext.PartCount = instanceEntries.Count;
_dicomInstanceEntries = instanceEntries;
_requiredStudyInstanceUid = requiredStudyInstanceUid;
long totalBytesStored = 0L;

for (int index = 0; index < instanceEntries.Count; index++)
{
Expand All @@ -115,6 +116,7 @@ public async Task<StoreResponse> ProcessAsync(
long len = length.GetValueOrDefault();
// Update Telemetry
_storeMeter.InstanceLength.Record(len);
totalBytesStored += len;
esmadau marked this conversation as resolved.
Show resolved Hide resolved
}
}
finally
Expand All @@ -125,6 +127,7 @@ public async Task<StoreResponse> ProcessAsync(
_ = Task.Run(() => DisposeResourceAsync(capturedIndex), CancellationToken.None);
}
}
_dicomRequestContextAccessor.RequestContext.TotalEgressBytes = totalBytesStored;
}

return _storeResponseBuilder.BuildResponse(requiredStudyInstanceUid, returnWarning202);
Expand Down
Loading