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 @@ -113,7 +113,7 @@ else if (!includeTypes.isEmpty() && !includeTypes.contains(telemetry.getClass())

return false;
}
samplingSupportingTelemetry.setSamplingPercentage(telemetrySamplingScore);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

telemetrySamplingScore is a dynamically generated value based on operation id. This cannot be set as Sampling percentage after sampled in since this will affect the item count value in the analytics portal. So replaced this with testedPercentage which will have the correct sampling percentage.

samplingSupportingTelemetry.setSamplingPercentage(testedPercentage);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,16 +157,21 @@ public boolean process(Telemetry telemetry) {
if (samplingSupportingTelemetry.getSamplingPercentage() == null) {

samplingSupportingTelemetry.setSamplingPercentage(samplingPercentage);

if (SamplingScoreGeneratorV2.getSamplingScore(telemetry) >= samplingPercentage) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As per existing code , sampling will work only when the user didn't set the sampling percentage. To fix this moved the code which samples the telemetry out of the if condition.


InternalLogger.INSTANCE.info("Item %s sampled out", telemetry.getClass());
return false;
}


} else {
InternalLogger.INSTANCE.info("Item has sampling percentage already set to :"
+ samplingSupportingTelemetry.getSamplingPercentage());

samplingPercentage = samplingSupportingTelemetry.getSamplingPercentage();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Override the local sampling percentage with the user set sampling percentage. Else global sampling percentage will be applied even if the user has set the sampling percentage.

}

if (SamplingScoreGeneratorV2.getSamplingScore(telemetry) >= samplingPercentage) {

InternalLogger.INSTANCE.info("Item %s sampled out", telemetry.getClass());
return false;
}

} else {
InternalLogger.INSTANCE.trace("Skip sampling since %s type is not sampling applicable", telemetry.getClass());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,16 +56,16 @@ public void telemetryItemHasSamplingPercentageSet() {
}

@Test
public void telemetryItemSamplingIsSkippedWhenSetByUser() {
public void telemetryItemSamplingWorksWhenSetByUser() {
FixedRateSamplingTelemetryProcessor processor = new FixedRateSamplingTelemetryProcessor();
processor.setSamplingPercentage("0.0");
processor.setSamplingPercentage("100.0");
Telemetry requestTelemetry = new RequestTelemetry();
((SupportSampling)requestTelemetry).setSamplingPercentage(100.0);
((SupportSampling)requestTelemetry).setSamplingPercentage(0.0);
int sentCount = 0;
if (processor.process(requestTelemetry)) {
++sentCount;
}
Assert.assertEquals(1, sentCount);
Assert.assertEquals(0, sentCount);
}

@Test
Expand Down