Skip to content

Commit

Permalink
feat: add serviceMonitor for apisix-gateway
Browse files Browse the repository at this point in the history
  • Loading branch information
mstefany committed Apr 12, 2024
1 parent 6b8acad commit 5bb8899
Show file tree
Hide file tree
Showing 7 changed files with 77 additions and 8 deletions.
5 changes: 5 additions & 0 deletions charts/apisix-ingress-controller/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,11 @@ The same for container level, you need to set:
| gateway.nginx.workerRlimitNofile | string | `"20480"` | Nginx workerRlimitNoFile |
| gateway.resources | object | `{}` | |
| gateway.securityContext | object | `{}` | |
| gateway.serviceMonitor | object | `{"annotations":{},"enabled":false,"interval":"15s","labels":{},"metricRelabelings":{},"namespace":"monitoring","path":"/apisix/prometheus/metrics"}` | Create ServiceMonitor object for apisix gateway for Prometheus operator Requires Prometheus operator v0.38.0 or higher. |
| gateway.serviceMonitor.annotations | object | `{}` | @param serviceMonitor.annotations ServiceMonitor annotations |
| gateway.serviceMonitor.labels | object | `{}` | @param serviceMonitor.labels ServiceMonitor extra labels |
| gateway.serviceMonitor.metricRelabelings | object | `{}` | @param serviceMonitor.metricRelabelings MetricRelabelConfigs to apply to samples before ingestion. ref: https://prometheus.io/docs/prometheus/latest/configuration/configuration/#metric_relabel_configs |
| gateway.serviceMonitor.path | string | `"/apisix/prometheus/metrics"` | @param serviceMonitor.path ServiceMonitor scrape path |
| gateway.tls.additionalContainerPorts | list | `[]` | Support multiple https ports, See [Configuration](https://github.com/apache/apisix/blob/0bc65ea9acd726f79f80ae0abd8f50b7eb172e3d/conf/config-default.yaml#L99) |
| gateway.tls.certCAFilename | string | `""` | Filename be used in the gateway.tls.existingCASecret |
| gateway.tls.containerPort | int | `9443` | |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,12 +164,12 @@ data:
plugin_attr:
prometheus:
enable_export_server: {{ .Values.serviceMonitor.enabled }}
{{- if .Values.serviceMonitor.enabled }}
enable_export_server: {{ .Values.gateway.serviceMonitor.enabled }}
{{- if .Values.gateway.serviceMonitor.enabled }}
export_addr:
ip: 0.0.0.0
port: 9091
export_uri: /apisix/prometheus/metrics
export_uri: {{ .Values.gateway.serviceMonitor.path }}
metric_prefix: apisix_
{{- end }}
{{ end }}
4 changes: 2 additions & 2 deletions charts/apisix-ingress-controller/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ spec:
image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
imagePullPolicy: {{ .Values.image.pullPolicy }}
ports:
- name: http
- name: http-controller
containerPort: {{ (.Values.config.httpListen | split ":")._1 }}
protocol: TCP
{{ if .Values.config.etcdserver.enabled }}
Expand Down Expand Up @@ -146,7 +146,7 @@ spec:
- name: https
containerPort: {{ .Values.gateway.tls.containerPort }}
protocol: TCP
{{- if .Values.serviceMonitor.enabled }}
{{- if .Values.gateway.serviceMonitor.enabled }}
- containerPort: 9091
name: prometheus
protocol: TCP
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{{- if .Values.config.etcdserver.enabled }}
apiVersion: v1
kind: Service
metadata:
Expand Down Expand Up @@ -41,4 +42,5 @@ spec:
{{- range $ip := .Values.gateway.externalIPs }}
- {{ $ip }}
{{- end }}
{{- end }}
{{- end }}
{{- end }}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
{{- if and .Values.config.etcdserver.enabled .Values.gateway.serviceMonitor.enabled }}
apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
name: {{ template "apisix-ingress-controller.fullname" . }}-apisix-gateway
{{- if .Values.gateway.serviceMonitor.namespace }}
namespace: {{ .Values.gateway.serviceMonitor.namespace }}
{{- end }}
{{- if .Values.gateway.serviceMonitor.labels }}
labels: {{- toYaml .Values.gateway.serviceMonitor.labels | nindent 4 }}
{{- end }}
{{- if .Values.gateway.serviceMonitor.annotations }}
annotations: {{- toYaml .Values.gateway.serviceMonitor.annotations | nindent 4 }}
{{- end }}
spec:
endpoints:
- targetPort: prometheus
scheme: http
path: {{ .Values.gateway.serviceMonitor.path }}
{{- if .Values.gateway.serviceMonitor.interval }}
interval: {{ .Values.gateway.serviceMonitor.interval }}
{{- end }}
{{- with .Values.gateway.serviceMonitor.metricRelabelings }}
metricRelabelings: {{ toYaml . | nindent 6 }}
{{- end }}
namespaceSelector:
matchNames:
- {{ template "apisix-ingress-controller.namespace" . }}
selector:
matchLabels:
{{- include "apisix-ingress-controller.labels" . | nindent 6 }}
{{- end }}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ metadata:
{{- end }}
spec:
endpoints:
- targetPort: http
- targetPort: http-controller
scheme: http
{{- if .Values.serviceMonitor.interval }}
interval: {{ .Values.serviceMonitor.interval }}
Expand All @@ -46,4 +46,3 @@ spec:
matchLabels:
{{- include "apisix-ingress-controller.labels" . | nindent 6 }}
{{- end }}

15 changes: 15 additions & 0 deletions charts/apisix-ingress-controller/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,21 @@ gateway:
# readOnlyRootFilesystem: true
# runAsNonRoot: true
# runAsUser: 636
# -- Create ServiceMonitor object for apisix gateway for Prometheus operator
# Requires Prometheus operator v0.38.0 or higher.
serviceMonitor:
enabled: false
namespace: "monitoring"
# -- @param serviceMonitor.path ServiceMonitor scrape path
path: "/apisix/prometheus/metrics"
interval: 15s
# -- @param serviceMonitor.labels ServiceMonitor extra labels
labels: {}
# -- @param serviceMonitor.annotations ServiceMonitor annotations
annotations: {}
# -- @param serviceMonitor.metricRelabelings MetricRelabelConfigs to apply to samples before ingestion.
# ref: https://prometheus.io/docs/prometheus/latest/configuration/configuration/#metric_relabel_configs
metricRelabelings: {}
tls:
enabled: false
servicePort: 443
Expand Down

0 comments on commit 5bb8899

Please sign in to comment.