mirror of https://github.com/k3s-io/k3s
Remove test/images/* from hack/.golint_failures
parent
224448b858
commit
d8390c4845
|
@ -746,14 +746,6 @@ test/e2e_node/environment
|
|||
test/e2e_node/remote
|
||||
test/e2e_node/runner/remote
|
||||
test/e2e_node/services
|
||||
test/images/net/nat
|
||||
test/images/netexec
|
||||
test/images/nettest
|
||||
test/images/no-snat-test
|
||||
test/images/no-snat-test-proxy
|
||||
test/images/resource-consumer
|
||||
test/images/resource-consumer/common
|
||||
test/images/resource-consumer/controller
|
||||
test/integration
|
||||
test/integration/auth
|
||||
test/integration/evictions
|
||||
|
|
|
@ -40,7 +40,7 @@ import (
|
|||
// connection assigned here.
|
||||
var leakedConnection *net.TCPConn
|
||||
|
||||
// Server JSON options.
|
||||
// CloseWaitServerOptions holds server JSON options.
|
||||
type CloseWaitServerOptions struct {
|
||||
// Address to bind for the test
|
||||
LocalAddr string
|
||||
|
@ -110,7 +110,7 @@ func (server *closeWaitServer) Run(logger *log.Logger, rawOptions interface{}) e
|
|||
return nil
|
||||
}
|
||||
|
||||
// Client JSON options
|
||||
// CloseWaitClientOptions holds client JSON options.
|
||||
type CloseWaitClientOptions struct {
|
||||
// RemoteAddr of the server to connect to.
|
||||
RemoteAddr string
|
||||
|
|
|
@ -80,7 +80,7 @@ func main() {
|
|||
|
||||
func startHTTPServer(httpPort int) {
|
||||
http.HandleFunc("/", rootHandler)
|
||||
http.HandleFunc("/clientip", clientIpHandler)
|
||||
http.HandleFunc("/clientip", clientIPHandler)
|
||||
http.HandleFunc("/echo", echoHandler)
|
||||
http.HandleFunc("/exit", exitHandler)
|
||||
http.HandleFunc("/hostname", hostnameHandler)
|
||||
|
@ -104,7 +104,7 @@ func echoHandler(w http.ResponseWriter, r *http.Request) {
|
|||
fmt.Fprintf(w, "%s", r.FormValue("msg"))
|
||||
}
|
||||
|
||||
func clientIpHandler(w http.ResponseWriter, r *http.Request) {
|
||||
func clientIPHandler(w http.ResponseWriter, r *http.Request) {
|
||||
log.Printf("GET /clientip")
|
||||
fmt.Fprintf(w, r.RemoteAddr)
|
||||
}
|
||||
|
|
|
@ -133,7 +133,7 @@ func (s *State) serveWrite(w http.ResponseWriter, r *http.Request) {
|
|||
if s.Received == nil {
|
||||
s.Received = map[string]int{}
|
||||
}
|
||||
s.Received[wp.Source] += 1
|
||||
s.Received[wp.Source]++
|
||||
}
|
||||
s.appendErr(json.NewEncoder(w).Encode(&WriteResp{Hostname: s.Hostname}))
|
||||
}
|
||||
|
@ -164,7 +164,7 @@ func (s *State) appendSuccessfulSend(toHostname string) {
|
|||
if s.Sent == nil {
|
||||
s.Sent = map[string]int{}
|
||||
}
|
||||
s.Sent[toHostname] += 1
|
||||
s.Sent[toHostname]++
|
||||
}
|
||||
|
||||
var (
|
||||
|
|
|
@ -30,22 +30,22 @@ import (
|
|||
|
||||
// This Pod's /checknosnat takes `target` and `ips` arguments, and queries {target}/checknosnat?ips={ips}
|
||||
|
||||
type MasqTestProxy struct {
|
||||
type masqTestProxy struct {
|
||||
Port string
|
||||
}
|
||||
|
||||
func NewMasqTestProxy() *MasqTestProxy {
|
||||
return &MasqTestProxy{
|
||||
func newMasqTestProxy() *masqTestProxy {
|
||||
return &masqTestProxy{
|
||||
Port: "31235",
|
||||
}
|
||||
}
|
||||
|
||||
func (m *MasqTestProxy) AddFlags(fs *pflag.FlagSet) {
|
||||
func (m *masqTestProxy) AddFlags(fs *pflag.FlagSet) {
|
||||
fs.StringVar(&m.Port, "port", m.Port, "The port to serve /checknosnat endpoint on.")
|
||||
}
|
||||
|
||||
func main() {
|
||||
m := NewMasqTestProxy()
|
||||
m := newMasqTestProxy()
|
||||
m.AddFlags(pflag.CommandLine)
|
||||
|
||||
flag.InitFlags()
|
||||
|
@ -58,7 +58,7 @@ func main() {
|
|||
}
|
||||
}
|
||||
|
||||
func (m *MasqTestProxy) Run() error {
|
||||
func (m *masqTestProxy) Run() error {
|
||||
// register handler
|
||||
http.HandleFunc("/checknosnat", checknosnat)
|
||||
|
||||
|
|
|
@ -34,22 +34,22 @@ import (
|
|||
// pip = this pod's ip
|
||||
// nip = this node's ip
|
||||
|
||||
type MasqTester struct {
|
||||
type masqTester struct {
|
||||
Port string
|
||||
}
|
||||
|
||||
func NewMasqTester() *MasqTester {
|
||||
return &MasqTester{
|
||||
func newMasqTester() *masqTester {
|
||||
return &masqTester{
|
||||
Port: "8080",
|
||||
}
|
||||
}
|
||||
|
||||
func (m *MasqTester) AddFlags(fs *pflag.FlagSet) {
|
||||
func (m *masqTester) AddFlags(fs *pflag.FlagSet) {
|
||||
fs.StringVar(&m.Port, "port", m.Port, "The port to serve /checknosnat and /whoami endpoints on.")
|
||||
}
|
||||
|
||||
func main() {
|
||||
m := NewMasqTester()
|
||||
m := newMasqTester()
|
||||
m.AddFlags(pflag.CommandLine)
|
||||
|
||||
flag.InitFlags()
|
||||
|
@ -62,7 +62,7 @@ func main() {
|
|||
}
|
||||
}
|
||||
|
||||
func (m *MasqTester) Run() error {
|
||||
func (m *masqTester) Run() error {
|
||||
// pip is the current pod's IP and nip is the current node's IP
|
||||
// pull the pip and nip out of the env
|
||||
pip, ok := os.LookupEnv("POD_IP")
|
||||
|
@ -145,9 +145,8 @@ func check(ip string, pip string, nip string) error {
|
|||
if rip != pip {
|
||||
if rip == nip {
|
||||
return fmt.Errorf("Returned ip %q != my Pod ip %q, == my Node ip %q - SNAT", rip, pip, nip)
|
||||
} else {
|
||||
return fmt.Errorf("Returned ip %q != my Pod ip %q or my Node ip %q - SNAT to unexpected ip (possible SNAT through unexpected interface on the way into another node)", rip, pip, nip)
|
||||
}
|
||||
return fmt.Errorf("Returned ip %q != my Pod ip %q or my Node ip %q - SNAT to unexpected ip (possible SNAT through unexpected interface on the way into another node)", rip, pip, nip)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -16,6 +16,7 @@ limitations under the License.
|
|||
|
||||
package common
|
||||
|
||||
// Constants related to Prometheus metrics.
|
||||
const (
|
||||
ConsumeCPUAddress = "/ConsumeCPU"
|
||||
ConsumeMemAddress = "/ConsumeMem"
|
||||
|
|
|
@ -25,7 +25,7 @@ import (
|
|||
"strconv"
|
||||
"sync"
|
||||
|
||||
. "k8s.io/kubernetes/test/images/resource-consumer/common"
|
||||
"k8s.io/kubernetes/test/images/resource-consumer/common"
|
||||
)
|
||||
|
||||
var port = flag.Int("port", 8080, "Port number.")
|
||||
|
@ -35,23 +35,23 @@ var consumerServiceNamespace = flag.String("consumer-service-namespace", "defaul
|
|||
|
||||
func main() {
|
||||
flag.Parse()
|
||||
mgr := NewController()
|
||||
mgr := newController()
|
||||
log.Fatal(http.ListenAndServe(fmt.Sprintf(":%d", *port), mgr))
|
||||
}
|
||||
|
||||
type Controller struct {
|
||||
type controller struct {
|
||||
responseWriterLock sync.Mutex
|
||||
waitGroup sync.WaitGroup
|
||||
}
|
||||
|
||||
func NewController() *Controller {
|
||||
c := &Controller{}
|
||||
func newController() *controller {
|
||||
c := &controller{}
|
||||
return c
|
||||
}
|
||||
|
||||
func (handler *Controller) ServeHTTP(w http.ResponseWriter, req *http.Request) {
|
||||
func (c *controller) ServeHTTP(w http.ResponseWriter, req *http.Request) {
|
||||
if req.Method != "POST" {
|
||||
http.Error(w, BadRequest, http.StatusBadRequest)
|
||||
http.Error(w, common.BadRequest, http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
// parsing POST request data and URL data
|
||||
|
@ -60,30 +60,30 @@ func (handler *Controller) ServeHTTP(w http.ResponseWriter, req *http.Request) {
|
|||
return
|
||||
}
|
||||
// handle consumeCPU
|
||||
if req.URL.Path == ConsumeCPUAddress {
|
||||
handler.handleConsumeCPU(w, req.Form)
|
||||
if req.URL.Path == common.ConsumeCPUAddress {
|
||||
c.handleConsumeCPU(w, req.Form)
|
||||
return
|
||||
}
|
||||
// handle consumeMem
|
||||
if req.URL.Path == ConsumeMemAddress {
|
||||
handler.handleConsumeMem(w, req.Form)
|
||||
if req.URL.Path == common.ConsumeMemAddress {
|
||||
c.handleConsumeMem(w, req.Form)
|
||||
return
|
||||
}
|
||||
// handle bumpMetric
|
||||
if req.URL.Path == BumpMetricAddress {
|
||||
handler.handleBumpMetric(w, req.Form)
|
||||
if req.URL.Path == common.BumpMetricAddress {
|
||||
c.handleBumpMetric(w, req.Form)
|
||||
return
|
||||
}
|
||||
http.Error(w, UnknownFunction, http.StatusNotFound)
|
||||
http.Error(w, common.UnknownFunction, http.StatusNotFound)
|
||||
}
|
||||
|
||||
func (handler *Controller) handleConsumeCPU(w http.ResponseWriter, query url.Values) {
|
||||
func (c *controller) handleConsumeCPU(w http.ResponseWriter, query url.Values) {
|
||||
// getting string data for consumeCPU
|
||||
durationSecString := query.Get(DurationSecQuery)
|
||||
millicoresString := query.Get(MillicoresQuery)
|
||||
requestSizeInMillicoresString := query.Get(RequestSizeInMillicoresQuery)
|
||||
durationSecString := query.Get(common.DurationSecQuery)
|
||||
millicoresString := query.Get(common.MillicoresQuery)
|
||||
requestSizeInMillicoresString := query.Get(common.RequestSizeInMillicoresQuery)
|
||||
if durationSecString == "" || millicoresString == "" || requestSizeInMillicoresString == "" {
|
||||
http.Error(w, NotGivenFunctionArgument, http.StatusBadRequest)
|
||||
http.Error(w, common.NotGivenFunctionArgument, http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -92,7 +92,7 @@ func (handler *Controller) handleConsumeCPU(w http.ResponseWriter, query url.Val
|
|||
millicores, millicoresError := strconv.Atoi(millicoresString)
|
||||
requestSizeInMillicores, requestSizeInMillicoresError := strconv.Atoi(requestSizeInMillicoresString)
|
||||
if durationSecError != nil || millicoresError != nil || requestSizeInMillicoresError != nil || requestSizeInMillicores <= 0 {
|
||||
http.Error(w, IncorrectFunctionArgument, http.StatusBadRequest)
|
||||
http.Error(w, common.IncorrectFunctionArgument, http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -100,23 +100,23 @@ func (handler *Controller) handleConsumeCPU(w http.ResponseWriter, query url.Val
|
|||
rest := millicores - count*requestSizeInMillicores
|
||||
fmt.Fprintf(w, "RC manager: sending %v requests to consume %v millicores each and 1 request to consume %v millicores\n", count, requestSizeInMillicores, rest)
|
||||
if count > 0 {
|
||||
handler.waitGroup.Add(count)
|
||||
handler.sendConsumeCPURequests(w, count, requestSizeInMillicores, durationSec)
|
||||
c.waitGroup.Add(count)
|
||||
c.sendConsumeCPURequests(w, count, requestSizeInMillicores, durationSec)
|
||||
}
|
||||
if rest > 0 {
|
||||
handler.waitGroup.Add(1)
|
||||
go handler.sendOneConsumeCPURequest(w, rest, durationSec)
|
||||
c.waitGroup.Add(1)
|
||||
go c.sendOneConsumeCPURequest(w, rest, durationSec)
|
||||
}
|
||||
handler.waitGroup.Wait()
|
||||
c.waitGroup.Wait()
|
||||
}
|
||||
|
||||
func (handler *Controller) handleConsumeMem(w http.ResponseWriter, query url.Values) {
|
||||
func (c *controller) handleConsumeMem(w http.ResponseWriter, query url.Values) {
|
||||
// getting string data for consumeMem
|
||||
durationSecString := query.Get(DurationSecQuery)
|
||||
megabytesString := query.Get(MegabytesQuery)
|
||||
requestSizeInMegabytesString := query.Get(RequestSizeInMegabytesQuery)
|
||||
durationSecString := query.Get(common.DurationSecQuery)
|
||||
megabytesString := query.Get(common.MegabytesQuery)
|
||||
requestSizeInMegabytesString := query.Get(common.RequestSizeInMegabytesQuery)
|
||||
if durationSecString == "" || megabytesString == "" || requestSizeInMegabytesString == "" {
|
||||
http.Error(w, NotGivenFunctionArgument, http.StatusBadRequest)
|
||||
http.Error(w, common.NotGivenFunctionArgument, http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -125,7 +125,7 @@ func (handler *Controller) handleConsumeMem(w http.ResponseWriter, query url.Val
|
|||
megabytes, megabytesError := strconv.Atoi(megabytesString)
|
||||
requestSizeInMegabytes, requestSizeInMegabytesError := strconv.Atoi(requestSizeInMegabytesString)
|
||||
if durationSecError != nil || megabytesError != nil || requestSizeInMegabytesError != nil || requestSizeInMegabytes <= 0 {
|
||||
http.Error(w, IncorrectFunctionArgument, http.StatusBadRequest)
|
||||
http.Error(w, common.IncorrectFunctionArgument, http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -133,24 +133,24 @@ func (handler *Controller) handleConsumeMem(w http.ResponseWriter, query url.Val
|
|||
rest := megabytes - count*requestSizeInMegabytes
|
||||
fmt.Fprintf(w, "RC manager: sending %v requests to consume %v MB each and 1 request to consume %v MB\n", count, requestSizeInMegabytes, rest)
|
||||
if count > 0 {
|
||||
handler.waitGroup.Add(count)
|
||||
handler.sendConsumeMemRequests(w, count, requestSizeInMegabytes, durationSec)
|
||||
c.waitGroup.Add(count)
|
||||
c.sendConsumeMemRequests(w, count, requestSizeInMegabytes, durationSec)
|
||||
}
|
||||
if rest > 0 {
|
||||
handler.waitGroup.Add(1)
|
||||
go handler.sendOneConsumeMemRequest(w, rest, durationSec)
|
||||
c.waitGroup.Add(1)
|
||||
go c.sendOneConsumeMemRequest(w, rest, durationSec)
|
||||
}
|
||||
handler.waitGroup.Wait()
|
||||
c.waitGroup.Wait()
|
||||
}
|
||||
|
||||
func (handler *Controller) handleBumpMetric(w http.ResponseWriter, query url.Values) {
|
||||
func (c *controller) handleBumpMetric(w http.ResponseWriter, query url.Values) {
|
||||
// getting string data for handleBumpMetric
|
||||
metric := query.Get(MetricNameQuery)
|
||||
deltaString := query.Get(DeltaQuery)
|
||||
durationSecString := query.Get(DurationSecQuery)
|
||||
requestSizeCustomMetricString := query.Get(RequestSizeCustomMetricQuery)
|
||||
metric := query.Get(common.MetricNameQuery)
|
||||
deltaString := query.Get(common.DeltaQuery)
|
||||
durationSecString := query.Get(common.DurationSecQuery)
|
||||
requestSizeCustomMetricString := query.Get(common.RequestSizeCustomMetricQuery)
|
||||
if durationSecString == "" || metric == "" || deltaString == "" || requestSizeCustomMetricString == "" {
|
||||
http.Error(w, NotGivenFunctionArgument, http.StatusBadRequest)
|
||||
http.Error(w, common.NotGivenFunctionArgument, http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -159,7 +159,7 @@ func (handler *Controller) handleBumpMetric(w http.ResponseWriter, query url.Val
|
|||
delta, deltaError := strconv.Atoi(deltaString)
|
||||
requestSizeCustomMetric, requestSizeCustomMetricError := strconv.Atoi(requestSizeCustomMetricString)
|
||||
if durationSecError != nil || deltaError != nil || requestSizeCustomMetricError != nil || requestSizeCustomMetric <= 0 {
|
||||
http.Error(w, IncorrectFunctionArgument, http.StatusBadRequest)
|
||||
http.Error(w, common.IncorrectFunctionArgument, http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -167,31 +167,31 @@ func (handler *Controller) handleBumpMetric(w http.ResponseWriter, query url.Val
|
|||
rest := delta - count*requestSizeCustomMetric
|
||||
fmt.Fprintf(w, "RC manager: sending %v requests to bump custom metric by %v each and 1 request to bump by %v\n", count, requestSizeCustomMetric, rest)
|
||||
if count > 0 {
|
||||
handler.waitGroup.Add(count)
|
||||
handler.sendConsumeCustomMetric(w, metric, count, requestSizeCustomMetric, durationSec)
|
||||
c.waitGroup.Add(count)
|
||||
c.sendConsumeCustomMetric(w, metric, count, requestSizeCustomMetric, durationSec)
|
||||
}
|
||||
if rest > 0 {
|
||||
handler.waitGroup.Add(1)
|
||||
go handler.sendOneConsumeCustomMetric(w, metric, rest, durationSec)
|
||||
c.waitGroup.Add(1)
|
||||
go c.sendOneConsumeCustomMetric(w, metric, rest, durationSec)
|
||||
}
|
||||
handler.waitGroup.Wait()
|
||||
c.waitGroup.Wait()
|
||||
}
|
||||
|
||||
func (manager *Controller) sendConsumeCPURequests(w http.ResponseWriter, requests, millicores, durationSec int) {
|
||||
func (c *controller) sendConsumeCPURequests(w http.ResponseWriter, requests, millicores, durationSec int) {
|
||||
for i := 0; i < requests; i++ {
|
||||
go manager.sendOneConsumeCPURequest(w, millicores, durationSec)
|
||||
go c.sendOneConsumeCPURequest(w, millicores, durationSec)
|
||||
}
|
||||
}
|
||||
|
||||
func (manager *Controller) sendConsumeMemRequests(w http.ResponseWriter, requests, megabytes, durationSec int) {
|
||||
func (c *controller) sendConsumeMemRequests(w http.ResponseWriter, requests, megabytes, durationSec int) {
|
||||
for i := 0; i < requests; i++ {
|
||||
go manager.sendOneConsumeMemRequest(w, megabytes, durationSec)
|
||||
go c.sendOneConsumeMemRequest(w, megabytes, durationSec)
|
||||
}
|
||||
}
|
||||
|
||||
func (manager *Controller) sendConsumeCustomMetric(w http.ResponseWriter, metric string, requests, delta, durationSec int) {
|
||||
func (c *controller) sendConsumeCustomMetric(w http.ResponseWriter, metric string, requests, delta, durationSec int) {
|
||||
for i := 0; i < requests; i++ {
|
||||
go manager.sendOneConsumeCustomMetric(w, metric, delta, durationSec)
|
||||
go c.sendOneConsumeCustomMetric(w, metric, delta, durationSec)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -200,10 +200,10 @@ func createConsumerURL(suffix string) string {
|
|||
}
|
||||
|
||||
// sendOneConsumeCPURequest sends POST request for cpu consumption
|
||||
func (c *Controller) sendOneConsumeCPURequest(w http.ResponseWriter, millicores int, durationSec int) {
|
||||
func (c *controller) sendOneConsumeCPURequest(w http.ResponseWriter, millicores int, durationSec int) {
|
||||
defer c.waitGroup.Done()
|
||||
query := createConsumerURL(ConsumeCPUAddress)
|
||||
_, err := http.PostForm(query, url.Values{MillicoresQuery: {strconv.Itoa(millicores)}, DurationSecQuery: {strconv.Itoa(durationSec)}})
|
||||
query := createConsumerURL(common.ConsumeCPUAddress)
|
||||
_, err := http.PostForm(query, url.Values{common.MillicoresQuery: {strconv.Itoa(millicores)}, common.DurationSecQuery: {strconv.Itoa(durationSec)}})
|
||||
c.responseWriterLock.Lock()
|
||||
defer c.responseWriterLock.Unlock()
|
||||
if err != nil {
|
||||
|
@ -214,10 +214,10 @@ func (c *Controller) sendOneConsumeCPURequest(w http.ResponseWriter, millicores
|
|||
}
|
||||
|
||||
// sendOneConsumeMemRequest sends POST request for memory consumption
|
||||
func (c *Controller) sendOneConsumeMemRequest(w http.ResponseWriter, megabytes int, durationSec int) {
|
||||
func (c *controller) sendOneConsumeMemRequest(w http.ResponseWriter, megabytes int, durationSec int) {
|
||||
defer c.waitGroup.Done()
|
||||
query := createConsumerURL(ConsumeMemAddress)
|
||||
_, err := http.PostForm(query, url.Values{MegabytesQuery: {strconv.Itoa(megabytes)}, DurationSecQuery: {strconv.Itoa(durationSec)}})
|
||||
query := createConsumerURL(common.ConsumeMemAddress)
|
||||
_, err := http.PostForm(query, url.Values{common.MegabytesQuery: {strconv.Itoa(megabytes)}, common.DurationSecQuery: {strconv.Itoa(durationSec)}})
|
||||
c.responseWriterLock.Lock()
|
||||
defer c.responseWriterLock.Unlock()
|
||||
if err != nil {
|
||||
|
@ -228,11 +228,11 @@ func (c *Controller) sendOneConsumeMemRequest(w http.ResponseWriter, megabytes i
|
|||
}
|
||||
|
||||
// sendOneConsumeCustomMetric sends POST request for custom metric consumption
|
||||
func (c *Controller) sendOneConsumeCustomMetric(w http.ResponseWriter, customMetricName string, delta int, durationSec int) {
|
||||
func (c *controller) sendOneConsumeCustomMetric(w http.ResponseWriter, customMetricName string, delta int, durationSec int) {
|
||||
defer c.waitGroup.Done()
|
||||
query := createConsumerURL(BumpMetricAddress)
|
||||
query := createConsumerURL(common.BumpMetricAddress)
|
||||
_, err := http.PostForm(query,
|
||||
url.Values{MetricNameQuery: {customMetricName}, DurationSecQuery: {strconv.Itoa(durationSec)}, DeltaQuery: {strconv.Itoa(delta)}})
|
||||
url.Values{common.MetricNameQuery: {customMetricName}, common.DurationSecQuery: {strconv.Itoa(durationSec)}, common.DeltaQuery: {strconv.Itoa(delta)}})
|
||||
c.responseWriterLock.Lock()
|
||||
defer c.responseWriterLock.Unlock()
|
||||
if err != nil {
|
||||
|
|
|
@ -24,26 +24,28 @@ import (
|
|||
"sync"
|
||||
"time"
|
||||
|
||||
. "k8s.io/kubernetes/test/images/resource-consumer/common"
|
||||
"k8s.io/kubernetes/test/images/resource-consumer/common"
|
||||
)
|
||||
|
||||
// ResourceConsumerHandler holds metrics for a resource consumer.
|
||||
type ResourceConsumerHandler struct {
|
||||
metrics map[string]float64
|
||||
metricsLock sync.Mutex
|
||||
}
|
||||
|
||||
// NewResourceConsumerHandler creates and initializes a ResourceConsumerHandler to defaults.
|
||||
func NewResourceConsumerHandler() *ResourceConsumerHandler {
|
||||
return &ResourceConsumerHandler{metrics: map[string]float64{}}
|
||||
}
|
||||
|
||||
func (handler *ResourceConsumerHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) {
|
||||
// handle exposing metrics in Prometheus format (both GET & POST)
|
||||
if req.URL.Path == MetricsAddress {
|
||||
if req.URL.Path == common.MetricsAddress {
|
||||
handler.handleMetrics(w)
|
||||
return
|
||||
}
|
||||
if req.Method != "POST" {
|
||||
http.Error(w, BadRequest, http.StatusBadRequest)
|
||||
http.Error(w, common.BadRequest, http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
// parsing POST request data and URL data
|
||||
|
@ -52,34 +54,34 @@ func (handler *ResourceConsumerHandler) ServeHTTP(w http.ResponseWriter, req *ht
|
|||
return
|
||||
}
|
||||
// handle consumeCPU
|
||||
if req.URL.Path == ConsumeCPUAddress {
|
||||
if req.URL.Path == common.ConsumeCPUAddress {
|
||||
handler.handleConsumeCPU(w, req.Form)
|
||||
return
|
||||
}
|
||||
// handle consumeMem
|
||||
if req.URL.Path == ConsumeMemAddress {
|
||||
if req.URL.Path == common.ConsumeMemAddress {
|
||||
handler.handleConsumeMem(w, req.Form)
|
||||
return
|
||||
}
|
||||
// handle getCurrentStatus
|
||||
if req.URL.Path == GetCurrentStatusAddress {
|
||||
if req.URL.Path == common.GetCurrentStatusAddress {
|
||||
handler.handleGetCurrentStatus(w)
|
||||
return
|
||||
}
|
||||
// handle bumpMetric
|
||||
if req.URL.Path == BumpMetricAddress {
|
||||
if req.URL.Path == common.BumpMetricAddress {
|
||||
handler.handleBumpMetric(w, req.Form)
|
||||
return
|
||||
}
|
||||
http.Error(w, fmt.Sprintf("%s: %s", UnknownFunction, req.URL.Path), http.StatusNotFound)
|
||||
http.Error(w, fmt.Sprintf("%s: %s", common.UnknownFunction, req.URL.Path), http.StatusNotFound)
|
||||
}
|
||||
|
||||
func (handler *ResourceConsumerHandler) handleConsumeCPU(w http.ResponseWriter, query url.Values) {
|
||||
// getting string data for consumeCPU
|
||||
durationSecString := query.Get(DurationSecQuery)
|
||||
millicoresString := query.Get(MillicoresQuery)
|
||||
durationSecString := query.Get(common.DurationSecQuery)
|
||||
millicoresString := query.Get(common.MillicoresQuery)
|
||||
if durationSecString == "" || millicoresString == "" {
|
||||
http.Error(w, NotGivenFunctionArgument, http.StatusBadRequest)
|
||||
http.Error(w, common.NotGivenFunctionArgument, http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -87,22 +89,22 @@ func (handler *ResourceConsumerHandler) handleConsumeCPU(w http.ResponseWriter,
|
|||
durationSec, durationSecError := strconv.Atoi(durationSecString)
|
||||
millicores, millicoresError := strconv.Atoi(millicoresString)
|
||||
if durationSecError != nil || millicoresError != nil {
|
||||
http.Error(w, IncorrectFunctionArgument, http.StatusBadRequest)
|
||||
http.Error(w, common.IncorrectFunctionArgument, http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
go ConsumeCPU(millicores, durationSec)
|
||||
fmt.Fprintln(w, ConsumeCPUAddress[1:])
|
||||
fmt.Fprintln(w, millicores, MillicoresQuery)
|
||||
fmt.Fprintln(w, durationSec, DurationSecQuery)
|
||||
fmt.Fprintln(w, common.ConsumeCPUAddress[1:])
|
||||
fmt.Fprintln(w, millicores, common.MillicoresQuery)
|
||||
fmt.Fprintln(w, durationSec, common.DurationSecQuery)
|
||||
}
|
||||
|
||||
func (handler *ResourceConsumerHandler) handleConsumeMem(w http.ResponseWriter, query url.Values) {
|
||||
// getting string data for consumeMem
|
||||
durationSecString := query.Get(DurationSecQuery)
|
||||
megabytesString := query.Get(MegabytesQuery)
|
||||
durationSecString := query.Get(common.DurationSecQuery)
|
||||
megabytesString := query.Get(common.MegabytesQuery)
|
||||
if durationSecString == "" || megabytesString == "" {
|
||||
http.Error(w, NotGivenFunctionArgument, http.StatusBadRequest)
|
||||
http.Error(w, common.NotGivenFunctionArgument, http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -110,20 +112,20 @@ func (handler *ResourceConsumerHandler) handleConsumeMem(w http.ResponseWriter,
|
|||
durationSec, durationSecError := strconv.Atoi(durationSecString)
|
||||
megabytes, megabytesError := strconv.Atoi(megabytesString)
|
||||
if durationSecError != nil || megabytesError != nil {
|
||||
http.Error(w, IncorrectFunctionArgument, http.StatusBadRequest)
|
||||
http.Error(w, common.IncorrectFunctionArgument, http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
go ConsumeMem(megabytes, durationSec)
|
||||
fmt.Fprintln(w, ConsumeMemAddress[1:])
|
||||
fmt.Fprintln(w, megabytes, MegabytesQuery)
|
||||
fmt.Fprintln(w, durationSec, DurationSecQuery)
|
||||
fmt.Fprintln(w, common.ConsumeMemAddress[1:])
|
||||
fmt.Fprintln(w, megabytes, common.MegabytesQuery)
|
||||
fmt.Fprintln(w, durationSec, common.DurationSecQuery)
|
||||
}
|
||||
|
||||
func (handler *ResourceConsumerHandler) handleGetCurrentStatus(w http.ResponseWriter) {
|
||||
GetCurrentStatus()
|
||||
fmt.Fprintln(w, "Warning: not implemented!")
|
||||
fmt.Fprint(w, GetCurrentStatusAddress[1:])
|
||||
fmt.Fprint(w, common.GetCurrentStatusAddress[1:])
|
||||
}
|
||||
|
||||
func (handler *ResourceConsumerHandler) handleMetrics(w http.ResponseWriter) {
|
||||
|
@ -154,11 +156,11 @@ func (handler *ResourceConsumerHandler) bumpMetric(metric string, delta float64,
|
|||
|
||||
func (handler *ResourceConsumerHandler) handleBumpMetric(w http.ResponseWriter, query url.Values) {
|
||||
// getting string data for handleBumpMetric
|
||||
metric := query.Get(MetricNameQuery)
|
||||
deltaString := query.Get(DeltaQuery)
|
||||
durationSecString := query.Get(DurationSecQuery)
|
||||
metric := query.Get(common.MetricNameQuery)
|
||||
deltaString := query.Get(common.DeltaQuery)
|
||||
durationSecString := query.Get(common.DurationSecQuery)
|
||||
if durationSecString == "" || metric == "" || deltaString == "" {
|
||||
http.Error(w, NotGivenFunctionArgument, http.StatusBadRequest)
|
||||
http.Error(w, common.NotGivenFunctionArgument, http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -166,13 +168,13 @@ func (handler *ResourceConsumerHandler) handleBumpMetric(w http.ResponseWriter,
|
|||
durationSec, durationSecError := strconv.Atoi(durationSecString)
|
||||
delta, deltaError := strconv.ParseFloat(deltaString, 64)
|
||||
if durationSecError != nil || deltaError != nil {
|
||||
http.Error(w, IncorrectFunctionArgument, http.StatusBadRequest)
|
||||
http.Error(w, common.IncorrectFunctionArgument, http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
go handler.bumpMetric(metric, delta, time.Duration(durationSec)*time.Second)
|
||||
fmt.Fprintln(w, BumpMetricAddress[1:])
|
||||
fmt.Fprintln(w, metric, MetricNameQuery)
|
||||
fmt.Fprintln(w, delta, DeltaQuery)
|
||||
fmt.Fprintln(w, durationSec, DurationSecQuery)
|
||||
fmt.Fprintln(w, common.BumpMetricAddress[1:])
|
||||
fmt.Fprintln(w, metric, common.MetricNameQuery)
|
||||
fmt.Fprintln(w, delta, common.DeltaQuery)
|
||||
fmt.Fprintln(w, durationSec, common.DurationSecQuery)
|
||||
}
|
||||
|
|
|
@ -28,6 +28,7 @@ const (
|
|||
consumeMemBinary = "stress"
|
||||
)
|
||||
|
||||
// ConsumeCPU consumes a given number of millicores for the specified duration.
|
||||
func ConsumeCPU(millicores int, durationSec int) {
|
||||
log.Printf("ConsumeCPU millicores: %v, durationSec: %v", millicores, durationSec)
|
||||
// creating new consume cpu process
|
||||
|
@ -37,6 +38,7 @@ func ConsumeCPU(millicores int, durationSec int) {
|
|||
consumeCPU.Run()
|
||||
}
|
||||
|
||||
// ConsumeMem consumes a given number of megabytes for the specified duration.
|
||||
func ConsumeMem(megabytes int, durationSec int) {
|
||||
log.Printf("ConsumeMem megabytes: %v, durationSec: %v", megabytes, durationSec)
|
||||
megabytesString := strconv.Itoa(megabytes) + "M"
|
||||
|
@ -46,6 +48,7 @@ func ConsumeMem(megabytes int, durationSec int) {
|
|||
consumeMem.Run()
|
||||
}
|
||||
|
||||
// GetCurrentStatus prints out a no-op.
|
||||
func GetCurrentStatus() {
|
||||
log.Printf("GetCurrentStatus")
|
||||
// not implemented
|
||||
|
|
Loading…
Reference in New Issue