From 48c7e3c172152dfa74ed4c2e6a031c48e66fc713 Mon Sep 17 00:00:00 2001 From: Kegan Dougal Date: Mon, 24 Feb 2020 17:53:02 +0000 Subject: [PATCH] Replace prometheus with a stub. sigh --- cmd/dendritejs/main.go | 9 ++--- go.mod | 2 ++ go.sum | 1 + prometheus/go.mod | 3 ++ prometheus/prometheus/promauto/promauto.go | 7 ++++ prometheus/prometheus/prometheus.go | 38 ++++++++++++++++++++++ prometheus/prometheus/promhttp/promhttp.go | 17 ++++++++++ 7 files changed, 73 insertions(+), 4 deletions(-) create mode 100644 prometheus/go.mod create mode 100644 prometheus/prometheus/promauto/promauto.go create mode 100644 prometheus/prometheus/prometheus.go create mode 100644 prometheus/prometheus/promhttp/promhttp.go diff --git a/cmd/dendritejs/main.go b/cmd/dendritejs/main.go index 6c18e4d75..0e8a07061 100644 --- a/cmd/dendritejs/main.go +++ b/cmd/dendritejs/main.go @@ -16,6 +16,7 @@ package main import ( "flag" + "fmt" "net/http" "github.com/matrix-org/dendrite/appservice" @@ -33,12 +34,15 @@ import ( "github.com/matrix-org/dendrite/typingserver" "github.com/matrix-org/dendrite/typingserver/cache" - "github.com/prometheus/client_golang/prometheus/promhttp" "github.com/sirupsen/logrus" _ "github.com/matrix-org/go-sqlite3-js" ) +func init() { + fmt.Println("dendrite.js starting...") +} + var ( httpBindAddr = flag.String("http-bind-address", ":8008", "The HTTP listening port for the server") httpsBindAddr = flag.String("https-bind-address", ":8448", "The HTTPS listening port for the server") @@ -76,9 +80,6 @@ func main() { httpHandler := common.WrapHandlerInCORS(base.APIMux) - // Set up the API endpoints we handle. /metrics is for prometheus, and is - // not wrapped by CORS, while everything else is - http.Handle("/metrics", promhttp.Handler()) http.Handle("/", httpHandler) // Expose the matrix APIs directly rather than putting them under a /api path. diff --git a/go.mod b/go.mod index e9038228a..6065dafa9 100644 --- a/go.mod +++ b/go.mod @@ -2,6 +2,8 @@ module github.com/matrix-org/dendrite replace github.com/lib/pq => github.com/matrix-org/pq v1.3.2 +replace github.com/prometheus/client_golang => ./prometheus + require ( github.com/DataDog/zstd v1.4.4 // indirect github.com/Shopify/toxiproxy v2.1.4+incompatible // indirect diff --git a/go.sum b/go.sum index 4e92dabc0..f411baeb8 100644 --- a/go.sum +++ b/go.sum @@ -178,6 +178,7 @@ golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5h golang.org/x/sys v0.0.0-20181116152217-5ac8a444bdc5/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190422165155-953cdadca894 h1:Cz4ceDQGXuKRnVBDTS23GTn/pU5OE2C0WrNTOYK1Uuc= golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191010194322-b09406accb47 h1:/XfQ9z7ib8eEJX2hdgFTZJ/ntt0swNk5oYBziWeTCvY= golang.org/x/sys v0.0.0-20191010194322-b09406accb47/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= diff --git a/prometheus/go.mod b/prometheus/go.mod new file mode 100644 index 000000000..dd6c7bda0 --- /dev/null +++ b/prometheus/go.mod @@ -0,0 +1,3 @@ +module github.com/prometheus/client_golang + +go 1.13 diff --git a/prometheus/prometheus/promauto/promauto.go b/prometheus/prometheus/promauto/promauto.go new file mode 100644 index 000000000..74d46c78e --- /dev/null +++ b/prometheus/prometheus/promauto/promauto.go @@ -0,0 +1,7 @@ +package promauto + +import "github.com/prometheus/client_golang/prometheus" + +func NewCounterVec(opts prometheus.CounterOpts, arr []string) *prometheus.CounterVec { + return nil +} diff --git a/prometheus/prometheus/prometheus.go b/prometheus/prometheus/prometheus.go new file mode 100644 index 000000000..1193d5ceb --- /dev/null +++ b/prometheus/prometheus/prometheus.go @@ -0,0 +1,38 @@ +package prometheus + +type CounterOpts struct { + Name string + Help string +} +type SummaryOpts struct { + Namespace string + Subsystem string + Name string + Help string +} + +type CounterVec struct{} + +type Collector interface { + WithLabelValues(a string, b string) Collector + Observe(c float64) + Inc() +} + +type col struct{} + +func (c col) WithLabelValues(a, b string) Collector { + return c +} +func (c col) Observe(d float64) {} +func (c col) Inc() {} + +func NewSummaryVec(opts SummaryOpts, arr []string) Collector { + return col{} +} + +func MustRegister(...Collector) {} + +func NewCounter(opt CounterOpts) col { + return col{} +} diff --git a/prometheus/prometheus/promhttp/promhttp.go b/prometheus/prometheus/promhttp/promhttp.go new file mode 100644 index 000000000..3a4c5d26c --- /dev/null +++ b/prometheus/prometheus/promhttp/promhttp.go @@ -0,0 +1,17 @@ +package promhttp + +import ( + "net/http" + + "github.com/prometheus/client_golang/prometheus" +) + +func InstrumentHandlerCounter(v *prometheus.CounterVec, next http.Handler) http.HandlerFunc { + return next.ServeHTTP +} + +func Handler() http.Handler { + return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + w.WriteHeader(400) + }) +}