boto-rb-management-ui 0.31.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (106) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +21 -0
  3. data/README.md +22 -0
  4. data/db/migrations/20261201000001_create_boto_monitor_instances.rb +14 -0
  5. data/db/migrations/20261201000002_create_boto_monitor_series.rb +20 -0
  6. data/db/migrations/20261201000003_create_boto_monitor_errors.rb +19 -0
  7. data/db/migrations/20261201000004_create_boto_monitor_traces.rb +19 -0
  8. data/db/migrations/20261201000005_create_boto_monitor_runtime.rb +23 -0
  9. data/db/migrations/20261201000006_create_boto_monitor_n_plus_ones.rb +17 -0
  10. data/db/migrations/20261201000007_add_browser_data_to_boto_monitor.rb +31 -0
  11. data/db/migrations/20261203000001_create_boto_monitor_streams.rb +24 -0
  12. data/db/migrations/20261203000002_add_streams_open_to_boto_monitor_instances.rb +12 -0
  13. data/lib/boto/companions/management_ui.rb +8 -0
  14. data/lib/boto/management_ui/app.rb +84 -0
  15. data/lib/boto/management_ui/app_traits.rb +34 -0
  16. data/lib/boto/management_ui/assets/monitor/api.js +36 -0
  17. data/lib/boto/management_ui/assets/monitor/charts.js +212 -0
  18. data/lib/boto/management_ui/assets/monitor/constants.js +70 -0
  19. data/lib/boto/management_ui/assets/monitor/dom.js +70 -0
  20. data/lib/boto/management_ui/assets/monitor/format.js +76 -0
  21. data/lib/boto/management_ui/assets/monitor/header.js +2 -0
  22. data/lib/boto/management_ui/assets/monitor/main.js +33 -0
  23. data/lib/boto/management_ui/assets/monitor/panes.js +109 -0
  24. data/lib/boto/management_ui/assets/monitor/runtime.js +26 -0
  25. data/lib/boto/management_ui/assets/monitor/services.js +174 -0
  26. data/lib/boto/management_ui/assets/monitor/spa.js +203 -0
  27. data/lib/boto/management_ui/assets/monitor/traces.js +88 -0
  28. data/lib/boto/management_ui/assets/panel/base.css +87 -0
  29. data/lib/boto/management_ui/assets/panel/errors.css +36 -0
  30. data/lib/boto/management_ui/assets/panel/gateway.css +3 -0
  31. data/lib/boto/management_ui/assets/panel/layout.css +63 -0
  32. data/lib/boto/management_ui/assets/panel/monitor_layout.css +77 -0
  33. data/lib/boto/management_ui/assets/panel/monitor_tables.css +97 -0
  34. data/lib/boto/management_ui/assets/panel/service_view.css +102 -0
  35. data/lib/boto/management_ui/assets/panel/services.css +55 -0
  36. data/lib/boto/management_ui/assets/panel/spa.css +41 -0
  37. data/lib/boto/management_ui/assets/panel/tables.css +67 -0
  38. data/lib/boto/management_ui/assets/panel/tabs.css +71 -0
  39. data/lib/boto/management_ui/assets/panel/traces.css +45 -0
  40. data/lib/boto/management_ui/browser_telemetry.rb +87 -0
  41. data/lib/boto/management_ui/gateway_view.rb +57 -0
  42. data/lib/boto/management_ui/health_probe.rb +70 -0
  43. data/lib/boto/management_ui/in_process_receiver.rb +17 -0
  44. data/lib/boto/management_ui/monitor/api.rb +87 -0
  45. data/lib/boto/management_ui/monitor/batch_schema/browser_call_entry.rb +26 -0
  46. data/lib/boto/management_ui/monitor/batch_schema/browser_error_entry.rb +41 -0
  47. data/lib/boto/management_ui/monitor/batch_schema/checks.rb +90 -0
  48. data/lib/boto/management_ui/monitor/batch_schema/error_entry.rb +37 -0
  49. data/lib/boto/management_ui/monitor/batch_schema/n_plus_one_entry.rb +30 -0
  50. data/lib/boto/management_ui/monitor/batch_schema/page_entry.rb +25 -0
  51. data/lib/boto/management_ui/monitor/batch_schema/runtime.rb +33 -0
  52. data/lib/boto/management_ui/monitor/batch_schema/series.rb +41 -0
  53. data/lib/boto/management_ui/monitor/batch_schema/streams.rb +46 -0
  54. data/lib/boto/management_ui/monitor/batch_schema/trace_entry.rb +45 -0
  55. data/lib/boto/management_ui/monitor/batch_schema.rb +138 -0
  56. data/lib/boto/management_ui/monitor/ingest.rb +126 -0
  57. data/lib/boto/management_ui/monitor/memory_store/error_table.rb +53 -0
  58. data/lib/boto/management_ui/monitor/memory_store/instance_table.rb +45 -0
  59. data/lib/boto/management_ui/monitor/memory_store/n_plus_one_table.rb +44 -0
  60. data/lib/boto/management_ui/monitor/memory_store/runtime_table.rb +55 -0
  61. data/lib/boto/management_ui/monitor/memory_store/series_table.rb +49 -0
  62. data/lib/boto/management_ui/monitor/memory_store/staleness.rb +20 -0
  63. data/lib/boto/management_ui/monitor/memory_store/stream_table.rb +36 -0
  64. data/lib/boto/management_ui/monitor/memory_store/trace_table.rb +41 -0
  65. data/lib/boto/management_ui/monitor/memory_store.rb +118 -0
  66. data/lib/boto/management_ui/monitor/percentile.rb +38 -0
  67. data/lib/boto/management_ui/monitor/period.rb +48 -0
  68. data/lib/boto/management_ui/monitor/queries/browser_calls.rb +56 -0
  69. data/lib/boto/management_ui/monitor/queries/browser_view.rb +91 -0
  70. data/lib/boto/management_ui/monitor/queries/charts.rb +66 -0
  71. data/lib/boto/management_ui/monitor/queries/live_instances.rb +44 -0
  72. data/lib/boto/management_ui/monitor/queries/points.rb +61 -0
  73. data/lib/boto/management_ui/monitor/queries/route_view.rb +46 -0
  74. data/lib/boto/management_ui/monitor/queries/runtime_view.rb +80 -0
  75. data/lib/boto/management_ui/monitor/queries/service_cards.rb +65 -0
  76. data/lib/boto/management_ui/monitor/queries/streams.rb +39 -0
  77. data/lib/boto/management_ui/monitor/queries/trace_tree.rb +47 -0
  78. data/lib/boto/management_ui/monitor/queries/vitals.rb +50 -0
  79. data/lib/boto/management_ui/monitor/queries.rb +171 -0
  80. data/lib/boto/management_ui/monitor/retention.rb +62 -0
  81. data/lib/boto/management_ui/monitor/schema.rb +64 -0
  82. data/lib/boto/management_ui/monitor/sql_store/error_writer.rb +62 -0
  83. data/lib/boto/management_ui/monitor/sql_store/instance_writer.rb +63 -0
  84. data/lib/boto/management_ui/monitor/sql_store/n_plus_one_writer.rb +50 -0
  85. data/lib/boto/management_ui/monitor/sql_store/rows.rb +99 -0
  86. data/lib/boto/management_ui/monitor/sql_store/series_writer.rb +52 -0
  87. data/lib/boto/management_ui/monitor/sql_store/streams_writer.rb +34 -0
  88. data/lib/boto/management_ui/monitor/sql_store.rb +139 -0
  89. data/lib/boto/management_ui/monitor/store.rb +78 -0
  90. data/lib/boto/management_ui/monitor/stream_point.rb +45 -0
  91. data/lib/boto/management_ui/panel/env_rows.rb +54 -0
  92. data/lib/boto/management_ui/panel/html_view.rb +43 -0
  93. data/lib/boto/management_ui/panel/json_view.rb +43 -0
  94. data/lib/boto/management_ui/panel/masking.rb +43 -0
  95. data/lib/boto/management_ui/panel/page.rb +41 -0
  96. data/lib/boto/management_ui/panel/service_info.rb +62 -0
  97. data/lib/boto/management_ui/panel.html.erb +207 -0
  98. data/lib/boto/management_ui/panel.rb +115 -0
  99. data/lib/boto/management_ui/password_auth.rb +26 -0
  100. data/lib/boto/management_ui/service_list.rb +59 -0
  101. data/lib/boto/management_ui/setup.rb +103 -0
  102. data/lib/boto/management_ui/spas.rb +73 -0
  103. data/lib/boto/management_ui/tabs.rb +40 -0
  104. data/lib/boto/management_ui/version.rb +7 -0
  105. data/lib/boto/management_ui.rb +15 -0
  106. metadata +203 -0
@@ -0,0 +1,102 @@
1
+ /* Monitor: service view */
2
+
3
+ .service-head {
4
+ display: flex;
5
+ flex-wrap: wrap;
6
+ align-items: center;
7
+ justify-content: space-between;
8
+ gap: 12px;
9
+ padding: 18px 22px;
10
+ border-bottom: 1px solid var(--line-soft);
11
+ }
12
+
13
+ .service-head__identity { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; }
14
+
15
+ .service-head__name { font-size: 22px; font-weight: 700; }
16
+
17
+ .back { font-size: 14px; }
18
+
19
+ .subtabs {
20
+ display: flex;
21
+ gap: 2px;
22
+ padding: 0 22px;
23
+ border-bottom: 1px solid var(--line-soft);
24
+ }
25
+
26
+ .subtabs button {
27
+ font: inherit;
28
+ font-size: 14px;
29
+ font-weight: 600;
30
+ color: var(--muted);
31
+ background: none;
32
+ border: 0;
33
+ border-bottom: 2px solid transparent;
34
+ padding: 10px 12px;
35
+ cursor: pointer;
36
+ }
37
+
38
+ .subtabs button[aria-selected="true"] { color: var(--ink); border-bottom-color: #cc342d; }
39
+
40
+ .subtabs .count { font-size: 12px; margin-left: 4px; color: #b42318; }
41
+
42
+ .pane { padding: 4px 0 8px; }
43
+
44
+ .charts {
45
+ display: grid;
46
+ grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
47
+ gap: 16px;
48
+ padding: 18px 22px;
49
+ }
50
+
51
+ .chart { border: 1px solid var(--line-soft); border-radius: 10px; padding: 12px 14px 8px; }
52
+
53
+ .chart__title { font-size: 13px; font-weight: 600; display: flex; justify-content: space-between; gap: 8px; }
54
+
55
+ .chart__now { font-size: 13px; font-weight: 600; font-variant-numeric: tabular-nums; }
56
+
57
+ .chart__now small { font-weight: 400; color: var(--muted); }
58
+
59
+ .chart__legend { font-size: 12px; color: var(--muted); display: flex; flex-wrap: wrap; gap: 12px; margin-top: 2px; }
60
+
61
+ .chart__legend i {
62
+ display: inline-block;
63
+ width: 10px;
64
+ height: 3px;
65
+ border-radius: 2px;
66
+ margin-right: 4px;
67
+ vertical-align: middle;
68
+ }
69
+
70
+ .chart__legend .dash { height: 0; border-top: 2px dashed #cc342d; background: none; }
71
+
72
+ .chart__plot { position: relative; margin-top: 6px; }
73
+
74
+ .chart__plot svg { display: block; overflow: visible; }
75
+
76
+ .chart__plot .axis { font-size: 10px; fill: #71717a; font-family: var(--sans); }
77
+
78
+ .chart__plot .grid { stroke: #f0f0f1; }
79
+
80
+ .chart__plot .cursor { stroke: #a1a1aa; stroke-width: 1; }
81
+
82
+ .tooltip {
83
+ position: absolute;
84
+ top: 0;
85
+ pointer-events: none;
86
+ background: var(--ink);
87
+ color: #ffffff;
88
+ border-radius: 8px;
89
+ padding: 7px 10px;
90
+ font-size: 12px;
91
+ line-height: 1.45;
92
+ white-space: nowrap;
93
+ box-shadow: 0 4px 14px rgba(0, 0, 0, 0.18);
94
+ z-index: 2;
95
+ }
96
+
97
+ .tooltip .row { display: flex; align-items: center; gap: 6px; font-variant-numeric: tabular-nums; }
98
+
99
+ .tooltip .row i { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
100
+
101
+ .tooltip .muted { color: #a1a1aa; font-size: 11px; }
102
+
@@ -0,0 +1,55 @@
1
+ /* Services */
2
+
3
+ .service__head {
4
+ justify-content: space-between;
5
+ gap: 12px;
6
+ padding: 18px 22px;
7
+ border-bottom: 1px solid var(--line-soft);
8
+ }
9
+
10
+ .service__identity { gap: 12px; }
11
+
12
+ .service__name { font-size: 19px; font-weight: 700; }
13
+
14
+ .service__status {
15
+ gap: 16px;
16
+ font-size: 14px;
17
+ }
18
+
19
+ .prefix {
20
+ font-family: var(--mono);
21
+ font-size: 14px;
22
+ padding: 2px 8px;
23
+ border-radius: 6px;
24
+ background: #fdf2f1;
25
+ color: #9f2a24;
26
+ }
27
+
28
+ .port-link { font-family: var(--mono); font-size: 14px; }
29
+
30
+ .link-strong { font-weight: 600; }
31
+
32
+ .health {
33
+ display: inline-flex;
34
+ align-items: center;
35
+ gap: 6px;
36
+ font-weight: 600;
37
+ color: var(--muted);
38
+ }
39
+
40
+ .health--ready { color: #166534; }
41
+
42
+ .health--failing { color: #b42318; }
43
+
44
+ .health-detail {
45
+ margin: 14px 22px 0;
46
+ padding: 10px 14px;
47
+ border-radius: 8px;
48
+ background: #fef3f2;
49
+ border: 1px solid #fecdca;
50
+ color: #912018;
51
+ font-family: var(--mono);
52
+ font-size: 14px;
53
+ word-break: break-word;
54
+ }
55
+
@@ -0,0 +1,41 @@
1
+ /* Spa: vitals, ⓘ tips, the split bar of browser calls, the browser's span and the callout of the Solution. */
2
+ .stat__value--warn { color: #9a3412; }
3
+ .badge--spa { background: #fdf2f1; color: #9f2a24; }
4
+ .callout { margin: 0 22px 18px; padding: 10px 14px; border-radius: 8px; background: #fdf2f1; border: 1px solid #fecdca; color: #912018; font-size: 13px; }
5
+
6
+ .legend { display: flex; flex-wrap: wrap; gap: 6px 16px; align-items: center; font-size: 12px; color: var(--muted); padding: 10px 22px 4px; }
7
+ .legend i { display: inline-block; width: 10px; height: 8px; border-radius: 2px; margin-right: 4px; vertical-align: middle; }
8
+ .legend .vital { min-width: 0; }
9
+ .legend .svc { background: #1e40af; }
10
+ .legend .net { background: #9a3412; }
11
+
12
+ .vital { display: inline-block; min-width: 64px; text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; padding: 1px 8px; border-radius: 6px; }
13
+ .vital--good { background: #dcfce7; color: #166534; }
14
+ .vital--warn { background: #ffedd5; color: #9a3412; }
15
+ .vital--poor { background: #fee2e2; color: #b42318; }
16
+
17
+ /* A card with an ⓘ puts it at the other end of its label, as in the approved design */
18
+ .stat__label:has(> .info) { display: flex; align-items: center; justify-content: space-between; gap: 6px; }
19
+ .info { position: relative; display: inline-flex; }
20
+ .info__btn { font: inherit; font-size: 11px; font-weight: 700; width: 16px; height: 16px; border-radius: 50%; border: 1px solid #a1a1aa; background: #fff; color: var(--muted); display: inline-flex; align-items: center; justify-content: center; padding: 0; line-height: 1; cursor: help; }
21
+ .info__btn:hover,
22
+ .info__btn:focus-visible { border-color: var(--ink); color: var(--ink); outline: none; }
23
+ .info__tip { display: none; position: absolute; top: 22px; right: -8px; z-index: 3; width: 260px; background: var(--ink); color: #fff; border-radius: 8px; padding: 8px 10px; font-size: 12px; font-weight: 400; line-height: 1.45; box-shadow: 0 4px 14px rgba(0, 0, 0, 0.18); white-space: normal; }
24
+ /* The first card sits at the card's left edge: its tip opens to the right so overflow: hidden does not clip it */
25
+ .summary .stat:first-child .info__tip { right: auto; left: -8px; }
26
+ .info__tip strong { font-weight: 600; }
27
+ .info__tip .limits { display: block; margin-top: 4px; color: #d4d4d8; }
28
+ .info:hover .info__tip,
29
+ .info:focus-within .info__tip { display: block; }
30
+
31
+ .chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
32
+ .chip { font-size: 12px; padding: 1px 8px; border-radius: 999px; background: #f4f4f5; border: 1px solid #e4e4e7; color: #3f3f46; }
33
+
34
+ .split { display: inline-flex; width: 140px; height: 8px; border-radius: 999px; background: #f4f4f5; overflow: hidden; vertical-align: middle; margin-right: 8px; }
35
+ .split i { display: block; height: 100%; }
36
+ .split .svc { background: #1e40af; }
37
+ .split .net { background: #9a3412; }
38
+ .split .browser { background: #71717a; }
39
+
40
+ .span__bar--browser { background: #a16207; }
41
+ .span__svc { font-size: 11px; font-weight: 700; padding: 0 6px; border-radius: 999px; background: #f4f4f5; color: #3f3f46; margin-right: 6px; }
@@ -0,0 +1,67 @@
1
+ /* Tables */
2
+
3
+ .table-wrap {
4
+ overflow-x: auto;
5
+ padding: 0 22px 16px;
6
+ }
7
+
8
+ .routes,
9
+ .env-table {
10
+ width: 100%;
11
+ border-collapse: collapse;
12
+ font-size: 14px;
13
+ }
14
+
15
+ .routes caption {
16
+ text-align: left;
17
+ padding: 8px 0;
18
+ font-size: 13px;
19
+ color: var(--muted);
20
+ }
21
+
22
+ .env-table thead,
23
+ .routes thead {
24
+ color: var(--muted);
25
+ font-size: 12px;
26
+ text-transform: uppercase;
27
+ letter-spacing: 0.6px;
28
+ }
29
+
30
+ .routes th,
31
+ .env-table th {
32
+ text-align: left;
33
+ font-weight: 600;
34
+ padding: 6px 12px 6px 0;
35
+ }
36
+
37
+ .routes td,
38
+ .env-table td {
39
+ padding: 9px 12px 9px 0;
40
+ border-top: 1px solid var(--line-soft);
41
+ white-space: nowrap;
42
+ }
43
+
44
+ .env-name { font-family: var(--mono); font-weight: 600; }
45
+
46
+ .env-value { font-family: var(--mono); }
47
+
48
+ .env-source { font-family: var(--mono); color: var(--muted); }
49
+
50
+ .route-path { font-family: var(--mono); }
51
+
52
+ .prefix-dim { color: #71717a; }
53
+
54
+ .endpoint { font-family: var(--mono); color: var(--muted); }
55
+
56
+ .masked-badge {
57
+ margin-left: 8px;
58
+ font-family: var(--sans);
59
+ font-size: 11px;
60
+ font-weight: 600;
61
+ padding: 1px 8px;
62
+ border-radius: 999px;
63
+ background: #f4f4f5;
64
+ color: var(--muted);
65
+ border: 1px solid var(--line);
66
+ }
67
+
@@ -0,0 +1,71 @@
1
+ /* HTTP verbs */
2
+
3
+ .verb {
4
+ display: inline-block;
5
+ min-width: 58px;
6
+ text-align: center;
7
+ font-family: var(--mono);
8
+ font-size: 12px;
9
+ font-weight: 700;
10
+ padding: 2px 8px;
11
+ border-radius: 6px;
12
+ }
13
+
14
+ .verb--get { background: #e0ecff; color: #1e40af; }
15
+
16
+ .verb--post { background: #dcfce7; color: #166534; }
17
+
18
+ .verb--put,
19
+ .verb--patch { background: #ffedd5; color: #9a3412; }
20
+
21
+ .verb--delete { background: #fee2e2; color: #991b1b; }
22
+
23
+ .verb--query { background: #ede9fe; color: #5b21b6; }
24
+
25
+ /* Environment disclosure inside each service */
26
+
27
+ .service__env { border-top: 1px solid var(--line-soft); }
28
+
29
+ .service__env-summary {
30
+ padding: 12px 22px;
31
+ font-size: 14px;
32
+ font-weight: 600;
33
+ }
34
+
35
+ .footer {
36
+ justify-content: space-between;
37
+ gap: 8px;
38
+ padding-top: 16px;
39
+ border-top: 1px solid var(--line);
40
+ font-size: 13px;
41
+ color: var(--muted);
42
+ }
43
+
44
+ /* Tabs and visibility */
45
+
46
+ [hidden] { display: none !important; }
47
+
48
+ .panel-view { display: flex; flex-direction: column; gap: 28px; }
49
+
50
+ .tabs {
51
+ display: flex;
52
+ gap: 4px;
53
+ max-width: 1120px;
54
+ margin: 0 auto;
55
+ padding: 10px 24px 0;
56
+ }
57
+
58
+ .tabs button {
59
+ font: inherit;
60
+ font-size: 14px;
61
+ font-weight: 600;
62
+ color: #d4d4d8;
63
+ background: none;
64
+ border: 0;
65
+ padding: 8px 14px 10px;
66
+ border-radius: 8px 8px 0 0;
67
+ cursor: pointer;
68
+ }
69
+
70
+ .tabs button[aria-selected="true"] { background: var(--page); color: var(--ink); }
71
+
@@ -0,0 +1,45 @@
1
+ /* Monitor: trace waterfall */
2
+
3
+ .trace { margin: 0 22px 18px; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
4
+
5
+ .trace__head {
6
+ display: flex;
7
+ flex-wrap: wrap;
8
+ justify-content: space-between;
9
+ gap: 8px;
10
+ padding: 10px 14px;
11
+ background: #fafafa;
12
+ border-bottom: 1px solid var(--line-soft);
13
+ font-size: 14px;
14
+ }
15
+
16
+ .span {
17
+ display: grid;
18
+ grid-template-columns: minmax(260px, 38%) 1fr 70px;
19
+ align-items: center;
20
+ gap: 10px;
21
+ padding: 5px 14px;
22
+ font-size: 13px;
23
+ border-top: 1px solid var(--line-soft);
24
+ }
25
+
26
+ .span__name { font-family: var(--mono); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
27
+
28
+ .span__track { position: relative; height: 14px; background: #f4f4f5; border-radius: 3px; }
29
+
30
+ .span__bar { position: absolute; top: 2px; height: 10px; border-radius: 3px; background: #1e40af; }
31
+
32
+ .span__bar--request { background: var(--ink); }
33
+
34
+ .span__bar--op { background: #cc342d; }
35
+
36
+ .span__bar--sql { background: #7c3aed; }
37
+
38
+ .span__bar--plugin { background: #71717a; }
39
+
40
+ .span__bar--http { background: #0e7490; }
41
+
42
+ .span__ms { text-align: right; font-variant-numeric: tabular-nums; color: var(--muted); }
43
+
44
+ .n1-note { margin: 0 22px 18px; padding: 10px 14px; border-radius: 8px; background: #f5f3ff; border: 1px solid #ddd6fe; color: #4c1d95; font-size: 13px; }
45
+
@@ -0,0 +1,87 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "json"
4
+
5
+ module Boto
6
+ module ManagementUi
7
+ # The browser side of a frontend in development. Its beacons (POST /<name>/_boto/rum) are taken by a receiver of
8
+ # this process and handed to the gateway's monitor, as the services' agents do. Built only with the telemetry gem.
9
+ class BrowserTelemetry
10
+ RUM_PATH = "/_boto/rum"
11
+ OPERATIONS_FILE = %w[public .boto operations.json].freeze
12
+ DEVELOPMENT = "development"
13
+ SLOW = 0.5
14
+ RUM_LIMIT = 60
15
+ RUM_PERIOD = 60
16
+
17
+ # The telemetry gem is optional: loaded when the bundle has it, and without it there is no browser side.
18
+ def self.available?
19
+ return true if defined?(Boto::Telemetry::Browser::Receiver)
20
+
21
+ require "boto/telemetry"
22
+ true
23
+ rescue LoadError
24
+ false
25
+ end
26
+
27
+ # The spa's operations.json sits beside the gateway's project dir (apps/<gateway> and apps/<spa>).
28
+ def self.operations_path(gateway_dir, name) = File.join(File.dirname(gateway_dir), name, *OPERATIONS_FILE)
29
+
30
+ # The spa's own project dir, as the run's telemetry plugin knows it; nil when the app has none.
31
+ def self.project_operations_path(project_dir) = project_dir && File.join(project_dir.to_s, *OPERATIONS_FILE)
32
+
33
+ attr_reader :name, :agent, :receiver
34
+
35
+ def initialize(name:, operations_path: nil)
36
+ @name = name
37
+ @started = false
38
+ @agent = build_agent
39
+ @receiver = build_receiver(operations_path)
40
+ end
41
+
42
+ def rum_path = "/#{name}#{RUM_PATH}"
43
+
44
+ # The content of the <meta> the spa reads, with the development defaults of the telemetry plugin.
45
+ def meta
46
+ JSON.generate(endpoint: rum_path, sample: Boto::Telemetry::Options::DEVELOPMENT_SAMPLE,
47
+ traceSample: Boto::Telemetry::Options::DEFAULT_TRACE_SAMPLE)
48
+ end
49
+
50
+ def start
51
+ return if @started
52
+
53
+ @started = true
54
+ @agent.start
55
+ end
56
+
57
+ def stop
58
+ return unless @started
59
+
60
+ @started = false
61
+ @agent.stop
62
+ end
63
+
64
+ def flush = @agent.flush
65
+
66
+ private
67
+
68
+ # No server routes: the agent only carries the browser series of this spa.
69
+ def build_agent
70
+ Boto::Telemetry::Agent.new(
71
+ service: name, routes: [], sampler: Boto::Telemetry::Tracing::Sampler.new(sample: 0.0, slow: SLOW),
72
+ delivery: Boto::Telemetry::Delivery::Destination.new(env: {}, env_name: DEVELOPMENT).build, project_dir: "",
73
+ boto_version: Boto::VERSION, pool: Boto::Telemetry::Metrics::DatabasePool.new(nil),
74
+ browser_routes: Boto::Telemetry::Options::DEFAULT_ROUTES
75
+ )
76
+ end
77
+
78
+ def build_receiver(operations_path)
79
+ Boto::Telemetry::Browser::Receiver.new(
80
+ collector: @agent.browser, operations: Boto::Telemetry::Browser::Operations.read(operations_path),
81
+ filter: Boto::Telemetry::Filter.new, client_ip: Boto::ClientIp.new,
82
+ limiter: Boto::Telemetry::Browser::RateWindow.new(limit: RUM_LIMIT, period: RUM_PERIOD)
83
+ )
84
+ end
85
+ end
86
+ end
87
+ end
@@ -0,0 +1,57 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Boto
4
+ module ManagementUi
5
+ # The mount table of the run's first gateway: one entry per service or frontend it mounts.
6
+ class GatewayView
7
+ Entry = Data.define(:prefix, :kind, :target, :port, :address, :health)
8
+
9
+ SERVICE_KIND = :service
10
+ SPA_KIND = :spa
11
+
12
+ # frontend_check: asks a frontend's port whether it answers (HealthProbe.frontend by default).
13
+ def initialize(context, frontend_check: HealthProbe.method(:frontend))
14
+ @context = context
15
+ @frontend_check = frontend_check
16
+ end
17
+
18
+ # The address of a path behind a gateway (or of a service's own port, with no prefix).
19
+ def self.address(host, port, path = "") = "http://#{host}:#{port}#{path}"
20
+
21
+ # [name, prefix, app] of the mounts the gateway plugin of an app holds; [] when the app has no gateway plugin.
22
+ def self.mounts(app)
23
+ plugin = AppTraits.gateway_plugin(app)
24
+ plugin ? plugin.mounts.entries : []
25
+ end
26
+
27
+ # nil without a gateway: the panel has no Gateway tab then.
28
+ def entries
29
+ gateway = @context.gateways.keys.first
30
+ return nil unless gateway
31
+
32
+ self.class.mounts(@context.apps.fetch(gateway)).map do |target, prefix, app|
33
+ entry(gateway, target, prefix, app)
34
+ end
35
+ end
36
+
37
+ private
38
+
39
+ def entry(gateway, target, prefix, app)
40
+ port = @context.ports[target]
41
+ Entry.new(prefix: prefix, kind: kind(app), target: target, port: port,
42
+ address: self.class.address(@context.host, @context.ports[gateway], prefix),
43
+ health: health(app, port))
44
+ end
45
+
46
+ def kind(app)
47
+ app.respond_to?(:frontend?) && app.frontend? ? SPA_KIND : SERVICE_KIND
48
+ end
49
+
50
+ def health(app, port)
51
+ return @frontend_check.call(port) if kind(app) == SPA_KIND
52
+
53
+ HealthProbe.check(app, host: @context.host)
54
+ end
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,70 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "net/http"
4
+ require "rack/mock_request"
5
+
6
+ module Boto
7
+ module ManagementUi
8
+ # Runs a service's own readiness probe in this process, so the panel shows what /health/ready says.
9
+ module HealthProbe
10
+ Result = Data.define(:status, :detail)
11
+
12
+ PROBE_PATH = "/health/ready"
13
+ HEALTH_PLUGIN = :health
14
+ OK = 200
15
+ DETAIL_LIMIT = 200
16
+ READY = :ready
17
+ FAILING = :failing
18
+ NONE = :none
19
+ UNKNOWN = :unknown
20
+ LOOPBACK = "127.0.0.1"
21
+ VITE_TIMEOUT = 1
22
+ UNREACHABLE = [SystemCallError, SocketError, Timeout::Error, IOError].freeze
23
+
24
+ module_function
25
+
26
+ def check(app, host: nil)
27
+ return Result.new(status: NONE, detail: nil) unless app.plugins.any? { |plugin| health_plugin?(plugin) }
28
+
29
+ probe(app, host)
30
+ rescue StandardError => error
31
+ failing("#{error.class}: #{error.message}")
32
+ end
33
+
34
+ def probe(app, host)
35
+ env = Rack::MockRequest.env_for(PROBE_PATH)
36
+ env["HTTP_HOST"] = host if host
37
+ status, _headers, body = app.call(env)
38
+ return Result.new(status: READY, detail: nil) if status == OK
39
+
40
+ failing(read_body(body))
41
+ end
42
+
43
+ # A frontend answers for itself (Vite): any HTTP answer is up, no answer is unknown, not failing.
44
+ def frontend(port)
45
+ Net::HTTP.start(LOOPBACK, port, open_timeout: VITE_TIMEOUT, read_timeout: VITE_TIMEOUT) do |http|
46
+ http.head("/")
47
+ end
48
+ Result.new(status: READY, detail: nil)
49
+ rescue *UNREACHABLE
50
+ Result.new(status: UNKNOWN, detail: nil)
51
+ end
52
+
53
+ def health_plugin?(plugin)
54
+ plugin.class.plugin_name == HEALTH_PLUGIN
55
+ end
56
+
57
+ def failing(detail)
58
+ Result.new(status: FAILING, detail: detail)
59
+ end
60
+
61
+ def read_body(body)
62
+ text = +""
63
+ body.each { |chunk| text << chunk }
64
+ text[0, DETAIL_LIMIT]
65
+ ensure
66
+ body.close if body.respond_to?(:close)
67
+ end
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Boto
4
+ module ManagementUi
5
+ # Receives the batches the agent hands over in development, without HTTP. It checks them like the ingest does,
6
+ # so the store only ever gets a validated batch.
7
+ class InProcessReceiver
8
+ def initialize(store:)
9
+ @store = store
10
+ end
11
+
12
+ def ingest(batch, received_at:)
13
+ @store.ingest(Boto::ManagementUi::Monitor::BatchSchema.validate(batch), received_at:)
14
+ end
15
+ end
16
+ end
17
+ end