108 Commits

Author SHA1 Message Date
Alex Ellis (OpenFaaS Ltd)
137b63e61f Add namespaces endpoint
This is being added because multiple namespaces can now be used
on Kubernetes. By listing namespaces, a client such as the UI
or CLI can then enumerate the namespaces to find functions
which may span across more than one namespace.

Signed-off-by: Alex Ellis (OpenFaaS Ltd) <alexellis2@gmail.com>
2019-09-21 18:07:38 +01:00
Alex Ellis (OpenFaaS Ltd)
df4126d8f5 Scale functions with namespace option
Allows alerts to trigger functions to scale when they
also have an optional namespace set.

Tested e2e with Kubernetes 1.15 and a non-default namespace.

Signed-off-by: Alex Ellis (OpenFaaS Ltd) <alexellis2@gmail.com>
2019-09-20 18:38:55 +01:00
Alex Ellis (OpenFaaS Ltd)
238ce1be23 Add feature for invoking namespaced functions
When coupled with the latest version of faas-netes, the gateway
can now invoke, query and deploy functions into alternative
namespaces.

Tested e2e by creating a namespace "fn" and deploying, then
invoking a function deployed there and in the default namespace.

Signed-off-by: Alex Ellis (OpenFaaS Ltd) <alexellis2@gmail.com>
2019-09-20 18:38:55 +01:00
Alex Ellis (OpenFaaS Ltd)
0a90125aba Allow dot in function name
This patch enables the use-case for multiple namepsaces by
allowing a dot to be used in the function name.

dep has been run to update OpenFaaS projects and also to
prune unused files.

Tested by doing a build.

Signed-off-by: Alex Ellis (OpenFaaS Ltd) <alexellis2@gmail.com>
2019-09-20 11:23:57 +01:00
Lucas Roesler
6df51a3516 Use context timeout to cancel the log request
**What**
- Pass the writetimeout to the logs handler to set the context timeout
of the log stream.

Signed-off-by: Lucas Roesler <roesler.lucas@gmail.com>
2019-07-06 10:42:46 +01:00
Lucas Roesler
e7e91ecd15 Implement log proxy handler
**What**
- Implement log handler method that will hijack the connection and clear
timeouts to allow long lived streams
- Proxies requests to the logs provider and returns the response
unmodified

Signed-off-by: Lucas Roesler <roesler.lucas@gmail.com>
2019-07-06 10:42:46 +01:00
Alex Ellis
e3b77514d0 Add error handling to basic auth injector
Fixes a problem where basic auth was disabled and a nill pointer
was hit, causing a panic.

Signed-off-by: Alex Ellis <alexellis2@gmail.com>
2019-06-09 20:08:39 +01:00
Alex Ellis
d2965df9f2 Remove un-used RoutelessProxy
Signed-off-by: Alex Ellis <alexellis2@gmail.com>
2019-06-09 20:08:39 +01:00
Alex Ellis
1cf030da48 Differentiate external service auth from user auth
Signed-off-by: Alex Ellis <alexellis2@gmail.com>
2019-06-09 20:08:39 +01:00
Alex Ellis
0758e484f7 Switch to external auth
This commit moves the OpenFaaS gateway from using in-process
basic-auth for everything to use an external auth URL instead.

When auth is not enable, this functionality is not added to the
handlers and behaves as before. When enabled, the configured
plugin with authenticate requests.

Tested on Docker Swarm with positive and negative tests.

Signed-off-by: Alex Ellis <alexellis2@gmail.com>
2019-06-09 20:08:39 +01:00
Vivek Singh
b87ecde60f Move /healthz handler to handlers package
Signed-off-by: Vivek Singh <vivekkmr45@yahoo.in>
2019-03-09 17:28:46 +00:00
Vivek Singh
40dbede065 Reduce timeout value metrics server to 5 second
Signed-off-by: Vivek Singh <vivekkmr45@yahoo.in>
2019-03-09 17:28:46 +00:00
Vivek Singh
54eda5ec0d Run metrics server in a separate method
This commit adds changes to run metrics server in a separate method and
also removed port 8082 from exposed port a/c to review comments.

It also uses a smaller static timeout value for new server.

Signed-off-by: Vivek Singh <vivekkmr45@yahoo.in>
2019-03-09 17:28:46 +00:00
Vivek Singh
90ddd56985 Add new HTTPServer to serve /metrics on port 8082
This commit runs a new HTTPServer on port 8082 in a goroutine to serve
/metrics endpoint on a different port.

This also update the configurations and compose files.

Fixes: #1081

Signed-off-by: Vivek Singh <vivekkmr45@yahoo.in>
2019-03-09 17:28:46 +00:00
Alex Ellis (VMware)
299e5a5933 Read config values from environment for max_conns tuning
- max_conns / idle / per host are now read from env-vars and have
defaults set to 1024 for both values
- logging / metrics are collected in the client transaction
rather than via defer (this may impact throughput)
- function cache moved to use RWMutex to try to improve latency
around locking when updating cache
- logging message added to show latency in running GetReplicas
because this was observed to increase in a linear fashion under
high concurrency
- changes tested against 3-node bare-metal 1.13 K8s cluster
with kubeadm

Signed-off-by: Alex Ellis (VMware) <alexellis2@gmail.com>
2019-02-04 11:50:25 +00:00
Alex Ellis (VMware)
b4a550327d Re-vendor queue-worker publisher for reconnect
- re-vendor queue-worker for publisher via 0.6.0
- bump queue-worker version to 0.6.0 in docker-compose.yml for
AMD64
- use new naming for NATS of nats -> NATS in variables where
required
- add default reconnect of 60 times, 2 seconds apart.

Signed-off-by: Alex Ellis (VMware) <alexellis2@gmail.com>
2019-01-29 15:15:48 +00:00
Lucas Roesler
f61735b155 Add basic auth to the system alert endpoint
**What**
- Protect the `/system/alert` endpoint when basic auth is enabled
- Update the alert manager config to send the basic auth credentials
- Bump the gateway version

Signed-off-by: Lucas Roesler <roesler.lucas@gmail.com>
2019-01-24 17:45:33 +00:00
Alex Ellis (VMware)
fca32a0e79 Instrument async handlers
- instruments async handler for report and for queueing async
requests
- make MustRegister only ever run once to prevent sync issues

Signed-off-by: Alex Ellis (VMware) <alexellis2@gmail.com>
2019-01-24 09:12:46 +00:00
Alex Ellis (VMware)
5a1bdcdb91 Add instrumentation to the alert handler
Signed-off-by: Alex Ellis (VMware) <alexellis2@gmail.com>
2019-01-24 09:12:46 +00:00
Alex Ellis (VMware)
64a3f4e495 Instrument system calls
Signed-off-by: Alex Ellis (VMware) <alexellis2@gmail.com>
2019-01-24 09:12:46 +00:00
Andrew Cornies
a9238f5631 Secrets iteration:
- added delete http verb to system/secrets
- added secrets request type
- added vagrant env provisioned by existing deploy_stack.sh

Signed-off-by: Andrew Cornies <acornies@gmail.com>
2019-01-04 16:51:01 +00:00
Andrew Cornies
d2ef8b9207 Initial support for secrets in gw:
- added SecretHandler type
- added discussed system/secret endpoint with appropriate http verbs

Signed-off-by: Andrew Cornies <acornies@gmail.com>
2019-01-04 16:51:01 +00:00
Alex Ellis (VMware)
117707df14 Enable backoff/retries on scaling up
- this change is needed for Docker Swarm which may give an error
when several concurrent requests come in to scale a deployment.

Tested on Docker Swarm before/after with the hey tool and figlet
scaled down to zero replicas.

Signed-off-by: Alex Ellis (VMware) <alexellis2@gmail.com>
2018-11-07 13:49:56 +00:00
Alex Ellis (VMware)
9cea08c728 Extract scaling from zero
- extracting this package means it can be used in other components
such as the asynchronous nats-queue-worker which may need to
invoke functions which are scaled down to zero replicas.

Ref: https://github.com/openfaas/nats-queue-worker/issues/32

Tested on Docker Swarm for scaling up, already scaled and not
found error.

Signed-off-by: Alex Ellis (VMware) <alexellis2@gmail.com>
2018-11-01 15:10:08 +00:00
Alex Ellis (VMware)
101b06243b Add documentation for scaling handler
- documents ScalingConfig and MakeScalingHandler

Signed-off-by: Alex Ellis (VMware) <alexellis2@gmail.com>
2018-10-28 12:24:25 +00:00
Alex Ellis (VMware)
3598da2e51 Enable basic auth for service query / scaling on provider
- this is a blocking issue for auth with Docker Swarm
fixes #879

Signed-off-by: Alex Ellis (VMware) <alexellis2@gmail.com>
2018-09-19 20:52:14 +01:00
Alex Ellis (VMware)
c67c9f2b30 Fix issue with direct_functions and path behaviour
- The path clipping / transforming behaviour must be turned-off
when we are not using direct_functions as is used in
faas-nomad and faas-ecs. This will need a change in each provider
to strip paths, but fixes a 404 error these users will see if they
upgrade to 0.9.2 or newer. 0.9.3 will have a this fix meaning
the whole un-edited path is passed to the provider when
direct_functions is set to false.

Signed-off-by: Alex Ellis (VMware) <alexellis2@gmail.com>
2018-09-15 14:40:22 +01:00
Vivek Singh
d926b2d886 Add basic auth support for /system/async-report
This commit adds basic authentication for `/system/async-report`
endpoint.

It also adds basic-auth secrets to `queue-worker` service which will be
used for gateway calls to `/system/async-report`.

Signed-off-by: Vivek Singh <vivekkmr45@yahoo.in>
2018-09-08 09:58:19 +01:00
Alex Ellis (VMware)
6937bc4d7f Move to auth package in faas-provider
The basic-auth middleware and credentials-loading code has been
moved into the faas-provider project. This has now been brought
back into the faas project via vendoring.

Signed-off-by: Alex Ellis (VMware) <alexellis2@gmail.com>
2018-09-06 16:14:53 +01:00
Alex Ellis (VMware)
ffd81afd02 Refactor #843
Code-review/refactoring for #843. Closes #843.

FaaSHandlers has had info and query handlers added to its list
of types for consistency.

Secrets added to queue-worker component ready for next PR.

Signed-off-by: Alex Ellis (VMware) <alexellis2@gmail.com>
2018-09-05 09:47:49 +01:00
Burton Rheutan
fa076fb2c4 Pass basic auth to all system calls
This changeset enables passing the basic auth credentials
to all /system/ calls to allow upstream providers to
perform authorization checks independent of the gateway.

This is essential for some providers, like Swarm, where
the system is accessible on the same network, and not
protected via the gateway

Signed-off-by: Burton Rheutan <rheutan7@gmail.com>
2018-09-05 09:47:49 +01:00
Alex Ellis (VMware)
2f98ca8802 Review changes for HTTP paths
This reviews the code and fixes up suggestions made by team for
the HTTP paths PR #789.

- Removed feature-flag (this is backwards-compatible, so I see
no value in adding the flag)
- There was a URL transform happening for calls proxied to the
back end, I changed this for the nil-transform - i.e. it does not
change anything in the URL
- Introduced variables to describe the regex indicies used in
the URL trimming.

Tested with Docker Swarm with a ruby-microservice, with
system calls and with function calls using the UI.

Signed-off-by: Alex Ellis (VMware) <alexellis2@gmail.com>
2018-08-29 12:41:04 +01:00
Thomas E Lackey
8749e0d891 Only truncate '/function/...' paths.
Signed-off-by: Thomas E Lackey <telackey@bozemanpass.com>
2018-08-29 12:41:04 +01:00
Thomas E Lackey
decf9addb3 Make 'URLPathTransformer' interface and implementation to do the function prefix trimming instead of baking it in. Also add a configuration option, 'pass_url_path_to_functions' to control whether the full path is passed to the functions or not.
Signed-off-by: Thomas E Lackey <telackey@bozemanpass.com>
2018-08-29 12:41:04 +01:00
Thomas E Lackey
7870b87c38 Implement proposal 716, passing full paths through the Gateway and fwatchdog.
Previously, only the query string of the URL was passed through the Gateway.
With this change, the entire path requested by the client is passed through as well as the query string.

While fwatchdog already supported passing the path through, in practice this would not happen
since the Gateway would have swallowed it before forwarding the request to the watchdog.

With this change, the path portion after the function name is added to the Http_Path environment
variable, provided that cgiHeaders are enabled.  This is similar to the of-watchdog equivalent.

Signed-off-by: Thomas E Lackey <telackey@bozemanpass.com>
2018-08-29 12:41:04 +01:00
Ken Fukuyama
4fabd50799 Changed Metrics to be exposed via Exporter
This change exposes the gateway metrics with an exporter which
implements the Collector interface of prometheus.
This change Fixes #697

Signed-off-by: Ken Fukuyama <kenfdev@gmail.com>
2018-08-24 09:01:41 +01:00
Alex Ellis (VMware)
c86de503c7 Attach X-Call-Id to asynchronous calls
Signed-off-by: Alex Ellis (VMware) <alexellis2@gmail.com>
2018-08-16 16:04:09 +01:00
Alex Ellis (VMware)
8f0d2d1fd6 Expose scale-function endpoint
- exposes scale-function endpoint for use with faas-idler, this
is protected by auth when enabled.

Signed-off-by: Alex Ellis (VMware) <alexellis2@gmail.com>
2018-07-23 15:24:11 +01:00
Alex Ellis (VMware)
9512f09d2b Refactor scaling to use existing code
Existing code has been used for scaling up and querying replicas.
This meant the new code was deleted and there is less duplication
now.

The cache store a whole query response rather than just the
available replica count and the tests were updated. This has been
tested with Docker swarm and the image:
 openfaas/gateway:scale-17-07-2018

This feature now needs the env-var of scale_from_zero to be enabled
in order to turn on the scaling behaviour.

Signed-off-by: Alex Ellis (VMware) <alexellis2@gmail.com>
2018-07-20 11:39:36 +01:00
Alex Ellis (VMware)
c58af8da56 Disable scaling from zero by default
This disables the scaling proxy by default since it is not the
default user-experience and is still under refinement.

Signed-off-by: Alex Ellis (VMware) <alexellis2@gmail.com>
2018-07-20 11:39:36 +01:00
Alex Ellis (VMware)
e67d45caa1 Add feature: scale from zero to 1 replicas
This change allows functions to be "idled" or scaled to zero
replicas and then be invoked later on. There is a penalty to
scaling up - the API gateway proxy will block until the function
is ready.

A cache is included to off-set the calls to upstream API to check
on readiness along with unit tests.

Testing via scaling to zero replicas and then invoking function.
On Swarm I observed 3 seconds on an Intel Nuc i5 for scaling back
from zero replicas.

Signed-off-by: Alex Ellis (VMware) <alexellis2@gmail.com>
2018-07-20 11:39:36 +01:00
Edward Wilde
aca2c7fe2a Enhance info endpoint to include gateway version
Extend the health endpoint and add gateway version information

Resolves: #733
Signed-off-by: Edward Wilde <ewilde@gmail.com>
2018-07-06 17:50:48 +01:00
Alex Ellis (VMware)
223c561706 Vendor new queue-worker version
Introduces 0.4.6 of queue-worker - see upstream repo for changes.

Signed-off-by: Alex Ellis (VMware) <alexellis2@gmail.com>
2018-06-18 20:10:46 +01:00
Alex Ellis (VMware)
8133414183 Read secrets from variable path
This change enables secrets to be read from any mount on disk
rather than hard-coding a certain location which suits Swarm or
K8s. The default value if not specified will look in the Swarm
location of /run/secrets/

README.md (docs) updated and set to off by default.

Signed-off-by: Alex Ellis (VMware) <alexellis2@gmail.com>
2018-05-23 11:42:42 +01:00
Alex Ellis (VMware)
a38931ce69 Enable basic auth on gateway
Fixes https://github.com/openfaas/faas/issues/687 allowing the
gateway to handle the responsibility of basic auth for when it is
in use.

To enable set basic_auth env-var to true and then mount two
secrets or plaintext files under /var/secrets/

basic_auth_user, basic_auth_password

Tested with faas-cli list/deploy and with Safari browser.

Signed-off-by: Alex Ellis (VMware) <alexellis2@gmail.com>
2018-05-23 11:42:42 +01:00
Alex Ellis (VMware)
4123270235 Add health and info endpoints
Fixes issue 689 by enabling /healthz and /system/info, see
swagger for more details.

Signed-off-by: Alex Ellis (VMware) <alexellis2@gmail.com>
2018-05-20 19:11:21 +01:00
Alex Ellis (VMware)
daa79aef75 Deprecate routeless proxy test
Routeless proxy allowed no HTTP path to be given when a Header
X-Function: name was given. This has been deprecated - I am
unaware of any usage of the feature.

Signed-off-by: Alex Ellis (VMware) <alexellis2@gmail.com>
2018-04-03 17:55:44 +01:00
Alex Ellis (VMware)
9a1b119c9f Remove Prometheus tracking for forwarded requests
Forwarded requests were being logged in the function metrics and
I saw this when doing some testing on auto-scaling with K8s.

This change removes the call to the Prometheus notifier for any
calls which are forwarded to the provider and retains them for the
functions.

Signed-off-by: Alex Ellis (VMware) <alexellis2@gmail.com>
2018-03-26 13:12:29 +01:00
John McCabe
fac3345668 Use http package consts for http methods
This commit replaces occurences of http method strings with the
corresponding consts from the http package.

*Note* UPDATE is not strictly speaking a valid method and as such isn't
part of the http package (should be a PUT or PATCH?)

Signed-off-by: John McCabe <john@johnmccabe.net>
2018-03-23 16:37:33 +00:00
Alex Ellis
0c7e59fe8a Add direct_functions mode to gateway for tuning
Adds a pair of configuration options for performance tuning. The
gateway can now invoke functions directly and can bypass the
provider. See updated table in README.md for configuration values.

BaseURLResolver is added with unit tests that decouples resolving
upstream URL from the reverse proxy client code.

- SingleHostBaseURLResolver resolves a single upstream host
- FunctionAsHostBaseURLResolver resolves host based upon conventions
within the URL of the request to a function for direct access

Tested with Kubernetes (faas-netes) and faas-swarm through UI, CLI
calling system endpoints and functions directly.

Signed-off-by: Alex Ellis (VMware) <alexellis2@gmail.com>
2018-03-23 16:35:37 +00:00