mirror of
https://github.com/grafana/grafana.git
synced 2025-01-16 11:42:35 -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 as builder
|
||||||
FROM golang:latest
|
|
||||||
ADD main.go /
|
ADD main.go /
|
||||||
WORKDIR /
|
WORKDIR /
|
||||||
RUN GO111MODULE=off go build -o main .
|
RUN GO111MODULE=off CGO_ENABLED=0 go build -o main .
|
||||||
|
|
||||||
|
FROM scratch
|
||||||
|
WORKDIR /
|
||||||
EXPOSE 3011
|
EXPOSE 3011
|
||||||
|
COPY --from=builder /main /main
|
||||||
ENTRYPOINT ["/main"]
|
ENTRYPOINT ["/main"]
|
||||||
|
@ -3,4 +3,5 @@
|
|||||||
ports:
|
ports:
|
||||||
- '3011:3011'
|
- '3011:3011'
|
||||||
environment:
|
environment:
|
||||||
ORIGIN_SERVER: 'http://host.docker.internal:9090/'
|
ORIGIN_SERVER: ${ORIGIN_SERVER}
|
||||||
|
SLEEP_DURATION: ${SLEEP_DURATION}
|
@ -1,7 +1,6 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/http/httputil"
|
"net/http/httputil"
|
||||||
@ -13,16 +12,26 @@ import (
|
|||||||
func main() {
|
func main() {
|
||||||
origin := os.Getenv("ORIGIN_SERVER")
|
origin := os.Getenv("ORIGIN_SERVER")
|
||||||
if origin == "" {
|
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)
|
originURL, _ := url.Parse(origin)
|
||||||
proxy := httputil.NewSingleHostReverseProxy(originURL)
|
proxy := httputil.NewSingleHostReverseProxy(originURL)
|
||||||
|
|
||||||
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
|
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)
|
<-time.After(sleep)
|
||||||
proxy.ServeHTTP(w, r)
|
proxy.ServeHTTP(w, r)
|
||||||
})
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user