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

Move Location of Experiments Call to CD Internal #720

Merged
merged 28 commits into from
Aug 17, 2023
Merged
Show file tree
Hide file tree
Changes from 21 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
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ namespace Microsoft.ComponentDetection.Orchestrator.Experiments;
/// </summary>
public static class DetectorExperiments
{
/// <summary>
/// Check to automatically proccess experiments.
/// </summary>
public static bool AutomaticallyProcessExperiments { get; set; }
amitla1 marked this conversation as resolved.
Show resolved Hide resolved

/// <summary>
/// Manually enables detector experiments.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,11 @@ public async Task FinishAsync()
return;
}

if (!DetectorExperiments.AutomaticallyProcessExperiments)
amitla1 marked this conversation as resolved.
Show resolved Hide resolved
{
return;
}

foreach (var (config, experiment) in this.experiments)
{
var controlComponents = experiment.ControlGroupComponents;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,9 @@ public async Task<DetectorProcessingResult> ProcessDetectorsAsync(IDetectionArgu
record.DetectedComponentCount = detectedComponents.Count();
var dependencyGraphs = componentRecorder.GetDependencyGraphsByLocation().Values;
record.ExplicitlyReferencedComponentCount = dependencyGraphs.Select(dependencyGraph =>
{
return dependencyGraph.GetAllExplicitlyReferencedComponents();
})
{
return dependencyGraph.GetAllExplicitlyReferencedComponents();
})
.SelectMany(x => x)
.Distinct()
.Count();
Expand Down Expand Up @@ -122,6 +122,7 @@ public async Task<DetectorProcessingResult> ProcessDetectorsAsync(IDetectionArgu
}).ToList();

var results = await Task.WhenAll(scanTasks);
DetectorExperiments.AutomaticallyProcessExperiments = false;
amitla1 marked this conversation as resolved.
Show resolved Hide resolved
await this.experimentService.FinishAsync();

var detectorProcessingResult = this.ConvertDetectorResultsIntoResult(results, exitCode);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ public async Task RecordDetectorRun_FiltersExperimentsAsync()
this.loggerMock.Object);

service.RecordDetectorRun(this.detectorMock.Object, this.componentRecorder, this.detectionArgsMock.Object);
DetectorExperiments.AutomaticallyProcessExperiments = true;
await service.FinishAsync();

filterConfigMock.Verify(x => x.ShouldRecord(this.detectorMock.Object, components.Count), Times.Once());
Expand Down Expand Up @@ -151,13 +152,37 @@ public async Task FinishAsync_ProcessesExperimentsAsync()
this.loggerMock.Object);
service.RecordDetectorRun(this.detectorMock.Object, this.componentRecorder, this.detectionArgsMock.Object);

DetectorExperiments.AutomaticallyProcessExperiments = true;

await service.FinishAsync();

this.experimentProcessorMock.Verify(
x => x.ProcessExperimentAsync(this.experimentConfigMock.Object, It.IsAny<ExperimentDiff>()),
Times.Once());
}

[TestMethod]
public async Task FinishAsync_DoNotAutomaticallyProcess_ProcessesExperimentsAsync()
{
var components = ExperimentTestUtils.CreateRandomComponents();
this.SetupGraphMock(components);

var service = new ExperimentService(
new[] { this.experimentConfigMock.Object },
new[] { this.experimentProcessorMock.Object },
this.graphTranslationServiceMock.Object,
this.loggerMock.Object);
service.RecordDetectorRun(this.detectorMock.Object, this.componentRecorder, this.detectionArgsMock.Object);

DetectorExperiments.AutomaticallyProcessExperiments = false;

await service.FinishAsync();

this.experimentProcessorMock.Verify(
x => x.ProcessExperimentAsync(this.experimentConfigMock.Object, It.IsAny<ExperimentDiff>()),
Times.Never);
}

[TestMethod]
public async Task FinishAsync_SwallowsExceptionsAsync()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -520,6 +520,8 @@ public async Task ProcessDetectorsAsync_FinishesExperimentsAsync()

await this.serviceUnderTest.ProcessDetectorsAsync(DefaultArgs, this.detectorsToUse, new DetectorRestrictions());

DetectorExperiments.AutomaticallyProcessExperiments = true;
amitla1 marked this conversation as resolved.
Show resolved Hide resolved

this.experimentServiceMock.Verify(x => x.FinishAsync(), Times.Once());
}

Expand Down
Loading