Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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 @@ -3,6 +3,7 @@ namespace Microsoft.ComponentDetection.Orchestrator.Experiments.Configs;
using Microsoft.ComponentDetection.Contracts;
using Microsoft.ComponentDetection.Detectors.Linux;
using Microsoft.ComponentDetection.Detectors.Npm;
using Microsoft.ComponentDetection.Detectors.NuGet;
using Microsoft.ComponentDetection.Detectors.Pip;

/// <summary>
Expand All @@ -22,12 +23,27 @@ public bool IsInControlGroup(IComponentDetector componentDetector) =>
is (LinuxContainerDetector and not LinuxApplicationLayerDetector)
or NpmComponentDetector
or NpmLockfileDetectorBase
or PipReportComponentDetector;
or PipReportComponentDetector
or NuGetComponentDetector
or NuGetProjectModelProjectCentricComponentDetector
or NuGetPackagesConfigDetector;

/// <inheritdoc />
public bool IsInExperimentGroup(IComponentDetector componentDetector) =>
componentDetector is LinuxApplicationLayerDetector;

/// <inheritdoc />
public bool ShouldRecord(IComponentDetector componentDetector, int numComponents) => true;
public bool ShouldRecord(IComponentDetector componentDetector, int numComponents)
{
// Only record telemetry if the experiment group detector (LinuxApplicationLayerDetector)
// actually found components.
if (componentDetector is LinuxApplicationLayerDetector)
{
return numComponents > 0;
}

// For control group detectors, record if the experiment group found anything
// This will be determined by the orchestrator based on whether the experiment group had components
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ namespace Microsoft.ComponentDetection.Orchestrator.Tests.Experiments;
using AwesomeAssertions;
using Microsoft.ComponentDetection.Detectors.Linux;
using Microsoft.ComponentDetection.Detectors.Npm;
using Microsoft.ComponentDetection.Detectors.NuGet;
using Microsoft.ComponentDetection.Detectors.Pip;
using Microsoft.ComponentDetection.Orchestrator.Experiments.Configs;
using Microsoft.VisualStudio.TestTools.UnitTesting;
Expand Down Expand Up @@ -41,6 +42,27 @@ public void IsInControlGroup_NpmComponentDetectorWithRoots_ReturnsTrue()
this.experiment.IsInControlGroup(npmDetectorWithRoots).Should().BeTrue();
}

[TestMethod]
public void IsInControlGroup_NuGetComponentDetector_ReturnsTrue()
{
var nuGetDetector = new NuGetComponentDetector(null, null, null);
this.experiment.IsInControlGroup(nuGetDetector).Should().BeTrue();
}

[TestMethod]
public void IsInControlGroup_NuGetProjectModelProjectCentricComponentDetector_ReturnsTrue()
{
var nuGetDetector = new NuGetProjectModelProjectCentricComponentDetector(null, null, null, null);
this.experiment.IsInControlGroup(nuGetDetector).Should().BeTrue();
}

[TestMethod]
public void IsInControlGroup_NuGetPackagesConfigDetector_ReturnsTrue()
{
var nuGetPackagesConfigDetector = new NuGetPackagesConfigDetector(null, null, null);
this.experiment.IsInControlGroup(nuGetPackagesConfigDetector).Should().BeTrue();
}

[TestMethod]
public void IsInControlGroup_PipReportComponentDetector_ReturnsTrue()
{
Expand Down Expand Up @@ -118,4 +140,54 @@ public void IsInExperimentGroup_PipReportComponentDetector_ReturnsFalse()

this.experiment.IsInExperimentGroup(pipDetector).Should().BeFalse();
}

[TestMethod]
public void IsInExperimentGroup_NuGetComponentDetector_ReturnsFalse()
{
var nuGetDetector = new NuGetComponentDetector(null, null, null);
this.experiment.IsInExperimentGroup(nuGetDetector).Should().BeFalse();
}

[TestMethod]
public void IsInExperimentGroup_NuGetProjectModelProjectCentricComponentDetector_ReturnsFalse()
{
var nuGetDetector = new NuGetProjectModelProjectCentricComponentDetector(null, null, null, null);
this.experiment.IsInExperimentGroup(nuGetDetector).Should().BeFalse();
}

[TestMethod]
public void ShouldRecord_ExperimentGroup_ReturnsTrue_WhenNumComponentsGreaterThanZero()
{
var experimentalDetector = new LinuxApplicationLayerDetector(null, null, null);
this.experiment.ShouldRecord(experimentalDetector, 1).Should().BeTrue();
}

[TestMethod]
public void ShouldRecord_ExperimentGroup_ReturnsFalse_WhenNumComponentsIsZero()
{
var experimentalDetector = new LinuxApplicationLayerDetector(null, null, null);
this.experiment.ShouldRecord(experimentalDetector, 0).Should().BeFalse();
}

[TestMethod]
public void ShouldRecord_ControlGroup_AlwaysReturnsTrue()
{
var linuxDetector = new LinuxContainerDetector(null, null, null);
this.experiment.ShouldRecord(linuxDetector, 0).Should().BeTrue();

var npmDetector = new NpmComponentDetector(null, null, null);
this.experiment.ShouldRecord(npmDetector, 0).Should().BeTrue();

var pipDetector = new PipReportComponentDetector(null, null, null, null, null, null, null, null, null);
this.experiment.ShouldRecord(pipDetector, 0).Should().BeTrue();

var nuGetDetector = new NuGetComponentDetector(null, null, null);
this.experiment.ShouldRecord(nuGetDetector, 0).Should().BeTrue();

var nuGetProjectCentricDetector = new NuGetProjectModelProjectCentricComponentDetector(null, null, null, null);
this.experiment.ShouldRecord(nuGetProjectCentricDetector, 0).Should().BeTrue();

var nuGetPackagesConfigDetector = new NuGetPackagesConfigDetector(null, null, null);
this.experiment.ShouldRecord(nuGetPackagesConfigDetector, 0).Should().BeTrue();
}
}
Loading