-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathmakefile
More file actions
747 lines (701 loc) · 33.3 KB
/
Copy pathmakefile
File metadata and controls
747 lines (701 loc) · 33.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
# REPORT/Makefile
# Central makefile for all report-related operations
# Delegates to build_report/Makefile for dashboard and ElasticSearch operations
.PHONY: help summary summary-with-testbed-info dashboard dashboard-stop dashboard-restart dashboard-status \
flatten flatten-pretty es-upload es-template es-check \
es-index-stats es-template-info es-index-mapping \
es-ilm-policy es-ilm-policy-no-delete es-ilm-info es-ilm-explain es-bootstrap-index \
es-list-batches es-batch-count es-batch-info es-delete-batch es-show-last-batch es-list-execution-labels \
es-delete-index \
build-container build-container-latest build-container-tag clean-container \
clean
# Configuration
PYTHON := python3
BUILD_REPORT_DIR := build_report
DASHBOARD_DIR := dashboard
ES_INTEGRATION_DIR := es_integration
REPORT_DIR := $(shell pwd)
GENERATED_DIR := $(REPORT_DIR)/generated
REG_ROOT ?= $(shell cd .. && pwd)
# ElasticSearch index configuration (matches es_config.py)
# BASE_NAME: Infrastructure constant for rollover index names (regulus-results-000001, 000002, etc.)
# ES_INDEX: Query pattern for reading data across all rollover indices
# ES_WRITE_ALIAS: Write alias pointing to current hot index for uploads
BASE_NAME ?= regulus-results
ES_INDEX ?= regulus-results-*
ES_WRITE_ALIAS ?= regulus-results-write
# Helper to sanitize ES_URL for display (removes credentials)
# Usage: echo $$(echo "$$ES_URL" | $(SANITIZE_URL))
SANITIZE_URL = sed -E 's|(https?://)([^:]+):([^@]+)@|\1***:***@|'
# Helper to determine ES_URL with priority: env > lab.config
# Usage: @$(SOURCE_ES_CONFIG); your_command_using_$$ES_URL
# Note: This exports ES_URL for use in subprocesses
SOURCE_ES_CONFIG = \
if [ -n "$${ES_URL:-}" ]; then \
export ES_URL; \
elif [ -f "$(REG_ROOT)/lab.config" ]; then \
. $(REG_ROOT)/lab.config; \
if [ -z "$${ES_URL:-}" ]; then \
if [ -z "$${ES_PROTOCOL:-}" ] || [ -z "$${ES_HOST:-}" ]; then \
echo "ERROR: lab.config must define ES_URL or (ES_PROTOCOL + ES_HOST)"; \
exit 1; \
fi; \
if [ -n "$${ES_USER:-}" ] && [ -n "$${ES_PASSWORD:-}" ]; then \
ES_URL=$$(ES_USER="$${ES_USER}" ES_PASSWORD="$${ES_PASSWORD}" ES_HOST="$${ES_HOST}" ES_PROTOCOL="$${ES_PROTOCOL}" python3 -c "import os, urllib.parse; print(os.environ['ES_PROTOCOL'] + '://' + urllib.parse.quote(urllib.parse.unquote(os.environ['ES_USER']), safe='') + ':' + urllib.parse.quote(urllib.parse.unquote(os.environ['ES_PASSWORD']), safe='') + '@' + os.environ['ES_HOST'])"); \
else \
ES_URL="$${ES_PROTOCOL}://$${ES_HOST}"; \
fi; \
fi; \
export ES_URL; \
else \
echo "ERROR: No ES configuration found."; \
echo " - No ES_URL environment variable"; \
echo " - No $(REG_ROOT)/lab.config file"; \
exit 1; \
fi
# Default target
help:
@echo "====================================================================="
@echo " REPORT - Regulus Benchmark Report Generation and Analysis"
@echo "====================================================================="
@echo ""
@echo "Report Generation:"
@echo " make summary - Generate report (unflatten + flatten outputs)"
@echo " make summary-with-testbed-info - Generate report with testbed info"
@echo ""
@echo "Dashboard & Visualization:"
@echo " make dashboard - Start interactive web dashboard"
@echo " make dashboard-stop - Stop dashboard instances"
@echo " make dashboard-restart - Restart dashboard"
@echo ""
@echo "Container Build:"
@echo " make build-container - Build dashboard container (latest tag)"
@echo " make build-container-tag TAG=<name> - Build with custom tag"
@echo " make clean-container - Remove container images"
@echo ""
@echo "ElasticSearch Integration:"
@echo " make flatten - Flatten existing report.json (or run summary)"
@echo " make flatten-pretty - Create human-readable JSON"
@echo " make es-template - Apply ES index template"
@echo " make es-upload - Generate report and upload to ElasticSearch"
@echo ""
@echo "ElasticSearch Debug & Info:"
@echo " make es-index-stats - Show ES index statistics"
@echo " make es-template-info - Show ES index template details"
@echo " make es-index-mapping - Show current index mapping"
@echo ""
@echo "Index Lifecycle Management (ILM):"
@echo " make es-ilm-policy - Apply ILM policy (with 90-day deletion)"
@echo " make es-ilm-policy-no-delete - Apply ILM policy (NO deletion, for CCR)"
@echo " make es-ilm-info - Show current ILM policy details"
@echo " make es-ilm-explain - Explain ILM phase for index"
@echo " make es-bootstrap-index - Create bootstrapped rollover index"
@echo ""
@echo "Batch Management:"
@echo " make es-list-batches - List all upload batches"
@echo " make es-batch-count ES_BATCH_ID=<uuid> - Count documents in batch"
@echo " make es-batch-info ES_BATCH_ID=<uuid> - Show batch details"
@echo " make es-delete-batch ES_BATCH_ID=<uuid> - Delete all documents in batch"
@echo " make es-show-last-batch - Show most recent batch"
@echo " make es-list-execution-labels - List all execution_label values"
@echo ""
@echo "Configuration:"
@echo " REG_ROOT = $(REG_ROOT)"
@echo " ES_URL = Set by caller (from lab.config or environment)"
@echo " BASE_NAME = $(BASE_NAME)"
@echo " ES_INDEX = $(ES_INDEX) (query pattern)"
@echo " ES_WRITE_ALIAS = $(ES_WRITE_ALIAS) (upload target)"
@echo "====================================================================="
# =============================================================================
# Report Generation Targets
# =============================================================================
summary:
@echo "Creating generated directory if needed..."
@mkdir -p $(GENERATED_DIR)
@# Backup report-with-testbed-info.json if it exists (to avoid dashboard duplicates)
@if [ -f "$(GENERATED_DIR)/report-with-testbed-info.json" ]; then \
echo "Backing up report-with-testbed-info.json to report-with-testbed-info.json.bak"; \
mv -f "$(GENERATED_DIR)/report-with-testbed-info.json" "$(GENERATED_DIR)/report-with-testbed-info.json.bak"; \
fi
@echo "Generating unflatten report (report.json, HTML, CSV) in REPORT/generated/..."
@cd $(REG_ROOT) && REG_ROOT=$(REG_ROOT) bash REPORT/$(BUILD_REPORT_DIR)/build_report --formats html csv --output REPORT/generated/report
@echo ""
@echo "Flattening report.json to NDJSON for ElasticSearch..."
@cd $(REPORT_DIR) && $(PYTHON) $(ES_INTEGRATION_DIR)/flatten_to_es.py $(GENERATED_DIR)/report.json -o $(GENERATED_DIR)/reports.ndjson --es-index $(ES_WRITE_ALIAS)
@echo ""
@echo "✓ Report generation complete:"
@echo " - Unflatten: $(GENERATED_DIR)/report.json"
@echo " - Flatten: $(GENERATED_DIR)/reports.ndjson"
@ls -lh $(GENERATED_DIR)/report.json $(GENERATED_DIR)/reports.ndjson 2>/dev/null || true
summary-with-testbed-info:
@mkdir -p $(GENERATED_DIR)
@# First generate base report.json if it doesn't exist
@if [ ! -f "$(GENERATED_DIR)/report.json" ]; then \
echo "Base report.json not found. Generating it first..."; \
echo ""; \
cd $(REG_ROOT) && REG_ROOT=$(REG_ROOT) bash REPORT/$(BUILD_REPORT_DIR)/build_report --formats html csv --output REPORT/generated/report; \
echo ""; \
fi
@echo "Generating report with testbed info..."
@cd $(REG_ROOT) && REG_ROOT=$(REG_ROOT) bash REPORT/assembly/assemble_report.sh
@echo ""
@echo "Flattening report-with-testbed-info.json to NDJSON for ElasticSearch..."
@cd $(REPORT_DIR) && $(PYTHON) $(ES_INTEGRATION_DIR)/flatten_to_es.py $(GENERATED_DIR)/report-with-testbed-info.json -o $(GENERATED_DIR)/reports-with-testbed-info.ndjson --es-index $(ES_WRITE_ALIAS)
@echo ""
@echo "✓ Report with testbed info generation complete:"
@echo " - Unflatten: $(GENERATED_DIR)/report-with-testbed-info.json"
@echo " - Flatten: $(GENERATED_DIR)/reports-with-testbed-info.ndjson"
@ls -lh $(GENERATED_DIR)/report-with-testbed-info.json $(GENERATED_DIR)/reports-with-testbed-info.ndjson 2>/dev/null || true
# =============================================================================
# Dashboard Targets
# =============================================================================
dashboard:
@echo "Starting dashboard with built-in reports from: $(GENERATED_DIR)"
@echo "Reports will be copied to /tmp/regulus-data and loaded from there"
@if [ -n "$(PORT)" ]; then \
PORT=$(PORT) $(DASHBOARD_DIR)/start_dashboard.sh; \
else \
$(DASHBOARD_DIR)/start_dashboard.sh; \
fi
dashboard-stop:
@echo "Stopping dashboard instances..."
@ps aux | grep "run_dashboard.py" | grep -v grep | awk '{print $$2}' | xargs kill 2>/dev/null || echo "No dashboard instances running"
dashboard-restart: dashboard-stop
@sleep 2
@echo "Restarting dashboard..."
@$(MAKE) dashboard
dashboard-status:
@echo "Dashboard Status:"
@ps aux | grep "$(DASHBOARD_DIR)/run_dashboard.py" | grep -v grep || echo " No dashboard instances running"
# =============================================================================
# ElasticSearch Targets
# =============================================================================
# Flatten report.json to NDJSON format
# Note: 'make summary' already generates both unflatten and flatten outputs
# This target is kept for backward compatibility
flatten:
@mkdir -p $(GENERATED_DIR)
@if [ ! -f "$(GENERATED_DIR)/report.json" ]; then \
echo "report.json not found. Running 'make summary' to generate both outputs..."; \
$(MAKE) summary; \
else \
echo "Flattening existing report.json..."; \
cd $(REPORT_DIR) && $(PYTHON) $(ES_INTEGRATION_DIR)/flatten_to_es.py $(GENERATED_DIR)/report.json -o $(GENERATED_DIR)/reports.ndjson --es-index $(ES_WRITE_ALIAS); \
echo "✓ Flatten complete: $(GENERATED_DIR)/reports.ndjson"; \
fi
# Create human-readable pretty JSON
flatten-pretty: flatten
@if [ ! -f "$(GENERATED_DIR)/reports.ndjson" ]; then \
echo "Error: $(GENERATED_DIR)/reports.ndjson does not exist"; \
echo "Run 'make flatten' first to generate the NDJSON file"; \
exit 1; \
fi
@echo "Creating pretty-printed version of flattened data..."
@grep -v '{"index"' $(GENERATED_DIR)/reports.ndjson | $(PYTHON) -c "import sys, json; docs = [json.loads(line) for line in sys.stdin if line.strip()]; print(json.dumps(docs, indent=2))" > $(GENERATED_DIR)/reports_pretty.json
@echo "✓ Pretty-printed JSON saved to: $(GENERATED_DIR)/reports_pretty.json"
@ls -lh $(GENERATED_DIR)/reports_pretty.json
# ElasticSearch operations
es-check:
@$(SOURCE_ES_CONFIG); \
SAFE_URL=$$(echo "$$ES_URL" | $(SANITIZE_URL)); \
echo "Checking ElasticSearch connection at $$SAFE_URL..."; \
curl -s "$${ES_URL}" > /dev/null && \
echo "✓ ElasticSearch is reachable at $$SAFE_URL" || \
echo "✗ Cannot connect to ElasticSearch at $$SAFE_URL"
es-template: es-check
@$(SOURCE_ES_CONFIG); \
echo "Detecting platform and applying index template..."; \
PLATFORM_VARS=$$(export ES_URL="$${ES_URL}"; bash $(ES_INTEGRATION_DIR)/detect_platform.sh 2>&1); \
if [ $$? -ne 0 ]; then \
echo "ERROR: Failed to detect platform"; \
echo "$$PLATFORM_VARS"; \
exit 1; \
fi; \
eval "$$PLATFORM_VARS"; \
echo "Detected platform: $$PLATFORM (version $$VERSION)"; \
echo "Applying template: $$TEMPLATE_FILE"; \
echo ""; \
curl -X PUT "$${ES_URL}/_index_template/regulus-template" \
-H 'Content-Type: application/json' \
-d @$(ES_INTEGRATION_DIR)/$${TEMPLATE_FILE} | $(PYTHON) -m json.tool; \
echo ""; \
echo "✓ Index template applied successfully"; \
echo " Platform: $$PLATFORM"; \
echo " Template: $$TEMPLATE_FILE"
es-upload: es-template summary
@$(SOURCE_ES_CONFIG); \
SAFE_URL=$$(echo "$$ES_URL" | $(SANITIZE_URL)); \
ALIAS_EXISTS=$$(curl -s "$${ES_URL}/_cat/aliases/$(ES_WRITE_ALIAS)" 2>/dev/null | grep -c "$(ES_WRITE_ALIAS)" || true); \
INDEX_EXISTS=$$(curl -s -o /dev/null -w '%{http_code}' "$${ES_URL}/_cat/indices/$(ES_WRITE_ALIAS)" 2>/dev/null); \
if [ "$$ALIAS_EXISTS" = "0" ] && [ "$$INDEX_EXISTS" != "200" ]; then \
echo "Write target '$(ES_WRITE_ALIAS)' not found. Auto-creating index..."; \
BASE_INDEX_EXISTS=$$(curl -s -o /dev/null -w '%{http_code}' "$${ES_URL}/_cat/indices/$(BASE_NAME)-000001" 2>/dev/null); \
if [ "$$BASE_INDEX_EXISTS" = "200" ]; then \
echo "ERROR: Index $(BASE_NAME)-000001 exists but write alias '$(ES_WRITE_ALIAS)' is missing."; \
echo " Add the alias manually:"; \
echo " curl -X POST \"\$$ES_URL/_aliases\" -H 'Content-Type: application/json' -d '{\"actions\":[{\"add\":{\"index\":\"$(BASE_NAME)-000001\",\"alias\":\"$(ES_WRITE_ALIAS)\",\"is_write_index\":true}}]}'"; \
exit 1; \
fi; \
HAS_ISM=$$(curl -s "$${ES_URL}/_cat/plugins" 2>/dev/null | grep -c "opensearch-index-management" || true); \
if [ "$$HAS_ISM" != "0" ]; then \
INDEX_BODY='{"aliases": {"$(ES_WRITE_ALIAS)": {"is_write_index": true}}, "settings": {"index.plugins.index_state_management.rollover_alias": "$(ES_WRITE_ALIAS)"}}'; \
else \
INDEX_BODY='{"aliases": {"$(ES_WRITE_ALIAS)": {"is_write_index": true}}}'; \
fi; \
RESPONSE=$$(curl -s -X PUT "$${ES_URL}/$(BASE_NAME)-000001" \
-H 'Content-Type: application/json' \
-d "$$INDEX_BODY"); \
if echo "$$RESPONSE" | grep -q '"error"'; then \
echo "ERROR: Failed to create index:"; \
echo "$$RESPONSE" | $(PYTHON) -m json.tool 2>/dev/null || echo "$$RESPONSE"; \
exit 1; \
fi; \
echo "✓ Created index $(BASE_NAME)-000001 with write alias $(ES_WRITE_ALIAS)"; \
fi; \
echo "Uploading reports to ElasticSearch..."; \
echo " Source: $(GENERATED_DIR)/reports.ndjson"; \
echo " ES URL: $$SAFE_URL"; \
echo " Write Alias: $(ES_WRITE_ALIAS)"; \
echo "Uploading $$(grep -c '{"index"' $(GENERATED_DIR)/reports.ndjson 2>/dev/null || echo 0) documents..."; \
curl -s -H "Content-Type: application/x-ndjson" \
-XPOST "$${ES_URL}/$(ES_WRITE_ALIAS)/_bulk" \
--data-binary @$(GENERATED_DIR)/reports.ndjson | \
$(PYTHON) $(ES_INTEGRATION_DIR)/debug_upload_errors.py
# =============================================================================
# ElasticSearch Debug and Info Targets
# =============================================================================
es-index-stats: es-check
@$(SOURCE_ES_CONFIG); \
SAFE_URL=$$(echo "$$ES_URL" | $(SANITIZE_URL)); \
echo "=========================================="; \
echo " ElasticSearch Index Statistics"; \
echo "=========================================="; \
echo ""; \
echo "Index: $(ES_INDEX)"; \
echo "URL: $$SAFE_URL"; \
echo ""; \
echo "Detailed Stats (verbose):"; \
curl -s "$${ES_URL}/_cat/indices/$(ES_INDEX)?v&h=health,status,index,uuid,pri,rep,docs.count,docs.deleted,store.size,pri.store.size"; \
echo ""; \
echo ""; \
echo "Index Settings and Stats (JSON):"; \
curl -s "$${ES_URL}/$(ES_INDEX)/_stats" | $(PYTHON) -m json.tool 2>/dev/null || echo "Index may not exist yet"
es-template-info: es-check
@$(SOURCE_ES_CONFIG); \
SAFE_URL=$$(echo "$$ES_URL" | $(SANITIZE_URL)); \
echo "=========================================="; \
echo " ElasticSearch Index Template Info"; \
echo "=========================================="; \
echo ""; \
echo "Template: regulus-template"; \
echo "URL: $$SAFE_URL"; \
echo ""; \
curl -s "$${ES_URL}/_index_template/regulus-template" | $(PYTHON) -m json.tool 2>/dev/null || echo "Template does not exist. Run 'make es-template' to create it."
es-index-mapping: es-check
@$(SOURCE_ES_CONFIG); \
SAFE_URL=$$(echo "$$ES_URL" | $(SANITIZE_URL)); \
echo "=========================================="; \
echo " ElasticSearch Index Mapping"; \
echo "=========================================="; \
echo ""; \
echo "Index: $(ES_INDEX)"; \
echo "URL: $$SAFE_URL"; \
echo ""; \
curl -s "$${ES_URL}/$(ES_INDEX)/_mapping" | $(PYTHON) -m json.tool 2>/dev/null || echo "Index does not exist yet"
# =============================================================================
# Batch Management Targets
# =============================================================================
es-list-batches:
@$(SOURCE_ES_CONFIG); \
$(MAKE) -C ../ORION list-batches ES_URL="$$ES_URL" ES_INDEX="$(ES_INDEX)"
es-batch-count: es-check
@if [ -z "$(ES_BATCH_ID)" ]; then \
echo "ERROR: ES_BATCH_ID required. Usage: make es-batch-count ES_BATCH_ID=<uuid>"; \
exit 1; \
fi
@$(SOURCE_ES_CONFIG); \
curl -s "$${ES_URL}/$(ES_INDEX)/_count?pretty" \
-H 'Content-Type: application/json' \
-d '{"query": {"term": {"batch_id.keyword": "$(ES_BATCH_ID)"}}}' | \
$(PYTHON) -c 'import sys, json; print("Documents in batch: {}".format(json.load(sys.stdin)["count"]))'
es-batch-info: es-check
@if [ -z "$(ES_BATCH_ID)" ]; then \
echo "ERROR: ES_BATCH_ID required. Usage: make es-batch-info ES_BATCH_ID=<uuid>"; \
exit 1; \
fi
@$(SOURCE_ES_CONFIG); \
echo "=========================================="; \
echo " Batch Information"; \
echo "=========================================="; \
echo ""; \
echo "Batch ID: $(ES_BATCH_ID)"; \
echo "Index: $(ES_INDEX)"; \
echo ""; \
curl -s "$${ES_URL}/$(ES_INDEX)/_search?size=5&pretty" \
-H 'Content-Type: application/json' \
-d '{"query": {"term": {"batch_id.keyword": "$(ES_BATCH_ID)"}}, "aggs": {"benchmarks": {"terms": {"field": "benchmark"}}, "models": {"terms": {"field": "model"}}}}' | \
$(PYTHON) -m json.tool
es-delete-batch: es-check
@if [ -z "$(ES_BATCH_ID)" ]; then \
echo "ERROR: ES_BATCH_ID required. Usage: make es-delete-batch ES_BATCH_ID=<uuid>"; \
exit 1; \
fi
@$(SOURCE_ES_CONFIG); \
echo "=========================================="; \
echo " WARNING: Delete Batch"; \
echo "=========================================="; \
echo ""; \
echo "This will DELETE all documents with batch_id=$(ES_BATCH_ID)"; \
echo "Index: $(ES_INDEX)"; \
echo ""; \
$(MAKE) es-batch-count ES_BATCH_ID=$(ES_BATCH_ID); \
echo ""; \
read -p "Are you sure you want to delete this batch? [y/N] " confirm && [ "$$confirm" = "y" ] || (echo "Cancelled."; exit 1); \
echo ""; \
echo "Deleting batch..."; \
curl -s -X POST "$${ES_URL}/$(ES_INDEX)/_delete_by_query?pretty" \
-H 'Content-Type: application/json' \
-d '{"query": {"term": {"batch_id.keyword": "$(ES_BATCH_ID)"}}}' | \
$(PYTHON) -m json.tool; \
echo ""; \
echo "✓ Batch deleted"
es-show-last-batch: es-check
@$(SOURCE_ES_CONFIG); \
echo "Most recent upload batch:"; \
curl -s "$${ES_URL}/$(ES_INDEX)/_search?size=0&pretty" \
-H 'Content-Type: application/json' \
-d '{"aggs": {"latest": {"terms": {"field": "batch_id.keyword", "size": 1, "order": {"max_timestamp": "desc"}}, "aggs": {"max_timestamp": {"max": {"field": "@timestamp"}}}}}}' | \
$(PYTHON) -c 'import sys, json; \
data = json.load(sys.stdin); \
buckets = data.get("aggregations", {}).get("latest", {}).get("buckets", []); \
print("Batch ID: {}".format(buckets[0]["key"]) if buckets else "No batches found"); \
print("Documents: {}".format(buckets[0]["doc_count"]) if buckets else ""); \
print("Last upload: {}".format(buckets[0]["max_timestamp"]["value_as_string"]) if buckets else "")'
es-list-execution-labels: es-check
@$(SOURCE_ES_CONFIG); \
echo "==========================================" ;\
echo " Execution Labels in $(ES_INDEX)" ;\
echo "==========================================" ;\
echo "" ;\
curl -s "$${ES_URL}/$(ES_INDEX)/_search?size=0&pretty" \
-H 'Content-Type: application/json' \
-d '{"aggs": {"execution_labels": {"terms": {"field": "execution_label", "size": 100, "missing": "__NULL__"}}}}' | \
$(PYTHON) -c 'import sys, json; data = json.load(sys.stdin); buckets = data.get("aggregations", {}).get("execution_labels", {}).get("buckets", []); print("No execution_label data found") if not buckets else print("Found {} unique execution label(s):\n".format(len(buckets))) or [print(" (not set): {} documents".format(b["doc_count"])) if b["key"] == "__NULL__" else print(" \"{}\": {} documents".format(b["key"], b["doc_count"])) for b in buckets]'
es-delete-index: es-check
@$(SOURCE_ES_CONFIG); \
SAFE_URL=$$(echo "$$ES_URL" | $(SANITIZE_URL)); \
echo "==========================================" ;\
echo " WARNING: Delete Index" ;\
echo "==========================================" ;\
echo "" ;\
echo "This will DELETE the entire index: $(ES_INDEX)" ;\
echo "URL: $$SAFE_URL" ;\
echo "" ;\
read -p "Are you sure? Type 'yes' to confirm: " confirm && [ "$$confirm" = "yes" ] || (echo "Cancelled."; exit 1); \
echo "" ;\
echo "Checking if $(ES_INDEX) is an alias or concrete index..." ;\
ALIAS_CHECK=$$(curl -s "$${ES_URL}/_cat/aliases/$(ES_INDEX)" | head -n 1 | awk '{print $$2}'); \
if [ -n "$$ALIAS_CHECK" ]; then \
echo "$(ES_INDEX) is an alias pointing to: $$ALIAS_CHECK" ;\
echo "Deleting concrete index: $$ALIAS_CHECK" ;\
curl -X DELETE "$${ES_URL}/$$ALIAS_CHECK" | $(PYTHON) -m json.tool; \
else \
echo "$(ES_INDEX) is a concrete index" ;\
echo "Deleting index..." ;\
curl -X DELETE "$${ES_URL}/$(ES_INDEX)" | $(PYTHON) -m json.tool; \
fi; \
echo "" ;\
echo "✓ Index $(ES_INDEX) deleted. Template will be applied on next upload."
# =============================================================================
# Index Lifecycle Management (ILM) Targets
# =============================================================================
es-ilm-policy: es-check
@$(SOURCE_ES_CONFIG); \
SAFE_URL=$$(echo "$$ES_URL" | $(SANITIZE_URL)); \
echo "Detecting platform and applying lifecycle policy..."; \
PLATFORM_VARS=$$(export ES_URL="$${ES_URL}"; bash $(ES_INTEGRATION_DIR)/detect_platform.sh 2>&1); \
if [ $$? -ne 0 ]; then \
echo "ERROR: Failed to detect platform"; \
echo "$$PLATFORM_VARS"; \
exit 1; \
fi; \
eval "$$PLATFORM_VARS"; \
echo "Detected platform: $$PLATFORM (version $$VERSION)"; \
HAS_ISM=$$(curl -s "$${ES_URL}/_cat/plugins" 2>/dev/null | grep -c "opensearch-index-management" || true); \
if [ "$$PLATFORM" = "opensearch" ] && [ "$$HAS_ISM" = "0" ]; then \
echo "⚠ SKIPPED: ISM plugin (opensearch-index-management) not installed."; \
echo " Install the plugin and retry, or operate without lifecycle management."; \
else \
echo "Applying policy: $$POLICY_NAME"; \
echo ""; \
RESPONSE=$$(curl -s -X PUT "$${ES_URL}$${POLICY_ENDPOINT}/$${POLICY_NAME}" \
-H 'Content-Type: application/json' \
-d @$(ES_INTEGRATION_DIR)/$${POLICY_FILE}); \
if echo "$$RESPONSE" | grep -q '"error"'; then \
echo "ERROR: Failed to apply lifecycle policy:"; \
echo "$$RESPONSE" | $(PYTHON) -m json.tool 2>/dev/null || echo "$$RESPONSE"; \
exit 1; \
fi; \
echo "$$RESPONSE" | $(PYTHON) -m json.tool 2>/dev/null || echo "$$RESPONSE"; \
echo ""; \
echo "✓ Lifecycle policy applied successfully"; \
echo " Platform: $$PLATFORM"; \
echo " Policy: $$POLICY_NAME"; \
echo " Phases: hot (30d) -> warm (7d) -> cold (30d) -> delete (90d)"; \
fi
es-ilm-policy-no-delete: es-check
@$(SOURCE_ES_CONFIG); \
SAFE_URL=$$(echo "$$ES_URL" | $(SANITIZE_URL)); \
echo "Detecting platform and applying lifecycle policy (NO DELETION)..."; \
PLATFORM_VARS=$$(export ES_URL="$${ES_URL}"; bash $(ES_INTEGRATION_DIR)/detect_platform.sh 2>&1); \
if [ $$? -ne 0 ]; then \
echo "ERROR: Failed to detect platform"; \
echo "$$PLATFORM_VARS"; \
exit 1; \
fi; \
eval "$$PLATFORM_VARS"; \
echo "Detected platform: $$PLATFORM (version $$VERSION)"; \
HAS_ISM=$$(curl -s "$${ES_URL}/_cat/plugins" 2>/dev/null | grep -c "opensearch-index-management" || true); \
if [ "$$PLATFORM" = "opensearch" ] && [ "$$HAS_ISM" = "0" ]; then \
echo "⚠ SKIPPED: ISM plugin (opensearch-index-management) not installed."; \
echo " Install the plugin and retry, or operate without lifecycle management."; \
elif [ "$$PLATFORM" != "opensearch" ]; then \
echo "ERROR: No-delete policy currently only available for OpenSearch"; \
echo "For ElasticSearch, manually edit es_ilm_policy.json to remove delete phase"; \
exit 1; \
else \
POLICY_FILE_NO_DELETE="opensearch_ism_policy_no_delete.json"; \
echo "Applying policy: $$POLICY_NAME"; \
echo ""; \
RESPONSE=$$(curl -s -X PUT "$${ES_URL}$${POLICY_ENDPOINT}/$${POLICY_NAME}" \
-H 'Content-Type: application/json' \
-d @$(ES_INTEGRATION_DIR)/$${POLICY_FILE_NO_DELETE}); \
if echo "$$RESPONSE" | grep -q '"error"'; then \
echo "ERROR: Failed to apply lifecycle policy:"; \
echo "$$RESPONSE" | $(PYTHON) -m json.tool 2>/dev/null || echo "$$RESPONSE"; \
exit 1; \
fi; \
echo "$$RESPONSE" | $(PYTHON) -m json.tool 2>/dev/null || echo "$$RESPONSE"; \
echo ""; \
echo "✓ Lifecycle policy applied successfully (NO DELETION)"; \
echo " Platform: $$PLATFORM"; \
echo " Policy: $$POLICY_NAME"; \
echo " Phases: hot (30d) -> warm (7d) -> cold (30d)"; \
echo " NOTE: No delete phase - data retained permanently for CCR"; \
fi
es-ilm-info: es-check
@$(SOURCE_ES_CONFIG); \
SAFE_URL=$$(echo "$$ES_URL" | $(SANITIZE_URL)); \
echo "=========================================="; \
echo " Lifecycle Policy Information"; \
echo "=========================================="; \
echo ""; \
PLATFORM_VARS=$$(export ES_URL="$${ES_URL}"; bash $(ES_INTEGRATION_DIR)/detect_platform.sh 2>&1); \
eval "$$PLATFORM_VARS"; \
echo "Platform: $$PLATFORM (version $$VERSION)"; \
echo "Policy: $$POLICY_NAME"; \
echo "URL: $$SAFE_URL"; \
echo ""; \
curl -s "$${ES_URL}$${POLICY_ENDPOINT}/$${POLICY_NAME}" | $(PYTHON) -m json.tool 2>/dev/null || echo "Policy does not exist. Run 'make es-ilm-policy' to create it."
es-ilm-explain: es-check
@$(SOURCE_ES_CONFIG); \
SAFE_URL=$$(echo "$$ES_URL" | $(SANITIZE_URL)); \
echo "=========================================="; \
echo " Lifecycle Phase Explanation for Index"; \
echo "=========================================="; \
echo ""; \
PLATFORM_VARS=$$(export ES_URL="$${ES_URL}"; bash $(ES_INTEGRATION_DIR)/detect_platform.sh 2>&1); \
eval "$$PLATFORM_VARS"; \
echo "Platform: $$PLATFORM"; \
echo "Index: $(ES_INDEX)"; \
echo "URL: $$SAFE_URL"; \
echo ""; \
curl -s "$${ES_URL}$${POLICY_EXPLAIN_PREFIX}$(ES_INDEX)$${POLICY_EXPLAIN_SUFFIX}" | $(PYTHON) -m json.tool 2>/dev/null || echo "Index does not exist or lifecycle management not enabled yet"
es-bootstrap-index: es-check es-template
@$(SOURCE_ES_CONFIG); \
SAFE_URL=$$(echo "$$ES_URL" | $(SANITIZE_URL)); \
echo "=========================================="; \
echo " Bootstrapping Rollover Index"; \
echo "=========================================="; \
echo ""; \
PLATFORM_VARS=$$(export ES_URL="$${ES_URL}"; bash $(ES_INTEGRATION_DIR)/detect_platform.sh 2>&1); \
eval "$$PLATFORM_VARS"; \
echo "Platform: $$PLATFORM"; \
echo "Creating initial write index: $(BASE_NAME)-000001"; \
echo "Write alias: $(ES_WRITE_ALIAS)"; \
echo "URL: $$SAFE_URL"; \
echo ""; \
HAS_ISM=$$(curl -s "$${ES_URL}/_cat/plugins" 2>/dev/null | grep -c "opensearch-index-management" || true); \
if [ "$$HAS_ISM" != "0" ]; then \
echo "ISM plugin detected. Applying lifecycle policy..."; \
$(MAKE) es-ilm-policy-no-delete; \
INDEX_BODY='{"aliases": {"$(ES_WRITE_ALIAS)": {"is_write_index": true}}, "settings": {"index.plugins.index_state_management.rollover_alias": "$(ES_WRITE_ALIAS)"}}'; \
else \
echo "NOTE: ISM plugin not installed. Creating index without lifecycle management."; \
echo " To add ISM later, install opensearch-index-management plugin and run 'make es-ilm-policy-no-delete'"; \
INDEX_BODY='{"aliases": {"$(ES_WRITE_ALIAS)": {"is_write_index": true}}}'; \
fi; \
RESPONSE=$$(curl -s -X PUT "$${ES_URL}/$(BASE_NAME)-000001" \
-H 'Content-Type: application/json' \
-d "$$INDEX_BODY"); \
if echo "$$RESPONSE" | grep -q '"error"'; then \
echo "ERROR: Failed to create index:"; \
echo "$$RESPONSE" | $(PYTHON) -m json.tool 2>/dev/null || echo "$$RESPONSE"; \
exit 1; \
fi; \
echo "$$RESPONSE" | $(PYTHON) -m json.tool 2>/dev/null || echo "$$RESPONSE"; \
echo ""; \
echo "✓ Bootstrapped index created successfully"; \
echo " Write index: $(BASE_NAME)-000001"; \
echo " Write alias: $(ES_WRITE_ALIAS)"; \
if [ "$$HAS_ISM" != "0" ]; then \
echo " ISM policy: regulus-ism-policy (attached)"; \
else \
echo " ISM policy: none (plugin not installed)"; \
fi; \
echo ""; \
echo "NOTE: Upload to '$(ES_WRITE_ALIAS)' alias, not directly to $(BASE_NAME)-000001"
# =============================================================================
# Container Build Targets
# =============================================================================
# Build container with latest tag
build-container: build-container-latest
build-container-latest:
@echo "================================================"
@echo " Building Dashboard Container Image"
@echo "================================================"
@echo ""
@# Check for built-in reports from generated/ directory
@if [ -d "generated" ]; then \
echo "Built-in reports source: generated/"; \
GENERATED_FILES=$$(find generated -name '*.json' 2>/dev/null); \
if [ -n "$$GENERATED_FILES" ]; then \
GENERATED_COUNT=$$(echo "$$GENERATED_FILES" | wc -l); \
echo "Found $$GENERATED_COUNT built-in report(s):"; \
echo "$$GENERATED_FILES" | while read file; do \
basename "$$file"; \
done | sed 's/^/ - /'; \
else \
echo "Found 0 built-in report(s)"; \
fi; \
else \
echo "No generated/ directory found"; \
echo "Found 0 built-in report(s)"; \
fi
@echo ""
@echo "Building image with tag: latest"
@echo "Build context: REPORT/ (includes dashboard/ and generated/)"
@echo ""
@podman build -f $(DASHBOARD_DIR)/docker/Dockerfile -t regulus-dashboard:latest .
@echo ""
@echo "================================================"
@echo "✓ Build complete!"
@echo "================================================"
@echo ""
@echo "Image: regulus-dashboard:latest"
@echo ""
@# List built-in reports in the final image
@if [ -d "generated" ]; then \
GENERATED_FILES=$$(find generated -name '*.json' 2>/dev/null); \
if [ -n "$$GENERATED_FILES" ]; then \
GENERATED_COUNT=$$(echo "$$GENERATED_FILES" | wc -l); \
echo "Built-in reports included from generated/ ($$GENERATED_COUNT):"; \
echo "$$GENERATED_FILES" | while read file; do \
basename "$$file"; \
done | sed 's/^/ - /'; \
echo ""; \
fi; \
fi
@echo "To run (recommended - interactive with auto-cleanup):"
@echo " podman run --rm -it -p 5000:5000 -v /tmp/regulus-data:/app/data:Z regulus-dashboard:latest"
@echo ""
@echo "Flags explained:"
@echo " --rm = Auto-remove container when stopped (prevents accumulation)"
@echo " -it = Interactive terminal with signal handling (Ctrl+C works)"
@echo ""
@echo "Or run in background:"
@echo " podman run -d --name dashboard -p 5000:5000 -v /tmp/regulus-data:/app/data:Z regulus-dashboard:latest"
@echo ""
@echo "Or using podman-compose:"
@echo " cd $(DASHBOARD_DIR)/docker && podman-compose up"
@echo ""
# Build container with custom tag
build-container-tag:
@if [ -z "$(TAG)" ]; then \
echo "Error: TAG not specified"; \
echo "Usage: make build-container-tag TAG=v1.0"; \
exit 1; \
fi
@echo "================================================"
@echo " Building Dashboard Container Image"
@echo "================================================"
@echo ""
@# Check for built-in reports from generated/ directory
@if [ -d "generated" ]; then \
echo "Built-in reports source: generated/"; \
GENERATED_FILES=$$(find generated -name '*.json' 2>/dev/null); \
if [ -n "$$GENERATED_FILES" ]; then \
GENERATED_COUNT=$$(echo "$$GENERATED_FILES" | wc -l); \
echo "Found $$GENERATED_COUNT built-in report(s):"; \
echo "$$GENERATED_FILES" | while read file; do \
basename "$$file"; \
done | sed 's/^/ - /'; \
else \
echo "Found 0 built-in report(s)"; \
fi; \
else \
echo "No generated/ directory found"; \
echo "Found 0 built-in report(s)"; \
fi
@echo ""
@echo "Building image with tag: $(TAG)"
@echo "Build context: REPORT/ (includes dashboard/ and generated/)"
@echo ""
@podman build -f $(DASHBOARD_DIR)/docker/Dockerfile -t regulus-dashboard:$(TAG) .
@echo ""
@echo "================================================"
@echo "✓ Build complete!"
@echo "================================================"
@echo ""
@echo "Image: regulus-dashboard:$(TAG)"
@echo ""
@# List built-in reports in the final image
@if [ -d "generated" ]; then \
GENERATED_FILES=$$(find generated -name '*.json' 2>/dev/null); \
if [ -n "$$GENERATED_FILES" ]; then \
GENERATED_COUNT=$$(echo "$$GENERATED_FILES" | wc -l); \
echo "Built-in reports included from generated/ ($$GENERATED_COUNT):"; \
echo "$$GENERATED_FILES" | while read file; do \
basename "$$file"; \
done | sed 's/^/ - /'; \
echo ""; \
fi; \
fi
@echo "To run (recommended - interactive with auto-cleanup):"
@echo " podman run --rm -it -p 5000:5000 -v /tmp/regulus-data:/app/data:Z regulus-dashboard:$(TAG)"
@echo ""
@echo "Flags explained:"
@echo " --rm = Auto-remove container when stopped (prevents accumulation)"
@echo " -it = Interactive terminal with signal handling (Ctrl+C works)"
@echo ""
@echo "Or run in background:"
@echo " podman run -d --name dashboard -p 5000:5000 -v /tmp/regulus-data:/app/data:Z regulus-dashboard:$(TAG)"
@echo ""
@echo "Or using podman-compose:"
@echo " cd $(DASHBOARD_DIR)/docker && podman-compose up"
@echo ""
# Clean up container images
clean-container:
@echo "Removing regulus-dashboard container images..."
@podman images | grep regulus-dashboard | awk '{print $$1":"$$2}' | xargs -r podman rmi || echo "No images to remove"
@echo "Done"
# =============================================================================
# Advanced Targets
# =============================================================================
# Clean build artifacts
clean:
@echo "Cleaning temporary files..."
@find . -type d -name __pycache__ -exec rm -rf {} + 2>/dev/null || true
@find . -type f -name "*.pyc" -delete 2>/dev/null || true
@rm -rf $(GENERATED_DIR)/*
@echo "✓ Report artifacts cleaned from REPORT/generated/"