Skip to content

Commit

Permalink
Remove /stats API endpoint.
Browse files Browse the repository at this point in the history
`/stats` is disused and useless now that we have a Prometheus gauge for
the route count. It didn't use to return anything else.
  • Loading branch information
sengi committed Aug 19, 2023
1 parent 991ae04 commit 9f6543e
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 78 deletions.
43 changes: 0 additions & 43 deletions integration_tests/reload_api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,49 +61,6 @@ var _ = Describe("reload API endpoint", func() {
})
})

Describe("route stats", func() {

Context("with some routes loaded", func() {
var data map[string]map[string]interface{}

BeforeEach(func() {
addRoute("/foo", NewRedirectRoute("/bar", "prefix"))
addRoute("/baz", NewRedirectRoute("/qux", "prefix"))
addRoute("/foo", NewRedirectRoute("/bar/baz"))
reloadRoutes(apiPort)
resp := doRequest(newRequest("GET", routerURL(apiPort, "/stats")))
Expect(resp.StatusCode).To(Equal(200))
readJSONBody(resp, &data)
})

It("should return the number of routes loaded", func() {
Expect(data["routes"]["count"]).To(BeEquivalentTo(3))
})
})

Context("with no routes", func() {
var data map[string]map[string]interface{}

BeforeEach(func() {
reloadRoutes(apiPort)

resp := doRequest(newRequest("GET", routerURL(apiPort, "/stats")))
Expect(resp.StatusCode).To(Equal(200))
readJSONBody(resp, &data)
})

It("should return the number of routes loaded", func() {
Expect(data["routes"]["count"]).To(BeEquivalentTo(0))
})
})

It("should return 405 for other verbs", func() {
resp := doRequest(newRequest("POST", routerURL(apiPort, "/stats")))
Expect(resp.StatusCode).To(Equal(405))
Expect(resp.Header.Get("Allow")).To(Equal("GET"))
})
})

Describe("memory stats", func() {
It("should return memory statistics", func() {
addRoute("/foo", NewRedirectRoute("/bar", "prefix"))
Expand Down
10 changes: 0 additions & 10 deletions lib/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -393,16 +393,6 @@ func (be *Backend) ParseURL() (*url.URL, error) {
return url.Parse(backendURL)
}

func (rt *Router) RouteStats() (stats map[string]interface{}) {
rt.lock.RLock()
mux := rt.mux
rt.lock.RUnlock()

stats = make(map[string]interface{})
stats["count"] = mux.RouteCount()
return
}

func shouldPreserveSegments(route *Route) bool {
switch route.RouteType {
case RouteTypeExact:
Expand Down
25 changes: 0 additions & 25 deletions lib/router_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package router

import (
"encoding/json"
"fmt"
"net/http"
"runtime"

Expand Down Expand Up @@ -47,30 +46,6 @@ func NewAPIHandler(rout *Router) (api http.Handler, err error) {
}
})

mux.HandleFunc("/stats", func(w http.ResponseWriter, r *http.Request) {
if r.Method != http.MethodGet {
w.Header().Set("Allow", http.MethodGet)
w.WriteHeader(http.StatusMethodNotAllowed)
return
}

stats := make(map[string]map[string]interface{})
stats["routes"] = rout.RouteStats()

jsonData, err := json.MarshalIndent(stats, "", " ")
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}

_, err = fmt.Fprintln(w, string(jsonData))
if err != nil {
logWarn(err)
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
})

mux.HandleFunc("/memory-stats", func(w http.ResponseWriter, r *http.Request) {
if r.Method != http.MethodGet {
w.Header().Set("Allow", http.MethodGet)
Expand Down

0 comments on commit 9f6543e

Please sign in to comment.