Repository: knative/serving
Pull request #8113 (2020-05-28 12:03:57)

Remove unnecessary separate stat reporting code.
<!--
Request Prow to automatically lint any go code in this PR:

/lint
-->

<!-- Please include the 'why' behind your changes if no issue exists -->
## Proposed Changes

The stats reporting code of the queue-proxy has become dead simple. So simple in fact, that we might as well just inline it.

The deleted tests have all been reimplemented in the consolidation of the underlying logic. It should be safe to remove them all.

/assign @vagababov @julz 


knative-prow-robot: [APPROVALNOTIFIER] This PR is **APPROVED**

This pull-request has been approved by: *<a href="https://github.com/knative/serving/pull/8113#" title="Author self-approved">markusthoemmes</a>*

The full list of commands accepted by this bot can be found [here](https://go.k8s.io/bot-commands?repo=knative%2Fserving).

The pull request process is described [here](https://git.k8s.io/community/contributors/guide/owners.md#the-code-review-process)

<details >
Needs approval from an approver in each of these files:

- ~~[cmd/queue/OWNERS](https://github.com/knative/serving/blob/master/cmd/queue/OWNERS)~~ [markusthoemmes]
- ~~[pkg/queue/OWNERS](https://github.com/knative/serving/blob/master/pkg/queue/OWNERS)~~ [markusthoemmes]

Approvers can indicate their approval by writing `/approve` in a comment
Approvers can cancel approval by writing `/approve cancel` in a comment
</details>
<!-- META={"approvers":[]} -->
julz: /lgtm
markusthoemmes: /hold

For @vagababov to have a look too, especially at the tests.
knative-prow-robot: @markusthoemmes: The following test **failed**, say `/retest` to rerun all failed tests:

Test name | Commit | Details | Rerun command
--- | --- | --- | ---
pull-knative-serving-autotls-tests | 91c59076521193524d96359145fce6011efc5128 | [link](https://prow.knative.dev/view/gcs/knative-prow/pr-logs/pull/knative_serving/8113/pull-knative-serving-autotls-tests/1265977194396520450) | `/test pull-knative-serving-autotls-tests`

[Full PR test history](https://gubernator.knative.dev/pr/knative_serving/8113). [Your PR dashboard](https://gubernator.knative.dev/pr/markusthoemmes).

<details>

Instructions for interacting with me using PR comments are available [here](https://git.k8s.io/community/contributors/guide/pull-requests.md).  If you have questions or suggestions related to my behavior, please file an issue against the [kubernetes/test-infra](https://github.com/kubernetes/test-infra/issues/new?title=Prow%20issue:) repository. I understand the commands that are listed [here](https://go.k8s.io/bot-commands).
</details>
<!-- test report -->
knative-prow-robot: @markusthoemmes: The following tests **failed**, say `/retest` to rerun all failed tests:

Test name | Commit | Details | Rerun command
--- | --- | --- | ---
pull-knative-serving-autotls-tests | 91c59076521193524d96359145fce6011efc5128 | [link](https://prow.knative.dev/view/gcs/knative-prow/pr-logs/pull/knative_serving/8113/pull-knative-serving-autotls-tests/1265977194396520450) | `/test pull-knative-serving-autotls-tests`
pull-knative-serving-integration-tests | 91c59076521193524d96359145fce6011efc5128 | [link](https://prow.knative.dev/view/gcs/knative-prow/pr-logs/pull/knative_serving/8113/pull-knative-serving-integration-tests/1265977194396520448) | `/test pull-knative-serving-integration-tests`

[Full PR test history](https://gubernator.knative.dev/pr/knative_serving/8113). [Your PR dashboard](https://gubernator.knative.dev/pr/markusthoemmes).

<details>

Instructions for interacting with me using PR comments are available [here](https://git.k8s.io/community/contributors/guide/pull-requests.md).  If you have questions or suggestions related to my behavior, please file an issue against the [kubernetes/test-infra](https://github.com/kubernetes/test-infra/issues/new?title=Prow%20issue:) repository. I understand the commands that are listed [here](https://go.k8s.io/bot-commands).
</details>
<!-- test report -->
knative-prow-robot: @markusthoemmes: The following tests **failed**, say `/retest` to rerun all failed tests:

Test name | Commit | Details | Rerun command
--- | --- | --- | ---
pull-knative-serving-autotls-tests | 91c59076521193524d96359145fce6011efc5128 | [link](https://prow.knative.dev/view/gcs/knative-prow/pr-logs/pull/knative_serving/8113/pull-knative-serving-autotls-tests/1265977194396520450) | `/test pull-knative-serving-autotls-tests`
pull-knative-serving-integration-tests | 91c59076521193524d96359145fce6011efc5128 | [link](https://prow.knative.dev/view/gcs/knative-prow/pr-logs/pull/knative_serving/8113/pull-knative-serving-integration-tests/1265977194396520448) | `/test pull-knative-serving-integration-tests`
pull-knative-serving-upgrade-tests | 91c59076521193524d96359145fce6011efc5128 | [link](https://prow.knative.dev/view/gcs/knative-prow/pr-logs/pull/knative_serving/8113/pull-knative-serving-upgrade-tests/1265977194392326146) | `/test pull-knative-serving-upgrade-tests`

[Full PR test history](https://gubernator.knative.dev/pr/knative_serving/8113). [Your PR dashboard](https://gubernator.knative.dev/pr/markusthoemmes).

<details>

Instructions for interacting with me using PR comments are available [here](https://git.k8s.io/community/contributors/guide/pull-requests.md).  If you have questions or suggestions related to my behavior, please file an issue against the [kubernetes/test-infra](https://github.com/kubernetes/test-infra/issues/new?title=Prow%20issue:) repository. I understand the commands that are listed [here](https://go.k8s.io/bot-commands).
</details>
<!-- test report -->
vagababov: /retest
knative-prow-robot: @markusthoemmes: The following tests **failed**, say `/retest` to rerun all failed tests:

Test name | Commit | Details | Rerun command
--- | --- | --- | ---
pull-knative-serving-integration-tests | 91c59076521193524d96359145fce6011efc5128 | [link](https://prow.knative.dev/view/gcs/knative-prow/pr-logs/pull/knative_serving/8113/pull-knative-serving-integration-tests/1265977194396520448) | `/test pull-knative-serving-integration-tests`
pull-knative-serving-upgrade-tests | 91c59076521193524d96359145fce6011efc5128 | [link](https://prow.knative.dev/view/gcs/knative-prow/pr-logs/pull/knative_serving/8113/pull-knative-serving-upgrade-tests/1265977194392326146) | `/test pull-knative-serving-upgrade-tests`
pull-knative-serving-autotls-tests | 91c59076521193524d96359145fce6011efc5128 | [link](https://prow.knative.dev/view/gcs/knative-prow/pr-logs/pull/knative_serving/8113/pull-knative-serving-autotls-tests/1266038096743370752) | `/test pull-knative-serving-autotls-tests`

[Full PR test history](https://gubernator.knative.dev/pr/knative_serving/8113). [Your PR dashboard](https://gubernator.knative.dev/pr/markusthoemmes).

<details>

Instructions for interacting with me using PR comments are available [here](https://git.k8s.io/community/contributors/guide/pull-requests.md).  If you have questions or suggestions related to my behavior, please file an issue against the [kubernetes/test-infra](https://github.com/kubernetes/test-infra/issues/new?title=Prow%20issue:) repository. I understand the commands that are listed [here](https://go.k8s.io/bot-commands).
</details>
<!-- test report -->
knative-prow-robot: @markusthoemmes: The following tests **failed**, say `/retest` to rerun all failed tests:

Test name | Commit | Details | Rerun command
--- | --- | --- | ---
pull-knative-serving-upgrade-tests | 91c59076521193524d96359145fce6011efc5128 | [link](https://prow.knative.dev/view/gcs/knative-prow/pr-logs/pull/knative_serving/8113/pull-knative-serving-upgrade-tests/1265977194392326146) | `/test pull-knative-serving-upgrade-tests`
pull-knative-serving-autotls-tests | 91c59076521193524d96359145fce6011efc5128 | [link](https://prow.knative.dev/view/gcs/knative-prow/pr-logs/pull/knative_serving/8113/pull-knative-serving-autotls-tests/1266038096743370752) | `/test pull-knative-serving-autotls-tests`
pull-knative-serving-integration-tests | 91c59076521193524d96359145fce6011efc5128 | [link](https://prow.knative.dev/view/gcs/knative-prow/pr-logs/pull/knative_serving/8113/pull-knative-serving-integration-tests/1266038096747565056) | `/test pull-knative-serving-integration-tests`

[Full PR test history](https://gubernator.knative.dev/pr/knative_serving/8113). [Your PR dashboard](https://gubernator.knative.dev/pr/markusthoemmes).

<details>

Instructions for interacting with me using PR comments are available [here](https://git.k8s.io/community/contributors/guide/pull-requests.md).  If you have questions or suggestions related to my behavior, please file an issue against the [kubernetes/test-infra](https://github.com/kubernetes/test-infra/issues/new?title=Prow%20issue:) repository. I understand the commands that are listed [here](https://go.k8s.io/bot-commands).
</details>
<!-- test report -->
knative-prow-robot: @markusthoemmes: The following tests **failed**, say `/retest` to rerun all failed tests:

Test name | Commit | Details | Rerun command
--- | --- | --- | ---
pull-knative-serving-autotls-tests | 91c59076521193524d96359145fce6011efc5128 | [link](https://prow.knative.dev/view/gcs/knative-prow/pr-logs/pull/knative_serving/8113/pull-knative-serving-autotls-tests/1266038096743370752) | `/test pull-knative-serving-autotls-tests`
pull-knative-serving-integration-tests | 91c59076521193524d96359145fce6011efc5128 | [link](https://prow.knative.dev/view/gcs/knative-prow/pr-logs/pull/knative_serving/8113/pull-knative-serving-integration-tests/1266038096747565056) | `/test pull-knative-serving-integration-tests`
pull-knative-serving-upgrade-tests | 91c59076521193524d96359145fce6011efc5128 | [link](https://prow.knative.dev/view/gcs/knative-prow/pr-logs/pull/knative_serving/8113/pull-knative-serving-upgrade-tests/1266038096743370753) | `/test pull-knative-serving-upgrade-tests`

[Full PR test history](https://gubernator.knative.dev/pr/knative_serving/8113). [Your PR dashboard](https://gubernator.knative.dev/pr/markusthoemmes).

<details>

Instructions for interacting with me using PR comments are available [here](https://git.k8s.io/community/contributors/guide/pull-requests.md).  If you have questions or suggestions related to my behavior, please file an issue against the [kubernetes/test-infra](https://github.com/kubernetes/test-infra/issues/new?title=Prow%20issue:) repository. I understand the commands that are listed [here](https://go.k8s.io/bot-commands).
</details>
<!-- test report -->
vagababov: Thanks! Fewer files — fewer bugs.
vagababov: /retest

Patch:
diff --git a/cmd/queue/main.go b/cmd/queue/main.go
index 3e547bb5a..50cd04083 100644
--- a/cmd/queue/main.go
+++ b/cmd/queue/main.go
@@ -350,7 +350,11 @@ func main() {
 	defer reportTicker.Stop()
 
 	stats := network.NewRequestStats(time.Now())
-	go queue.ReportStats(time.Now(), stats, reportTicker.C, promStatReporter.Report)
+	go func() {
+		for now := range reportTicker.C {
+			promStatReporter.Report(stats.Report(now))
+		}
+	}()
 
 	// Setup probe to run for checking user-application healthiness.
 	probe := buildProbe(env.ServingReadinessProbe)
diff --git a/pkg/queue/prometheus_stats_reporter.go b/pkg/queue/prometheus_stats_reporter.go
index eb301245b..95bb7de16 100644
--- a/pkg/queue/prometheus_stats_reporter.go
+++ b/pkg/queue/prometheus_stats_reporter.go
@@ -24,6 +24,7 @@ import (
 
 	"github.com/prometheus/client_golang/prometheus"
 	"github.com/prometheus/client_golang/prometheus/promhttp"
+	"knative.dev/serving/pkg/network"
 )
 
 const (
@@ -125,13 +126,13 @@ func NewPrometheusStatsReporter(namespace, config, revision, pod string, reporti
 }
 
 // Report captures request metrics.
-func (r *PrometheusStatsReporter) Report(acr float64, apcr float64, rc float64, prc float64) {
+func (r *PrometheusStatsReporter) Report(stats network.RequestStatsReport) {
 	// Requests per second is a rate over time while concurrency is not.
 	rp := r.reportingPeriod.Seconds()
-	r.requestsPerSecond.Set(rc / rp)
-	r.proxiedRequestsPerSecond.Set(prc / rp)
-	r.averageConcurrentRequests.Set(acr)
-	r.averageProxiedConcurrentRequests.Set(apcr)
+	r.requestsPerSecond.Set(stats.RequestCount / rp)
+	r.proxiedRequestsPerSecond.Set(stats.ProxiedRequestCount / rp)
+	r.averageConcurrentRequests.Set(stats.AverageConcurrency)
+	r.averageProxiedConcurrentRequests.Set(stats.AverageProxiedConcurrency)
 	r.processUptime.Set(time.Since(r.startTime).Seconds())
 }
 
diff --git a/pkg/queue/stats.go b/pkg/queue/stats.go
deleted file mode 100644
index 0c7216463..000000000
--- a/pkg/queue/stats.go
+++ /dev/null
@@ -1,40 +0,0 @@
-/*
-Copyright 2018 The Knative Authors
-
-Licensed under the Apache License, Version 2.0 (the "License");
-you may not use this file except in compliance with the License.
-You may obtain a copy of the License at
-
-    http://www.apache.org/licenses/LICENSE-2.0
-
-Unless required by applicable law or agreed to in writing, software
-distributed under the License is distributed on an "AS IS" BASIS,
-WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-See the License for the specific language governing permissions and
-limitations under the License.
-*/
-
-package queue
-
-import (
-	"time"
-
-	"knative.dev/serving/pkg/network"
-)
-
-// ReportStats continually processes network events from reqCh and reports
-// aggregated stats via the `report` function whenever reportCh ticks.
-func ReportStats(startedAt time.Time, stats *network.RequestStats, reportCh <-chan time.Time, report func(float64, float64, float64, float64)) {
-	for {
-		select {
-		case now := <-reportCh:
-			stat := stats.Report(now)
-			report(
-				stat.AverageConcurrency,
-				stat.AverageProxiedConcurrency,
-				stat.RequestCount,
-				stat.ProxiedRequestCount,
-			)
-		}
-	}
-}


Test patch:
diff --git a/cmd/queue/main_test.go b/cmd/queue/main_test.go
index 50f66b638..932409e1e 100644
--- a/cmd/queue/main_test.go
+++ b/cmd/queue/main_test.go
@@ -510,7 +510,11 @@ func BenchmarkProxyHandler(b *testing.B) {
 	if err != nil {
 		b.Fatal("Failed to create stats reporter:", err)
 	}
-	go queue.ReportStats(time.Now(), stats, reportTicker.C, promStatReporter.Report)
+	go func() {
+		for now := range reportTicker.C {
+			promStatReporter.Report(stats.Report(now))
+		}
+	}()
 	req := httptest.NewRequest(http.MethodPost, "http://example.com", nil)
 	req.Header.Set(network.OriginalHostHeader, wantHost)
 
diff --git a/pkg/apis/serving/k8s_validation_test.go b/pkg/apis/serving/k8s_validation_test.go
index e78a74a2d..20ed14685 100644
--- a/pkg/apis/serving/k8s_validation_test.go
+++ b/pkg/apis/serving/k8s_validation_test.go
@@ -386,10 +386,10 @@ func TestContainerValidation(t *testing.T) {
 			Image: "foo",
 			Resources: corev1.ResourceRequirements{
 				Limits: corev1.ResourceList{
-					corev1.ResourceName("memory"): resource.MustParse("250M"),
+					corev1.ResourceMemory: resource.MustParse("250M"),
 				},
 				Requests: corev1.ResourceList{
-					corev1.ResourceName("cpu"): resource.MustParse("25m"),
+					corev1.ResourceCPU: resource.MustParse("25m"),
 				},
 			},
 		},
diff --git a/pkg/apis/serving/v1/revision_validation_test.go b/pkg/apis/serving/v1/revision_validation_test.go
index 20dc82e9e..da6ab75ef 100644
--- a/pkg/apis/serving/v1/revision_validation_test.go
+++ b/pkg/apis/serving/v1/revision_validation_test.go
@@ -542,7 +542,7 @@ func TestImmutableFields(t *testing.T) {
 					Containers: []corev1.Container{{
 						Resources: corev1.ResourceRequirements{
 							Requests: corev1.ResourceList{
-								corev1.ResourceName("cpu"): resource.MustParse("50m"),
+								corev1.ResourceCPU: resource.MustParse("50m"),
 							},
 						},
 					}},
@@ -558,7 +558,7 @@ func TestImmutableFields(t *testing.T) {
 					Containers: []corev1.Container{{
 						Resources: corev1.ResourceRequirements{
 							Requests: corev1.ResourceList{
-								corev1.ResourceName("cpu"): resource.MustParse("100m"),
+								corev1.ResourceCPU: resource.MustParse("100m"),
 							},
 						},
 					}},
diff --git a/pkg/apis/serving/v1alpha1/revision_validation_test.go b/pkg/apis/serving/v1alpha1/revision_validation_test.go
index 2c81f043c..080db721b 100644
--- a/pkg/apis/serving/v1alpha1/revision_validation_test.go
+++ b/pkg/apis/serving/v1alpha1/revision_validation_test.go
@@ -669,7 +669,7 @@ func TestImmutableFields(t *testing.T) {
 					Image: "busybox",
 					Resources: corev1.ResourceRequirements{
 						Requests: corev1.ResourceList{
-							corev1.ResourceName("cpu"): resource.MustParse("50m"),
+							corev1.ResourceCPU: resource.MustParse("50m"),
 						},
 					},
 				},
@@ -684,7 +684,7 @@ func TestImmutableFields(t *testing.T) {
 					Image: "busybox",
 					Resources: corev1.ResourceRequirements{
 						Requests: corev1.ResourceList{
-							corev1.ResourceName("cpu"): resource.MustParse("100m"),
+							corev1.ResourceCPU: resource.MustParse("100m"),
 						},
 					},
 				},
diff --git a/pkg/apis/serving/v1beta1/revision_validation_test.go b/pkg/apis/serving/v1beta1/revision_validation_test.go
index 3ee08493b..1b6a36a98 100644
--- a/pkg/apis/serving/v1beta1/revision_validation_test.go
+++ b/pkg/apis/serving/v1beta1/revision_validation_test.go
@@ -543,7 +543,7 @@ func TestImmutableFields(t *testing.T) {
 					Containers: []corev1.Container{{
 						Resources: corev1.ResourceRequirements{
 							Requests: corev1.ResourceList{
-								corev1.ResourceName("cpu"): resource.MustParse("50m"),
+								corev1.ResourceCPU: resource.MustParse("50m"),
 							},
 						},
 					}},
@@ -559,7 +559,7 @@ func TestImmutableFields(t *testing.T) {
 					Containers: []corev1.Container{{
 						Resources: corev1.ResourceRequirements{
 							Requests: corev1.ResourceList{
-								corev1.ResourceName("cpu"): resource.MustParse("100m"),
+								corev1.ResourceCPU: resource.MustParse("100m"),
 							},
 						},
 					}},
diff --git a/pkg/queue/prometheus_stats_reporter_test.go b/pkg/queue/prometheus_stats_reporter_test.go
index e32ed4f0c..0f24bef2e 100644
--- a/pkg/queue/prometheus_stats_reporter_test.go
+++ b/pkg/queue/prometheus_stats_reporter_test.go
@@ -22,6 +22,7 @@ import (
 	"time"
 
 	"github.com/prometheus/client_golang/prometheus"
+	"knative.dev/serving/pkg/network"
 
 	dto "github.com/prometheus/client_model/go"
 )
@@ -42,44 +43,39 @@ func TestNewPrometheusStatsReporter_negative(t *testing.T) {
 		config    string
 		revision  string
 		pod       string
-	}{
-		{
-			"Empty_Namespace_Value",
-			"Expected namespace empty error",
-			errors.New("namespace must not be empty"),
-			"",
-			config,
-			revision,
-			pod,
-		},
-		{
-			"Empty_Config_Value",
-			"Expected config empty error",
-			errors.New("config must not be empty"),
-			namespace,
-			"",
-			revision,
-			pod,
-		},
-		{
-			"Empty_Revision_Value",
-			"Expected revision empty error",
-			errors.New("revision must not be empty"),
-			namespace,
-			config,
-			"",
-			pod,
-		},
-		{
-			"Empty_Pod_Value",
-			"Expected pod empty error",
-			errors.New("pod must not be empty"),
-			namespace,
-			config,
-			revision,
-			"",
-		},
-	}
+	}{{
+		"Empty_Namespace_Value",
+		"Expected namespace empty error",
+		errors.New("namespace must not be empty"),
+		"",
+		config,
+		revision,
+		pod,
+	}, {
+		"Empty_Config_Value",
+		"Expected config empty error",
+		errors.New("config must not be empty"),
+		namespace,
+		"",
+		revision,
+		pod,
+	}, {
+		"Empty_Revision_Value",
+		"Expected revision empty error",
+		errors.New("revision must not be empty"),
+		namespace,
+		config,
+		"",
+		pod,
+	}, {
+		"Empty_Pod_Value",
+		"Expected pod empty error",
+		errors.New("pod must not be empty"),
+		namespace,
+		config,
+		revision,
+		"",
+	}}
 
 	for _, test := range tests {
 		t.Run(test.name, func(t *testing.T) {
@@ -154,8 +150,7 @@ func TestReporterReport(t *testing.T) {
 		expectedConcurrency:         3,
 		expectedProxiedRequestCount: 15,
 		expectedProxiedConcurrency:  2,
-	},
-	}
+	}}
 
 	for _, test := range tests {
 		t.Run(test.name, func(t *testing.T) {
@@ -165,7 +160,12 @@ func TestReporterReport(t *testing.T) {
 			}
 			// Make the value slightly more interesting, rather than microseconds.
 			reporter.startTime = reporter.startTime.Add(-5 * time.Second)
-			reporter.Report(test.concurrency, test.proxiedConcurrency, test.reqCount, test.proxiedReqCount)
+			reporter.Report(network.RequestStatsReport{
+				AverageConcurrency:        test.concurrency,
+				AverageProxiedConcurrency: test.proxiedConcurrency,
+				RequestCount:              test.reqCount,
+				ProxiedRequestCount:       test.proxiedReqCount,
+			})
 			checkData(t, requestsPerSecondGV, test.expectedReqCount)
 			checkData(t, averageConcurrentRequestsGV, test.expectedConcurrency)
 			checkData(t, proxiedRequestsPerSecondGV, test.expectedProxiedRequestCount)
diff --git a/pkg/queue/stats_test.go b/pkg/queue/stats_test.go
deleted file mode 100644
index a5b272d00..000000000
--- a/pkg/queue/stats_test.go
+++ /dev/null
@@ -1,287 +0,0 @@
-/*
-Copyright 2018 The Knative Authors
-
-Licensed under the Apache License, Version 2.0 (the "License");
-you may not use this file except in compliance with the License.
-You may obtain a copy of the License at
-
-    http://www.apache.org/licenses/LICENSE-2.0
-
-Unless required by applicable law or agreed to in writing, software
-distributed under the License is distributed on an "AS IS" BASIS,
-WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-See the License for the specific language governing permissions and
-limitations under the License.
-*/
-
-package queue
-
-import (
-	"testing"
-	"time"
-
-	"github.com/google/go-cmp/cmp"
-	"knative.dev/serving/pkg/network"
-)
-
-type reportedStat struct {
-	Concurrency         float64
-	ProxiedConcurrency  float64
-	RequestCount        float64
-	ProxiedRequestCount float64
-}
-
-func TestNoData(t *testing.T) {
-	now := time.Now()
-	s := newTestStats(t, now)
-
-	got := s.report(now)
-	want := reportedStat{
-		Concurrency:  0.0,
-		RequestCount: 0,
-	}
-	if diff := cmp.Diff(want, got); diff != "" {
-		t.Errorf("Unexpected stat (-want +got): %v", diff)
-	}
-}
-
-func TestSingleRequestWholeTime(t *testing.T) {
-	now := time.Now()
-	s := newTestStats(t, now)
-
-	s.requestStart(now)
-	now = now.Add(1 * time.Second)
-	s.requestEnd(now)
-
-	got := s.report(now)
-
-	want := reportedStat{
-		Concurrency:  1.0,
-		RequestCount: 1,
-	}
-	if diff := cmp.Diff(want, got); diff != "" {
-		t.Errorf("Unexpected stat (-want +got): %v", diff)
-	}
-}
-
-func TestSingleRequestHalfTime(t *testing.T) {
-	now := time.Now()
-	s := newTestStats(t, now)
-
-	s.requestStart(now)
-	now = now.Add(1 * time.Second)
-	s.requestEnd(now)
-	now = now.Add(1 * time.Second)
-	got := s.report(now)
-
-	want := reportedStat{
-		Concurrency:  0.5,
-		RequestCount: 1,
-	}
-	if diff := cmp.Diff(want, got); diff != "" {
-		t.Errorf("Unexpected stat (-want +got): %v", diff)
-	}
-}
-
-func TestVeryShortLivedRequest(t *testing.T) {
-	now := time.Now()
-	s := newTestStats(t, now)
-
-	s.requestStart(now)
-	now = now.Add(10 * time.Millisecond)
-	s.requestEnd(now)
-
-	now = now.Add(990 * time.Millisecond) // make the second full
-	got := s.report(now)
-
-	want := reportedStat{
-		Concurrency:  float64(10) / float64(1000),
-		RequestCount: 1,
-	}
-	if diff := cmp.Diff(want, got); diff != "" {
-		t.Errorf("Unexpected stat (-want +got): %v", diff)
-	}
-}
-
-func TestMultipleRequestsWholeTime(t *testing.T) {
-	now := time.Now()
-	s := newTestStats(t, now)
-
-	s.requestStart(now)
-	now = now.Add(300 * time.Millisecond)
-	s.requestEnd(now)
-
-	s.requestStart(now)
-	now = now.Add(300 * time.Millisecond)
-	s.requestEnd(now)
-
-	s.requestStart(now)
-	now = now.Add(400 * time.Millisecond)
-	s.requestEnd(now)
-
-	got := s.report(now)
-
-	want := reportedStat{
-		Concurrency:  1.0,
-		RequestCount: 3,
-	}
-	if diff := cmp.Diff(want, got); diff != "" {
-		t.Errorf("Unexpected stat (-want +got): %v", diff)
-	}
-}
-
-func TestMultipleRequestsInterleaved(t *testing.T) {
-	now := time.Now()
-	s := newTestStats(t, now)
-
-	s.requestStart(now)
-	now = now.Add(100 * time.Millisecond)
-	s.requestStart(now)
-	now = now.Add(500 * time.Millisecond)
-	s.requestEnd(now)
-	now = now.Add(400 * time.Millisecond)
-	s.requestEnd(now)
-
-	got := s.report(now)
-
-	want := reportedStat{
-		Concurrency:  1.5,
-		RequestCount: 2,
-	}
-	if diff := cmp.Diff(want, got); diff != "" {
-		t.Errorf("Unexpected stat (-want +got): %v", diff)
-	}
-}
-
-func TestOneRequestAcrossReportings(t *testing.T) {
-	now := time.Now()
-	s := newTestStats(t, now)
-
-	s.requestStart(now)
-	now = now.Add(1 * time.Second)
-	got1 := s.report(now)
-	want1 := reportedStat{
-		Concurrency:  1.0,
-		RequestCount: 1,
-	}
-
-	now = now.Add(500 * time.Millisecond)
-	s.requestEnd(now)
-	now = now.Add(500 * time.Millisecond)
-	got2 := s.report(now)
-	want2 := reportedStat{
-		Concurrency:  0.5,
-		RequestCount: 0,
-	}
-
-	if diff := cmp.Diff(want1, got1); diff != "" {
-		t.Errorf("Unexpected stat (-want +got): %v", diff)
-	}
-	if diff := cmp.Diff(want2, got2); diff != "" {
-		t.Errorf("Unexpected stat (-want +got): %v", diff)
-	}
-}
-
-func TestOneProxiedRequest(t *testing.T) {
-	now := time.Now()
-	s := newTestStats(t, now)
-	s.proxiedStart(now)
-	now = now.Add(1 * time.Second)
-	got := s.report(now)
-	want := reportedStat{
-		Concurrency:         1.0,
-		ProxiedConcurrency:  1.0,
-		RequestCount:        1,
-		ProxiedRequestCount: 1,
-	}
-	if diff := cmp.Diff(want, got); diff != "" {
-		t.Errorf("Unexpected stat (-want +got): %v", diff)
-	}
-}
-
-func TestOneEndedProxiedRequest(t *testing.T) {
-	now := time.Now()
-	s := newTestStats(t, now)
-	s.proxiedStart(now)
-	now = now.Add(500 * time.Millisecond)
-	s.proxiedEnd(now)
-	now = now.Add(500 * time.Millisecond)
-	got := s.report(now)
-	want := reportedStat{
-		Concurrency:         0.5,
-		ProxiedConcurrency:  0.5,
-		RequestCount:        1,
-		ProxiedRequestCount: 1,
-	}
-	if diff := cmp.Diff(want, got); diff != "" {
-		t.Errorf("Unexpected stat (-want +got): %v", diff)
-	}
-}
-
-func TestTwoRequestsOneProxied(t *testing.T) {
-	now := time.Now()
-	s := newTestStats(t, now)
-	s.proxiedStart(now)
-	now = now.Add(500 * time.Millisecond)
-	s.proxiedEnd(now)
-	s.requestStart(now)
-	now = now.Add(500 * time.Millisecond)
-	got := s.report(now)
-	want := reportedStat{
-		Concurrency:         1.0,
-		ProxiedConcurrency:  0.5,
-		RequestCount:        2,
-		ProxiedRequestCount: 1,
-	}
-	if diff := cmp.Diff(want, got); diff != "" {
-		t.Errorf("Unexpected stat (-want +got): %v", diff)
-	}
-}
-
-// Test type to hold the bi-directional time channels
-type testStats struct {
-	stats        *network.RequestStats
-	reportBiChan chan time.Time
-	statChan     chan reportedStat
-}
-
-func newTestStats(t *testing.T, now time.Time) *testStats {
-	stats := network.NewRequestStats(now)
-	reportBiChan := make(chan time.Time)
-	statChan := make(chan reportedStat)
-	report := func(acr float64, apcr float64, rc float64, prc float64) {
-		statChan <- reportedStat{
-			Concurrency:         acr,
-			ProxiedConcurrency:  apcr,
-			RequestCount:        rc,
-			ProxiedRequestCount: prc,
-		}
-	}
-	go ReportStats(now, stats, reportBiChan, report)
-	return &testStats{
-		stats:        stats,
-		reportBiChan: reportBiChan,
-		statChan:     statChan,
-	}
-}
-
-func (s *testStats) requestStart(now time.Time) {
-	s.stats.HandleEvent(network.ReqEvent{Time: now, Type: network.ReqIn})
-}
-
-func (s *testStats) requestEnd(now time.Time) {
-	s.stats.HandleEvent(network.ReqEvent{Time: now, Type: network.ReqOut})
-}
-
-func (s *testStats) proxiedStart(now time.Time) {
-	s.stats.HandleEvent(network.ReqEvent{Time: now, Type: network.ProxiedIn})
-}
-
-func (s *testStats) proxiedEnd(now time.Time) {
-	s.stats.HandleEvent(network.ReqEvent{Time: now, Type: network.ProxiedOut})
-}
-
-func (s *testStats) report(now time.Time) reportedStat {
-	s.reportBiChan <- now
-	return <-s.statChan
-}
diff --git a/pkg/reconciler/revision/resources/queue_test.go b/pkg/reconciler/revision/resources/queue_test.go
index 901fdd3ad..ccc92660a 100644
--- a/pkg/reconciler/revision/resources/queue_test.go
+++ b/pkg/reconciler/revision/resources/queue_test.go
@@ -306,8 +306,8 @@ func TestMakeQueueContainerWithPercentageAnnotation(t *testing.T) {
 					ReadinessProbe: testProbe,
 					Resources: corev1.ResourceRequirements{
 						Limits: corev1.ResourceList{
-							corev1.ResourceName("memory"): resource.MustParse("2Gi"),
-							corev1.ResourceName("cpu"):    resource.MustParse("2"),
+							corev1.ResourceMemory: resource.MustParse("2Gi"),
+							corev1.ResourceCPU:    resource.MustParse("2"),
 						},
 					}},
 				}
@@ -315,8 +315,8 @@ func TestMakeQueueContainerWithPercentageAnnotation(t *testing.T) {
 		want: queueContainer(func(c *corev1.Container) {
 			c.Env = env(map[string]string{})
 			c.Resources.Limits = corev1.ResourceList{
-				corev1.ResourceName("memory"): *resource.NewMilliQuantity(429496729600, resource.BinarySI),
-				corev1.ResourceName("cpu"):    *resource.NewMilliQuantity(400, resource.BinarySI),
+				corev1.ResourceMemory: *resource.NewMilliQuantity(429496729600, resource.BinarySI),
+				corev1.ResourceCPU:    *resource.NewMilliQuantity(400, resource.BinarySI),
 			}
 			c.Image = "alpine"
 		}),
@@ -335,8 +335,8 @@ func TestMakeQueueContainerWithPercentageAnnotation(t *testing.T) {
 					ReadinessProbe: testProbe,
 					Resources: corev1.ResourceRequirements{
 						Requests: corev1.ResourceList{
-							corev1.ResourceName("cpu"):    resource.MustParse("50m"),
-							corev1.ResourceName("memory"): resource.MustParse("128Mi"),
+							corev1.ResourceCPU:    resource.MustParse("50m"),
+							corev1.ResourceMemory: resource.MustParse("128Mi"),
 						},
 					},
 				}}
@@ -344,8 +344,8 @@ func TestMakeQueueContainerWithPercentageAnnotation(t *testing.T) {
 		want: queueContainer(func(c *corev1.Container) {
 			c.Env = env(map[string]string{})
 			c.Resources.Requests = corev1.ResourceList{
-				corev1.ResourceName("cpu"):    resource.MustParse("25m"),
-				corev1.ResourceName("memory"): resource.MustParse("50Mi"),
+				corev1.ResourceCPU:    resource.MustParse("25m"),
+				corev1.ResourceMemory: resource.MustParse("50Mi"),
 			}
 			c.Image = "alpine"
 		}),
@@ -364,8 +364,8 @@ func TestMakeQueueContainerWithPercentageAnnotation(t *testing.T) {
 					ReadinessProbe: testProbe,
 					Resources: corev1.ResourceRequirements{
 						Requests: corev1.ResourceList{
-							corev1.ResourceName("cpu"):    resource.MustParse("50m"),
-							corev1.ResourceName("memory"): resource.MustParse("128Mi"),
+							corev1.ResourceCPU:    resource.MustParse("50m"),
+							corev1.ResourceMemory: resource.MustParse("128Mi"),
 						},
 					},
 				}}
@@ -373,7 +373,7 @@ func TestMakeQueueContainerWithPercentageAnnotation(t *testing.T) {
 		want: queueContainer(func(c *corev1.Container) {
 			c.Env = env(map[string]string{})
 			c.Resources.Requests = corev1.ResourceList{
-				corev1.ResourceName("cpu"): resource.MustParse("25m"),
+				corev1.ResourceCPU: resource.MustParse("25m"),
 			}
 			c.Image = "alpine"
 		}),
@@ -392,7 +392,7 @@ func TestMakeQueueContainerWithPercentageAnnotation(t *testing.T) {
 					ReadinessProbe: testProbe,
 					Resources: corev1.ResourceRequirements{
 						Requests: corev1.ResourceList{
-							corev1.ResourceName("memory"): resource.MustParse("900000Pi"),
+							corev1.ResourceMemory: resource.MustParse("900000Pi"),
 						},
 					},
 				}}
@@ -400,8 +400,8 @@ func TestMakeQueueContainerWithPercentageAnnotation(t *testing.T) {
 		want: queueContainer(func(c *corev1.Container) {
 			c.Env = env(map[string]string{})
 			c.Resources.Requests = corev1.ResourceList{
-				corev1.ResourceName("cpu"):    resource.MustParse("25m"),
-				corev1.ResourceName("memory"): resource.MustParse("200Mi"),
+				corev1.ResourceCPU:    resource.MustParse("25m"),
+				corev1.ResourceMemory: resource.MustParse("200Mi"),
 			}
 			c.Image = "alpine"
 		}),
@@ -486,7 +486,7 @@ func TestProbeGenerationHTTPDefaults(t *testing.T) {
 			"SERVING_READINESS_PROBE": string(wantProbeJSON),
 		})
 		c.Resources.Requests = corev1.ResourceList{
-			corev1.ResourceName("cpu"): resource.MustParse("25m"),
+			corev1.ResourceCPU: resource.MustParse("25m"),
 		}
 		c.ReadinessProbe = &corev1.Probe{
 			Handler: corev1.Handler{
@@ -625,7 +625,7 @@ func TestTCPProbeGeneration(t *testing.T) {
 		},
 		want: queueContainer(func(c *corev1.Container) {
 			c.Resources.Requests = corev1.ResourceList{
-				corev1.ResourceName("cpu"): resource.MustParse("25m"),
+				corev1.ResourceCPU: resource.MustParse("25m"),
 			}
 			c.ReadinessProbe = &corev1.Probe{
 				Handler: corev1.Handler{
@@ -667,7 +667,7 @@ func TestTCPProbeGeneration(t *testing.T) {
 		},
 		want: queueContainer(func(c *corev1.Container) {
 			c.Resources.Requests = corev1.ResourceList{
-				corev1.ResourceName("cpu"): resource.MustParse("25m"),
+				corev1.ResourceCPU: resource.MustParse("25m"),
 			}
 			c.ReadinessProbe = &corev1.Probe{
 				Handler: corev1.Handler{
@@ -719,7 +719,7 @@ func TestTCPProbeGeneration(t *testing.T) {
 		},
 		want: queueContainer(func(c *corev1.Container) {
 			c.Resources.Requests = corev1.ResourceList{
-				corev1.ResourceName("cpu"): resource.MustParse("25m"),
+				corev1.ResourceCPU: resource.MustParse("25m"),
 			}
 			c.ReadinessProbe = &corev1.Probe{
 				Handler: corev1.Handler{
diff --git a/test/e2e/helloworld_test.go b/test/e2e/helloworld_test.go
index 3d7b2bb1f..4495719e7 100644
--- a/test/e2e/helloworld_test.go
+++ b/test/e2e/helloworld_test.go
@@ -105,12 +105,12 @@ func TestQueueSideCarResourceLimit(t *testing.T) {
 	resources, err := v1test.CreateServiceReady(t, clients, &names,
 		rtesting.WithResourceRequirements(corev1.ResourceRequirements{
 			Requests: corev1.ResourceList{
-				corev1.ResourceName("cpu"):    resource.MustParse("50m"),
-				corev1.ResourceName("memory"): resource.MustParse("128Mi"),
+				corev1.ResourceCPU:    resource.MustParse("50m"),
+				corev1.ResourceMemory: resource.MustParse("128Mi"),
 			},
 			Limits: corev1.ResourceList{
-				corev1.ResourceName("cpu"):    resource.MustParse("100m"),
-				corev1.ResourceName("memory"): resource.MustParse("258Mi"),
+				corev1.ResourceCPU:    resource.MustParse("100m"),
+				corev1.ResourceMemory: resource.MustParse("258Mi"),
 			},
 		}), rtesting.WithConfigAnnotations(map[string]string{
 			serving.QueueSideCarResourcePercentageAnnotation: "0.2",