Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for jmx metrics and prometheus exporter #183

Merged
merged 3 commits into from
Jun 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ You can then run `helm search repo trino` to see the charts.
Then you can install chart using:

```console
helm install my-trino trino/trino --version 0.23.0
helm install my-trino trino/trino --version 0.24.0
```

Also, you can check the manifests using:
Expand Down
2 changes: 1 addition & 1 deletion charts/trino/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ type: application
# This is the chart version. This version number should be incremented each time you make changes
# to the chart and its templates, including the app version.
# Versions are expected to follow Semantic Versioning (https://semver.org/)
version: 0.23.1
version: 0.24.0

# This is the version number of the application being deployed. This version number should be
# incremented each time you make changes to the application. Versions are not expected to
Expand Down
46 changes: 45 additions & 1 deletion charts/trino/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# trino

![Version: 0.23.1](https://img.shields.io/badge/Version-0.23.1-informational?style=flat-square) ![Type: application](https://img.shields.io/badge/Type-application-informational?style=flat-square) ![AppVersion: 449](https://img.shields.io/badge/AppVersion-449-informational?style=flat-square)
![Version: 0.24.0](https://img.shields.io/badge/Version-0.24.0-informational?style=flat-square) ![Type: application](https://img.shields.io/badge/Type-application-informational?style=flat-square) ![AppVersion: 449](https://img.shields.io/badge/AppVersion-449-informational?style=flat-square)

Fast distributed SQL query engine for big data analytics that helps you explore your data universe

Expand Down Expand Up @@ -605,6 +605,50 @@ Fast distributed SQL query engine for big data analytics that helps you explore
}
}
```
* `jmx.enabled` - bool, default: `false`

Set to true to enable the RMI server to expose Trino's [JMX metrics](https://trino.io/docs/current/admin/jmx.html).
* `jmx.registryPort` - int, default: `9080`
* `jmx.serverPort` - int, default: `9081`
* `jmx.exporter.enabled` - bool, default: `false`

Set to true to export JMX Metrics via HTTP for [Prometheus](https://github.com/prometheus/jmx_exporter) consumption
* `jmx.exporter.image` - string, default: `"bitnami/jmx-exporter:latest"`
* `jmx.exporter.pullPolicy` - string, default: `"Always"`
* `jmx.exporter.port` - int, default: `5556`
* `jmx.exporter.configProperties` - list, default: `[]`

JMX Config Properties is mounted to /etc/jmx-exporter/jmx-exporter-config.yaml
Example:
```yaml
configProperties: |-
startDelaySeconds: 0
ssl: false
lowercaseOutputName: false
lowercaseOutputLabelNames: false
includeObjectNames: ["java.lang:type=Threading"]
autoExcludeObjectNameAttributes: true
excludeObjectNameAttributes:
"java.lang:type=OperatingSystem":
- "ObjectName"
"java.lang:type=Runtime":
- "ClassPath"
- "SystemProperties"
rules:
- pattern: 'java\.lang<type=Threading><(.*)>ThreadCount: (.*)'
name: java_lang_Threading_ThreadCount
value: '$2'
help: 'ThreadCount (java.lang<type=Threading><>ThreadCount)'
type: UNTYPED
* `serviceMonitor.enabled` - bool, default: `false`

Set to true to create resources for the [prometheus-operator](https://github.com/prometheus-operator/prometheus-operator).
* `serviceMonitor.labels` - object, default: `{"prometheus":"kube-prometheus"}`

Labels for serviceMonitor, so that Prometheus can select it
* `serviceMonitor.interval` - string, default: `"30s"`

The serviceMonitor web endpoint interval
* `commonLabels` - object, default: `{}`

Labels that get applied to every resource's metadata
Expand Down
7 changes: 7 additions & 0 deletions charts/trino/templates/configmap-coordinator.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ data:
{{- range $configValue := .Values.coordinator.additionalJVMConfig }}
{{ $configValue }}
{{- end }}
{{- if .Values.jmx.enabled }}
-Dcom.sun.management.jmxremote.rmi.port={{ .Values.jmx.serverPort }}
{{- end }}

config.properties: |
coordinator=true
Expand All @@ -69,6 +72,10 @@ data:
http-server.https.port={{ .Values.server.config.https.port }}
http-server.https.keystore.path={{ .Values.server.config.https.keystore.path }}
{{- end }}
{{- if .Values.jmx.enabled }}
jmx.rmiregistry.port={{ .Values.jmx.registryPort }}
jmx.rmiserver.port={{ .Values.jmx.serverPort }}
{{- end }}
{{- if .Values.server.coordinatorExtraConfig }}
{{- .Values.server.coordinatorExtraConfig | nindent 4 }}
{{- end }}
Expand Down
13 changes: 13 additions & 0 deletions charts/trino/templates/configmap-jmx-exporter.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{{- if .Values.jmx.exporter.enabled -}}
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ template "trino.fullname" . }}-jmx-exporter-config
namespace: {{ .Release.Namespace }}
labels:
{{- include "trino.labels" . | nindent 4 }}
app.kubernetes.io/component: jmx
data:
jmx-exporter-config.yaml: |-
{{- .Values.jmx.exporter.configProperties | nindent 4 }}
{{- end }}
29 changes: 29 additions & 0 deletions charts/trino/templates/deployment-coordinator.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,11 @@ spec:
path: group.db
{{- end }}
{{- end }}
{{- if .Values.jmx.exporter.enabled }}
- name: jmx-exporter-config-volume
configMap:
name: {{ template "trino.fullname" . }}-jmx-exporter-config
{{- end }}
{{- range .Values.configMounts }}
- name: {{ .name }}
configMap:
Expand Down Expand Up @@ -155,6 +160,19 @@ spec:
- name: http
containerPort: {{ .Values.service.port }}
protocol: TCP
{{- if .Values.jmx.enabled }}
- name: jmx-registry
containerPort: {{ .Values.jmx.registryPort }}
protocol: TCP
- name: jmx-server
containerPort: {{ .Values.jmx.serverPort }}
protocol: TCP
{{- end }}
{{- if .Values.jmx.exporter.enabled }}
- name: jmx-exporter
containerPort: {{ .Values.jmx.exporter.port }}
protocol: TCP
{{- end }}
{{- range $key, $value := .Values.coordinator.additionalExposedPorts }}
- name: {{ $value.name }}
containerPort: {{ $value.port }}
Expand All @@ -181,6 +199,17 @@ spec:
{{- toYaml .Values.coordinator.lifecycle | nindent 12 }}
resources:
{{- toYaml .Values.coordinator.resources | nindent 12 }}
{{- if .Values.jmx.exporter.enabled }}
- name: jmx-exporter
image: {{ .Values.jmx.exporter.image }}
imagePullPolicy: {{ .Values.jmx.exporter.pullPolicy }}
args:
- "{{ .Values.jmx.exporter.port }}"
- /etc/jmx-exporter/jmx-exporter-config.yaml
volumeMounts:
- mountPath: /etc/jmx-exporter/
name: jmx-exporter-config-volume
{{- end }}
{{- if .Values.sidecarContainers.coordinator }}
{{- toYaml .Values.sidecarContainers.coordinator | nindent 8 }}
{{- end }}
Expand Down
6 changes: 6 additions & 0 deletions charts/trino/templates/service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ spec:
targetPort: http
protocol: TCP
name: http
{{- if .Values.jmx.exporter.enabled }}
- port: {{ .Values.jmx.exporter.port }}
targetPort: jmx-exporter
protocol: TCP
name: jmx-exporter
{{- end }}
{{- range $key, $value := .Values.coordinator.additionalExposedPorts }}
- port: {{ $value.servicePort }}
name: {{ $value.name }}
Expand Down
22 changes: 22 additions & 0 deletions charts/trino/templates/servicemonitor.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{{- if .Values.serviceMonitor.enabled -}}
apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
name: {{ template "trino.fullname" . }}
namespace: {{ .Release.Namespace }}
labels:
{{- include "trino.labels" . | nindent 4 }}
{{- if .Values.serviceMonitor.labels }}
{{- toYaml .Values.serviceMonitor.labels | nindent 4 }}
{{- end }}
spec:
selector:
matchLabels:
{{- include "trino.selectorLabels" . | nindent 6 }}
namespaceSelector:
matchNames:
- {{ .Release.Namespace }}
endpoints:
- port: jmx-exporter
interval: {{ .Values.serviceMonitor.interval }}
{{- end }}
5 changes: 3 additions & 2 deletions charts/trino/templates/tests/test-connection.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ metadata:
labels:
{{- include "trino.labels" . | nindent 4 }}
app.kubernetes.io/component: test
test: connection
annotations:
"helm.sh/hook": test-success
"helm.sh/hook": test
spec:
containers:
- name: cli
Expand All @@ -24,8 +25,8 @@ spec:
- --password
{{- end }}
- --debug
- --network-logging=BODY
- --execute=SELECT 1
- --no-progress
{{- if eq .Values.server.config.authenticationType "PASSWORD" }}
env:
- name: TRINO_PASSWORD
Expand Down
67 changes: 67 additions & 0 deletions charts/trino/templates/tests/test-jmx.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
{{- if or .Values.jmx.exporter.enabled .Values.serviceMonitor.enabled }}
apiVersion: v1
kind: Pod
metadata:
name: {{ include "trino.fullname" . }}-test-jmx
labels:
{{- include "trino.labels" . | nindent 4 }}
app.kubernetes.io/component: test
test: jmx
annotations:
"helm.sh/hook": test
spec:
containers:
{{- if .Values.jmx.exporter.enabled }}
- name: trino-jmx
image: {{ include "trino.image" . }}
command: ["/bin/bash", "-c"]
args:
- curl -s {{ include "trino.fullname" . }}.{{ .Release.Namespace }}:5556 | grep -q trino
{{- end }}
{{- if .Values.serviceMonitor.enabled }}
- name: service-monitor
image: python:3-slim
command: ["python", "/tests/test.py"]
volumeMounts:
- name: tests
mountPath: /tests
{{- end }}
volumes:
- name: tests
configMap:
name: {{ include "trino.fullname" . }}-test-jmx
restartPolicy: Never
---
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ include "trino.fullname" . }}-test-jmx
labels:
{{- include "trino.labels" . | nindent 4 }}
app.kubernetes.io/component: test
test: jmx
data:
test.py: |
from urllib.request import urlopen
from urllib.error import URLError, HTTPError
import json

url = "http://prometheus-operator-kube-p-prometheus:9090/api/v1/targets?scrapePool=serviceMonitor/{{ .Release.Namespace }}/{{ include "trino.fullname" . }}/0&state=active"
while True:
try:
with urlopen(url) as response:
data = json.load(response)
except (URLError, HTTPError) as e:
print("Error fetching targets, Prometheus service might not be ready: ", e)
continue

try:
service_name = data["data"]["activeTargets"][0]["discoveredLabels"]["__meta_kubernetes_service_name"]
except (KeyError, IndexError) as e:
print("Invalid Prometheus response: ", e)
continue

if service_name == "{{ include "trino.fullname" . }}":
print("Found expected service in Prometheus targets")
break
{{- end }}
45 changes: 45 additions & 0 deletions charts/trino/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -727,6 +727,51 @@ kafka:
# }
# ```

jmx:
# -- Set to true to enable the RMI server to expose Trino's [JMX metrics](https://trino.io/docs/current/admin/jmx.html).
enabled: false
registryPort: 9080
serverPort: 9081
exporter:
# jmx.exporter.enabled -- Set to true to export JMX Metrics via HTTP for [Prometheus](https://github.com/prometheus/jmx_exporter) consumption
enabled: false
image: bitnami/jmx-exporter:latest
pullPolicy: Always
port: 5556
configProperties: []
# jmx.exporter.configProperties -- JMX Config Properties is mounted to /etc/jmx-exporter/jmx-exporter-config.yaml
# @raw
# Example:
# ```yaml
# configProperties: |-
# startDelaySeconds: 0
# ssl: false
# lowercaseOutputName: false
# lowercaseOutputLabelNames: false
# includeObjectNames: ["java.lang:type=Threading"]
# autoExcludeObjectNameAttributes: true
# excludeObjectNameAttributes:
# "java.lang:type=OperatingSystem":
# - "ObjectName"
# "java.lang:type=Runtime":
# - "ClassPath"
# - "SystemProperties"
# rules:
# - pattern: 'java\.lang<type=Threading><(.*)>ThreadCount: (.*)'
# name: java_lang_Threading_ThreadCount
# value: '$2'
# help: 'ThreadCount (java.lang<type=Threading><>ThreadCount)'
# type: UNTYPED

serviceMonitor:
# serviceMonitor.enabled -- Set to true to create resources for the [prometheus-operator](https://github.com/prometheus-operator/prometheus-operator).
enabled: false
# serviceMonitor.labels -- Labels for serviceMonitor, so that Prometheus can select it
labels:
prometheus: kube-prometheus
# serviceMonitor.interval -- The serviceMonitor web endpoint interval
interval: "30s"

# -- Labels that get applied to every resource's metadata
commonLabels: {}

Expand Down
22 changes: 22 additions & 0 deletions test-values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,28 @@ accessControl:
]
}

jmx:
enabled: true
registryPort: 9080
serverPort: 9081
exporter:
enabled: true
image: bitnami/jmx-exporter:latest
pullPolicy: Always
port: 5556
configProperties: |
startDelaySeconds: 0
hostPort: 127.0.0.1:9080
rules:
- pattern: 'trino.memory*'
- pattern: 'trino.execution<name=QueryManager>*'

serviceMonitor:
enabled: true
selector:
prometheus: default
interval: "30s"

ingress:
enabled: true
hosts:
Expand Down
Loading