Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
c4b5139
chore: Add smoke kuttl test
sbernauer Mar 27, 2025
0dc5b0c
Add kuttl test for routing
sbernauer Mar 27, 2025
2b6cd8d
feat: Support receving Trino query events
sbernauer Mar 28, 2025
0fd9f6c
docs
sbernauer Mar 28, 2025
dfb1260
Add two different proxying strategies
sbernauer Apr 7, 2025
aa36bd4
Merge remote-tracking branch 'origin/chore/kuttl-tests' into feat/tri…
sbernauer Apr 8, 2025
0d2efdc
Add kuttl test for proxy mode
sbernauer Apr 8, 2025
281c506
Some docs
sbernauer Apr 8, 2025
8f4d7dc
changelog
sbernauer Apr 8, 2025
88b3005
linter
sbernauer Apr 8, 2025
9e9f0cf
linter
sbernauer Apr 9, 2025
6caf0a6
Add a diagram
sbernauer Apr 10, 2025
af0d3eb
Markdown linter
sbernauer Apr 10, 2025
286386b
Update docs/proxy-modes.md
sbernauer Apr 10, 2025
43b3b5d
Update docs/design.md
sbernauer Apr 10, 2025
0001851
Update docs/proxy-modes.md
sbernauer Apr 10, 2025
c3f1aec
Apply suggestions from code review
sbernauer Apr 10, 2025
03e72a4
Update docs/proxy-modes.md
sbernauer Apr 10, 2025
764bb5b
Reword
sbernauer Apr 10, 2025
c214c1b
Remove sentence from docs
sbernauer Apr 10, 2025
1ad3685
Document compression layers
sbernauer Apr 10, 2025
4bad5b4
Add some
sbernauer Apr 10, 2025
e44dd5b
Add more derives
sbernauer Apr 10, 2025
918b334
Move test fixtures
sbernauer Apr 10, 2025
f7a3828
Update trino-lb/src/http_server/mod.rs
sbernauer Apr 10, 2025
9e446b4
Apply suggestions from code review
sbernauer Apr 11, 2025
90c655e
Clean up test-definition.yaml
sbernauer Apr 11, 2025
0fc40c4
Apply suggestions from code review
sbernauer Apr 11, 2025
05f59e3
Check in missing test files
sbernauer Apr 11, 2025
0b3a6a0
Change casing
sbernauer Apr 11, 2025
b9ed460
Update docs/design.md
sbernauer Apr 11, 2025
bc0ece2
Fingers crossed :)
sbernauer Apr 11, 2025
ce4e3b6
fix: Remove todo!()
sbernauer Apr 11, 2025
1b4657b
Rework architecture to increment at query submition and decrement at …
sbernauer Apr 15, 2025
3025ea6
Support alternative hostnames for Trino clusters
sbernauer Apr 16, 2025
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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@ All notable changes to this project will be documented in this file.

- The Stackable scaler now ensures that a `TrinoCluster` has changed to `ready` more than 5 seconds
ago before marking it as `ready` ([#68]).
- Support two different proxy modes: `ProxyAllCalls` (default) and `ProxyFirstCall`.
Read the [proxy modes docs](./docs/proxy-modes.md) for details ([#82]).

[#68]: https://github.com/stackabletech/trino-lb/pull/68
[#82]: https://github.com/stackabletech/trino-lb/pull/82

## [0.5.0] - 2025-03-14

Expand Down
16 changes: 12 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ sqlx = { version = "0.8.2", features = [
strum = { version = "0.27", features = ["derive"] }
tokio = "1.39"
tower = "0.5"
tower-http = { version = "0.6", features = ["compression-full", "tracing"] }
tower-http = { version = "0.6", features = ["compression-full", "decompression-full", "tracing"] }
tracing = "0.1"
tracing-opentelemetry = "0.25"
tracing-subscriber = { version = "0.3", features = ["env-filter"] }
Expand All @@ -94,4 +94,4 @@ urlencoding = "2.1"
indicatif = "0.17"

[patch.crates-io]
prusto = { git = "https://github.com/sbernauer/prusto.git", branch = "feat/derive-name-attribute" }
prusto = { git = "https://github.com/sbernauer/prusto.git", branch = "feat/derive-name-attribute-2" }
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ A highly available load balancer with support for queueing, routing and auto-sca
* [Postgres](./docs/persistence/postgres.md)
* [Scaling](./docs/scaling/index.md)
* [Stackable](./docs/scaling/stackable.md)
* [Proxy modes](./docs/proxy-modes.md)

## Try it out locally

Expand Down
9 changes: 5 additions & 4 deletions deploy/helm/trino-lb/configs/trino-lb-config.yaml
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
trinoLb:

Check warning on line 1 in deploy/helm/trino-lb/configs/trino-lb-config.yaml

View workflow job for this annotation

GitHub Actions / pre-commit

1:1 [document-start] missing document start "---"
externalAddress: https://5.250.179.64:8443
externalAddress: https://85.215.178.111:8443
tls:
enabled: true
certPemFile: /certificates/cert.pem
keyPemFile: /certificates/key.pem
certPemFile: /certificates/tls.crt
keyPemFile: /certificates/tls.key
persistence:
redis:
clusterMode: true
endpoint: redis://:[email protected]:6379/
# postgres:

Check warning on line 11 in deploy/helm/trino-lb/configs/trino-lb-config.yaml

View workflow job for this annotation

GitHub Actions / pre-commit

11:5 [comments-indentation] comment not indented like content
# # helm install postgres bitnami/postgresql --version 13.2.18 --set auth.username=trino-lb,auth.password=trino-lb,auth.database=trino_lb
# url: postgres://trino-lb:[email protected]/trino_lb
# maxConnections: 10
proxyMode: ProxyFirstCall # ProxyFirstCall
refreshQueryCounterInterval: 30s # It is low for testing purpose and to get frequent running queries metrics
tracing:
enabled: true
Expand Down Expand Up @@ -56,7 +57,7 @@
- name: trino-m-2
endpoint: https://trino-m-2-coordinator-default.default.svc.cluster.local:8443
credentials: *common-credentials
# oidc:

Check warning on line 60 in deploy/helm/trino-lb/configs/trino-lb-config.yaml

View workflow job for this annotation

GitHub Actions / pre-commit

60:3 [comments-indentation] comment not indented like content
# maxRunningQueries: 3
# trinoClusters:
# - name: trino-oidc-1
Expand Down Expand Up @@ -101,7 +102,7 @@
routingFallback: m

clusterAutoscaler:
reconcileInterval: 1s
# reconcileInterval: 1s
stackable:
clusters:
trino-s-1:
Expand Down
22 changes: 20 additions & 2 deletions deploy/helm/trino-lb/templates/deployment.yaml
Original file line number Diff line number Diff line change
@@ -1,27 +1,30 @@
apiVersion: apps/v1

Check warning on line 1 in deploy/helm/trino-lb/templates/deployment.yaml

View workflow job for this annotation

GitHub Actions / pre-commit

1:1 [document-start] missing document start "---"
kind: Deployment
metadata:
name: {{ .Release.Name }}-deployment

Check failure on line 4 in deploy/helm/trino-lb/templates/deployment.yaml

View workflow job for this annotation

GitHub Actions / pre-commit

4:28 syntax error: expected <block end>, but found '<scalar>' (syntax)

Check failure on line 4 in deploy/helm/trino-lb/templates/deployment.yaml

View workflow job for this annotation

GitHub Actions / pre-commit

4:25 [braces] too many spaces inside braces

Check failure on line 4 in deploy/helm/trino-lb/templates/deployment.yaml

View workflow job for this annotation

GitHub Actions / pre-commit

4:11 [braces] too many spaces inside braces
labels:
app.kubernetes.io/name: trino-lb
app.kubernetes.io/instance: {{ .Release.Name }}

Check failure on line 7 in deploy/helm/trino-lb/templates/deployment.yaml

View workflow job for this annotation

GitHub Actions / pre-commit

7:49 [braces] too many spaces inside braces
spec:
replicas: {{ .Values.replicas }}

Check failure on line 9 in deploy/helm/trino-lb/templates/deployment.yaml

View workflow job for this annotation

GitHub Actions / pre-commit

9:32 [braces] too many spaces inside braces

Check failure on line 9 in deploy/helm/trino-lb/templates/deployment.yaml

View workflow job for this annotation

GitHub Actions / pre-commit

9:15 [braces] too many spaces inside braces
selector:
matchLabels:
app.kubernetes.io/name: trino-lb
app.kubernetes.io/instance: {{ .Release.Name }}

Check failure on line 13 in deploy/helm/trino-lb/templates/deployment.yaml

View workflow job for this annotation

GitHub Actions / pre-commit

13:51 [braces] too many spaces inside braces

Check failure on line 13 in deploy/helm/trino-lb/templates/deployment.yaml

View workflow job for this annotation

GitHub Actions / pre-commit

13:37 [braces] too many spaces inside braces
template:
metadata:
labels:
app.kubernetes.io/name: trino-lb
app.kubernetes.io/instance: {{ .Release.Name }}

Check failure on line 18 in deploy/helm/trino-lb/templates/deployment.yaml

View workflow job for this annotation

GitHub Actions / pre-commit

18:53 [braces] too many spaces inside braces

Check failure on line 18 in deploy/helm/trino-lb/templates/deployment.yaml

View workflow job for this annotation

GitHub Actions / pre-commit

18:39 [braces] too many spaces inside braces
spec:
containers:
- name: trino-lb
image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
imagePullPolicy: {{ .Values.image.pullPolicy }}
command: ["trino-lb", "--config-file", "/etc/stackable/trino-lb/config/trino-lb-config.yaml"]
# env:
# - name: RUST_LOG
# value: debug
ports:
- containerPort: 8443
- containerPort: 9090
Expand All @@ -36,7 +39,22 @@
- name: config
secret:
secretName: {{ .Release.Name }}-config
# - name: certificates
# secret:
# secretName: {{ .Release.Name }}-certificates
- name: certificates
secret:
secretName: {{ .Release.Name }}-certificates
ephemeral:
volumeClaimTemplate:
metadata:
annotations:
secrets.stackable.tech/class: tls
secrets.stackable.tech/scope: pod,service=trino-lb
secrets.stackable.tech/format: tls-pem
spec:
storageClassName: secrets.stackable.tech
accessModes:
- ReadWriteOnce
resources:
requests:
storage: "1"
serviceAccountName: {{ .Release.Name }}
65 changes: 33 additions & 32 deletions deploy/helm/trino-lb/templates/trinos.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# 1 small cluster
{{- range untilStep 1 2 1 }}
{{- $trinos := list "trino-s-1" "trino-m-1" "trino-m-2" }}

Check warning on line 1 in deploy/helm/trino-lb/templates/trinos.yaml

View workflow job for this annotation

GitHub Actions / pre-commit

1:1 [document-start] missing document start "---"
{{- range $trinos }}
---
apiVersion: trino.stackable.tech/v1alpha1
kind: TrinoCluster
metadata:
name: trino-s-{{ . }}
name: {{ . }}
namespace: default
spec:
image:
Expand All @@ -21,46 +21,47 @@
config.properties:
tracing.enabled: "true"
tracing.exporter.endpoint: http://jaeger-collector.default.svc.cluster.local:4317
event-listener.config-files: /tmp/http-event-listener.properties
podOverrides: &podOverrides
spec:
containers:
- name: trino
volumeMounts:
- name: http-event-listener-config
mountPath: /tmp/http-event-listener.properties
subPath: http-event-listener.properties
volumes:
- name: http-event-listener-config
configMap:
name: {{ . }}-http-event-listener-config
roleGroups:
default:
replicas: 1
workers:
configOverrides: *configOverrides
podOverrides: *podOverrides
roleGroups:
default:
replicas: 1
{{- end }}
# 2 medium clusters
{{- range untilStep 1 3 1 }}
---
apiVersion: trino.stackable.tech/v1alpha1
kind: TrinoCluster
apiVersion: v1
kind: ConfigMap
metadata:
name: trino-m-{{ . }}
name: {{ . }}-http-event-listener-config
namespace: default
spec:
image:
productVersion: "455"
clusterConfig:
catalogLabelSelector:
matchLabels:
trino: trino
listenerClass: external-stable
authentication:
- authenticationClass: trino-users
coordinators:
configOverrides: &configOverrides
config.properties:
tracing.enabled: "true"
tracing.exporter.endpoint: http://jaeger-collector.default.svc.cluster.local:4317
roleGroups:
default:
replicas: 1
workers:
configOverrides: *configOverrides
roleGroups:
default:
replicas: 1
data:
http-event-listener.properties: |
event-listener.name=http

http-event-listener.connect-ingest-uri=https://trino-lb.trino-lb.svc.cluster.local:8443/v1/trino-event-listener
http-event-listener.connect-retry-count=10
# http-event-listener.connect-http-headers="Trino-Cluster:{{ . }}" # IS BROKEN!
http-event-listener.http-client.trust-store-path=/stackable/server_tls/truststore.p12
http-event-listener.http-client.trust-store-password=changeit

http-event-listener.log-created=true
http-event-listener.log-completed=true
http-event-listener.log-split=false
{{- end }}
---
apiVersion: v1
Expand Down
45 changes: 43 additions & 2 deletions docs/design.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,12 @@ Currently the following autoscalers are implemented:

Read on the [scaling page](./scaling/index.md) for more details.

## 6. Proxy modes

trino-lb can be configured to either proxy all calls to the underlying Trino clusters or only the initial `POST` request and instruct the client to connect directly to the Trino cluster for the subsequent polling requests.

Read on the [proxy modes page](./proxy-modes.md) for more details.

## Monitoring

trino-lb emits [OpenTelemetry Metrics](https://opentelemetry.io/docs/concepts/signals/metrics/), which (for now) are only exposed as [Prometheus](https://prometheus.io/) metrics on `http://0.0.0.0:9090/metrics`.
Expand All @@ -107,6 +113,7 @@ Also, the cluster `trino-s-1` was started on demand, executed the 60 queries and
![Grafana screenshot](./assets/grafana-screenshot.png)

## Tracing

trino-lb emits [OpenTelemetry Traces](https://opentelemetry.io/docs/concepts/signals/traces/) to [OTLP](https://opentelemetry.io/docs/specs/otel/protocol/) endpoints such as [Jaeger](https://www.jaegertracing.io/).
When proxy-ing requests to Trino we take care of [OpenTelemetry Propagation](https://opentelemetry.io/docs/instrumentation/js/propagation/), so that the Trino spans will show up within the trino-lb spans.
This enables nice tracing across trino-lb and trino (as seen in the screenshot below)
Expand All @@ -118,6 +125,40 @@ This enables nice tracing across trino-lb and trino (as seen in the screenshot b
This flowchart represents a Trino client submitting a query.
It might be send to a Trino clusters or queued if all clusters are full.

### General flow

```mermaid
sequenceDiagram
actor client as Trino client
participant lb as trino-lb
participant trino as Trino

client ->>+ lb: Submit query using <br/> POST /v1/statement
lb ->> lb: Determine if query should be queued<br/>or which Trino cluster it should be routed to.<br/>See below diagram for details
lb ->>- client: # Don't strip space

loop While queued
client ->>+ lb: Poll
lb ->>- client: # Don't strip space
end

alt Proxy mode: Proxy all calls
loop While query running
client ->>+ lb: Poll
lb -->+ trino: # Don't strip space
trino ->>- lb: # Don't strip space
lb ->>- client: # Don<>'t strip space
end
else Proxy mode: Proxy first call
loop While query running
client ->>+ trino: Poll
trino ->>- client: # Don't strip space
end
end
```

### Detailed initial `POST /v1/statement`

```mermaid
sequenceDiagram
actor client as Trino client
Expand All @@ -141,7 +182,7 @@ sequenceDiagram

lb ->> lb: Determine cluster with the fewest running queries

alt All active clusters full
alt All active clusters reached query limit or all clusters unhealthy
lb ->>+ persistence: Store queued query
persistence ->>- lb: # Don't strip space

Expand All @@ -156,7 +197,7 @@ sequenceDiagram
lb ->>+ persistence: Store query
persistence ->>- lb: # Don't strip space

lb ->> lb: Change nextUri to point to trino-lb
lb ->> lb: Change nextUri to point to trino-lb in case all requests should be proxied
end

lb ->>- client: Response containing nextUri
Expand Down
Loading
Loading