@@ -191,9 +191,11 @@ public void GetSnapshot_With_JobMemoryLimit_Set_To_Zero_ProducesCorrectSnapshot(
191191 }
192192
193193 [ Theory ]
194- [ InlineData ( ResourceUtilizationInstruments . ProcessCpuUtilization ) ]
195- [ InlineData ( ResourceUtilizationInstruments . ContainerCpuLimitUtilization ) ]
196- public void SnapshotProvider_EmitsCpuMetrics ( string instrumentName )
194+ [ InlineData ( ResourceUtilizationInstruments . ProcessCpuUtilization , true ) ]
195+ [ InlineData ( ResourceUtilizationInstruments . ProcessCpuUtilization , false ) ]
196+ [ InlineData ( ResourceUtilizationInstruments . ContainerCpuLimitUtilization , true ) ]
197+ [ InlineData ( ResourceUtilizationInstruments . ContainerCpuLimitUtilization , false ) ]
198+ public void SnapshotProvider_EmitsCpuMetrics ( string instrumentName , bool useZeroToOneRange )
197199 {
198200 // Simulating 10% CPU usage (2 CPUs, 2000 ticks initially, 4000 ticks after 1 ms):
199201 JOBOBJECT_BASIC_ACCOUNTING_INFORMATION updatedAccountingInfo = default ;
@@ -216,8 +218,12 @@ public void SnapshotProvider_EmitsCpuMetrics(string instrumentName)
216218 . Returns ( meter ) ;
217219 using var metricCollector = new MetricCollector < double > ( meter , instrumentName , fakeClock ) ;
218220
219- var options = new ResourceMonitoringOptions { CpuConsumptionRefreshInterval = TimeSpan . FromMilliseconds ( 2 ) } ;
220-
221+ var options = new ResourceMonitoringOptions
222+ {
223+ CpuConsumptionRefreshInterval = TimeSpan . FromMilliseconds ( 2 ) ,
224+ UseZeroToOneRangeForMetrics = useZeroToOneRange
225+ } ;
226+ var multiplier = useZeroToOneRange ? 1 : 100 ;
221227 var snapshotProvider = new WindowsContainerSnapshotProvider (
222228 _memoryInfoMock . Object ,
223229 _systemInfoMock . Object ,
@@ -237,27 +243,29 @@ public void SnapshotProvider_EmitsCpuMetrics(string instrumentName)
237243 fakeClock . Advance ( TimeSpan . FromMilliseconds ( 1 ) ) ;
238244 metricCollector . RecordObservableInstruments ( ) ;
239245
240- Assert . Equal ( 10 , metricCollector . LastMeasurement . Value ) ; // Consumed 10% of the CPU.
246+ Assert . Equal ( 0.1 * multiplier , metricCollector . LastMeasurement . Value ) ; // Consumed 10% of the CPU.
241247
242248 // Step #2 - simulate 1 millisecond passing and collect metrics again:
243249 fakeClock . Advance ( TimeSpan . FromMilliseconds ( 1 ) ) ;
244250 metricCollector . RecordObservableInstruments ( ) ;
245251
246252 // CPU usage should be the same as before, as we didn't recalculate it:
247- Assert . Equal ( 10 , metricCollector . LastMeasurement . Value ) ; // Still consuming 10% as gauge wasn't updated.
253+ Assert . Equal ( 0.1 * multiplier , metricCollector . LastMeasurement . Value ) ; // Still consuming 10% as gauge wasn't updated.
248254
249255 // Step #3 - simulate 1 millisecond passing and collect metrics again:
250256 fakeClock . Advance ( TimeSpan . FromMilliseconds ( 1 ) ) ;
251257 metricCollector . RecordObservableInstruments ( ) ;
252258
253259 // CPU usage should be the same as before, as we're not simulating any CPU usage:
254- Assert . Equal ( 10 , metricCollector . LastMeasurement . Value ) ; // Consumed 10% of the CPU.
260+ Assert . Equal ( 0.1 * multiplier , metricCollector . LastMeasurement . Value ) ; // Consumed 10% of the CPU.
255261 }
256262
257263 [ Theory ]
258- [ InlineData ( ResourceUtilizationInstruments . ProcessMemoryUtilization ) ]
259- [ InlineData ( ResourceUtilizationInstruments . ContainerMemoryLimitUtilization ) ]
260- public void SnapshotProvider_EmitsMemoryMetrics ( string instrumentName )
264+ [ InlineData ( ResourceUtilizationInstruments . ProcessMemoryUtilization , true ) ]
265+ [ InlineData ( ResourceUtilizationInstruments . ProcessMemoryUtilization , false ) ]
266+ [ InlineData ( ResourceUtilizationInstruments . ContainerMemoryLimitUtilization , true ) ]
267+ [ InlineData ( ResourceUtilizationInstruments . ContainerMemoryLimitUtilization , false ) ]
268+ public void SnapshotProvider_EmitsMemoryMetrics ( string instrumentName , bool useZeroToOneRange )
261269 {
262270 _appMemoryUsage = 200UL ;
263271 ulong updatedAppMemoryUsage = 600UL ;
@@ -279,8 +287,12 @@ public void SnapshotProvider_EmitsMemoryMetrics(string instrumentName)
279287 . Returns ( meter ) ;
280288 using var metricCollector = new MetricCollector < double > ( meter , instrumentName , fakeClock ) ;
281289
282- var options = new ResourceMonitoringOptions { MemoryConsumptionRefreshInterval = TimeSpan . FromMilliseconds ( 2 ) } ;
283-
290+ var options = new ResourceMonitoringOptions
291+ {
292+ MemoryConsumptionRefreshInterval = TimeSpan . FromMilliseconds ( 2 ) ,
293+ UseZeroToOneRangeForMetrics = useZeroToOneRange
294+ } ;
295+ var multiplier = useZeroToOneRange ? 1 : 100 ;
284296 var snapshotProvider = new WindowsContainerSnapshotProvider (
285297 _memoryInfoMock . Object ,
286298 _systemInfoMock . Object ,
@@ -294,17 +306,17 @@ public void SnapshotProvider_EmitsMemoryMetrics(string instrumentName)
294306 // Step #0 - state in the beginning:
295307 metricCollector . RecordObservableInstruments ( ) ;
296308 Assert . NotNull ( metricCollector . LastMeasurement ? . Value ) ;
297- Assert . Equal ( 10 , metricCollector . LastMeasurement . Value ) ; // Consuming 10% of the memory initially.
309+ Assert . Equal ( 0.1 * multiplier , metricCollector . LastMeasurement . Value ) ; // Consuming 10% of the memory initially.
298310
299311 // Step #1 - simulate 1 millisecond passing and collect metrics again:
300312 fakeClock . Advance ( options . MemoryConsumptionRefreshInterval - TimeSpan . FromMilliseconds ( 1 ) ) ;
301313 metricCollector . RecordObservableInstruments ( ) ;
302- Assert . Equal ( 10 , metricCollector . LastMeasurement . Value ) ; // Still consuming 10% as gauge wasn't updated.
314+ Assert . Equal ( 0.1 * multiplier , metricCollector . LastMeasurement . Value ) ; // Still consuming 10% as gauge wasn't updated.
303315
304316 // Step #2 - simulate 2 milliseconds passing and collect metrics again:
305317 fakeClock . Advance ( TimeSpan . FromMilliseconds ( 1 ) ) ;
306318 metricCollector . RecordObservableInstruments ( ) ;
307- Assert . Equal ( 30 , metricCollector . LastMeasurement . Value ) ; // Consuming 30% of the memory afterwards.
319+ Assert . Equal ( 0.3 * multiplier , metricCollector . LastMeasurement . Value ) ; // Consuming 30% of the memory afterwards.
308320 }
309321
310322 [ Fact ]
0 commit comments