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,70 @@
1
+ var DEFAULT_PERIOD = "1h";
2
+ var DEFAULT_SUB = "routes";
3
+ var MINUTE_STEP = 60;
4
+ var WARN_SHARE = 90;
5
+ var INDENT = 12;
6
+ var MB = 1024 * 1024;
7
+ var GB = 1024 * MB;
8
+ var SVG_NS = "http://www.w3.org/2000/svg";
9
+ var CHART = { width: 300, height: 150, left: 40, right: 6, top: 8, bottom: 18 };
10
+ var SPARK = { width: 90, height: 22 };
11
+ var COLORS = { total: "#cc342d", errors: "#b42318", p50: "#71717a", p95: "#1e40af", p99: "#cc342d", usage: "#1e40af", limit: "#cc342d" };
12
+ var SUB_TABS = [["routes", "Rotas"], ["errors", "Erros"], ["n_plus_one", "N+1"], ["traces", "Traces"], ["runtime", "Runtime"]];
13
+ var SPA_SUB_TABS = [["pages", "Páginas"], ["js_errors", "Erros de JS"], ["apis", "APIs"], ["traces", "Traces"], ["runtime", "Runtime"]];
14
+ var SPA_DEFAULT_SUB = "pages";
15
+ var SPAN_CLASSES = {
16
+ plugin: "span__bar--plugin", operation: "span__bar--op", sql: "span__bar--sql", http: "span__bar--http",
17
+ browser: "span__bar--browser", fetch: "span__bar--http"
18
+ };
19
+ var MS_PER_SECOND = 1000;
20
+ var VITAL_LIMITS = { LCP: 2500, INP: 200 };
21
+ var VITAL_GOOD = { LCP: "2,5 s", INP: "200 ms", CLS: "0,1" };
22
+ var VITAL_CLASSES = { good: "vital--good", needs_improvement: "vital--warn", poor: "vital--poor" };
23
+ var VITAL_TONES = { needs_improvement: "warn", poor: "failing" };
24
+ var RATING_TEXT = { good: "bom", needs_improvement: "precisa melhorar", poor: "ruim" };
25
+ var PAGE_VITALS = ["LCP", "INP", "CLS", "FCP", "TTFB"];
26
+ var PAGE_HEADERS = [["Página"], ["Visualizações", true]].concat(PAGE_VITALS.map(function (name) { return [name, true]; }));
27
+ var API_HEADERS = [["API"], ["Operação"], ["Chamadas", true], ["Navegador p50", true], ["Navegador p95", true],
28
+ ["Navegador p99", true], ["Serviço p95", true], ["Onde vai o p95"], ["Erros", true]];
29
+ // The texts of the ⓘ tips, as the approved design writes them.
30
+ var INFO = {
31
+ views: { label: "Visualizações", title: "Visualizações", text: "quantas vezes uma página do spa foi carregada por segundo no período, estimado a partir das sessões amostradas. Abaixo, o total do período." },
32
+ LCP: { label: "LCP p75", title: "Largest Contentful Paint", text: "tempo até o maior elemento visível da página (uma imagem ou um bloco de texto) aparecer. Mede quando a página parece carregada. O p75 quer dizer que 75% das visualizações foram mais rápidas que esse valor. É uma estimativa feita a partir de faixas de valores: serve para o selo, não como medida exata.", limits: "Bom até 2,5 s · ruim acima de 4 s" },
33
+ INP: { label: "INP p75", title: "Interaction to Next Paint", text: "quanto a página demora para mostrar a resposta a um clique, toque ou tecla, pela interação mais lenta de cada visita. Mede se a página parece travada. O p75 quer dizer que 75% das visualizações responderam mais rápido. É uma estimativa feita a partir de faixas de valores: serve para o selo, não como medida exata.", limits: "Bom até 200 ms · ruim acima de 500 ms" },
34
+ CLS: { label: "CLS p75", title: "Cumulative Layout Shift", text: "quanto o conteúdo pula de lugar sem o visitante pedir, como um botão que desce quando uma imagem carrega. Não tem unidade: quanto menor, mais estável. O p75 quer dizer que 75% das visualizações ficaram abaixo desse valor. É uma estimativa feita a partir de faixas de valores: serve para o selo, não como medida exata.", limits: "Bom até 0,1 · ruim acima de 0,25" },
35
+ errors: { label: "Erros de JS", title: "Erros de JS", text: "parte das visualizações que teve pelo menos um erro de JavaScript não tratado (uma exceção ou uma promessa rejeitada). Os erros, agrupados, ficam na aba Erros de JS." }
36
+ };
37
+ var REASONS = {
38
+ error: ["erro", "badge--error"], slow: ["lento", "badge--slow"], sample: ["amostra", "badge--sample"],
39
+ all: ["todos", "badge--sample"], n_plus_one: ["N+1", "badge--n1"],
40
+ parent: ["pai", "badge--parent"]
41
+ };
42
+ var MIN_REPEATS = 2;
43
+ var MESSAGES = {
44
+ empty: "Ainda não chegou nenhum lote de serviço. Os lotes chegam dos projetos a cada poucos segundos.",
45
+ loading: "Carregando…",
46
+ noService: "Este serviço não enviou lotes.",
47
+ noRequests: "Nenhum request neste período.",
48
+ noErrors: "Nenhum erro de 500 neste período. Os 4xx são respostas, não falhas.",
49
+ noNPlusOne: "Nenhum N+1 guardado para este serviço. Consultas repetidas no mesmo request aparecem aqui.",
50
+ noTraces: "Nenhum trace guardado neste período.",
51
+ traceMissing: "Este trace não ficou guardado: só entram os amostrados, os com erro e os lentos.",
52
+ noInstances: "Nenhuma instância enviou lotes recentemente.",
53
+ noData: "Sem dados neste período.",
54
+ runtime: "Uma linha por instância (a soma dos workers do fork). Uma instância que para de enviar some depois de 2 minutos sem lote.",
55
+ sql: "O SQL aparece com os valores trocados por ?: nenhum dado do usuário sai do serviço.",
56
+ spaColumns: "No spa, as colunas são do servidor que entrega o dist/ (o StaticSite). O que o visitante sente, Web Vitals, erros de JS e chamadas às APIs, fica na visão dele.",
57
+ noJsErrors: "Nenhum erro de JavaScript neste período.",
58
+ jsErrors: "Agrupados por mensagem e arquivo:linha. A mensagem passa pelo filter: do :telemetry (token, senha, e-mail e números longos mascarados). Só a família e a versão maior do navegador são guardadas.",
59
+ noCalls: "Nenhuma chamada de API vista pelo navegador neste período.",
60
+ calls: "Por ref e operationId do cliente gerado; só entram as operações do operations.json que o servidor conhece.",
61
+ failed: "Não foi possível ler o monitor"
62
+ };
63
+ var SERVICE_HEADERS = [["Serviço"], ["Instâncias", true], ["Requests"], ["req/s", true], ["p50", true], ["p95", true], ["p99", true], ["Erros", true], ["CPU"], ["Memória"]];
64
+ var ROUTE_HEADERS = [["Método"], ["Rota"], ["Requests"], ["req/min", true], ["p50", true], ["p95", true], ["p99", true], ["Erros", true]];
65
+ var TRACE_HEADERS = [["Quando"], ["Request"], ["Status", true], ["Duração", true], ["Por que foi guardado"]];
66
+ var N_PLUS_ONE_HEADERS = [["Rota"], ["Consulta"], ["Vezes", true], ["Máx. repetições", true], ["Última vez"], ["Trace"]];
67
+ var STREAM_HEADERS = [["Rota"], ["Abertos", true], ["Retomados", true], ["Recusas"], ["Fechamentos"], ["Eventos", true],
68
+ ["Falhas", true], ["Overflows", true], ["p50", true], ["p95", true]];
69
+ var RUNTIME_HEADERS = [["Instância"], ["Desde"], ["Workers", true], ["CPU"], ["Memória"], ["GC/min", true], ["Pool do banco"], ["Em andamento", true], ["Último lote"]];
70
+
@@ -0,0 +1,70 @@
1
+ var $ = function (selector, scope) { return (scope || document).querySelector(selector); };
2
+ var $$ = function (selector, scope) { return Array.prototype.slice.call((scope || document).querySelectorAll(selector)); };
3
+
4
+ var root = document.getElementById("monitor-view");
5
+ var content = $("[data-content]", root);
6
+ var base = root.dataset.base;
7
+ var production = root.dataset.env === "production";
8
+ // The subtabs each service lists (the panel's tabs); a service without a list keeps every subtab.
9
+ var subtabs = JSON.parse(root.dataset.subtabs || "{}");
10
+ var state = { period: DEFAULT_PERIOD, service: null, sub: DEFAULT_SUB, traceId: null };
11
+ var sequence = 0;
12
+
13
+ // Adds children to a node: strings become text nodes, arrays are flattened, null and false are skipped.
14
+ function append(node, items) {
15
+ (Array.isArray(items) ? items : [items]).forEach(function (item) {
16
+ if (item == null || item === false) return;
17
+ if (Array.isArray(item)) append(node, item);
18
+ else node.appendChild(item instanceof Node ? item : document.createTextNode(String(item)));
19
+ });
20
+ return node;
21
+ }
22
+
23
+ function fill(node, children) {
24
+ node.replaceChildren();
25
+ return append(node, children);
26
+ }
27
+
28
+ function setProp(node, key, value) {
29
+ if (value == null) return;
30
+ if (key === "className") node.className = value;
31
+ else if (key === "onclick") node.addEventListener("click", value);
32
+ else if (key === "hidden") node.hidden = value;
33
+ else node.setAttribute(key, value);
34
+ }
35
+
36
+ function el(tag, props, children) {
37
+ var node = document.createElement(tag);
38
+ Object.keys(props || {}).forEach(function (key) { setProp(node, key, props[key]); });
39
+ return append(node, children);
40
+ }
41
+
42
+ function svg(tag, attrs, children) {
43
+ var node = document.createElementNS(SVG_NS, tag);
44
+ Object.keys(attrs || {}).forEach(function (key) { node.setAttribute(key, attrs[key]); });
45
+ return append(node, children);
46
+ }
47
+
48
+ function note(text) { return el("p", { className: "note" }, text); }
49
+
50
+ function card(title, hint, body) {
51
+ return el("div", { className: "card" }, [
52
+ el("div", { className: "card__head" }, [el("h2", { className: "card__title" }, title), el("span", { className: "muted" }, hint)]),
53
+ body
54
+ ]);
55
+ }
56
+
57
+ function grid(headers, rows, className) {
58
+ var head = el("thead", null, el("tr", null, headers.map(function (header) {
59
+ return el("th", { className: header[1] ? "num" : null }, header[0]);
60
+ })));
61
+ return el("div", { className: "table-wrap" }, el("table", { className: className }, [head, el("tbody", null, rows)]));
62
+ }
63
+
64
+ function row(cells, onclick, selected) {
65
+ var classes = [onclick ? "clickable" : "", selected ? "selected" : ""].join(" ").trim();
66
+ return el("tr", { className: classes, onclick: onclick }, cells);
67
+ }
68
+
69
+ function cell(content, className) { return el("td", { className: className }, content); }
70
+
@@ -0,0 +1,76 @@
1
+ // Formatting: pt-BR numbers, and "—" for a value the store did not have.
2
+ function fmt(value, digits) {
3
+ return value == null ? "—" : value.toLocaleString("pt-BR", { maximumFractionDigits: digits });
4
+ }
5
+
6
+ function msValue(seconds) { return seconds == null ? "—" : fmt(seconds * 1000, 0); }
7
+
8
+ function ms(seconds) { return seconds == null ? "—" : msValue(seconds) + " ms"; }
9
+
10
+ function percent(rate) { return rate == null ? "—" : fmt(rate * 100, 1) + "%"; }
11
+
12
+ function errorClass(rate, base) { return rate > 0 ? base + " err" : base; }
13
+
14
+ function memory(bytes) {
15
+ if (bytes == null) return "—";
16
+ return bytes >= GB ? fmt(bytes / GB, 1) + " GB" : fmt(bytes / MB, 0) + " MB";
17
+ }
18
+
19
+ function cpuValue(cores) { return fmt(cores, 2); }
20
+
21
+ function plural(count, word) { return count + " " + (count === 1 ? word : word + "s"); }
22
+
23
+ function clock(iso) { return new Date(iso).toLocaleTimeString("pt-BR", { hour: "2-digit", minute: "2-digit" }); }
24
+
25
+ var AGO_UNITS = [[86400, "d"], [3600, "h"], [60, "min"]];
26
+
27
+ function ago(iso) {
28
+ if (!iso) return "—";
29
+ var seconds = Math.max(0, Math.round((Date.now() - Date.parse(iso)) / 1000));
30
+ var unit = AGO_UNITS.find(function (entry) { return seconds >= entry[0]; });
31
+ return unit ? "há " + Math.floor(seconds / unit[0]) + " " + unit[1] : "há " + seconds + " s";
32
+ }
33
+
34
+ function shortId(traceId) { return traceId.slice(0, 8) + "…" + traceId.slice(-4); }
35
+
36
+ // A trace that starts in the browser has no verb: it begins at the page, not at a request.
37
+ function verbBadge(verb) {
38
+ if (!verb) return null;
39
+ return el("span", { className: "verb verb--" + verb.toLowerCase() }, verb);
40
+ }
41
+
42
+ function statusBadge(code) {
43
+ return el("span", { className: "status status--" + String(code).charAt(0) }, String(code));
44
+ }
45
+
46
+ function reasonBadge(reason) {
47
+ var entry = REASONS[reason] || [reason, "badge--sample"];
48
+ return el("span", { className: "badge " + entry[1] }, entry[0]);
49
+ }
50
+
51
+ // Usage text: "used / limit", or only "used" when the container has no limit.
52
+ function usageText(used, limit, format) {
53
+ if (used == null) return "—";
54
+ return limit == null ? format(used) : format(used) + " / " + format(limit);
55
+ }
56
+
57
+ function meter(used, limit) {
58
+ var share = Math.min(100, used / limit * 100);
59
+ return el("span", { className: "meter" + (share >= WARN_SHARE ? " meter--warn" : "") }, el("i", { style: "width:" + share + "%" }));
60
+ }
61
+
62
+ function usageCell(used, limit, format) {
63
+ var text = usageText(used, limit, format);
64
+ return used == null || !limit ? text : el("span", null, [meter(used, limit), text]);
65
+ }
66
+
67
+ function spark(values) {
68
+ var max = Math.max.apply(null, [1].concat(values));
69
+ var step = values.length > 1 ? SPARK.width / (values.length - 1) : 0;
70
+ var points = values.map(function (value, i) {
71
+ return (i * step).toFixed(1) + "," + (SPARK.height - 1 - value / max * (SPARK.height - 2)).toFixed(1);
72
+ }).join(" ");
73
+ return svg("svg", { "class": "spark", viewBox: "0 0 " + SPARK.width + " " + SPARK.height },
74
+ svg("polyline", { points: points, fill: "none", stroke: COLORS.total, "stroke-width": 1.6 }));
75
+ }
76
+
@@ -0,0 +1,2 @@
1
+ // Behaviour of the /_boto panel: the Serviços and Monitor tabs, and the monitor's JSON api under data-base.
2
+ // Data never reaches innerHTML: nodes are built with createTextNode, and the charts are SVG built with setAttribute.
@@ -0,0 +1,33 @@
1
+ // ---------- Tabs and period ----------
2
+
3
+ function showMainTab(name) {
4
+ $$("[data-main]").forEach(function (tab) { tab.setAttribute("aria-selected", String(tab.dataset.main === name)); });
5
+ $("#services-view").hidden = name !== "services";
6
+ var gatewayView = $("#gateway-view");
7
+ if (gatewayView) gatewayView.hidden = name !== "gateway";
8
+ root.hidden = name !== "monitor";
9
+ if (name === "monitor") refresh();
10
+ }
11
+
12
+ function refresh() {
13
+ // A panel without the monitor (no :telemetry in the run) keeps its section hidden: nothing to load.
14
+ if (root.hidden) return;
15
+ if (state.service) openService(state.service, state.sub);
16
+ else openSolution();
17
+ }
18
+
19
+ $$("[data-main]").forEach(function (tab) {
20
+ tab.addEventListener("click", function () { showMainTab(tab.dataset.main); });
21
+ });
22
+
23
+ $$("[data-period]", root).forEach(function (button) {
24
+ button.addEventListener("click", function () {
25
+ state.period = button.dataset.period;
26
+ $$("[data-period]", root).forEach(function (other) { other.setAttribute("aria-pressed", String(other === button)); });
27
+ refresh();
28
+ });
29
+ });
30
+
31
+ window.addEventListener("resize", function () { drawAll(content); });
32
+
33
+ refresh();
@@ -0,0 +1,109 @@
1
+ function routesPane() {
2
+ var paths = ["/routes.json", "/charts.json", "/streams.json"];
3
+ return Promise.all(paths.map(function (path) { return load(servicePath() + path); })).then(function (results) {
4
+ var routes = results[0].routes;
5
+ var nodes = [chartsRow([requestsChart(results[1]), latencyChart(results[1])]),
6
+ routes.length ? grid(ROUTE_HEADERS, routes.map(routeRow), null) : note(MESSAGES.noRequests)];
7
+ return results[2].routes.length ? nodes.concat(streamsSection(results[2])) : nodes;
8
+ });
9
+ }
10
+
11
+ // Only shown when the service had streams in the period: under the route list, with the open ones of now.
12
+ function streamsSection(data) {
13
+ return [
14
+ el("h3", { className: "streams__title" }, "Streams"),
15
+ el("p", { className: "muted" }, fmt(data.open, 0) + " abertos agora"),
16
+ grid(STREAM_HEADERS, data.routes.map(streamRow), null)
17
+ ];
18
+ }
19
+
20
+ function streamRow(stream) {
21
+ return row([
22
+ cell(stream.route, "route-path"),
23
+ cell(fmt(stream.opened, 0), "num"),
24
+ cell(fmt(stream.resumed, 0), "num"),
25
+ cell(reasonsText(stream.rejected)),
26
+ cell(reasonsText(stream.closed)),
27
+ cell(fmt(stream.events_sent, 0), "num"),
28
+ cell(fmt(stream.serialization_failures + stream.write_failures, 0), "num"),
29
+ cell(fmt(stream.overflows, 0), "num"),
30
+ cell(ms(stream.duration.p50), "num"),
31
+ cell(ms(stream.duration.p95), "num")
32
+ ]);
33
+ }
34
+
35
+ // The reasons with a count, as "draining 2 · client 1"; "—" when none.
36
+ function reasonsText(counts) {
37
+ var parts = Object.keys(counts).filter(function (reason) { return counts[reason] > 0; })
38
+ .map(function (reason) { return reason + " " + counts[reason]; });
39
+ return parts.length ? parts.join(" · ") : "—";
40
+ }
41
+
42
+ function routeRow(route) {
43
+ var unmatched = route.route == null;
44
+ var flag = route.n_plus_one ? el("span", { className: "badge badge--n1", title: "Consultas repetidas num request" }, "N+1") : null;
45
+ var streamFlag = route.streams ? el("span", { className: "badge badge--stream", title: "Conexões SSE no período" }, "stream") : null;
46
+ return row([
47
+ cell(unmatched ? "—" : verbBadge(route.verb)),
48
+ cell(unmatched ? "sem rota (404 e 405)" : [route.route, flag, streamFlag], "route-path"),
49
+ cell(spark(route.spark)),
50
+ cell(fmt(route.requests_per_minute, 0), "num"),
51
+ cell(ms(route.latency.p50), "num"),
52
+ cell(ms(route.latency.p95), "num"),
53
+ cell(ms(route.latency.p99), "num"),
54
+ cell(percent(route.error_rate), errorClass(route.error_rate, "num"))
55
+ ]);
56
+ }
57
+
58
+ function errorsPane() {
59
+ return load(servicePath() + "/errors.json").then(function (data) {
60
+ return data.errors.length ? data.errors.map(errorRow) : note(MESSAGES.noErrors);
61
+ });
62
+ }
63
+
64
+ function nPlusOnePane() {
65
+ return load(servicePath() + "/n_plus_ones.json").then(function (data) {
66
+ return data.n_plus_ones.length ? grid(N_PLUS_ONE_HEADERS, data.n_plus_ones.map(nPlusOneRow), null) : note(MESSAGES.noNPlusOne);
67
+ });
68
+ }
69
+
70
+ function nPlusOneRow(group) {
71
+ return row([
72
+ cell(routeOf(group)),
73
+ cell(el("span", { className: "sql" }, group.sql)),
74
+ cell(fmt(group.count, 0), "num"),
75
+ cell(fmt(group.max_repeats, 0), "num"),
76
+ cell(ago(group.last_at), "muted"),
77
+ cell(traceLink(group.trace_id))
78
+ ]);
79
+ }
80
+
81
+ function errorRow(error) {
82
+ return el("div", { className: "error-row" }, [
83
+ el("div", null, [
84
+ el("span", { className: "error-class" }, error.class),
85
+ el("div", { className: "error-msg" }, error.message),
86
+ el("div", { className: "error-meta" }, [
87
+ error.location || "—", " · ", routeOf(error), " · primeira vez ", ago(error.first_at),
88
+ " · última ", ago(error.last_at), " ", traceLink(error.trace_id)
89
+ ])
90
+ ]),
91
+ occurrences(error.count),
92
+ error.backtrace.length ? el("pre", { className: "backtrace" }, error.backtrace.join("\n")) : null
93
+ ]);
94
+ }
95
+
96
+ function occurrences(count) {
97
+ return el("div", { className: "error-count" }, [fmt(count, 0), el("small", null, count === 1 ? "ocorrência" : "ocorrências")]);
98
+ }
99
+
100
+ function routeOf(error) {
101
+ if (!error.verb || !error.route) return "—";
102
+ return [verbBadge(error.verb), " ", el("span", { className: "route-path" }, error.route)];
103
+ }
104
+
105
+ function traceLink(traceId) {
106
+ if (!traceId) return null;
107
+ return el("button", { type: "button", className: "link", onclick: function () { openTrace(traceId); } }, "ver trace");
108
+ }
109
+
@@ -0,0 +1,26 @@
1
+ function runtimePane() {
2
+ return Promise.all([load(servicePath() + "/runtime.json"), load(servicePath() + "/charts.json")]).then(function (pair) {
3
+ var instances = pair[0].instances;
4
+ var charts = pair[1];
5
+ return [
6
+ instances.length ? grid(RUNTIME_HEADERS, instances.map(instanceRow), "compact") : note(MESSAGES.noInstances),
7
+ chartsRow([usageChart("CPU do serviço", charts.cpu, charts.step, cpuValue), usageChart("Memória do serviço", charts.memory, charts.step, memory)]),
8
+ note(MESSAGES.runtime)
9
+ ];
10
+ });
11
+ }
12
+
13
+ function instanceRow(info) {
14
+ return row([
15
+ cell(el("span", { className: "route-path" }, info.instance)),
16
+ cell(ago(info.started_at), "muted"),
17
+ cell(fmt(info.workers, 0), "num"),
18
+ cell(usageCell(info.cores, info.cpu_limit, cpuValue)),
19
+ cell(usageCell(info.memory, info.memory_limit, memory)),
20
+ cell(fmt(info.gc_per_minute, 0), "num"),
21
+ cell(info.pool ? usageCell(info.pool.in_use, info.pool.size, function (value) { return fmt(value, 0); }) : "—"),
22
+ cell(fmt(info.in_flight, 0), "num"),
23
+ cell(ago(info.last_batch_at), "muted")
24
+ ]);
25
+ }
26
+
@@ -0,0 +1,174 @@
1
+ // ---------- Solution overview ----------
2
+
3
+ function openSolution() {
4
+ state.service = null;
5
+ $("#view-title", root).textContent = "Solution";
6
+ show(Promise.all([load("/solution.json"), load("/services.json")]), function (pair) {
7
+ renderSolution(pair[0], pair[1].services);
8
+ });
9
+ }
10
+
11
+ function renderSolution(solution, services) {
12
+ fillSource(solution);
13
+ fill(content, services.length ? [summary(solution), servicesCard(services)] : note(MESSAGES.empty));
14
+ drawAll(content);
15
+ }
16
+
17
+ // tone: "failing" (red), "warn" (amber) or nothing.
18
+ function stat(label, value, unit, delta, tone) {
19
+ return el("div", { className: "stat" }, [
20
+ el("div", { className: "stat__label" }, label),
21
+ el("div", { className: "stat__value" + (tone ? " stat__value--" + tone : "") }, [value, unit ? el("small", null, unit) : null]),
22
+ el("div", { className: "stat__delta" }, delta)
23
+ ]);
24
+ }
25
+
26
+ // Only request and error numbers: CPU and memory belong to each service, not to the solution.
27
+ function summary(solution) {
28
+ var rate = solution.error_rate;
29
+ return el("section", { className: "summary", "aria-label": "Resumo" }, [
30
+ stat("Requests", fmt(solution.requests_per_second, 1), "req/s", fmt(solution.requests, 0) + " requests no período"),
31
+ stat("Latência p95", msValue(solution.latency.p95), "ms", "p50 " + ms(solution.latency.p50) + " · p99 " + ms(solution.latency.p99)),
32
+ stat("Erros (5xx)", rate == null ? "—" : fmt(rate * 100, 1), "%", "sobre os requests do período", rate > 0 ? "failing" : null),
33
+ stat("Em andamento", fmt(solution.in_flight, 0), null, "soma das instâncias, agora")
34
+ ]);
35
+ }
36
+
37
+ function servicesCard(services) {
38
+ var hasSpa = services.some(isSpa);
39
+ return card("Serviços", "clique num serviço para ver as rotas, os erros, os traces e o runtime", [
40
+ grid(SERVICE_HEADERS, services.map(serviceRow), "compact"),
41
+ hasSpa ? el("p", { className: "callout" }, MESSAGES.spaColumns) : null
42
+ ]);
43
+ }
44
+
45
+ function serviceRow(service) {
46
+ return row([
47
+ cell([el("strong", null, service.name), kindBadge(service)]),
48
+ cell(service.instances, "num"),
49
+ cell(spark(service.spark)),
50
+ cell(fmt(service.requests_per_second, 1), "num"),
51
+ cell(ms(service.latency.p50), "num"),
52
+ cell(ms(service.latency.p95), "num"),
53
+ cell(ms(service.latency.p99), "num"),
54
+ cell(percent(service.error_rate), errorClass(service.error_rate, "num")),
55
+ cell(usageCell(service.cpu, service.cpu_limit, cpuValue)),
56
+ cell(usageCell(service.memory, service.memory_limit, memory))
57
+ ], function () { openService(service.name); });
58
+ }
59
+
60
+ // ---------- One service ----------
61
+
62
+ function openService(name, sub) {
63
+ if (name !== state.service) state.traceId = null;
64
+ state.service = name;
65
+ state.sub = sub || null;
66
+ $("#view-title", root).textContent = "Solution · " + name;
67
+ show(loadService(name), function (loaded) {
68
+ renderService(loaded.service, loaded.counts, loaded.pages);
69
+ });
70
+ }
71
+
72
+ function openTrace(traceId) {
73
+ state.traceId = traceId;
74
+ openService(state.service, "traces");
75
+ }
76
+
77
+ // Fetches what the header and the sub tabs need. A spa adds its pages summary and its JS error count.
78
+ function loadService(name) {
79
+ var path = servicePath(name);
80
+ return Promise.all([load("/services.json"), load(path + "/errors.json"), load(path + "/n_plus_ones.json")]).then(function (results) {
81
+ var service = results[0].services.find(function (entry) { return entry.name === name; });
82
+ var loaded = {
83
+ service: service, pages: null,
84
+ counts: { errors: results[1].errors.length, n_plus_one: results[2].n_plus_ones.length }
85
+ };
86
+ return service && isSpa(service) ? loadSpaHead(path, loaded) : loaded;
87
+ });
88
+ }
89
+
90
+ function loadSpaHead(path, loaded) {
91
+ return Promise.all([load(path + "/pages.json"), load(path + "/browser_errors.json")]).then(function (pair) {
92
+ loaded.pages = pair[0].summary;
93
+ loaded.counts.js_errors = pair[1].errors.length;
94
+ return loaded;
95
+ });
96
+ }
97
+
98
+ // pages: the summary of a spa's pages, null for the other kinds.
99
+ function renderService(service, counts, pages) {
100
+ if (!service) return fill(content, note(MESSAGES.noService));
101
+ state.sub = state.sub || (isSpa(service) ? SPA_DEFAULT_SUB : DEFAULT_SUB);
102
+ // The default subtab may be one the service does not list: open the first it does.
103
+ var listed = subtabs[service.name];
104
+ if (listed && listed.length && listed.indexOf(state.sub) === -1) state.sub = listed[0];
105
+ fill(content, [el("div", { className: "card" }, [serviceHead(service, pages), subTabs(service, counts), el("div", { className: "pane" })])]);
106
+ return showSub(state.sub);
107
+ }
108
+
109
+ function serviceHead(service, pages) {
110
+ var summaryText = isSpa(service) ? spaSummaryText(pages) : serverSummaryText(service);
111
+ var kind = isSpa(service) ? "spa · " : "";
112
+ return el("div", { className: "service-head" }, [
113
+ el("div", { className: "service-head__identity" }, [
114
+ el("a", { href: "#", className: "back", onclick: function (event) { event.preventDefault(); openSolution(); } }, "← Solution"),
115
+ el("h2", { className: "service-head__name" }, service.name),
116
+ el("span", { className: "muted" }, kind + plural(service.instances, "instância"))
117
+ ]),
118
+ el("div", { className: "muted" }, summaryText)
119
+ ]);
120
+ }
121
+
122
+ function serverSummaryText(service) {
123
+ return [
124
+ fmt(service.requests_per_second, 1) + " req/s",
125
+ "p95 " + ms(service.latency.p95),
126
+ "erros " + percent(service.error_rate),
127
+ "CPU " + usageText(service.cpu, service.cpu_limit, cpuValue),
128
+ "memória " + usageText(service.memory, service.memory_limit, memory)
129
+ ].join(" · ");
130
+ }
131
+
132
+ // Only the subtabs the panel lists for the service (its tabs in services.json); without a list, all of them.
133
+ function listedSubTabs(service, all) {
134
+ var listed = subtabs[service.name];
135
+ return listed ? all.filter(function (tab) { return listed.indexOf(tab[0]) !== -1; }) : all;
136
+ }
137
+
138
+ // counts: the number shown next to a sub tab's name, when it has any (errors, N+1 and a spa's JS errors).
139
+ function subTabs(service, counts) {
140
+ var tabs = listedSubTabs(service, isSpa(service) ? SPA_SUB_TABS : SUB_TABS);
141
+ return el("div", { className: "subtabs", role: "tablist" }, tabs.map(function (tab) {
142
+ var label = [tab[1]];
143
+ if (counts[tab[0]]) label.push(el("span", { className: "count" }, String(counts[tab[0]])));
144
+ return el("button", {
145
+ type: "button", role: "tab", "data-sub": tab[0], "aria-selected": String(tab[0] === state.sub),
146
+ onclick: function () { showSub(tab[0]); }
147
+ }, label);
148
+ }));
149
+ }
150
+
151
+ function showSub(sub) {
152
+ state.sub = sub;
153
+ $$("[data-sub]", content).forEach(function (button) {
154
+ button.setAttribute("aria-selected", String(button.dataset.sub === sub));
155
+ });
156
+ var pane = $(".pane", content);
157
+ fill(pane, note(MESSAGES.loading));
158
+ show(PANES[sub](), function (nodes) {
159
+ fill(pane, nodes);
160
+ drawAll(pane);
161
+ });
162
+ }
163
+
164
+ var PANES = {
165
+ routes: routesPane,
166
+ errors: errorsPane,
167
+ n_plus_one: nPlusOnePane,
168
+ traces: tracesPane,
169
+ runtime: runtimePane,
170
+ pages: pagesPane,
171
+ js_errors: jsErrorsPane,
172
+ apis: apisPane
173
+ };
174
+