mirror of
https://github.com/openfaas/faasd.git
synced 2025-06-18 03:56:35 +00:00
update provider to v0.19
Signed-off-by: Nitishkumar Singh <nitishkumarsingh71@gmail.com> updated go version Signed-off-by: Nitishkumar Singh <nitishkumarsingh71@gmail.com>
This commit is contained in:
committed by
Alex Ellis
parent
2b0cbeb25d
commit
b7be42e5ec
54
vendor/github.com/openfaas/faas-provider/httputil/write_interceptor.go
generated
vendored
Normal file
54
vendor/github.com/openfaas/faas-provider/httputil/write_interceptor.go
generated
vendored
Normal file
@ -0,0 +1,54 @@
|
||||
package httputil
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"net"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func NewHttpWriteInterceptor(w http.ResponseWriter) *HttpWriteInterceptor {
|
||||
return &HttpWriteInterceptor{w, 0}
|
||||
}
|
||||
|
||||
type HttpWriteInterceptor struct {
|
||||
http.ResponseWriter
|
||||
StatusCode int
|
||||
}
|
||||
|
||||
func (c *HttpWriteInterceptor) Status() int {
|
||||
if c.StatusCode == 0 {
|
||||
return http.StatusOK
|
||||
}
|
||||
return c.StatusCode
|
||||
}
|
||||
|
||||
func (c *HttpWriteInterceptor) Header() http.Header {
|
||||
return c.ResponseWriter.Header()
|
||||
}
|
||||
|
||||
func (c *HttpWriteInterceptor) Write(data []byte) (int, error) {
|
||||
return c.ResponseWriter.Write(data)
|
||||
}
|
||||
|
||||
func (c *HttpWriteInterceptor) WriteHeader(code int) {
|
||||
c.StatusCode = code
|
||||
c.ResponseWriter.WriteHeader(code)
|
||||
}
|
||||
|
||||
func (c *HttpWriteInterceptor) Flush() {
|
||||
fl := c.ResponseWriter.(http.Flusher)
|
||||
fl.Flush()
|
||||
}
|
||||
|
||||
func (c *HttpWriteInterceptor) Hijack() (net.Conn, *bufio.ReadWriter, error) {
|
||||
hj := c.ResponseWriter.(http.Hijacker)
|
||||
return hj.Hijack()
|
||||
}
|
||||
|
||||
func (c *HttpWriteInterceptor) CloseNotify() <-chan bool {
|
||||
notifier, ok := c.ResponseWriter.(http.CloseNotifier)
|
||||
if ok == false {
|
||||
return nil
|
||||
}
|
||||
return notifier.CloseNotify()
|
||||
}
|
72
vendor/github.com/openfaas/faas-provider/metrics.go
generated
vendored
Normal file
72
vendor/github.com/openfaas/faas-provider/metrics.go
generated
vendored
Normal file
@ -0,0 +1,72 @@
|
||||
package bootstrap
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"github.com/openfaas/faas-provider/httputil"
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
"github.com/prometheus/client_golang/prometheus/promauto"
|
||||
)
|
||||
|
||||
// httpMetrics is for recording R.E.D. metrics for system endpoint calls
|
||||
// for HTTP status code, method, duration and path.
|
||||
type httpMetrics struct {
|
||||
// RequestsTotal is a Prometheus counter vector partitioned by method and status.
|
||||
RequestsTotal *prometheus.CounterVec
|
||||
|
||||
// RequestDurationHistogram is a Prometheus summary vector partitioned by method and status.
|
||||
RequestDurationHistogram *prometheus.HistogramVec
|
||||
}
|
||||
|
||||
// newHttpMetrics initialises a new httpMetrics struct for
|
||||
// recording R.E.D. metrics for system endpoint calls
|
||||
func newHttpMetrics() *httpMetrics {
|
||||
return &httpMetrics{
|
||||
RequestsTotal: promauto.NewCounterVec(prometheus.CounterOpts{
|
||||
Subsystem: "provider",
|
||||
Name: "http_requests_total",
|
||||
Help: "Total number of HTTP requests.",
|
||||
}, []string{"code", "method", "path"}),
|
||||
RequestDurationHistogram: promauto.NewHistogramVec(prometheus.HistogramOpts{
|
||||
Subsystem: "provider",
|
||||
Name: "http_request_duration_seconds",
|
||||
Help: "Seconds spent serving HTTP requests.",
|
||||
Buckets: prometheus.DefBuckets,
|
||||
}, []string{"code", "method", "path"}),
|
||||
}
|
||||
}
|
||||
|
||||
func (hm *httpMetrics) InstrumentHandler(next http.Handler, pathOverride string) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
start := time.Now()
|
||||
ww := httputil.NewHttpWriteInterceptor(w)
|
||||
next.ServeHTTP(ww, r)
|
||||
duration := time.Since(start)
|
||||
|
||||
path := r.URL.Path
|
||||
if len(pathOverride) > 0 {
|
||||
path = pathOverride
|
||||
}
|
||||
|
||||
defer func() {
|
||||
hm.RequestsTotal.With(
|
||||
prometheus.Labels{"code": strconv.Itoa(ww.StatusCode),
|
||||
"method": r.Method,
|
||||
"path": path,
|
||||
}).
|
||||
Inc()
|
||||
}()
|
||||
|
||||
defer func() {
|
||||
hm.RequestDurationHistogram.With(
|
||||
prometheus.Labels{"code": strconv.Itoa(ww.StatusCode),
|
||||
"method": r.Method,
|
||||
"path": path,
|
||||
}).
|
||||
Observe(duration.Seconds())
|
||||
}()
|
||||
}
|
||||
}
|
40
vendor/github.com/openfaas/faas-provider/serve.go
generated
vendored
40
vendor/github.com/openfaas/faas-provider/serve.go
generated
vendored
@ -11,6 +11,8 @@ import (
|
||||
"github.com/gorilla/mux"
|
||||
"github.com/openfaas/faas-provider/auth"
|
||||
"github.com/openfaas/faas-provider/types"
|
||||
|
||||
"github.com/prometheus/client_golang/prometheus/promhttp"
|
||||
)
|
||||
|
||||
// NameExpression for a function / service
|
||||
@ -52,30 +54,42 @@ func Serve(handlers *types.FaaSHandlers, config *types.FaaSConfig) {
|
||||
handlers.LogHandler = auth.DecorateWithBasicAuth(handlers.LogHandler, credentials)
|
||||
}
|
||||
|
||||
hm := newHttpMetrics()
|
||||
|
||||
// System (auth) endpoints
|
||||
r.HandleFunc("/system/functions", handlers.FunctionReader).Methods(http.MethodGet)
|
||||
r.HandleFunc("/system/functions", handlers.DeployHandler).Methods(http.MethodPost)
|
||||
r.HandleFunc("/system/functions", handlers.DeleteHandler).Methods(http.MethodDelete)
|
||||
r.HandleFunc("/system/functions", handlers.UpdateHandler).Methods(http.MethodPut)
|
||||
r.HandleFunc("/system/functions", hm.InstrumentHandler(handlers.FunctionReader, "")).Methods(http.MethodGet)
|
||||
r.HandleFunc("/system/functions", hm.InstrumentHandler(handlers.DeployHandler, "")).Methods(http.MethodPost)
|
||||
r.HandleFunc("/system/functions", hm.InstrumentHandler(handlers.DeleteHandler, "")).Methods(http.MethodDelete)
|
||||
r.HandleFunc("/system/functions", hm.InstrumentHandler(handlers.UpdateHandler, "")).Methods(http.MethodPut)
|
||||
|
||||
r.HandleFunc("/system/function/{name:["+NameExpression+"]+}", handlers.ReplicaReader).Methods(http.MethodGet)
|
||||
r.HandleFunc("/system/scale-function/{name:["+NameExpression+"]+}", handlers.ReplicaUpdater).Methods(http.MethodPost)
|
||||
r.HandleFunc("/system/info", handlers.InfoHandler).Methods(http.MethodGet)
|
||||
r.HandleFunc("/system/function/{name:["+NameExpression+"]+}",
|
||||
hm.InstrumentHandler(handlers.ReplicaReader, "/system/function")).Methods(http.MethodGet)
|
||||
r.HandleFunc("/system/scale-function/{name:["+NameExpression+"]+}",
|
||||
|
||||
r.HandleFunc("/system/secrets", handlers.SecretHandler).Methods(http.MethodGet, http.MethodPut, http.MethodPost, http.MethodDelete)
|
||||
r.HandleFunc("/system/logs", handlers.LogHandler).Methods(http.MethodGet)
|
||||
hm.InstrumentHandler(handlers.ReplicaUpdater, "/system/scale-function")).Methods(http.MethodPost)
|
||||
r.HandleFunc("/system/info",
|
||||
hm.InstrumentHandler(handlers.InfoHandler, "")).Methods(http.MethodGet)
|
||||
|
||||
r.HandleFunc("/system/namespaces", handlers.ListNamespaceHandler).Methods(http.MethodGet)
|
||||
r.HandleFunc("/system/secrets",
|
||||
hm.InstrumentHandler(handlers.SecretHandler, "")).Methods(http.MethodGet, http.MethodPut, http.MethodPost, http.MethodDelete)
|
||||
r.HandleFunc("/system/logs",
|
||||
hm.InstrumentHandler(handlers.LogHandler, "")).Methods(http.MethodGet)
|
||||
|
||||
r.HandleFunc("/system/namespaces", hm.InstrumentHandler(handlers.ListNamespaceHandler, "")).Methods(http.MethodGet)
|
||||
|
||||
proxyHandler := handlers.FunctionProxy
|
||||
|
||||
// Open endpoints
|
||||
r.HandleFunc("/function/{name:["+NameExpression+"]+}", handlers.FunctionProxy)
|
||||
r.HandleFunc("/function/{name:["+NameExpression+"]+}/", handlers.FunctionProxy)
|
||||
r.HandleFunc("/function/{name:["+NameExpression+"]+}/{params:.*}", handlers.FunctionProxy)
|
||||
r.HandleFunc("/function/{name:["+NameExpression+"]+}", proxyHandler)
|
||||
r.HandleFunc("/function/{name:["+NameExpression+"]+}/", proxyHandler)
|
||||
r.HandleFunc("/function/{name:["+NameExpression+"]+}/{params:.*}", proxyHandler)
|
||||
|
||||
if handlers.HealthHandler != nil {
|
||||
r.HandleFunc("/healthz", handlers.HealthHandler).Methods(http.MethodGet)
|
||||
}
|
||||
|
||||
r.HandleFunc("/metrics", promhttp.Handler().ServeHTTP)
|
||||
|
||||
readTimeout := config.ReadTimeout
|
||||
writeTimeout := config.WriteTimeout
|
||||
|
||||
|
Reference in New Issue
Block a user