From 6bbd87199af468b606f1cf44d45f24091d788023 Mon Sep 17 00:00:00 2001
From: Henry Msiska <henrymsi+dev@gmail.com>
Date: Wed, 30 Oct 2024 11:37:46 +0400
Subject: [PATCH] add state monitoring stream

---
 .github/workflows/continuous-deploy.yml | 16 ++++++++++++++
 tilt/cloudapi/nats/templates/job.yaml   | 29 +++++++++++++++++++++----
 tilt/cloudapi/nats/values.yaml          | 10 +++++++++
 3 files changed, 51 insertions(+), 4 deletions(-)

diff --git a/.github/workflows/continuous-deploy.yml b/.github/workflows/continuous-deploy.yml
index 4d9a8eabbb..6a23fd5952 100644
--- a/.github/workflows/continuous-deploy.yml
+++ b/.github/workflows/continuous-deploy.yml
@@ -609,6 +609,9 @@ jobs:
           nats --creds ./nats.creds \
             --server ${{ secrets.NATS_URL }} \
               stream rm acapy_events -f
+          nats --creds ./nats.creds \
+            --server ${{ secrets.NATS_URL }} \
+              stream rm cloudapi_aries_state_monitoring -f
 
           nats --creds ./nats.creds \
             --server ${{ secrets.NATS_URL }} \
@@ -638,6 +641,19 @@ jobs:
             --replicas 3 \
             --compression s2
 
+          nats --creds ./nats.creds \
+            --server ${{ secrets.NATS_URL }} \
+            stream add cloudapi_aries_state_monitoring --subjects "cloudapi.aries.state_monitoring.*.*.>" \
+            --defaults \
+            --storage file \
+            --replicas 3 \
+            --compression s2 \
+            --retention limits \
+            --discard old \
+            --max-age 1m \
+            --dupe-window 1m \
+            --max-msgs-per-subject 1000
+
           rm -f ./nats.creds
 
       - name: Helmfile Apply # Apply default helmfile (without RDS proxy) when resetting deployments.
diff --git a/tilt/cloudapi/nats/templates/job.yaml b/tilt/cloudapi/nats/templates/job.yaml
index bf83619b70..bafe5a4704 100644
--- a/tilt/cloudapi/nats/templates/job.yaml
+++ b/tilt/cloudapi/nats/templates/job.yaml
@@ -41,9 +41,30 @@ spec:
               {{- range $stream, $config := .Values.postInstall.streams }}
               nats --server nats://{{ template "common.names.fullname" $ }}:{{ default 4222 $.Values.nats.service.ports.client }} stream add {{ $stream }} \
                   --subjects {{ join "," $config.subjects | quote }} \
-                  {{- if $config.defaults }}
-                  --defaults \
-                  {{- end }}
                   --storage {{ $config.storage }} \
-                  --replicas={{ $.Values.nats.replicaCount }}
+                  --replicas={{ $.Values.nats.replicaCount }} \
+                  {{- if $config.compression }}
+                  --compression {{ $config.compression }} \
+                  {{- end }}
+                  {{- if $config.maxAge }}
+                  --max-age {{ $config.maxAge }} \
+                  {{- end }}
+                  {{- if $config.maxBytes }}
+                  --max-bytes {{ $config.maxBytes }} \
+                  {{- end }}
+                  {{- if $config.maxMsgs }}
+                  --max-msgs {{ $config.maxMsgs }} \
+                  {{- end }}
+                  {{- if $config.maxMsgsPerSubject }}
+                  --max-msgs-per-subject {{ $config.maxMsgsPerSubject }} \
+                  {{- end }}
+                  {{- if $config.retention }}
+                  --retention {{ $config.retention }} \
+                  {{- end }}
+                  {{- if $config.discard }}
+                  --discard {{ $config.discard }} \
+                  {{- end }}
+                  {{- if $config.duplicateWindow }}
+                  --dupe-window {{ $config.duplicateWindow }} \
+                  {{- end }}
               {{- end }}
diff --git a/tilt/cloudapi/nats/values.yaml b/tilt/cloudapi/nats/values.yaml
index bcd99f6475..f1bf26a285 100644
--- a/tilt/cloudapi/nats/values.yaml
+++ b/tilt/cloudapi/nats/values.yaml
@@ -15,6 +15,16 @@ postInstall:
         - cloudapi.aries.events.*.*
       defaults: true
       storage: file
+    cloudapi_aries_state_monitoring:
+      subjects:
+        - cloudapi.aries.state_monitoring.*.*.>
+      defaults: true
+      storage: file
+      retention: limits
+      discard: old
+      maxAge: 1m
+      duplicateWindow: 1m
+      maxMsgsPerSubject: 1000
     acapy_events:
       subjects:
         - acapy.>