Created
July 14, 2021 21:25
-
-
Save stuartnelson3/528efb313bb1aeaeabf72afbb6223846 to your computer and use it in GitHub Desktop.
reverse proxy to intermittently interrupt requests to /_xpack
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"log" | |
"math/rand" | |
"net/http" | |
"net/http/httputil" | |
"net/url" | |
"time" | |
) | |
func main() { | |
rpURL, err := url.Parse("http://localhost:9200") | |
if err != nil { | |
log.Fatal(err) | |
} | |
rand.Seed(time.Now().UnixNano()) | |
rp := httputil.NewSingleHostReverseProxy(rpURL) | |
log.Printf("listening on :9201, proxying to %v\n", rpURL) | |
log.Fatal(http.ListenAndServe(":9201", wrap(rp))) | |
} | |
func wrap(h http.Handler) http.Handler { | |
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | |
if r.URL.Path == "/_xpack" { | |
log.Println("hit xpack path") | |
if rand.Intn(100) < 40 { | |
log.Println("responding with error") | |
http.Error(w, `{"error":"whoops"}`, http.StatusInternalServerError) | |
return | |
} | |
} | |
h.ServeHTTP(w, r) | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment