Commit b426ff52 by Carl Bergquist Committed by GitHub

devenv: add slow reverse proxy (#16943)

this can be useful when testing timeouts etc
in the dataproxy

ref #16923
parent 17ce1273
......@@ -13,6 +13,11 @@ datasources:
access: proxy
url: http://localhost:9090
- name: gdev-slow-prometheus
type: prometheus
access: proxy
url: http://localhost:3011
- name: gdev-testdata
type: testdata
isDefault: true
......
FROM golang:latest
ADD main.go /
WORKDIR /
RUN go build -o main .
EXPOSE 3011
ENTRYPOINT ["/main"]
slow_proxy:
build: docker/blocks/slow_proxy
network_mode: host
ports:
- "3011:3011"
environment:
ORIGIN_SERVER: "http://localhost:9090/"
\ No newline at end of file
package main
import (
"fmt"
"log"
"net/http"
"net/http/httputil"
"net/url"
"os"
"time"
)
func main() {
origin := os.Getenv("ORIGIN_SERVER")
if origin == "" {
origin = "http://localhost:9090/"
}
sleep := time.Minute
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)
<-time.After(sleep)
proxy.ServeHTTP(w, r)
})
log.Fatal(http.ListenAndServe(":3011", nil))
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment