Skip to content

Commit

Permalink
[DEV-revert] box-only: Start a local proxy server to simulate an unre…
Browse files Browse the repository at this point in the history
…liable storage

Just proxies to Minio with a random error chance
  • Loading branch information
victorges committed Jun 24, 2024
1 parent 3408e19 commit 75789c3
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import (
"fmt"
"log"
"math/rand"
"net/http"
"net/http/httputil"
"os"
"os/signal"
"strings"
Expand Down Expand Up @@ -39,7 +41,35 @@ import (
"golang.org/x/sync/errgroup"
)

func startProxyServer() error {
proxy := &httputil.ReverseProxy{
Director: func(req *http.Request) {
req.URL.Scheme = "http"
req.URL.Host = "localhost:9000"
},
}

http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
errorChance := float32(0.5)
if r.Method != "GET" {
errorChance = 0.95
}
if rand.Float32() < errorChance {
glog.Errorf("Random error for path=%s", r.URL.Path)
http.Error(w, "Internal Server Error", http.StatusInternalServerError)
return
}
proxy.ServeHTTP(w, r)
})

return http.ListenAndServe(":9420", nil)
}

func main() {
go func() {
log.Fatal(startProxyServer())
}()

err := flag.Set("logtostderr", "true")
if err != nil {
glog.Fatal(err)
Expand Down

0 comments on commit 75789c3

Please sign in to comment.