Skip to content

Commit

Permalink
Add support for Database resource group manager
Browse files Browse the repository at this point in the history
  • Loading branch information
yassan authored and nineinchnick committed Nov 17, 2024
1 parent 1e7c08a commit 35cd04e
Show file tree
Hide file tree
Showing 8 changed files with 156 additions and 8 deletions.
18 changes: 16 additions & 2 deletions charts/trino/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -175,9 +175,23 @@ Fast distributed SQL query engine for big data analytics that helps you explore
```
* `resourceGroups` - object, default: `{}`

Resource groups file is mounted to /etc/trino/resource-groups/resource-groups.json
Example:
[Resource groups control](https://trino.io/docs/current/admin/resource-groups.html)
Set the type property to either:
* `configmap`, and provide the Resource groups file contents in `resourceGroupsConfig`,
* `properties`, and provide configuration properties in `properties`.
Properties example:
```yaml
type: properties
properties: |
resource-groups.configuration-manager=db
resource-groups.config-db-url=jdbc:postgresql://trino-postgresql.postgresql.svc.cluster.local:3306/resource_groups
resource-groups.config-db-user=username
resource-groups.config-db-password=password
```
Config map example:
```yaml
type: configmap
# Resource groups file is mounted to /etc/trino/resource-groups/resource-groups.json
resourceGroupsConfig: |-
{
"rootGroups": [
Expand Down
13 changes: 12 additions & 1 deletion charts/trino/templates/configmap-coordinator.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,20 @@ data:
{{- end }}

{{- if .Values.resourceGroups }}
{{- if eq .Values.resourceGroups.type "configmap" }}
resource-groups.properties: |
resource-groups.configuration-manager=file
resource-groups.config-file={{ .Values.server.config.path }}/resource-groups/resource-groups.json
{{- else if eq .Values.resourceGroups.type "properties" }}
resource-groups.properties: |
{{- if .Values.resourceGroups.properties }}
{{- .Values.resourceGroups.properties | nindent 4 }}
{{- else}}
{{- fail "resourceGroups.properties is required when resourceGroups.type is 'properties'." }}
{{- end }}
{{- else}}
{{- fail "Invalid resourceGroups.type value. It must be either 'configmap' or 'properties'." }}
{{- end }}
{{- end }}

{{- if .Values.server.exchangeManager }}
Expand Down Expand Up @@ -151,7 +162,7 @@ data:
{{ $fileName }}: |
{{- tpl $fileContent $ | nindent 4 }}
{{- end }}
{{- if .Values.resourceGroups }}
{{- if eq .Values.resourceGroups.type "configmap" }}
---
apiVersion: v1
kind: ConfigMap
Expand Down
4 changes: 2 additions & 2 deletions charts/trino/templates/deployment-coordinator.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ spec:
configMap:
name: {{ template "trino.fullname" . }}-access-control-volume-coordinator
{{- end }}
{{- if .Values.resourceGroups }}
{{- if eq .Values.resourceGroups.type "configmap" }}
- name: resource-groups-volume
configMap:
name: {{ template "trino.fullname" . }}-resource-groups-volume-coordinator
Expand Down Expand Up @@ -150,7 +150,7 @@ spec:
- mountPath: {{ .Values.server.config.path }}/access-control
name: access-control-volume
{{- end }}
{{- if .Values.resourceGroups }}
{{- if eq .Values.resourceGroups.type "configmap" }}
- mountPath: {{ .Values.server.config.path }}/resource-groups
name: resource-groups-volume
{{- end }}
Expand Down
17 changes: 17 additions & 0 deletions charts/trino/templates/tests/test-connection.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,23 @@ metadata:
annotations:
"helm.sh/hook": test
spec:
{{- if eq .Values.resourceGroups.type "properties" }}
initContainers:
- name: postgresql-client
image: bitnami/postgresql:17.1.0
command:
- /bin/sh
- -c
- |
echo "Inserting resource groups data";
PGUSER=trino PGPASSWORD=pass0000 psql -h trino-resource-groups-db-postgresql.postgresql.svc.cluster.local resource_groups <<SQL
-- create a root group 'admin' with NULL parent
INSERT INTO resource_groups (name, soft_memory_limit, hard_concurrency_limit, max_queued, scheduling_policy, environment)
VALUES ('admin', '100%', 50, 100, 'query_priority', 'production');
-- use ID of 'admin' resource group for selector
INSERT INTO selectors (resource_group_id, user_regex, priority) VALUES ((SELECT resource_group_id FROM resource_groups WHERE name = 'admin'), 'admin', 6);
SQL
{{- end }}
containers:
- name: cli
image: {{ include "trino.image" . }}
Expand Down
18 changes: 16 additions & 2 deletions charts/trino/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -183,10 +183,24 @@ accessControl: {}
# ```

resourceGroups: {}
# resourceGroups -- Resource groups file is mounted to /etc/trino/resource-groups/resource-groups.json
# resourceGroups -- [Resource groups control](https://trino.io/docs/current/admin/resource-groups.html)
# @raw
# Example:
# Set the type property to either:
# * `configmap`, and provide the Resource groups file contents in `resourceGroupsConfig`,
# * `properties`, and provide configuration properties in `properties`.
# Properties example:
# ```yaml
# type: properties
# properties: |
# resource-groups.configuration-manager=db
# resource-groups.config-db-url=jdbc:postgresql://trino-postgresql.postgresql.svc.cluster.local:3306/resource_groups
# resource-groups.config-db-user=username
# resource-groups.config-db-password=password
# ```
# Config map example:
# ```yaml
# type: configmap
# # Resource groups file is mounted to /etc/trino/resource-groups/resource-groups.json
# resourceGroupsConfig: |-
# {
# "rootGroups": [
Expand Down
15 changes: 15 additions & 0 deletions test-resource-groups-properties-values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Resource Groups 'properties' values to test.
# This is a YAML-formatted file.

server:
log:
trino:
level: INFO

resourceGroups:
type: properties
properties: |
resource-groups.configuration-manager=db
resource-groups.config-db-url=jdbc:postgresql://trino-resource-groups-db-postgresql.postgresql.svc.cluster.local:5432/resource_groups
resource-groups.config-db-user=trino
resource-groups.config-db-password=pass0000
60 changes: 60 additions & 0 deletions test-values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,66 @@ accessControl:
]
}
resourceGroups:
type: configmap
resourceGroupsConfig: |-
{
"rootGroups": [
{
"name": "global",
"softMemoryLimit": "80%",
"hardConcurrencyLimit": 100,
"maxQueued": 100,
"schedulingPolicy": "fair",
"jmxExport": true,
"subGroups": [
{
"name": "admin",
"softMemoryLimit": "30%",
"hardConcurrencyLimit": 20,
"maxQueued": 10
},
{
"name": "finance_human_resources",
"softMemoryLimit": "20%",
"hardConcurrencyLimit": 15,
"maxQueued": 10
},
{
"name": "general",
"softMemoryLimit": "30%",
"hardConcurrencyLimit": 20,
"maxQueued": 10
},
{
"name": "readonly",
"softMemoryLimit": "10%",
"hardConcurrencyLimit": 5,
"maxQueued": 5
}
]
}
],
"selectors": [
{
"user": "admin",
"group": "global.admin"
},
{
"group": "finance|human_resources",
"group": "global.finance_human_resources"
},
{
"user": "alice",
"group": "global.readonly"
},
{
"group": "global.general"
}
]
}
jmx:
enabled: true
registryPort: 9080
Expand Down
19 changes: 18 additions & 1 deletion test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ declare -A testCases=(
[exchange_manager_values]="--values test-exchange-manager-values.yaml"
[graceful_shutdown]="--values test-graceful-shutdown-values.yaml"
[gateway]=""
[resource_groups_properties]="--values test-resource-groups-properties-values.yaml"
)

declare -A testCaseCharts=(
Expand All @@ -22,6 +23,7 @@ declare -A testCaseCharts=(
[exchange_manager_values]="charts/trino"
[graceful_shutdown]="charts/trino"
[gateway]="charts/gateway"
[resource_groups_properties]="charts/trino"
)

function join_by {
Expand All @@ -33,13 +35,14 @@ function join_by {

# default to randomly generated namespace, same as chart-testing would do, but we need to load secrets into the same namespace
NAMESPACE=trino-$(LC_ALL=C tr -dc 'a-z0-9' </dev/urandom | head -c 6 || true)
DB_NAMESPACE=postgresql
HELM_EXTRA_SET_ARGS=
CT_ARGS=(
--skip-clean-up
--helm-extra-args="--timeout 2m"
)
CLEANUP_NAMESPACE=true
TEST_NAMES=(default single_node complete_values access_control_properties_values exchange_manager_values graceful_shutdown)
TEST_NAMES=(default single_node complete_values access_control_properties_values exchange_manager_values graceful_shutdown resource_groups_properties)

usage() {
cat <<EOF 1>&2
Expand Down Expand Up @@ -115,6 +118,18 @@ if printf '%s\0' "${TEST_NAMES[@]}" | grep -qwz complete_values; then
kubectl rollout status --watch deployments -l release=prometheus-operator -n "$NAMESPACE"
fi

# only install the PostgreSQL Helm chart when running the `resource_groups_properties` test
if printf '%s\0' "${TEST_NAMES[@]}" | grep -qwz resource_groups_properties; then
helm upgrade --install trino-resource-groups-db oci://registry-1.docker.io/bitnamicharts/postgresql -n "$DB_NAMESPACE" \
--create-namespace \
--version "16.2.1" \
--set auth.username=trino \
--set auth.password=pass0000 \
--set auth.database=resource_groups \
--set primary.persistence.enabled=false
kubectl wait --for=condition=ready pod -l app.kubernetes.io/name=postgresql --timeout=300s -n "$DB_NAMESPACE"
fi

CT_ARGS+=(--namespace "$NAMESPACE")

result=0
Expand All @@ -139,6 +154,8 @@ for test_name in "${TEST_NAMES[@]}"; do
done

if [ "$CLEANUP_NAMESPACE" == "true" ]; then
helm -n "$DB_NAMESPACE" uninstall trino-resource-groups-db --ignore-not-found
kubectl delete namespace "$DB_NAMESPACE" --ignore-not-found
helm -n "$NAMESPACE" uninstall prometheus-operator --ignore-not-found
kubectl delete namespace "$NAMESPACE"
mapfile -t crds < <(kubectl api-resources --api-group=monitoring.coreos.com --output name)
Expand Down

0 comments on commit 35cd04e

Please sign in to comment.