mirror of
https://github.com/grafana/grafana.git
synced 2024-12-28 01:41:24 -06:00
devenv: slow_proxy_mac: make configurable and smaller (#34560)
This commit is contained in:
parent
68513b9a3f
commit
0c2bb9562a
2
devenv/docker/blocks/slow_proxy_mac/.env
Normal file
2
devenv/docker/blocks/slow_proxy_mac/.env
Normal file
@ -0,0 +1,2 @@
|
||||
ORIGIN_SERVER=http://host.docker.internal:9090/
|
||||
SLEEP_DURATION=60s
|
@ -1,7 +1,10 @@
|
||||
|
||||
FROM golang:latest
|
||||
FROM golang:latest as builder
|
||||
ADD main.go /
|
||||
WORKDIR /
|
||||
RUN GO111MODULE=off go build -o main .
|
||||
RUN GO111MODULE=off CGO_ENABLED=0 go build -o main .
|
||||
|
||||
FROM scratch
|
||||
WORKDIR /
|
||||
EXPOSE 3011
|
||||
COPY --from=builder /main /main
|
||||
ENTRYPOINT ["/main"]
|
||||
|
@ -3,4 +3,5 @@
|
||||
ports:
|
||||
- '3011:3011'
|
||||
environment:
|
||||
ORIGIN_SERVER: 'http://host.docker.internal:9090/'
|
||||
ORIGIN_SERVER: ${ORIGIN_SERVER}
|
||||
SLEEP_DURATION: ${SLEEP_DURATION}
|
@ -1,7 +1,6 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"net/http"
|
||||
"net/http/httputil"
|
||||
@ -13,16 +12,26 @@ import (
|
||||
func main() {
|
||||
origin := os.Getenv("ORIGIN_SERVER")
|
||||
if origin == "" {
|
||||
origin = "http://host.docker.internal:9090/"
|
||||
// it is never not-set, the default is in the `.env` file
|
||||
log.Fatalf("missing env-variable ORIGIN_SERVER")
|
||||
}
|
||||
|
||||
sleep := time.Minute
|
||||
sleepDurationStr := os.Getenv("SLEEP_DURATION")
|
||||
if sleepDurationStr == "" {
|
||||
// it is never not-set, the default is in the `.env` file
|
||||
log.Fatalf("missing env-variable SLEEP_DURATION")
|
||||
}
|
||||
|
||||
sleep, err := time.ParseDuration(sleepDurationStr)
|
||||
if err != nil {
|
||||
log.Fatalf("failed to parse SLEEP_DURATION: %v", err)
|
||||
}
|
||||
|
||||
originURL, _ := url.Parse(origin)
|
||||
proxy := httputil.NewSingleHostReverseProxy(originURL)
|
||||
|
||||
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
|
||||
fmt.Printf("sleeping for %s then proxying request: %s", sleep.String(), r.RequestURI)
|
||||
log.Printf("sleeping for %s then proxying request: url '%s', headers: '%v'", sleep.String(), r.RequestURI, r.Header)
|
||||
<-time.After(sleep)
|
||||
proxy.ServeHTTP(w, r)
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user