Skip to content

Commit

Permalink
Scrape function Pods
Browse files Browse the repository at this point in the history
As part of openfaas/docs#173 this
patch gives Prometheus a directive and permissions to scrape
Pods in the openfaas-fn namespace, so that they can be used
in HPAv2.

The Prometheus kubernetes_sd_configs is updated to add the
default function namespace into scope for scraping.

Longer term, a ClusterRoleBinding will be needed to cover the
"multiple namespaces" use-case, like there is a ClusterRole/
Binding for faas-netes as a non-default option. The
Prometheus scraping may need to look for namespaces or Pods
that match an annotation, or have a wildcard scan across
all namespaces, instead of the two it has after this PR
is merged.

@LucasRoesler also raised Push Gateways as an option for
future consideration.

The watchdog has built-in metrics on port 8082, and will be
scraped if the Prometheus scrape annotation is added.

Custom HTTP servers are also supported, and you can serve on
port 8080, or specify an alternative port via annotations.

For instance:
prometheus.io/scrape: true
prometheus.io/port: 8080

Issue #621 allows the scrape annotation to be overridden, which
current cannot due a default set in the controller.

Signed-off-by: Alex Ellis (OpenFaaS Ltd) <alexellis2@gmail.com>
  • Loading branch information
alexellis committed Apr 24, 2020
1 parent 07bb58e commit 71edafa
Show file tree
Hide file tree
Showing 26 changed files with 280 additions and 186 deletions.
2 changes: 1 addition & 1 deletion chart/openfaas/Chart.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
apiVersion: v1
description: Enable Kubernetes as a backend for OpenFaaS (Functions as a Service)
name: openfaas
version: 5.7.1
version: 5.7.2
sources:
- https://github.com/openfaas/faas
- https://github.com/openfaas/faas-netes
Expand Down
1 change: 1 addition & 0 deletions chart/openfaas/templates/prometheus-cfg.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ data:
namespaces:
names:
- {{ .Release.Namespace }}
- {{ $functionNs }}
relabel_configs:
- action: labelmap
regex: __meta_kubernetes_pod_label_(.+)
Expand Down
25 changes: 22 additions & 3 deletions chart/openfaas/templates/prometheus-rbac.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,9 @@ metadata:
release: {{ .Release.Name }}
---
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
kind: ClusterRole
metadata:
name: {{ .Release.Name }}-prometheus
namespace: {{ .Release.Namespace | quote }}
labels:
app: {{ template "openfaas.name" . }}
chart: {{ .Chart.Name }}-{{ .Chart.Version }}
Expand Down Expand Up @@ -45,7 +44,27 @@ metadata:
release: {{ .Release.Name }}
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: Role
kind: ClusterRole
name: {{ .Release.Name }}-prometheus
subjects:
- kind: ServiceAccount
name: {{ .Release.Name }}-prometheus
namespace: {{ .Release.Namespace | quote }}
---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
name: {{ .Release.Name }}-prometheus
namespace: {{ $functionNs | quote }}
labels:
app: {{ template "openfaas.name" . }}
chart: {{ .Chart.Name }}-{{ .Chart.Version }}
component: prometheus
heritage: {{ .Release.Service }}
release: {{ .Release.Name }}
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: {{ .Release.Name }}-prometheus
subjects:
- kind: ServiceAccount
Expand Down
2 changes: 1 addition & 1 deletion contrib/create-static-manifest.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ for filepath in $TEMPLATE_FILE; do
filename=$(basename $filepath)
outputname="${filename%%.*}.yml"
# Use helm to generate the yaml and then use sed to remove the helm specific lables/annotations.
helm template "$CHART_DIR" --name=faas --namespace="$NAMEPSPACE" --set "functionNamespace=$FUNCTIONNAMESPACE" -x templates/$filename --values="$VALUESNAME" \
helm template "$CHART_DIR" --name=openfaas --namespace="$NAMEPSPACE" --set "functionNamespace=$FUNCTIONNAMESPACE" -x templates/$filename --values="$VALUESNAME" \
| sed -E '/(chart:)|(release:)|(heritage:)/d' \
| sed -E '/# Source:/d' \
| sed -E '/^$/d' \
Expand Down
Binary file modified docs/cron-connector-0.3.1.tgz
Binary file not shown.
Loading

0 comments on commit 71edafa

Please sign in to comment.