Skip to content

Commit b87be02

Browse files
committed
DEVOPS-2707 - Added support for keycloak-events queue in rabbitmq for new Lightrun-related keycloak feature of fetching events
1 parent 226a8b3 commit b87be02

File tree

6 files changed

+131
-16
lines changed

6 files changed

+131
-16
lines changed

chart/templates/_helpers.tpl

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
{{/*
2+
Get queue name by prefix from the queue_names list.
3+
4+
Parameters:
5+
- prefix: The prefix to match against queue names
6+
- Values: The chart values context
7+
- strict (optional): If true, fail if no matching queue is found (default: false)
8+
9+
Returns:
10+
- The first queue name that matches the prefix
11+
- If no match found and strict=false, returns the first queue name
12+
- If no match found and strict=true, fails the template
13+
*/}}
14+
{{- define "lightrun-mq.getQueueNameByPrefix" -}}
15+
{{- $queue_names := .Values.general.mq.queue_names | default (list .Values.general.mq.queue_name) }}
16+
{{- if not $queue_names }}
17+
{{- fail "No queue names defined in general.mq.queue_names or general.mq.queue_name" }}
18+
{{- end }}
19+
{{- $prefix := .prefix | default "" | lower }}
20+
{{- $strict := .strict | default false }}
21+
{{- $matching_queue := "" }}
22+
{{- range $queue_names }}
23+
{{- if and . (hasPrefix $prefix (. | lower)) }}
24+
{{- $matching_queue = . }}
25+
{{- break }}
26+
{{- end }}
27+
{{- end }}
28+
{{- if and $strict (eq $matching_queue "") }}
29+
{{- fail (printf "No queue found with prefix '%s' in queue_names list" $prefix) }}
30+
{{- end }}
31+
{{- if eq $matching_queue "" }}
32+
{{- $matching_queue = (index $queue_names 0) }}
33+
{{- end }}
34+
{{- $matching_queue }}
35+
{{- end }}

chart/templates/backend-deployment.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ spec:
303303
- name: SPRING_RABBITMQ_PORT
304304
value: {{ .Values.general.mq.port | quote }}
305305
- name: TRACKING_MIXPANEL_QUEUE_NAME
306-
value: {{ .Values.general.mq.queue_name | quote }}
306+
value: {{ include "lightrun-mq.getQueueNameByPrefix" (dict "prefix" "mixpanel-events" "Values" .Values) | quote }}
307307
{{- end }}
308308
{{- if .Values.deployments.backend.extraEnvs }}
309309
{{- toYaml .Values.deployments.backend.extraEnvs | nindent 12 }}
@@ -322,7 +322,7 @@ spec:
322322
value: "{{ include "http.scheme" . }}://{{ include "data_streamer.name" . }}:8080/events/post"
323323
{{- end }}
324324

325-
# waiting for mysql and keycloak initialization
325+
# waiting for mysql, rabbitmq and keycloak initialization
326326
initContainers:
327327
{{- include "lightrun-backend.initContainer.download-async-profiler" . | nindent 6 }}
328328

chart/templates/helpers/_helpers.tpl

+28
Original file line numberDiff line numberDiff line change
@@ -703,4 +703,32 @@ Container SecurityContext of lightrun artifacts
703703
{{- end -}}
704704
{{- end -}}
705705

706+
{{/*
707+
Get queue name by prefix from the queue_names list.
708+
709+
Parameters:
710+
- prefix: The prefix to match against queue names
711+
- Values: The chart values context
706712
713+
Returns:
714+
- The first queue name that matches the prefix
715+
- Fails if no matching queue is found
716+
*/}}
717+
{{- define "lightrun-mq.getQueueNameByPrefix" -}}
718+
{{- $queue_names := .Values.general.mq.queue_names | default (list .Values.general.mq.queue_name) }}
719+
{{- if not $queue_names }}
720+
{{- fail "No queue names defined in general.mq.queue_names or general.mq.queue_name" }}
721+
{{- end }}
722+
{{- $prefix := .prefix | default "" | lower }}
723+
{{- $matching_queue := "" }}
724+
{{- range $queue_names }}
725+
{{- if and . (hasPrefix $prefix (. | lower)) }}
726+
{{- $matching_queue = . }}
727+
{{- break }}
728+
{{- end }}
729+
{{- end }}
730+
{{- if eq $matching_queue "" }}
731+
{{- fail (printf "No queue found with prefix '%s' in queue_names list" $prefix) }}
732+
{{- end }}
733+
{{- $matching_queue }}
734+
{{- end }}

chart/templates/keycloak-deployment.yaml

+41
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,12 @@ spec:
170170
port: 9080
171171
{{- end }}
172172
env:
173+
{{- if .Values.general.mq.enabled }}
174+
- name: SPRING_RABBITMQ_HOST
175+
value: {{ include "lightrun-mq.endpoint" . }}
176+
- name: SPRING_RABBITMQ_PORT
177+
value: {{ .Values.general.mq.port | quote }}
178+
{{- end }}
173179
- name: INFO_DEPLOYMENT
174180
{{ if eq .Values.general.deployment_type "saas" }}
175181
value: "SaaS"
@@ -293,6 +299,41 @@ spec:
293299
}}
294300
initContainers:
295301
{{- include "lightrun-keycloak.initContainer.download-async-profiler" . | nindent 6 }}
302+
{{ if .Values.general.mq.enabled }}
303+
- name: wait-for-rabbitmq
304+
image: "{{ .Values.deployments.keycloak.initContainers.wait_for_rabbitmq.image.repository }}:{{ .Values.deployments.keycloak.initContainers.wait_for_rabbitmq.image.tag }}"
305+
imagePullPolicy: {{ .Values.deployments.keycloak.initContainers.wait_for_rabbitmq.image.pullPolicy }}
306+
securityContext: {{ include "lightrun-keycloak.containerSecurityContext" . | indent 10 }}
307+
command:
308+
- sh
309+
- /scripts/wait-for-200.sh
310+
resources:
311+
limits:
312+
memory: "100Mi"
313+
cpu: "100m"
314+
requests:
315+
memory: "100Mi"
316+
cpu: "100m"
317+
env:
318+
- name: MY_POD_NAMESPACE
319+
valueFrom:
320+
fieldRef:
321+
fieldPath: metadata.namespace
322+
- name: AUTH_USER
323+
valueFrom:
324+
secretKeyRef:
325+
name: {{ include "secrets.backend.name" . }}
326+
key: SPRING_RABBITMQ_USERNAME
327+
- name: AUTH_PASSWORD
328+
valueFrom:
329+
secretKeyRef:
330+
name: {{ include "secrets.backend.name" . }}
331+
key: SPRING_RABBITMQ_PASSWORD
332+
- name: RABBITMQ_TCP_PORT
333+
value: "15672"
334+
- name: URL
335+
value: {{ include "http.scheme" . }}://{{ include "lightrun-mq.endpoint" . }}:$(RABBITMQ_TCP_PORT)/api/overview {{ if .Values.general.internal_tls.enabled }}--no-check-certificate{{ end }}
336+
{{- end }}
296337
{{- end -}}
297338
{{- if .Values.general.readOnlyRootFilesystem }}
298339
{{- include "lightrun-keycloak.initContainer.read-only-rootfs" . }}

chart/templates/rabbitmq-cm.yaml

+10-6
Original file line numberDiff line numberDiff line change
@@ -45,28 +45,32 @@ data:
4545
}
4646
],
4747
"queues": [
48+
{{- $queue_names := .Values.general.mq.queue_names | default (list .Values.general.mq.queue_name) }}
49+
{{- $last_index := sub (len $queue_names) 1 }}
50+
{{- range $index, $queue_name := $queue_names }}
4851
{
49-
"name": "{{ .Values.general.mq.queue_name }}.dlq",
52+
"name": "{{ $queue_name }}.dlq",
5053
"vhost": "/",
5154
"durable": true,
5255
"auto_delete": false,
5356
"arguments": {
5457
"x-queue-type": "quorum",
5558
"x-created-by": "lightrun-onprem-server-chart"
5659
}
57-
},
58-
{
59-
"name": {{ .Values.general.mq.queue_name | quote }},
60+
},
61+
{
62+
"name": {{ $queue_name | quote }},
6063
"vhost": "/",
6164
"durable": true,
6265
"auto_delete": false,
6366
"arguments": {
6467
"x-dead-letter-exchange": "",
65-
"x-dead-letter-routing-key": "{{ .Values.general.mq.queue_name }}.dlq",
68+
"x-dead-letter-routing-key": "{{ $queue_name }}.dlq",
6669
"x-queue-type": "quorum",
6770
"x-created-by": "lightrun-onprem-server-chart"
6871
}
69-
}
72+
}{{ if not (eq $index $last_index) }},{{ end }}
73+
{{- end }}
7074
]
7175
}
7276

chart/values.yaml

+15-8
Original file line numberDiff line numberDiff line change
@@ -79,20 +79,22 @@ general:
7979
## Changing the queue name results in a new queue (and dlq) being created
8080
## Old queues will not be deleted automatically
8181
## New messages will be pushed and consumed from the new queue
82-
queue_name: "mixpanel-events"
82+
queue_names:
83+
- "mixpanel-events"
84+
- "keycloak-events"
8385
## RabbitMQ Policy configuration
8486
## Applies on all queues that match queue_regex_pattern
8587
policy:
86-
queue_regex_pattern: "^mixpanel-events.*"
87-
# The following configuration supports a queue size of up to 2000 messages,
88+
queue_regex_pattern: "^.*-events.*"
89+
# The following configuration supports queues size of up to 2000 messages,
8890
# where each message is 500 bytes, with a message TTL (time-to-live) of one week.
8991
#
90-
# - message_ttl: Sets the time-to-live for messages in the queue to approximately 7 days (600,000,000 ms).
91-
# - max_length: Limits the queue to a maximum of 2000 messages. New messages will be rejected if this limit is reached.
92-
# - overflow: Configures the queue to "reject-publish," meaning new messages are rejected when the queue hits max_length.
93-
# - max_length_bytes: Restricts the total size of all messages in the queue to 1,000,000 bytes (500 bytes × 2000 messages).
92+
# - message_ttl: Sets the time-to-live for messages in the queues to approximately 7 days (600,000,000 ms).
93+
# - max_length: Limits the queues to a maximum of 2000 messages. New messages will be rejected if this limit is reached.
94+
# - overflow: Configures the queues to "reject-publish," meaning new messages are rejected when the queue hits max_length.
95+
# - max_length_bytes: Restricts the total size of all messages in the queues to 1,000,000 bytes (500 bytes × 2000 messages).
9496
#
95-
# This configuration ensures the queue does not exceed its size or time limits and avoids overloading the system.
97+
# This configuration ensures the queues does not exceed its size or time limits and avoids overloading the system.
9698
message_ttl: 600000000
9799
max_length: 2000
98100
overflow: "reject-publish"
@@ -689,6 +691,11 @@ deployments:
689691
repository: lightruncom/chart-helper
690692
tag: "0.3.0-alpine-3.21.3-r0.lr-0"
691693
pullPolicy: ""
694+
wait_for_rabbitmq:
695+
image:
696+
repository: lightruncom/chart-helper
697+
tag: "0.3.0-alpine-3.21.3-r0.lr-0"
698+
pullPolicy: ""
692699
topologySpreadConstraints: []
693700
affinity: {}
694701
startupProbe:

0 commit comments

Comments
 (0)