Skip to content

Commit

Permalink
[404-server] Remove metrics and move files
Browse files Browse the repository at this point in the history
Signed-off-by: Jonathan Pulsifer <[email protected]>
  • Loading branch information
jonpulsifer committed Nov 13, 2018
1 parent b24ce4c commit 6151f89
Show file tree
Hide file tree
Showing 109 changed files with 12 additions and 24,439 deletions.
8 changes: 5 additions & 3 deletions images/404-server/Dockerfile → Dockerfile.404-server
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@

FROM scratch

# nobody:nobody
ADD bin/ARG_ARCH/ARG_BIN /ARG_BIN

# nobody:nobody
USER 65534:65534
COPY server /
ENTRYPOINT ["/server"]

ENTRYPOINT ["/ARG_BIN"]
File renamed without changes.
6 changes: 6 additions & 0 deletions cmd/404-server/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# 404-server (default backend)

404-server is a simple webserver that satisfies the ingress, which means it has to do two things:

1. Serves a 404 page at `/`
2. Serves a 200 at `/healthz`
42 changes: 1 addition & 41 deletions images/404-server/server.go → cmd/404-server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,40 +24,18 @@ import (
"net/http"
"os"
"os/signal"
"strconv"
"syscall"
"time"

"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promhttp"
)

func init() {
// Register the summary and the histogram with Prometheus's default registry.
prometheus.MustRegister(requestCount)
prometheus.MustRegister(requestDuration)
}

func main() {
// command line arguments
port := flag.Int("port", 8080, "Port number to serve default backend 404 page.")
healthPort := flag.Int("svc-port", 10254, "Port number to serve /healthz and /metrics.")

timeout := flag.Duration("timeout", 5*time.Second, "Time in seconds to wait before forcefully terminating the server.")

flag.Parse()

notFound := newHTTPServer(fmt.Sprintf(":%d", *port), notFound())
metrics := newHTTPServer(fmt.Sprintf(":%d", *healthPort), metrics())

// start the the healthz and metrics http server
go func() {
err := metrics.ListenAndServe()
if err != http.ErrServerClosed {
fmt.Fprintf(os.Stderr, "could not start healthz/metrics http server: %s\n", err)
os.Exit(1)
}
}()

// start the main http server
go func() {
Expand Down Expand Up @@ -89,6 +67,7 @@ func newHTTPServer(addr string, handler http.Handler) *http.Server {
IdleTimeout: 10 * time.Second,
}
}

func notFound(options ...func(*server)) *server {
s := &server{mux: http.NewServeMux()}
// TODO: this handler exists only to avoid breaking existing deployments
Expand All @@ -97,28 +76,9 @@ func notFound(options ...func(*server)) *server {
fmt.Fprint(w, "ok")
})
s.mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
start := time.Now()
w.WriteHeader(http.StatusNotFound)
fmt.Fprint(w, "default backend - 404")

duration := time.Now().Sub(start).Seconds() * 1e3

proto := strconv.Itoa(r.ProtoMajor)
proto = proto + "." + strconv.Itoa(r.ProtoMinor)

requestCount.WithLabelValues(proto).Inc()
requestDuration.WithLabelValues(proto).Observe(duration)
})
return s
}

func metrics() *server {
s := &server{mux: http.NewServeMux()}
s.mux.HandleFunc("/healthz", func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusOK)
fmt.Fprint(w, "ok")
})
s.mux.Handle("/metrics", promhttp.Handler())
return s
}

Expand Down
1 change: 0 additions & 1 deletion images/404-server/.gitignore

This file was deleted.

57 changes: 0 additions & 57 deletions images/404-server/Godeps/Godeps.json

This file was deleted.

5 changes: 0 additions & 5 deletions images/404-server/Godeps/Readme

This file was deleted.

44 changes: 0 additions & 44 deletions images/404-server/Makefile

This file was deleted.

33 changes: 0 additions & 33 deletions images/404-server/README.md

This file was deleted.

43 changes: 0 additions & 43 deletions images/404-server/cloudbuild.yaml

This file was deleted.

45 changes: 0 additions & 45 deletions images/404-server/metrics.go

This file was deleted.

20 changes: 0 additions & 20 deletions images/404-server/vendor/github.com/beorn7/perks/LICENSE

This file was deleted.

Loading

0 comments on commit 6151f89

Please sign in to comment.