@@ -217,6 +217,7 @@ func expectedEBC(totCap, targetBC, recordedConcurrency, numPods float64) int32 {
217217}
218218
219219func TestAutoscalerStartMetrics (t * testing.T ) {
220+ expectedAttrs := attribute .NewSet (attribute .String ("foo" , "bar" ))
220221 metrics := & metricClient {StableConcurrency : 50.0 , PanicConcurrency : 50.0 }
221222
222223 _ , _ , reader := newTestAutoscalerWithScalingMetric (
@@ -227,39 +228,16 @@ func TestAutoscalerStartMetrics(t *testing.T) {
227228
228229 metricstest .AssertMetrics (
229230 t , reader ,
230- metricstest .MetricsEqual (scopeName , panicMetric (true )),
231- )
232- }
233-
234- func TestAutoscalerMetrics (t * testing.T ) {
235- metrics := & metricClient {StableConcurrency : 50.0 , PanicConcurrency : 50.0 }
236- a , _ , reader := newTestAutoscaler (10 , 100 , metrics )
237- expectedAttrs := attribute .NewSet (attribute .String ("foo" , "bar" ))
238-
239- // Non-panic created autoscaler.
240- metricstest .AssertMetrics (
241- t , reader ,
242- metricstest .MetricsEqual (scopeName , panicMetric (false )),
243- )
244-
245- ebc := expectedEBC (10 , 100 , 50 , 1 )
246- expectScale (t , a , time .Now (), ScaleResult {5 , ebc , true })
247- spec := a .currentSpec ()
248-
249- metricstest .AssertMetrics (
250- t , reader ,
251- metricstest .MetricsEqual (
252- scopeName ,
231+ metricstest .MetricsEqual (scopeName ,
253232 panicMetric (true ),
254-
255233 metricdata.Metrics {
256234 Name : "kn.revision.pods.desired" ,
257235 Description : "Number of pods the autoscaler wants to allocate" ,
258236 Unit : "{item}" ,
259237 Data : metricdata.Gauge [int64 ]{
260238 DataPoints : []metricdata.DataPoint [int64 ]{{
261239 Attributes : expectedAttrs ,
262- Value : 5 ,
240+ Value : 0 ,
263241 }},
264242 },
265243 },
@@ -271,7 +249,7 @@ func TestAutoscalerMetrics(t *testing.T) {
271249 Data : metricdata.Gauge [float64 ]{
272250 DataPoints : []metricdata.DataPoint [float64 ]{{
273251 Attributes : expectedAttrs ,
274- Value : float64 (ebc ),
252+ Value : float64 (0 ),
275253 }},
276254 },
277255 },
@@ -283,7 +261,7 @@ func TestAutoscalerMetrics(t *testing.T) {
283261 Data : metricdata.Gauge [float64 ]{
284262 DataPoints : []metricdata.DataPoint [float64 ]{{
285263 Attributes : expectedAttrs ,
286- Value : 50 ,
264+ Value : 0 ,
287265 }},
288266 },
289267 },
@@ -295,7 +273,7 @@ func TestAutoscalerMetrics(t *testing.T) {
295273 Data : metricdata.Gauge [float64 ]{
296274 DataPoints : []metricdata.DataPoint [float64 ]{{
297275 Attributes : expectedAttrs ,
298- Value : 50 ,
276+ Value : 0 ,
299277 }},
300278 },
301279 },
@@ -307,14 +285,39 @@ func TestAutoscalerMetrics(t *testing.T) {
307285 Data : metricdata.Gauge [float64 ]{
308286 DataPoints : []metricdata.DataPoint [float64 ]{{
309287 Attributes : expectedAttrs ,
310- Value : float64 (spec . TargetValue ),
288+ Value : float64 (0 ),
311289 }},
312290 },
313291 },
314292 ),
315293 )
316294}
317295
296+ func TestAutoscalerMetrics (t * testing.T ) {
297+ metrics := & metricClient {StableConcurrency : 50.0 , PanicConcurrency : 50.0 }
298+ a , _ , reader := newTestAutoscaler (10 , 100 , metrics )
299+ expectedAttrs := attribute .NewSet (attribute .String ("foo" , "bar" ))
300+
301+ expectedMetrics := concurrencyDataPoints (expectedAttrs , false , 0 , 0 , 0 , 0 , 0 )
302+
303+ // Non-panic created autoscaler.
304+ metricstest .AssertMetrics (
305+ t , reader ,
306+ metricstest .MetricsEqual (scopeName , expectedMetrics ... ),
307+ )
308+
309+ ebc := expectedEBC (10 , 100 , 50 , 1 )
310+ expectScale (t , a , time .Now (), ScaleResult {5 , ebc , true })
311+ spec := a .currentSpec ()
312+
313+ expectedMetrics = concurrencyDataPoints (expectedAttrs , true , 5 , float64 (ebc ), 50 , 50 , spec .TargetValue )
314+
315+ metricstest .AssertMetrics (
316+ t , reader ,
317+ metricstest .MetricsEqual (scopeName , expectedMetrics ... ),
318+ )
319+ }
320+
318321func TestAutoscalerMetricsWithRPS (t * testing.T ) {
319322 expectedAttrs := attribute .NewSet (attribute .String ("foo" , "bar" ))
320323 metrics := & metricClient {PanicRPS : 99.0 , StableRPS : 100 }
@@ -936,3 +939,68 @@ func panicMetric(panic bool) metricdata.Metrics {
936939 },
937940 }
938941}
942+
943+ func concurrencyDataPoints (attrs attribute.Set , isPanic bool , pods int64 , ebc , stable , panic , target float64 ) []metricdata.Metrics {
944+ return []metricdata.Metrics {
945+ panicMetric (isPanic ),
946+ {
947+ Name : "kn.revision.pods.desired" ,
948+ Description : "Number of pods the autoscaler wants to allocate" ,
949+ Unit : "{item}" ,
950+ Data : metricdata.Gauge [int64 ]{
951+ DataPoints : []metricdata.DataPoint [int64 ]{{
952+ Attributes : attrs ,
953+ Value : pods ,
954+ }},
955+ },
956+ },
957+
958+ {
959+ Name : "kn.revision.capacity.excess" ,
960+ Description : "Excess burst capacity observed over the stable window" ,
961+ Unit : "{concurrency}" ,
962+ Data : metricdata.Gauge [float64 ]{
963+ DataPoints : []metricdata.DataPoint [float64 ]{{
964+ Attributes : attrs ,
965+ Value : ebc ,
966+ }},
967+ },
968+ },
969+
970+ {
971+ Name : "kn.revision.concurrency.stable" ,
972+ Description : "Average of request count per observed pod over the stable window" ,
973+ Unit : "{concurrency}" ,
974+ Data : metricdata.Gauge [float64 ]{
975+ DataPoints : []metricdata.DataPoint [float64 ]{{
976+ Attributes : attrs ,
977+ Value : stable ,
978+ }},
979+ },
980+ },
981+
982+ {
983+ Name : "kn.revision.concurrency.panic" ,
984+ Description : "Average of request count per observed pod over the panic window" ,
985+ Unit : "{concurrency}" ,
986+ Data : metricdata.Gauge [float64 ]{
987+ DataPoints : []metricdata.DataPoint [float64 ]{{
988+ Attributes : attrs ,
989+ Value : panic ,
990+ }},
991+ },
992+ },
993+
994+ {
995+ Name : "kn.revision.concurrency.target" ,
996+ Description : "The desired concurrent requests for each pod" ,
997+ Unit : "{concurrency}" ,
998+ Data : metricdata.Gauge [float64 ]{
999+ DataPoints : []metricdata.DataPoint [float64 ]{{
1000+ Attributes : attrs ,
1001+ Value : target ,
1002+ }},
1003+ },
1004+ },
1005+ }
1006+ }
0 commit comments