Skip to content

Commit 941bb73

Browse files
Address PR #78 review comments
- Remove hardcoded AWS config and LocalStack from deploy/.env - Remove LocalStack service from deploy/docker-compose.yml - Remove exposed PostgreSQL port from docker-compose.yml - Add database migrations (up/down) for dynamic profiling
1 parent e55dedf commit 941bb73

File tree

4 files changed

+418
-105
lines changed

4 files changed

+418
-105
lines changed

deploy/.env

Lines changed: 5 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ DOMAIN=http://localhost
44

55
# AWS:
66

7-
AWS_REGION=us-east-1
7+
# AWS region is required to set for service
8+
AWS_REGION=
89

910
# AWS credentials, can be empty if running on EC2 with IAM role
1011
AWS_ACCESS_KEY_ID=
@@ -32,36 +33,12 @@ REST_USERNAME=user
3233
REST_PASSWORD=pass
3334

3435
# webapp:
35-
36-
BUCKET_NAME=performance-studio-bucket
37-
SQS_QUEUE_NAME=performance-studio-queue
38-
SQS_WEBAPP_QUEUE_URL=http://sqs.us-east-1.localhost.localstack.cloud:4566/000000000000/performance-studio-queue
39-
SQS_INDEXER_QUEUE_URL=performance-studio-queue
36+
# BUCKET_NAME and SQS_INDEXER_QUEUE_URL are required for service up running
37+
BUCKET_NAME=
38+
SQS_INDEXER_QUEUE_URL=
4039
WEBAPP_APP_LOG_FILE_PATH="webapp.log"
41-
SLACK_BOT_TOKEN=
42-
SLACK_CHANNELS=""
4340

4441
# agents-logs:
4542

4643
AGENTS_LOGS_APP_LOG_FILE_PATH="${COMMON_LOGS_DIR}/agents-logs-app.log"
4744
AGENTS_LOGS_LOG_FILE_PATH="${COMMON_LOGS_DIR}/agents-logs.log"
48-
49-
# ==========================================
50-
# Local Testing Only - DO NOT COMMIT
51-
# ==========================================
52-
53-
# LocalStack Configuration (for local S3/SQS simulation)
54-
AWS_ENDPOINT_URL=http://localstack:4566
55-
S3_ENDPOINT_URL=http://localstack:4566
56-
57-
# Metrics Configuration (for local testing)
58-
METRICS_ENABLED=true
59-
METRICS_AGENT_URL=tcp://host.docker.internal:18126
60-
METRICS_SERVICE_NAME=gprofiler-webapp
61-
METRICS_SLI_UUID=test-sli-uuid-12345
62-
63-
# Indexer Metrics Configuration (for local testing)
64-
INDEXER_METRICS_ENABLED=true
65-
INDEXER_METRICS_AGENT_URL=tcp://host.docker.internal:18126
66-
INDEXER_METRICS_SERVICE_NAME=gprofiler-indexer
67-
INDEXER_METRICS_SLI_UUID=test-sli-uuid-indexer-67890

deploy/docker-compose.yml

Lines changed: 1 addition & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,6 @@ services:
3838
- ../src/gprofiler_indexer/sql/create_ch_schema.sql:/docker-entrypoint-initdb.d/create_schema.sql
3939
- logs:/var/log/clickhouse-server/
4040
- db_clickhouse:/var/lib/clickhouse/
41-
healthcheck:
42-
test: ["CMD", "wget", "--no-verbose", "--tries=1", "--spider", "http://localhost:8123/ping"]
43-
interval: 10s
44-
timeout: 5s
45-
retries: 5
46-
start_period: 30s
4741

4842
# ---
4943
db_postgres:
@@ -54,18 +48,9 @@ services:
5448
- POSTGRES_USER=$POSTGRES_USER
5549
- POSTGRES_PASSWORD=$POSTGRES_PASSWORD
5650
- POSTGRES_DB=$POSTGRES_DB
57-
# for debug
58-
ports:
59-
- "5432:5432"
6051
volumes:
6152
- db_postgres:/var/lib/postgresql/data
6253
- ../scripts/setup/postgres/gprofiler_recreate.sql:/docker-entrypoint-initdb.d/create_scheme.sql
63-
healthcheck:
64-
test: ["CMD-SHELL", "pg_isready -U $POSTGRES_USER -d $POSTGRES_DB"]
65-
interval: 10s
66-
timeout: 5s
67-
retries: 5
68-
start_period: 30s
6954

7055
# ---
7156
webapp:
@@ -74,16 +59,13 @@ services:
7459
dockerfile: gprofiler/Dockerfile
7560
container_name: gprofiler-ps-webapp
7661
restart: always
77-
extra_hosts:
78-
- "host.docker.internal:host-gateway"
7962
environment:
8063
- BUCKET_NAME=$BUCKET_NAME
8164
- QUERY_API_BASE_URL=https://ch-rest-service:4433
8265
- REST_VERIFY_TLS=FALSE
8366
- REST_USERNAME=$REST_USERNAME
8467
- REST_PASSWORD=$REST_PASSWORD
8568
- SQS_INDEXER_QUEUE_URL=$SQS_INDEXER_QUEUE_URL
86-
- SQS_WEBAPP_QUEUE_URL=$SQS_WEBAPP_QUEUE_URL
8769
- GPROFILER_POSTGRES_DB_NAME=$POSTGRES_DB
8870
- GPROFILER_POSTGRES_PORT=$POSTGRES_PORT
8971
- GPROFILER_POSTGRES_HOST=$POSTGRES_HOST
@@ -93,30 +75,14 @@ services:
9375
- APP_LOG_LEVEL=INFO
9476
- AWS_METADATA_SERVICE_NUM_ATTEMPTS=100
9577
- REDIRECT_DOMAIN=$DOMAIN
96-
- SQS_ENDPOINT_URL=http://localstack:4566
78+
- SQS_ENDPOINT_URL=https://sqs.${AWS_REGION}.amazonaws.com
9779
- AWS_ACCESS_KEY_ID=$AWS_ACCESS_KEY_ID
9880
- AWS_SECRET_ACCESS_KEY=$AWS_SECRET_ACCESS_KEY
9981
- AWS_SESSION_TOKEN=$AWS_SESSION_TOKEN
10082
- AWS_DEFAULT_REGION=$AWS_REGION
101-
- SLACK_BOT_TOKEN=$SLACK_BOT_TOKEN
102-
- SLACK_CHANNELS=$SLACK_CHANNELS
103-
# Local Testing: S3 Endpoint for LocalStack
104-
- S3_ENDPOINT_URL=$S3_ENDPOINT_URL
105-
# Local Testing: Metrics Configuration
106-
- METRICS_ENABLED=$METRICS_ENABLED
107-
- METRICS_AGENT_URL=$METRICS_AGENT_URL
108-
- METRICS_SERVICE_NAME=$METRICS_SERVICE_NAME
109-
- METRICS_SLI_UUID=$METRICS_SLI_UUID
11083
# for debug
11184
# ports:
11285
# - "8888:80"
113-
depends_on:
114-
db_postgres:
115-
condition: service_healthy
116-
ch-rest-service:
117-
condition: service_healthy
118-
localstack:
119-
condition: service_healthy
12086

12187
# ---
12288
ch-rest-service:
@@ -142,9 +108,6 @@ services:
142108
interval: 10s
143109
retries: 10
144110
start_period: 20s
145-
depends_on:
146-
db_clickhouse:
147-
condition: service_healthy
148111

149112
# ---
150113
agents-logs-backend:
@@ -192,8 +155,6 @@ services:
192155
dockerfile: Dockerfile
193156
container_name: gprofiler-ps-ch-indexer
194157
restart: always
195-
extra_hosts:
196-
- "host.docker.internal:host-gateway"
197158
environment:
198159
- SQS_QUEUE_URL=$SQS_INDEXER_QUEUE_URL
199160
- AWS_REGION=$AWS_REGION
@@ -211,18 +172,6 @@ services:
211172
- AWS_ACCESS_KEY_ID=$AWS_ACCESS_KEY_ID
212173
- AWS_SECRET_ACCESS_KEY=$AWS_SECRET_ACCESS_KEY
213174
- AWS_SESSION_TOKEN=$AWS_SESSION_TOKEN
214-
# Local Testing: Metrics Configuration
215-
- METRICS_ENABLED=$INDEXER_METRICS_ENABLED
216-
- METRICS_AGENT_URL=$INDEXER_METRICS_AGENT_URL
217-
- METRICS_SERVICE_NAME=$INDEXER_METRICS_SERVICE_NAME
218-
- METRICS_SLI_UUID=$INDEXER_METRICS_SLI_UUID
219-
# Local Testing: LocalStack Endpoint
220-
- AWS_ENDPOINT_URL=$AWS_ENDPOINT_URL
221-
depends_on:
222-
localstack:
223-
condition: service_healthy
224-
db_clickhouse:
225-
condition: service_healthy
226175
#---
227176
nginx-load-balancer:
228177
image: nginx:1.23.3
@@ -239,31 +188,6 @@ services:
239188
- agents-logs-backend
240189
- webapp
241190

242-
# ---
243-
# LocalStack for local S3/SQS simulation (Local Testing Only)
244-
localstack:
245-
image: localstack/localstack:3.0
246-
container_name: gprofiler-ps-localstack
247-
restart: always
248-
ports:
249-
- "4566:4566" # LocalStack Gateway
250-
- "4510-4559:4510-4559" # External services port range
251-
environment:
252-
- SERVICES=s3,sqs
253-
- DEBUG=1
254-
- DOCKER_HOST=unix:///var/run/docker.sock
255-
- AWS_DEFAULT_REGION=us-east-1
256-
- AWS_ACCESS_KEY_ID=test
257-
- AWS_SECRET_ACCESS_KEY=test
258-
volumes:
259-
- "./localstack_init:/etc/localstack/init/ready.d"
260-
- "/var/run/docker.sock:/var/run/docker.sock"
261-
healthcheck:
262-
test: ["CMD", "curl", "-f", "http://localhost:4566/_localstack/health"]
263-
interval: 10s
264-
timeout: 5s
265-
retries: 5
266-
267191
volumes:
268192
db_clickhouse:
269193
driver: local
Lines changed: 166 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,166 @@
1+
--
2+
-- Copyright (C) 2025 Intel Corporation
3+
--
4+
-- Licensed under the Apache License, Version 2.0 (the "License");
5+
-- you may not use this file except in compliance with the License.
6+
-- You may obtain a copy of the License at
7+
--
8+
-- http://www.apache.org/licenses/LICENSE-2.0
9+
--
10+
-- Unless required by applicable law or agreed to in writing, software
11+
-- distributed under the License is distributed on an "AS IS" BASIS,
12+
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
-- See the License for the specific language governing permissions and
14+
-- limitations under the License.
15+
--
16+
17+
-- ============================================================
18+
-- ROLLBACK MIGRATION: Remove Dynamic Profiling Feature
19+
-- ============================================================
20+
-- This rollback script removes the dynamic profiling feature
21+
-- and restores the database to its pre-migration state.
22+
--
23+
-- WARNING: This will permanently delete all dynamic profiling data!
24+
--
25+
-- Usage:
26+
-- psql -U performance_studio -d performance_studio -f add_dynamic_profiling.down.sql
27+
--
28+
-- To restore the feature:
29+
-- psql -U performance_studio -d performance_studio -f add_dynamic_profiling.up.sql
30+
-- ============================================================
31+
32+
BEGIN;
33+
34+
-- ============================================================
35+
-- STEP 1: Backup Warning
36+
-- ============================================================
37+
38+
DO $$
39+
BEGIN
40+
RAISE NOTICE '========================================';
41+
RAISE NOTICE 'ROLLBACK: Removing Dynamic Profiling Feature';
42+
RAISE NOTICE '========================================';
43+
RAISE NOTICE 'This will permanently delete:';
44+
RAISE NOTICE ' - All profiling requests';
45+
RAISE NOTICE ' - All profiling commands';
46+
RAISE NOTICE ' - All profiling executions';
47+
RAISE NOTICE ' - All host heartbeat data';
48+
RAISE NOTICE '';
49+
RAISE NOTICE 'Ensure you have a backup if you need this data!';
50+
RAISE NOTICE '========================================';
51+
END $$;
52+
53+
54+
-- ============================================================
55+
-- STEP 2: Drop Indexes
56+
-- ============================================================
57+
-- Drop indexes first for cleaner table drops
58+
59+
-- ProfilingExecutions indexes
60+
DROP INDEX IF EXISTS idx_profilingexecutions_status;
61+
DROP INDEX IF EXISTS idx_profilingexecutions_profiling_request_id;
62+
DROP INDEX IF EXISTS idx_profilingexecutions_hostname;
63+
DROP INDEX IF EXISTS idx_profilingexecutions_command_id;
64+
65+
-- ProfilingCommands indexes
66+
DROP INDEX IF EXISTS idx_profilingcommands_hostname_service;
67+
DROP INDEX IF EXISTS idx_profilingcommands_status;
68+
DROP INDEX IF EXISTS idx_profilingcommands_service_name;
69+
DROP INDEX IF EXISTS idx_profilingcommands_hostname;
70+
DROP INDEX IF EXISTS idx_profilingcommands_command_id;
71+
72+
-- ProfilingRequests indexes
73+
DROP INDEX IF EXISTS idx_profilingrequests_created_at;
74+
DROP INDEX IF EXISTS idx_profilingrequests_request_type;
75+
DROP INDEX IF EXISTS idx_profilingrequests_status;
76+
DROP INDEX IF EXISTS idx_profilingrequests_service_name;
77+
DROP INDEX IF EXISTS idx_profilingrequests_request_id;
78+
79+
-- HostHeartbeats indexes
80+
DROP INDEX IF EXISTS idx_hostheartbeats_heartbeat_timestamp;
81+
DROP INDEX IF EXISTS idx_hostheartbeats_status;
82+
DROP INDEX IF EXISTS idx_hostheartbeats_service_name;
83+
DROP INDEX IF EXISTS idx_hostheartbeats_hostname;
84+
85+
86+
-- ============================================================
87+
-- STEP 3: Drop Tables (in correct order for foreign keys)
88+
-- ============================================================
89+
90+
-- Drop ProfilingExecutions first (has FK to ProfilingRequests)
91+
DROP TABLE IF EXISTS ProfilingExecutions CASCADE;
92+
93+
-- Drop ProfilingCommands (no dependencies)
94+
DROP TABLE IF EXISTS ProfilingCommands CASCADE;
95+
96+
-- Drop ProfilingRequests (has FK to Services, referenced by ProfilingExecutions)
97+
DROP TABLE IF EXISTS ProfilingRequests CASCADE;
98+
99+
-- Drop HostHeartbeats (no dependencies)
100+
DROP TABLE IF EXISTS HostHeartbeats CASCADE;
101+
102+
103+
-- ============================================================
104+
-- STEP 4: Drop ENUM Types
105+
-- ============================================================
106+
-- Drop types after tables that use them
107+
108+
DROP TYPE IF EXISTS HostStatus CASCADE;
109+
DROP TYPE IF EXISTS CommandStatus CASCADE;
110+
DROP TYPE IF EXISTS ProfilingRequestStatus CASCADE;
111+
DROP TYPE IF EXISTS ProfilingMode CASCADE;
112+
113+
114+
-- ============================================================
115+
-- STEP 5: Verify Rollback Success
116+
-- ============================================================
117+
118+
DO $$
119+
DECLARE
120+
remaining_tables integer;
121+
remaining_types integer;
122+
BEGIN
123+
-- Count remaining tables
124+
SELECT COUNT(*) INTO remaining_tables
125+
FROM information_schema.tables
126+
WHERE table_schema = 'public'
127+
AND table_name IN ('hostheartbeats', 'profilingrequests', 'profilingcommands', 'profilingexecutions');
128+
129+
-- Count remaining types
130+
SELECT COUNT(*) INTO remaining_types
131+
FROM pg_type
132+
WHERE typname IN ('profilingmode', 'profilingrequeststatus', 'commandstatus', 'hoststatus');
133+
134+
IF remaining_tables > 0 THEN
135+
RAISE WARNING 'Some tables still exist: %', remaining_tables;
136+
END IF;
137+
138+
IF remaining_types > 0 THEN
139+
RAISE WARNING 'Some types still exist: %', remaining_types;
140+
END IF;
141+
142+
IF remaining_tables = 0 AND remaining_types = 0 THEN
143+
RAISE NOTICE '========================================';
144+
RAISE NOTICE 'Rollback completed successfully!';
145+
RAISE NOTICE '========================================';
146+
RAISE NOTICE 'Removed:';
147+
RAISE NOTICE ' - 4 tables (HostHeartbeats, ProfilingRequests, ProfilingCommands, ProfilingExecutions)';
148+
RAISE NOTICE ' - 4 ENUM types (ProfilingMode, ProfilingRequestStatus, CommandStatus, HostStatus)';
149+
RAISE NOTICE ' - 14 indexes';
150+
RAISE NOTICE '';
151+
RAISE NOTICE 'Database restored to pre-dynamic-profiling state.';
152+
RAISE NOTICE '========================================';
153+
ELSE
154+
RAISE EXCEPTION 'Rollback incomplete: % tables, % types remain', remaining_tables, remaining_types;
155+
END IF;
156+
END $$;
157+
158+
COMMIT;
159+
160+
-- ============================================================
161+
-- Rollback Complete
162+
-- ============================================================
163+
-- The dynamic profiling feature has been successfully removed.
164+
-- All related tables, types, and indexes have been dropped.
165+
-- ============================================================
166+

0 commit comments

Comments
 (0)