-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a new stat metric in queue to prevent double counting
Currently a request pending in both the activator and queue proxy is counted twice, once in the activator, and one in the queue proxy. This change fixes it by letting queue report a concurrency metric for proxied requests and letting the autoscaler discount such concurrency when it calculates the total concurrency for scaling decision.
- Loading branch information
Showing
13 changed files
with
417 additions
and
85 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/* | ||
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 main | ||
|
||
import ( | ||
"net/http" | ||
"net/http/httptest" | ||
"net/http/httputil" | ||
"net/url" | ||
"testing" | ||
|
||
"github.com/knative/serving/pkg/activator" | ||
"github.com/knative/serving/pkg/network" | ||
|
||
"github.com/knative/serving/pkg/queue" | ||
) | ||
|
||
func TestHandler_ReqEvent(t *testing.T) { | ||
var httpHandler http.HandlerFunc = func(w http.ResponseWriter, r *http.Request) { | ||
if r.Header.Get(activator.RevisionHeaderName) != "" { | ||
w.WriteHeader(http.StatusBadRequest) | ||
return | ||
} | ||
|
||
if r.Header.Get(activator.RevisionHeaderNamespace) != "" { | ||
w.WriteHeader(http.StatusBadRequest) | ||
return | ||
} | ||
|
||
w.WriteHeader(http.StatusOK) | ||
} | ||
|
||
server := httptest.NewServer(httpHandler) | ||
serverURL, _ := url.Parse(server.URL) | ||
|
||
defer server.Close() | ||
proxy := httputil.NewSingleHostReverseProxy(serverURL) | ||
|
||
params := queue.BreakerParams{QueueDepth: 10, MaxConcurrency: 10, InitialCapacity: 10} | ||
breaker := queue.NewBreaker(params) | ||
reqChan := make(chan queue.ReqEvent, 10) | ||
h := handler(reqChan, breaker, proxy, proxy) | ||
|
||
writer := httptest.NewRecorder() | ||
req := httptest.NewRequest(http.MethodPost, "http://example.com", nil) | ||
req.Header.Set(network.ProxyHeaderName, activator.Name) | ||
h(writer, req) | ||
e := <-reqChan | ||
if e.EventType != queue.ProxiedIn { | ||
t.Errorf("Want: %v, got: %v\n", queue.ReqIn, e.EventType) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.