mirror of
https://github.com/ceph/ceph-csi.git
synced 2025-06-14 10:53:34 +00:00
vendor files
This commit is contained in:
3
vendor/k8s.io/kubernetes/test/images/resource-consumer/.gitignore
generated
vendored
Normal file
3
vendor/k8s.io/kubernetes/test/images/resource-consumer/.gitignore
generated
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
consumer
|
||||
consume-cpu/consume-cpu
|
||||
controller/controller
|
4
vendor/k8s.io/kubernetes/test/images/resource-consumer/BASEIMAGE
generated
vendored
Normal file
4
vendor/k8s.io/kubernetes/test/images/resource-consumer/BASEIMAGE
generated
vendored
Normal file
@ -0,0 +1,4 @@
|
||||
amd64=gcr.io/google-containers/debian-base-amd64:0.3
|
||||
arm=gcr.io/google-containers/debian-base-arm:0.3
|
||||
arm64=gcr.io/google-containers/debian-base-arm64:0.3
|
||||
ppc64le=gcr.io/google-containers/debian-base-ppc64le:0.3
|
42
vendor/k8s.io/kubernetes/test/images/resource-consumer/BUILD
generated
vendored
Normal file
42
vendor/k8s.io/kubernetes/test/images/resource-consumer/BUILD
generated
vendored
Normal file
@ -0,0 +1,42 @@
|
||||
package(default_visibility = ["//visibility:public"])
|
||||
|
||||
load(
|
||||
"@io_bazel_rules_go//go:def.bzl",
|
||||
"go_binary",
|
||||
"go_library",
|
||||
)
|
||||
|
||||
go_binary(
|
||||
name = "resource-consumer",
|
||||
importpath = "k8s.io/kubernetes/test/images/resource-consumer",
|
||||
library = ":go_default_library",
|
||||
)
|
||||
|
||||
go_library(
|
||||
name = "go_default_library",
|
||||
srcs = [
|
||||
"resource_consumer.go",
|
||||
"resource_consumer_handler.go",
|
||||
"utils.go",
|
||||
],
|
||||
importpath = "k8s.io/kubernetes/test/images/resource-consumer",
|
||||
deps = ["//test/images/resource-consumer/common:go_default_library"],
|
||||
)
|
||||
|
||||
filegroup(
|
||||
name = "package-srcs",
|
||||
srcs = glob(["**"]),
|
||||
tags = ["automanaged"],
|
||||
visibility = ["//visibility:private"],
|
||||
)
|
||||
|
||||
filegroup(
|
||||
name = "all-srcs",
|
||||
srcs = [
|
||||
":package-srcs",
|
||||
"//test/images/resource-consumer/common:all-srcs",
|
||||
"//test/images/resource-consumer/consume-cpu:all-srcs",
|
||||
"//test/images/resource-consumer/controller:all-srcs",
|
||||
],
|
||||
tags = ["automanaged"],
|
||||
)
|
24
vendor/k8s.io/kubernetes/test/images/resource-consumer/Dockerfile
generated
vendored
Normal file
24
vendor/k8s.io/kubernetes/test/images/resource-consumer/Dockerfile
generated
vendored
Normal file
@ -0,0 +1,24 @@
|
||||
# Copyright 2016 The Kubernetes 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.
|
||||
|
||||
FROM BASEIMAGE
|
||||
|
||||
CROSS_BUILD_COPY qemu-QEMUARCH-static /usr/bin/
|
||||
|
||||
RUN clean-install stress
|
||||
|
||||
ADD consumer /consumer
|
||||
ADD consume-cpu /consume-cpu
|
||||
EXPOSE 8080
|
||||
ENTRYPOINT ["/consumer"]
|
25
vendor/k8s.io/kubernetes/test/images/resource-consumer/Makefile
generated
vendored
Normal file
25
vendor/k8s.io/kubernetes/test/images/resource-consumer/Makefile
generated
vendored
Normal file
@ -0,0 +1,25 @@
|
||||
# Copyright 2016 The Kubernetes 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.
|
||||
|
||||
SRCS = consumer consume-cpu/consume-cpu
|
||||
ARCH ?= amd64
|
||||
TARGET ?= $(CURDIR)
|
||||
GOLANG_VERSION ?= latest
|
||||
SRC_DIR = $(notdir $(shell pwd))
|
||||
export
|
||||
|
||||
bin:
|
||||
../image-util.sh bin $(SRCS)
|
||||
|
||||
.PHONY: bin
|
85
vendor/k8s.io/kubernetes/test/images/resource-consumer/README.md
generated
vendored
Normal file
85
vendor/k8s.io/kubernetes/test/images/resource-consumer/README.md
generated
vendored
Normal file
@ -0,0 +1,85 @@
|
||||
# Resource Consumer
|
||||
|
||||
## Overview
|
||||
Resource Consumer is a tool which allows to generate cpu/memory utilization in a container.
|
||||
The reason why it was created is testing kubernetes autoscaling.
|
||||
Resource Consumer can help with autoscaling tests for:
|
||||
- cluster size autoscaling,
|
||||
- horizontal autoscaling of pod - changing the size of replication controller,
|
||||
- vertical autoscaling of pod - changing its resource limits.
|
||||
|
||||
## Usage
|
||||
Resource Consumer starts an HTTP server and handle sent requests.
|
||||
It listens on port given as a flag (default 8080).
|
||||
Action of consuming resources is send to the container by a POST http request.
|
||||
Each http request creates new process.
|
||||
Http request handler is in file resource_consumer_handler.go
|
||||
|
||||
The container consumes specified amount of resources:
|
||||
|
||||
- CPU in millicores,
|
||||
- Memory in megabytes,
|
||||
- Fake custom metrics.
|
||||
|
||||
###Consume CPU http request
|
||||
- suffix "ConsumeCPU",
|
||||
- parameters "millicores" and "durationSec".
|
||||
|
||||
Consumes specified amount of millicores for durationSec seconds.
|
||||
Consume CPU uses "./consume-cpu/consume-cpu" binary (file consume-cpu/consume_cpu.go).
|
||||
When CPU consumption is too low this binary uses cpu by calculating math.sqrt(0) 10^7 times
|
||||
and if consumption is too high binary sleeps for 10 millisecond.
|
||||
One replica of Resource Consumer cannot consume more that 1 cpu.
|
||||
|
||||
###Consume Memory http request
|
||||
- suffix "ConsumeMem",
|
||||
- parameters "megabytes" and "durationSec".
|
||||
|
||||
Consumes specified amount of megabytes for durationSec seconds.
|
||||
Consume Memory uses stress tool (stress -m 1 --vm-bytes megabytes --vm-hang 0 -t durationSec).
|
||||
Request leading to consuming more memory then container limit will be ignored.
|
||||
|
||||
###Bump value of a fake custom metric
|
||||
- suffix "BumpMetric",
|
||||
- parameters "metric", "delta" and "durationSec".
|
||||
|
||||
Bumps metric with given name by delta for durationSec seconds.
|
||||
Custom metrics in Prometheus format are exposed on "/metrics" endpoint.
|
||||
|
||||
###CURL example
|
||||
```console
|
||||
$ kubectl run resource-consumer --image=gcr.io/google_containers/resource_consumer:beta --expose --service-overrides='{ "spec": { "type": "LoadBalancer" } }' --port 8080
|
||||
$ kubectl get services resource-consumer
|
||||
```
|
||||
|
||||
There are two IPs. The first one is internal, while the second one is the external load-balanced IP. Both serve port 8080. (Use second one)
|
||||
|
||||
```console
|
||||
$ curl --data "millicores=300&durationSec=600" http://<EXTERNAL-IP>:8080/ConsumeCPU
|
||||
```
|
||||
|
||||
300 millicores will be consumed for 600 seconds.
|
||||
|
||||
## Image
|
||||
|
||||
Docker image of Resource Consumer can be found in Google Container Registry as gcr.io/google_containers/resource_consumer:beta
|
||||
|
||||
## Use cases
|
||||
|
||||
###Cluster size autoscaling
|
||||
1. Consume more resources on each node that is specified for autoscaler
|
||||
2. Observe that cluster size increased
|
||||
|
||||
###Horizontal autoscaling of pod
|
||||
1. Create consuming RC and start consuming appropriate amount of resources
|
||||
2. Observe that RC has been resized
|
||||
3. Observe that usage on each replica decreased
|
||||
|
||||
###Vertical autoscaling of pod
|
||||
1. Create consuming pod and start consuming appropriate amount of resources
|
||||
2. Observed that limits has been increased
|
||||
|
||||
|
||||
|
||||
|
||||
[]()
|
1
vendor/k8s.io/kubernetes/test/images/resource-consumer/VERSION
generated
vendored
Normal file
1
vendor/k8s.io/kubernetes/test/images/resource-consumer/VERSION
generated
vendored
Normal file
@ -0,0 +1 @@
|
||||
1.3
|
25
vendor/k8s.io/kubernetes/test/images/resource-consumer/common/BUILD
generated
vendored
Normal file
25
vendor/k8s.io/kubernetes/test/images/resource-consumer/common/BUILD
generated
vendored
Normal file
@ -0,0 +1,25 @@
|
||||
package(default_visibility = ["//visibility:public"])
|
||||
|
||||
load(
|
||||
"@io_bazel_rules_go//go:def.bzl",
|
||||
"go_library",
|
||||
)
|
||||
|
||||
go_library(
|
||||
name = "go_default_library",
|
||||
srcs = ["common.go"],
|
||||
importpath = "k8s.io/kubernetes/test/images/resource-consumer/common",
|
||||
)
|
||||
|
||||
filegroup(
|
||||
name = "package-srcs",
|
||||
srcs = glob(["**"]),
|
||||
tags = ["automanaged"],
|
||||
visibility = ["//visibility:private"],
|
||||
)
|
||||
|
||||
filegroup(
|
||||
name = "all-srcs",
|
||||
srcs = [":package-srcs"],
|
||||
tags = ["automanaged"],
|
||||
)
|
41
vendor/k8s.io/kubernetes/test/images/resource-consumer/common/common.go
generated
vendored
Normal file
41
vendor/k8s.io/kubernetes/test/images/resource-consumer/common/common.go
generated
vendored
Normal file
@ -0,0 +1,41 @@
|
||||
/*
|
||||
Copyright 2016 The Kubernetes 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 common
|
||||
|
||||
const (
|
||||
ConsumeCPUAddress = "/ConsumeCPU"
|
||||
ConsumeMemAddress = "/ConsumeMem"
|
||||
BumpMetricAddress = "/BumpMetric"
|
||||
GetCurrentStatusAddress = "/GetCurrentStatus"
|
||||
MetricsAddress = "/Metrics"
|
||||
|
||||
MillicoresQuery = "millicores"
|
||||
MegabytesQuery = "megabytes"
|
||||
MetricNameQuery = "metric"
|
||||
DeltaQuery = "delta"
|
||||
DurationSecQuery = "durationSec"
|
||||
RequestSizeInMillicoresQuery = "requestSizeMillicores"
|
||||
RequestSizeInMegabytesQuery = "requestSizeMegabytes"
|
||||
RequestSizeCustomMetricQuery = "requestSizeMetrics"
|
||||
|
||||
BadRequest = "Bad request. Not a POST request"
|
||||
UnknownFunction = "unknown function"
|
||||
IncorrectFunctionArgument = "incorrect function argument"
|
||||
NotGivenFunctionArgument = "not given function argument"
|
||||
|
||||
FrameworkName = "horizontal-pod-autoscaling"
|
||||
)
|
33
vendor/k8s.io/kubernetes/test/images/resource-consumer/consume-cpu/BUILD
generated
vendored
Normal file
33
vendor/k8s.io/kubernetes/test/images/resource-consumer/consume-cpu/BUILD
generated
vendored
Normal file
@ -0,0 +1,33 @@
|
||||
package(default_visibility = ["//visibility:public"])
|
||||
|
||||
load(
|
||||
"@io_bazel_rules_go//go:def.bzl",
|
||||
"go_binary",
|
||||
"go_library",
|
||||
)
|
||||
|
||||
go_binary(
|
||||
name = "consume-cpu",
|
||||
importpath = "k8s.io/kubernetes/test/images/resource-consumer/consume-cpu",
|
||||
library = ":go_default_library",
|
||||
)
|
||||
|
||||
go_library(
|
||||
name = "go_default_library",
|
||||
srcs = ["consume_cpu.go"],
|
||||
importpath = "k8s.io/kubernetes/test/images/resource-consumer/consume-cpu",
|
||||
deps = ["//vendor/bitbucket.org/bertimus9/systemstat:go_default_library"],
|
||||
)
|
||||
|
||||
filegroup(
|
||||
name = "package-srcs",
|
||||
srcs = glob(["**"]),
|
||||
tags = ["automanaged"],
|
||||
visibility = ["//visibility:private"],
|
||||
)
|
||||
|
||||
filegroup(
|
||||
name = "all-srcs",
|
||||
srcs = [":package-srcs"],
|
||||
tags = ["automanaged"],
|
||||
)
|
56
vendor/k8s.io/kubernetes/test/images/resource-consumer/consume-cpu/consume_cpu.go
generated
vendored
Normal file
56
vendor/k8s.io/kubernetes/test/images/resource-consumer/consume-cpu/consume_cpu.go
generated
vendored
Normal file
@ -0,0 +1,56 @@
|
||||
/*
|
||||
Copyright 2015 The Kubernetes 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 (
|
||||
"flag"
|
||||
"math"
|
||||
"time"
|
||||
|
||||
"bitbucket.org/bertimus9/systemstat"
|
||||
)
|
||||
|
||||
const sleep = time.Duration(10) * time.Millisecond
|
||||
|
||||
func doSomething() {
|
||||
for i := 1; i < 10000000; i++ {
|
||||
x := float64(0)
|
||||
x += math.Sqrt(0)
|
||||
}
|
||||
}
|
||||
|
||||
var (
|
||||
millicores = flag.Int("millicores", 0, "millicores number")
|
||||
durationSec = flag.Int("duration-sec", 0, "duration time in seconds")
|
||||
)
|
||||
|
||||
func main() {
|
||||
flag.Parse()
|
||||
// convert millicores to percentage
|
||||
millicoresPct := float64(*millicores) / float64(10)
|
||||
duration := time.Duration(*durationSec) * time.Second
|
||||
start := time.Now()
|
||||
first := systemstat.GetProcCPUSample()
|
||||
for time.Now().Sub(start) < duration {
|
||||
cpu := systemstat.GetProcCPUAverage(first, systemstat.GetProcCPUSample(), systemstat.GetUptime().Uptime)
|
||||
if cpu.TotalPct < millicoresPct {
|
||||
doSomething()
|
||||
} else {
|
||||
time.Sleep(sleep)
|
||||
}
|
||||
}
|
||||
}
|
5
vendor/k8s.io/kubernetes/test/images/resource-consumer/controller/BASEIMAGE
generated
vendored
Normal file
5
vendor/k8s.io/kubernetes/test/images/resource-consumer/controller/BASEIMAGE
generated
vendored
Normal file
@ -0,0 +1,5 @@
|
||||
amd64=busybox
|
||||
arm=arm32v6/busybox
|
||||
arm64=arm64v8/busybox
|
||||
ppc64le=ppc64le/busybox
|
||||
s390x=s390x/busybox
|
33
vendor/k8s.io/kubernetes/test/images/resource-consumer/controller/BUILD
generated
vendored
Normal file
33
vendor/k8s.io/kubernetes/test/images/resource-consumer/controller/BUILD
generated
vendored
Normal file
@ -0,0 +1,33 @@
|
||||
package(default_visibility = ["//visibility:public"])
|
||||
|
||||
load(
|
||||
"@io_bazel_rules_go//go:def.bzl",
|
||||
"go_binary",
|
||||
"go_library",
|
||||
)
|
||||
|
||||
go_binary(
|
||||
name = "controller",
|
||||
importpath = "k8s.io/kubernetes/test/images/resource-consumer/controller",
|
||||
library = ":go_default_library",
|
||||
)
|
||||
|
||||
go_library(
|
||||
name = "go_default_library",
|
||||
srcs = ["controller.go"],
|
||||
importpath = "k8s.io/kubernetes/test/images/resource-consumer/controller",
|
||||
deps = ["//test/images/resource-consumer/common:go_default_library"],
|
||||
)
|
||||
|
||||
filegroup(
|
||||
name = "package-srcs",
|
||||
srcs = glob(["**"]),
|
||||
tags = ["automanaged"],
|
||||
visibility = ["//visibility:private"],
|
||||
)
|
||||
|
||||
filegroup(
|
||||
name = "all-srcs",
|
||||
srcs = [":package-srcs"],
|
||||
tags = ["automanaged"],
|
||||
)
|
18
vendor/k8s.io/kubernetes/test/images/resource-consumer/controller/Dockerfile
generated
vendored
Normal file
18
vendor/k8s.io/kubernetes/test/images/resource-consumer/controller/Dockerfile
generated
vendored
Normal file
@ -0,0 +1,18 @@
|
||||
# Copyright 2016 The Kubernetes 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.
|
||||
|
||||
FROM BASEIMAGE
|
||||
ADD controller /controller
|
||||
EXPOSE 8080
|
||||
ENTRYPOINT ["/controller"]
|
25
vendor/k8s.io/kubernetes/test/images/resource-consumer/controller/Makefile
generated
vendored
Normal file
25
vendor/k8s.io/kubernetes/test/images/resource-consumer/controller/Makefile
generated
vendored
Normal file
@ -0,0 +1,25 @@
|
||||
# Copyright 2017 The Kubernetes 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.
|
||||
|
||||
SRCS=controller
|
||||
ARCH ?= amd64
|
||||
TARGET ?= $(CURDIR)
|
||||
GOLANG_VERSION ?= latest
|
||||
SRC_DIR = resource-consumer/$(notdir $(shell pwd))
|
||||
export
|
||||
|
||||
bin:
|
||||
../../image-util.sh bin $(SRCS)
|
||||
|
||||
.PHONY: bin
|
1
vendor/k8s.io/kubernetes/test/images/resource-consumer/controller/VERSION
generated
vendored
Normal file
1
vendor/k8s.io/kubernetes/test/images/resource-consumer/controller/VERSION
generated
vendored
Normal file
@ -0,0 +1 @@
|
||||
1.0
|
243
vendor/k8s.io/kubernetes/test/images/resource-consumer/controller/controller.go
generated
vendored
Normal file
243
vendor/k8s.io/kubernetes/test/images/resource-consumer/controller/controller.go
generated
vendored
Normal file
@ -0,0 +1,243 @@
|
||||
/*
|
||||
Copyright 2016 The Kubernetes 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 (
|
||||
"flag"
|
||||
"fmt"
|
||||
"log"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strconv"
|
||||
"sync"
|
||||
|
||||
. "k8s.io/kubernetes/test/images/resource-consumer/common"
|
||||
)
|
||||
|
||||
var port = flag.Int("port", 8080, "Port number.")
|
||||
var consumerPort = flag.Int("consumer-port", 8080, "Port number of consumers.")
|
||||
var consumerServiceName = flag.String("consumer-service-name", "resource-consumer", "Name of service containing resource consumers.")
|
||||
var consumerServiceNamespace = flag.String("consumer-service-namespace", "default", "Namespace of service containing resource consumers.")
|
||||
|
||||
func main() {
|
||||
flag.Parse()
|
||||
mgr := NewController()
|
||||
log.Fatal(http.ListenAndServe(fmt.Sprintf(":%d", *port), mgr))
|
||||
}
|
||||
|
||||
type Controller struct {
|
||||
responseWriterLock sync.Mutex
|
||||
waitGroup sync.WaitGroup
|
||||
}
|
||||
|
||||
func NewController() *Controller {
|
||||
c := &Controller{}
|
||||
return c
|
||||
}
|
||||
|
||||
func (handler *Controller) ServeHTTP(w http.ResponseWriter, req *http.Request) {
|
||||
if req.Method != "POST" {
|
||||
http.Error(w, BadRequest, http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
// parsing POST request data and URL data
|
||||
if err := req.ParseForm(); err != nil {
|
||||
http.Error(w, err.Error(), http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
// handle consumeCPU
|
||||
if req.URL.Path == ConsumeCPUAddress {
|
||||
handler.handleConsumeCPU(w, req.Form)
|
||||
return
|
||||
}
|
||||
// handle consumeMem
|
||||
if req.URL.Path == ConsumeMemAddress {
|
||||
handler.handleConsumeMem(w, req.Form)
|
||||
return
|
||||
}
|
||||
// handle bumpMetric
|
||||
if req.URL.Path == BumpMetricAddress {
|
||||
handler.handleBumpMetric(w, req.Form)
|
||||
return
|
||||
}
|
||||
http.Error(w, UnknownFunction, http.StatusNotFound)
|
||||
}
|
||||
|
||||
func (handler *Controller) handleConsumeCPU(w http.ResponseWriter, query url.Values) {
|
||||
// geting string data for consumeCPU
|
||||
durationSecString := query.Get(DurationSecQuery)
|
||||
millicoresString := query.Get(MillicoresQuery)
|
||||
requestSizeInMillicoresString := query.Get(RequestSizeInMillicoresQuery)
|
||||
if durationSecString == "" || millicoresString == "" || requestSizeInMillicoresString == "" {
|
||||
http.Error(w, NotGivenFunctionArgument, http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
// convert data (strings to ints) for consumeCPU
|
||||
durationSec, durationSecError := strconv.Atoi(durationSecString)
|
||||
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)
|
||||
return
|
||||
}
|
||||
|
||||
count := millicores / requestSizeInMillicores
|
||||
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)
|
||||
}
|
||||
if rest > 0 {
|
||||
handler.waitGroup.Add(1)
|
||||
go handler.sendOneConsumeCPURequest(w, rest, durationSec)
|
||||
}
|
||||
handler.waitGroup.Wait()
|
||||
}
|
||||
|
||||
func (handler *Controller) handleConsumeMem(w http.ResponseWriter, query url.Values) {
|
||||
// geting string data for consumeMem
|
||||
durationSecString := query.Get(DurationSecQuery)
|
||||
megabytesString := query.Get(MegabytesQuery)
|
||||
requestSizeInMegabytesString := query.Get(RequestSizeInMegabytesQuery)
|
||||
if durationSecString == "" || megabytesString == "" || requestSizeInMegabytesString == "" {
|
||||
http.Error(w, NotGivenFunctionArgument, http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
// convert data (strings to ints) for consumeMem
|
||||
durationSec, durationSecError := strconv.Atoi(durationSecString)
|
||||
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)
|
||||
return
|
||||
}
|
||||
|
||||
count := megabytes / requestSizeInMegabytes
|
||||
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)
|
||||
}
|
||||
if rest > 0 {
|
||||
handler.waitGroup.Add(1)
|
||||
go handler.sendOneConsumeMemRequest(w, rest, durationSec)
|
||||
}
|
||||
handler.waitGroup.Wait()
|
||||
}
|
||||
|
||||
func (handler *Controller) handleBumpMetric(w http.ResponseWriter, query url.Values) {
|
||||
// geting string data for handleBumpMetric
|
||||
metric := query.Get(MetricNameQuery)
|
||||
deltaString := query.Get(DeltaQuery)
|
||||
durationSecString := query.Get(DurationSecQuery)
|
||||
requestSizeCustomMetricString := query.Get(RequestSizeCustomMetricQuery)
|
||||
if durationSecString == "" || metric == "" || deltaString == "" || requestSizeCustomMetricString == "" {
|
||||
http.Error(w, NotGivenFunctionArgument, http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
// convert data (strings to ints/floats) for handleBumpMetric
|
||||
durationSec, durationSecError := strconv.Atoi(durationSecString)
|
||||
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)
|
||||
return
|
||||
}
|
||||
|
||||
count := delta / requestSizeCustomMetric
|
||||
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)
|
||||
}
|
||||
if rest > 0 {
|
||||
handler.waitGroup.Add(1)
|
||||
go handler.sendOneConsumeCustomMetric(w, metric, rest, durationSec)
|
||||
}
|
||||
handler.waitGroup.Wait()
|
||||
}
|
||||
|
||||
func (manager *Controller) sendConsumeCPURequests(w http.ResponseWriter, requests, millicores, durationSec int) {
|
||||
for i := 0; i < requests; i++ {
|
||||
go manager.sendOneConsumeCPURequest(w, millicores, durationSec)
|
||||
}
|
||||
}
|
||||
|
||||
func (manager *Controller) sendConsumeMemRequests(w http.ResponseWriter, requests, megabytes, durationSec int) {
|
||||
for i := 0; i < requests; i++ {
|
||||
go manager.sendOneConsumeMemRequest(w, megabytes, durationSec)
|
||||
}
|
||||
}
|
||||
|
||||
func (manager *Controller) sendConsumeCustomMetric(w http.ResponseWriter, metric string, requests, delta, durationSec int) {
|
||||
for i := 0; i < requests; i++ {
|
||||
go manager.sendOneConsumeCustomMetric(w, metric, delta, durationSec)
|
||||
}
|
||||
}
|
||||
|
||||
func createConsumerURL(suffix string) string {
|
||||
return fmt.Sprintf("http://%s.%s.svc.cluster.local:%d%s", *consumerServiceName, *consumerServiceNamespace, *consumerPort, suffix)
|
||||
}
|
||||
|
||||
// sendOneConsumeCPURequest sends POST request for cpu consumption
|
||||
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)}})
|
||||
c.responseWriterLock.Lock()
|
||||
defer c.responseWriterLock.Unlock()
|
||||
if err != nil {
|
||||
fmt.Fprintf(w, "Failed to connect to consumer: %v\n", err)
|
||||
return
|
||||
}
|
||||
fmt.Fprintf(w, "Consumed %d millicores\n", millicores)
|
||||
}
|
||||
|
||||
// sendOneConsumeMemRequest sends POST request for memory consumption
|
||||
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)}})
|
||||
c.responseWriterLock.Lock()
|
||||
defer c.responseWriterLock.Unlock()
|
||||
if err != nil {
|
||||
fmt.Fprintf(w, "Failed to connect to consumer: %v\n", err)
|
||||
return
|
||||
}
|
||||
fmt.Fprintf(w, "Consumed %d megabytes\n", megabytes)
|
||||
}
|
||||
|
||||
// sendOneConsumeCustomMetric sends POST request for custom metric consumption
|
||||
func (c *Controller) sendOneConsumeCustomMetric(w http.ResponseWriter, customMetricName string, delta int, durationSec int) {
|
||||
defer c.waitGroup.Done()
|
||||
query := createConsumerURL(BumpMetricAddress)
|
||||
_, err := http.PostForm(query,
|
||||
url.Values{MetricNameQuery: {customMetricName}, DurationSecQuery: {strconv.Itoa(durationSec)}, DeltaQuery: {strconv.Itoa(delta)}})
|
||||
c.responseWriterLock.Lock()
|
||||
defer c.responseWriterLock.Unlock()
|
||||
if err != nil {
|
||||
fmt.Fprintf(w, "Failed to connect to consumer: %v\n", err)
|
||||
return
|
||||
}
|
||||
fmt.Fprintf(w, "Bumped metric %s by %d\n", customMetricName, delta)
|
||||
}
|
32
vendor/k8s.io/kubernetes/test/images/resource-consumer/resource_consumer.go
generated
vendored
Normal file
32
vendor/k8s.io/kubernetes/test/images/resource-consumer/resource_consumer.go
generated
vendored
Normal file
@ -0,0 +1,32 @@
|
||||
/*
|
||||
Copyright 2015 The Kubernetes 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 (
|
||||
"flag"
|
||||
"fmt"
|
||||
"log"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
var port = flag.Int("port", 8080, "Port number.")
|
||||
|
||||
func main() {
|
||||
flag.Parse()
|
||||
resourceConsumerHandler := NewResourceConsumerHandler()
|
||||
log.Fatal(http.ListenAndServe(fmt.Sprintf(":%d", *port), resourceConsumerHandler))
|
||||
}
|
178
vendor/k8s.io/kubernetes/test/images/resource-consumer/resource_consumer_handler.go
generated
vendored
Normal file
178
vendor/k8s.io/kubernetes/test/images/resource-consumer/resource_consumer_handler.go
generated
vendored
Normal file
@ -0,0 +1,178 @@
|
||||
/*
|
||||
Copyright 2015 The Kubernetes 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 (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strconv"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
. "k8s.io/kubernetes/test/images/resource-consumer/common"
|
||||
)
|
||||
|
||||
type ResourceConsumerHandler struct {
|
||||
metrics map[string]float64
|
||||
metricsLock sync.Mutex
|
||||
}
|
||||
|
||||
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 {
|
||||
handler.handleMetrics(w)
|
||||
return
|
||||
}
|
||||
if req.Method != "POST" {
|
||||
http.Error(w, BadRequest, http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
// parsing POST request data and URL data
|
||||
if err := req.ParseForm(); err != nil {
|
||||
http.Error(w, err.Error(), http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
// handle consumeCPU
|
||||
if req.URL.Path == ConsumeCPUAddress {
|
||||
handler.handleConsumeCPU(w, req.Form)
|
||||
return
|
||||
}
|
||||
// handle consumeMem
|
||||
if req.URL.Path == ConsumeMemAddress {
|
||||
handler.handleConsumeMem(w, req.Form)
|
||||
return
|
||||
}
|
||||
// handle getCurrentStatus
|
||||
if req.URL.Path == GetCurrentStatusAddress {
|
||||
handler.handleGetCurrentStatus(w)
|
||||
return
|
||||
}
|
||||
// handle bumpMetric
|
||||
if req.URL.Path == BumpMetricAddress {
|
||||
handler.handleBumpMetric(w, req.Form)
|
||||
return
|
||||
}
|
||||
http.Error(w, fmt.Sprintf("%s: %s", UnknownFunction, req.URL.Path), http.StatusNotFound)
|
||||
}
|
||||
|
||||
func (handler *ResourceConsumerHandler) handleConsumeCPU(w http.ResponseWriter, query url.Values) {
|
||||
// geting string data for consumeCPU
|
||||
durationSecString := query.Get(DurationSecQuery)
|
||||
millicoresString := query.Get(MillicoresQuery)
|
||||
if durationSecString == "" || millicoresString == "" {
|
||||
http.Error(w, NotGivenFunctionArgument, http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
// convert data (strings to ints) for consumeCPU
|
||||
durationSec, durationSecError := strconv.Atoi(durationSecString)
|
||||
millicores, millicoresError := strconv.Atoi(millicoresString)
|
||||
if durationSecError != nil || millicoresError != nil {
|
||||
http.Error(w, IncorrectFunctionArgument, http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
go ConsumeCPU(millicores, durationSec)
|
||||
fmt.Fprintln(w, ConsumeCPUAddress[1:])
|
||||
fmt.Fprintln(w, millicores, MillicoresQuery)
|
||||
fmt.Fprintln(w, durationSec, DurationSecQuery)
|
||||
}
|
||||
|
||||
func (handler *ResourceConsumerHandler) handleConsumeMem(w http.ResponseWriter, query url.Values) {
|
||||
// geting string data for consumeMem
|
||||
durationSecString := query.Get(DurationSecQuery)
|
||||
megabytesString := query.Get(MegabytesQuery)
|
||||
if durationSecString == "" || megabytesString == "" {
|
||||
http.Error(w, NotGivenFunctionArgument, http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
// convert data (strings to ints) for consumeMem
|
||||
durationSec, durationSecError := strconv.Atoi(durationSecString)
|
||||
megabytes, megabytesError := strconv.Atoi(megabytesString)
|
||||
if durationSecError != nil || megabytesError != nil {
|
||||
http.Error(w, IncorrectFunctionArgument, http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
go ConsumeMem(megabytes, durationSec)
|
||||
fmt.Fprintln(w, ConsumeMemAddress[1:])
|
||||
fmt.Fprintln(w, megabytes, MegabytesQuery)
|
||||
fmt.Fprintln(w, durationSec, DurationSecQuery)
|
||||
}
|
||||
|
||||
func (handler *ResourceConsumerHandler) handleGetCurrentStatus(w http.ResponseWriter) {
|
||||
GetCurrentStatus()
|
||||
fmt.Fprintln(w, "Warning: not implemented!")
|
||||
fmt.Fprint(w, GetCurrentStatusAddress[1:])
|
||||
}
|
||||
|
||||
func (handler *ResourceConsumerHandler) handleMetrics(w http.ResponseWriter) {
|
||||
handler.metricsLock.Lock()
|
||||
defer handler.metricsLock.Unlock()
|
||||
for k, v := range handler.metrics {
|
||||
fmt.Fprintf(w, "# HELP %s info message.\n", k)
|
||||
fmt.Fprintf(w, "# TYPE %s gauge\n", k)
|
||||
fmt.Fprintf(w, "%s %f\n", k, v)
|
||||
}
|
||||
}
|
||||
|
||||
func (handler *ResourceConsumerHandler) bumpMetric(metric string, delta float64, duration time.Duration) {
|
||||
handler.metricsLock.Lock()
|
||||
if _, ok := handler.metrics[metric]; ok {
|
||||
handler.metrics[metric] += delta
|
||||
} else {
|
||||
handler.metrics[metric] = delta
|
||||
}
|
||||
handler.metricsLock.Unlock()
|
||||
|
||||
time.Sleep(duration)
|
||||
|
||||
handler.metricsLock.Lock()
|
||||
handler.metrics[metric] -= delta
|
||||
handler.metricsLock.Unlock()
|
||||
}
|
||||
|
||||
func (handler *ResourceConsumerHandler) handleBumpMetric(w http.ResponseWriter, query url.Values) {
|
||||
// geting string data for handleBumpMetric
|
||||
metric := query.Get(MetricNameQuery)
|
||||
deltaString := query.Get(DeltaQuery)
|
||||
durationSecString := query.Get(DurationSecQuery)
|
||||
if durationSecString == "" || metric == "" || deltaString == "" {
|
||||
http.Error(w, NotGivenFunctionArgument, http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
// convert data (strings to ints/floats) for handleBumpMetric
|
||||
durationSec, durationSecError := strconv.Atoi(durationSecString)
|
||||
delta, deltaError := strconv.ParseFloat(deltaString, 64)
|
||||
if durationSecError != nil || deltaError != nil {
|
||||
http.Error(w, 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)
|
||||
}
|
52
vendor/k8s.io/kubernetes/test/images/resource-consumer/utils.go
generated
vendored
Normal file
52
vendor/k8s.io/kubernetes/test/images/resource-consumer/utils.go
generated
vendored
Normal file
@ -0,0 +1,52 @@
|
||||
/*
|
||||
Copyright 2015 The Kubernetes 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 (
|
||||
"fmt"
|
||||
"log"
|
||||
"os/exec"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
const (
|
||||
consumeCPUBinary = "./consume-cpu/consume-cpu"
|
||||
consumeMemBinary = "stress"
|
||||
)
|
||||
|
||||
func ConsumeCPU(millicores int, durationSec int) {
|
||||
log.Printf("ConsumeCPU millicores: %v, durationSec: %v", millicores, durationSec)
|
||||
// creating new consume cpu process
|
||||
arg1 := fmt.Sprintf("-millicores=%d", millicores)
|
||||
arg2 := fmt.Sprintf("-duration-sec=%d", durationSec)
|
||||
consumeCPU := exec.Command(consumeCPUBinary, arg1, arg2)
|
||||
consumeCPU.Run()
|
||||
}
|
||||
|
||||
func ConsumeMem(megabytes int, durationSec int) {
|
||||
log.Printf("ConsumeMem megabytes: %v, durationSec: %v", megabytes, durationSec)
|
||||
megabytesString := strconv.Itoa(megabytes) + "M"
|
||||
durationSecString := strconv.Itoa(durationSec)
|
||||
// creating new consume memory process
|
||||
consumeMem := exec.Command(consumeMemBinary, "-m", "1", "--vm-bytes", megabytesString, "--vm-hang", "0", "-t", durationSecString)
|
||||
consumeMem.Run()
|
||||
}
|
||||
|
||||
func GetCurrentStatus() {
|
||||
log.Printf("GetCurrentStatus")
|
||||
// not implemented
|
||||
}
|
Reference in New Issue
Block a user