diff --git a/go.mod b/go.mod index 6f68fa5..bb7ab7f 100644 --- a/go.mod +++ b/go.mod @@ -4,6 +4,8 @@ go 1.17 require ( github.com/foomo/keel v0.3.1 + github.com/prometheus/client_golang v1.10.0 + github.com/spf13/viper v1.7.1 github.com/stretchr/testify v1.7.0 go.uber.org/zap v1.19.1 ) @@ -27,7 +29,6 @@ require ( github.com/pelletier/go-toml v1.7.0 // indirect github.com/pkg/errors v0.9.1 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect - github.com/prometheus/client_golang v1.10.0 // indirect github.com/prometheus/client_model v0.2.0 // indirect github.com/prometheus/common v0.18.0 // indirect github.com/prometheus/procfs v0.6.0 // indirect @@ -36,7 +37,6 @@ require ( github.com/spf13/cast v1.3.0 // indirect github.com/spf13/jwalterweatherman v1.0.0 // indirect github.com/spf13/pflag v1.0.3 // indirect - github.com/spf13/viper v1.7.1 // indirect github.com/subosito/gotenv v1.2.0 // indirect go.opentelemetry.io/contrib v0.20.0 // indirect go.opentelemetry.io/contrib/instrumentation/host v0.20.0 // indirect diff --git a/proxy/proxy.go b/proxy/proxy.go index 055893d..4d3ee40 100644 --- a/proxy/proxy.go +++ b/proxy/proxy.go @@ -3,9 +3,10 @@ package proxy import ( "context" "encoding/json" - "github.com/foomo/contentfulproxy/packages/go/metrics" "net/http" + "github.com/foomo/contentfulproxy/packages/go/metrics" + "github.com/prometheus/client_golang/prometheus" "github.com/foomo/contentfulproxy/packages/go/log" @@ -21,7 +22,7 @@ type Info struct { type Metrics struct { NumUpdate prometheus.Counter NumProxyRequest prometheus.Counter - NumApiRequest prometheus.Counter + NumAPIRequest prometheus.Counter } type Proxy struct { @@ -71,7 +72,7 @@ func (p *Proxy) ServeHTTP(w http.ResponseWriter, r *http.Request) { } cachedResponse = jobDone.cachedResponse p.l.Info("serve response after cache creation", log.FURL(r.RequestURI), log.FCacheID(string(cacheID))) - p.metrics.NumApiRequest.Inc() + p.metrics.NumAPIRequest.Inc() } else { p.l.Info("serve response from cache", log.FURL(r.RequestURI), log.FCacheID(string(cacheID))) } @@ -156,10 +157,11 @@ func jsonResponse(w http.ResponseWriter, v interface{}, statusCode int) { http.Error(w, "could not marshal info export", http.StatusInternalServerError) } } + func getMetrics() *Metrics { return &Metrics{ - NumUpdate: metrics.NewCounter("numupdates", "number of times the update webhook was called"), - NumApiRequest: metrics.NewCounter("numapirequests", "number of times the proxy performed a contentful api-request"), + NumUpdate: metrics.NewCounter("numupdates", "number of times the update webhook was called"), + NumAPIRequest: metrics.NewCounter("numapirequests", "number of times the proxy performed a contentful api-request"), NumProxyRequest: metrics.NewCounter("numproxyrequests", "number of times the proxy received an api-request"), } }