Elffuss BraidHub

kikocis/falkordb-omnistrate public

Merge pull request #44 from FalkorDB/43-create-sigterm-handler-to-shudown-falkordb-safely

43 create sigterm handler to shudown falkordb safely
Changeset848dd218fe66b9ed993dd420f2e7197d4d5751203c9c029aaee962041e63fe8c
AuthorDudi <16744955+dudizimber@users.noreply.github.com> · 2024-06-05 12:50 +03:00
CommitterGitHub <noreply@github.com> · 2024-06-05 12:50 +03:00
Parents6b4963dc2cce, fd4577d48898

Browse the files at this changeset

9 files changed

modified .github/workflows/build-release-image.yaml +5 −5
@@ -69,10 +69,10 @@
6969
7070 - name: Replace Variables
7171 run: |
72- sed -i 's/$GcpProjectId/${{ vars.GCP_PROJECT_ID }}/g' omnistrate.${{ matrix.plans.key}}.yaml
73- sed -i 's/$GcpProjectNumber/${{ vars.GCP_PROJECT_NUMBER }}/g' omnistrate.${{ matrix.plans.key}}.yaml
74- sed -i 's/$GcpServiceAccountEmail/${{ vars.GCP_SERVICE_ACCOUNT_EMAIL }}/g' omnistrate.${{ matrix.plans.key}}.yaml
75- sed -i 's/$FalkorDBNodeImage/falkordb\/falkordb-node:${{ github.ref_name }}/g' omnistrate.${{ matrix.plans.key}}.yaml
72+ sed -i 's/$GcpProjectId/${{ vars.GCP_PROJECT_ID }}/g' omnistrate.${{ matrix.plans.key }}.yaml
73+ sed -i 's/$GcpProjectNumber/${{ vars.GCP_PROJECT_NUMBER }}/g' omnistrate.${{ matrix.plans.key }}.yaml
74+ sed -i 's/$GcpServiceAccountEmail/${{ vars.GCP_SERVICE_ACCOUNT_EMAIL }}/g' omnistrate.${{ matrix.plans.key }}.yaml
75+ sed -i 's/$FalkorDBNodeImage/falkordb\/falkordb-node:${{ github.ref_name }}/g' omnistrate.${{ matrix.plans.key }}.yaml
7676
7777 - name: Update Omnistrate plan
7878 if: ${{ contains(vars.OMNISTRATE_RELEASE_PLANS, matrix.plans.key) }}
@@ -81,4 +81,4 @@
8181 username: ${{ secrets.OMNISTRATE_USERNAME }}
8282 password: ${{ secrets.OMNISTRATE_PASSWORD }}
8383 file: ${{ matrix.plans.file }}
84- plan-name: ${{ matrix.plans.name }}
84+ service-name: ${{ matrix.plans.name }}
modified .github/workflows/build-test-image.yaml +2 −1
@@ -69,7 +69,7 @@
6969 sudo add-apt-repository ppa:rmescandon/yq
7070 sudo apt update
7171 sudo apt install yq -y
72- yq ea '. as $item ireduce ({}; . * $item )' omnistrate.free.yaml omnistrate.pro.yaml | sed 's/FalkorDB Pro/${{ github.ref_name }}/' > merged.yaml
72+ yq ea '. as $item ireduce ({}; . * $item )' omnistrate.free.yaml omnistrate.pro.yaml | sed 's/FalkorDB Pro/${{ github.ref_name == 'main' && 'FalkorDB Internal' || github.ref_name }}/' > merged.yaml
7373
7474 - name: Upload yaml as artifact
7575 uses: actions/upload-artifact@v2
@@ -205,6 +205,7 @@
205205 API_PATH: ${{ matrix.instances.apiPath }}
206206 API_FAILOVER_PATH: ${{ matrix.instances.apiFailoverPath }}
207207 API_SIGN_IN_PATH: ${{ matrix.instances.apiSignInPath }}
208+ REF_NAME: ${{ github.ref_name }}
208209 extraParams: ${{ matrix.instances.extraParams }}
209210 run: |
210211 python ./tests/${{ matrix.instances.testFile }} ${{ secrets.OMNISTRATE_USERNAME }} ${{ secrets.OMNISTRATE_PASSWORD }} ${{ env.CLOUD_PROVIDER }} ${{ env.CLOUD_REGION }} ${{ env.extraParams }}
modified falkordb-node/node-entrypoint.sh +44 −1
@@ -243,6 +243,7 @@
243243 fi
244244
245245 redis-server $NODE_CONF_FILE --logfile $FALKORDB_LOG_FILE_PATH &
246+ falkordb_pid=$!
246247 tail -F $FALKORDB_LOG_FILE_PATH &
247248
248249 sleep 10
@@ -328,6 +329,7 @@
328329 fi
329330
330331 redis-server $SENTINEL_CONF_FILE --sentinel --logfile $SENTINEL_LOG_FILE_PATH &
332+ sentinel_pid=$!
331333 tail -F $SENTINEL_LOG_FILE_PATH &
332334
333335 sleep 10
@@ -351,6 +353,7 @@
351353 echo "Starting Metrics"
352354 exporter_url=$(if [[ $TLS == "true" ]]; then echo "rediss://$NODE_HOST:$NODE_PORT"; else echo "redis://$NODE_HOST_IP:$NODE_PORT"; fi)
353355 redis_exporter -skip-tls-verification -redis.password $ADMIN_PASSWORD -redis.addr $exporter_url &
356+ redis_exporter_pid=$!
354357 fi
355358
356359 if [[ $RUN_HEALTH_CHECK -eq 1 ]]; then
@@ -358,6 +361,7 @@
358361 if [ -f /usr/local/bin/healthcheck ]; then
359362 echo "Starting Healthcheck"
360363 healthcheck &
364+ healthcheck_pid=$!
361365 else
362366 echo "Healthcheck binary not found"
363367 fi
@@ -365,4 +369,43 @@
365369
366370 while true; do
367371 sleep 1
368-done
No newline at the end of the file
372+done
373+
374+
375+
376+
377+# Handle signals
378+
379+handle_sigterm() {
380+ echo "Caught SIGTERM"
381+ echo "Stopping FalkorDB"
382+
383+ if [[ $RUN_NODE -eq 1 && ! -z $falkordb_pid ]]; then
384+ kill -TERM $falkordb_pid
385+ fi
386+
387+ if [[ $RUN_SENTINEL -eq 1 && ! -z $sentinel_pid ]]; then
388+ kill -TERM $sentinel_pid
389+ fi
390+
391+ if [[ $RUN_METRICS -eq 1 && ! -z $redis_exporter_pid ]]; then
392+ kill -TERM $redis_exporter_pid
393+ fi
394+
395+ if [[ $RUN_HEALTH_CHECK -eq 1 && ! -z $healthcheck_pid ]]; then
396+ kill -TERM $healthcheck_pid
397+ fi
398+
399+ if [[ ! -z $falkordb_pid ]]; then
400+ wait $falkordb_pid
401+ fi
402+
403+ if [[ ! -z $sentinel_pid ]]; then
404+ wait $sentinel_pid
405+ fi
406+
407+}
408+
409+trap handle_sigterm SIGTERM
410+
411+wait $falkordb_pid
No newline at the end of the file
modified tests/requirements.txt +1 −1
@@ -1,4 +1,4 @@
11 redis
22 requests
3-git+https://github.com/FalkorDB/falkordb-py@sentinel
3+git+https://github.com/FalkorDB/falkordb-py
44 pyjwt
No newline at the end of the file
modified tests/test_free.py +11 −0
@@ -29,6 +29,17 @@
2929 )
3030 SUBSCRIPTION_ID = os.getenv("SUBSCRIPTION_ID", "sub-bHEl5iUoPd")
3131
32+REF_NAME = os.getenv("REF_NAME", None)
33+if REF_NAME is not None:
34+ if len(REF_NAME) > 50:
35+ # Replace the second occurrence of REF_NAME with the first 50 characters of REF_NAME
36+ API_PATH = f"customer-hosted/{REF_NAME[:50]}".join(
37+ API_PATH.split(f"customer-hosted/{REF_NAME}")
38+ )
39+ API_FAILOVER_PATH = f"customer-hosted/{REF_NAME[:50]}".join(
40+ API_FAILOVER_PATH.split(f"customer-hosted/{REF_NAME}")
41+ )
42+
3243
3344 def test_free():
3445
modified tests/test_multi_zone.py +27 −13
@@ -37,6 +37,17 @@
3737 )
3838 SUBSCRIPTION_ID = os.getenv("SUBSCRIPTION_ID", "sub-bHEl5iUoPd")
3939
40+REF_NAME = os.getenv("REF_NAME", None)
41+if REF_NAME is not None:
42+ if len(REF_NAME) > 50:
43+ # Replace the second occurrence of REF_NAME with the first 50 characters of REF_NAME
44+ API_PATH = f"customer-hosted/{REF_NAME[:50]}".join(
45+ API_PATH.split(f"customer-hosted/{REF_NAME}")
46+ )
47+ API_FAILOVER_PATH = f"customer-hosted/{REF_NAME[:50]}".join(
48+ API_FAILOVER_PATH.split(f"customer-hosted/{REF_NAME}")
49+ )
50+
4051
4152 def test_multi_zone():
4253
@@ -98,7 +109,12 @@
98109 filter(lambda resource: resource["id"].startswith("node-mz"), resources)
99110 )
100111 sentinel_resource = next(
101- (resource for resource in resources if resource["id"].startswith("sentinel-mz")), None
112+ (
113+ resource
114+ for resource in resources
115+ if resource["id"].startswith("sentinel-mz")
116+ ),
117+ None,
102118 )
103119 db_0 = FalkorDB(
104120 host=db_resource[0]["endpoint"],
@@ -132,10 +148,14 @@
132148 },
133149 )
134150
135- sentinels_list = random.choice(sentinels.sentinels).execute_command("sentinel sentinels master")
151+ sentinels_list = random.choice(sentinels.sentinels).execute_command(
152+ "sentinel sentinels master"
153+ )
136154
137155 if len(sentinels_list) != 2:
138- raise Exception(f"Sentinel list not correct. Expected 2, got {len(sentinels_list)}")
156+ raise Exception(
157+ f"Sentinel list not correct. Expected 2, got {len(sentinels_list)}"
158+ )
139159
140160 graph_0 = db_0.select_graph("test")
141161
@@ -153,9 +173,7 @@
153173 print("Triggering failover for node-mz-0")
154174 # Trigger failover
155175 instance.trigger_failover(
156- replica_id="node-mz-0",
157- wait_for_ready=False,
158- resource_id="node-mz"
176+ replica_id="node-mz-0", wait_for_ready=False, resource_id="node-mz"
159177 )
160178
161179 promotion_completed = False
@@ -189,13 +207,11 @@
189207
190208 # wait until the node-mz-0 is ready
191209 instance.wait_for_ready(timeout_seconds=600)
192-
210+
193211 print("Triggering failover for sentinel-mz-0")
194212 # Trigger sentinel failover
195213 instance.trigger_failover(
196- replica_id="sentinel-mz-0",
197- wait_for_ready=False,
198- resource_id="sentinel-mz"
214+ replica_id="sentinel-mz-0", wait_for_ready=False, resource_id="sentinel-mz"
199215 )
200216
201217 graph_1 = db_1.select_graph("test")
@@ -213,9 +229,7 @@
213229 print("Triggering failover for node-mz-1")
214230 # Trigger failover
215231 instance.trigger_failover(
216- replica_id="node-mz-1",
217- wait_for_ready=False,
218- resource_id="node-mz"
232+ replica_id="node-mz-1", wait_for_ready=False, resource_id="node-mz"
219233 )
220234
221235 promotion_completed = False
modified tests/test_single_zone.py +27 −13
@@ -37,6 +37,17 @@
3737 )
3838 SUBSCRIPTION_ID = os.getenv("SUBSCRIPTION_ID", "sub-bHEl5iUoPd")
3939
40+REF_NAME = os.getenv("REF_NAME", None)
41+if REF_NAME is not None:
42+ if len(REF_NAME) > 50:
43+ # Replace the second occurrence of REF_NAME with the first 50 characters of REF_NAME
44+ API_PATH = f"customer-hosted/{REF_NAME[:50]}".join(
45+ API_PATH.split(f"customer-hosted/{REF_NAME}")
46+ )
47+ API_FAILOVER_PATH = f"customer-hosted/{REF_NAME[:50]}".join(
48+ API_FAILOVER_PATH.split(f"customer-hosted/{REF_NAME}")
49+ )
50+
4051
4152 def test_single_zone():
4253
@@ -98,7 +109,12 @@
98109 filter(lambda resource: resource["id"].startswith("node-sz"), resources)
99110 )
100111 sentinel_resource = next(
101- (resource for resource in resources if resource["id"].startswith("sentinel-sz")), None
112+ (
113+ resource
114+ for resource in resources
115+ if resource["id"].startswith("sentinel-sz")
116+ ),
117+ None,
102118 )
103119 db_0 = FalkorDB(
104120 host=db_resource[0]["endpoint"],
@@ -132,10 +148,14 @@
132148 },
133149 )
134150
135- sentinels_list = random.choice(sentinels.sentinels).execute_command("sentinel sentinels master")
151+ sentinels_list = random.choice(sentinels.sentinels).execute_command(
152+ "sentinel sentinels master"
153+ )
136154
137155 if len(sentinels_list) != 2:
138- raise Exception(f"Sentinel list not correct. Expected 2, got {len(sentinels_list)}")
156+ raise Exception(
157+ f"Sentinel list not correct. Expected 2, got {len(sentinels_list)}"
158+ )
139159
140160 graph_0 = db_0.select_graph("test")
141161
@@ -153,9 +173,7 @@
153173 print("Triggering failover for node-sz-0")
154174 # Trigger failover
155175 instance.trigger_failover(
156- replica_id="node-sz-0",
157- wait_for_ready=False,
158- resource_id="node-sz"
176+ replica_id="node-sz-0", wait_for_ready=False, resource_id="node-sz"
159177 )
160178
161179 promotion_completed = False
@@ -189,13 +207,11 @@
189207
190208 # wait until the node-sz-0 is ready
191209 instance.wait_for_ready(timeout_seconds=600)
192-
210+
193211 print("Triggering failover for sentinel-sz-0")
194212 # Trigger sentinel failover
195213 instance.trigger_failover(
196- replica_id="sentinel-sz-0",
197- wait_for_ready=False,
198- resource_id="sentinel-sz"
214+ replica_id="sentinel-sz-0", wait_for_ready=False, resource_id="sentinel-sz"
199215 )
200216
201217 graph_1 = db_1.select_graph("test")
@@ -213,9 +229,7 @@
213229 print("Triggering failover for node-sz-1")
214230 # Trigger failover
215231 instance.trigger_failover(
216- replica_id="node-sz-1",
217- wait_for_ready=False,
218- resource_id="node-sz"
232+ replica_id="node-sz-1", wait_for_ready=False, resource_id="node-sz"
219233 )
220234
221235 promotion_completed = False
modified tests/test_standalone.py +11 −0
@@ -33,6 +33,17 @@
3333 )
3434 SUBSCRIPTION_ID = os.getenv("SUBSCRIPTION_ID", "sub-bHEl5iUoPd")
3535
36+REF_NAME = os.getenv("REF_NAME", None)
37+if REF_NAME is not None:
38+ if len(REF_NAME) > 50:
39+ # Replace the second occurrence of REF_NAME with the first 50 characters of REF_NAME
40+ API_PATH = f"customer-hosted/{REF_NAME[:50]}".join(
41+ API_PATH.split(f"customer-hosted/{REF_NAME}")
42+ )
43+ API_FAILOVER_PATH = f"customer-hosted/{REF_NAME[:50]}".join(
44+ API_FAILOVER_PATH.split(f"customer-hosted/{REF_NAME}")
45+ )
46+
3647
3748 def test_standalone():
3849
modified tests/test_update_memory.py +18 −3
@@ -34,6 +34,17 @@
3434 )
3535 SUBSCRIPTION_ID = os.getenv("SUBSCRIPTION_ID", "sub-bHEl5iUoPd")
3636
37+REF_NAME = os.getenv("REF_NAME", None)
38+if REF_NAME is not None:
39+ if len(REF_NAME) > 50:
40+ # Replace the second occurrence of REF_NAME with the first 50 characters of REF_NAME
41+ API_PATH = f"customer-hosted/{REF_NAME[:50]}".join(
42+ API_PATH.split(f"customer-hosted/{REF_NAME}")
43+ )
44+ API_FAILOVER_PATH = f"customer-hosted/{REF_NAME[:50]}".join(
45+ API_FAILOVER_PATH.split(f"customer-hosted/{REF_NAME}")
46+ )
47+
3748
3849 def test_update_memory():
3950
@@ -67,7 +78,9 @@
6778 instance.generate_data(graph_count=1000)
6879
6980 # Update memory
70- instance.update_instance_type(DEPLOYMENT_INSTANCE_TYPE_NEW, wait_until_ready=True)
81+ instance.update_instance_type(
82+ DEPLOYMENT_INSTANCE_TYPE_NEW, wait_until_ready=True
83+ )
7184
7285 check_data_loss(instance, keys=1000)
7386
@@ -89,8 +102,10 @@
89102 info = connection.execute_command("INFO")
90103
91104 # Check the number of keys
92- assert int(info["db0"]["keys"]) > keys, f"Data loss detected. Expected {keys} keys, got {info['db0']['keys']}"
105+ assert (
106+ int(info["db0"]["keys"]) > keys
107+ ), f"Data loss detected. Expected {keys} keys, got {info['db0']['keys']}"
93108
94109
95110 if __name__ == "__main__":
96- test_update_memory()
No newline at the end of the file
111+ test_update_memory()