/* Urutau - page SLO ("Services"): one card per backend service with its SLI, error budget, Apdex, p95 latency and traffic; latency bands (total, origin, proxy) and a profile radar. Data: /api/v1/services. Log data is hostile: textContent only. */ (function () { 'use strict'; var U = window.Urutau; if (!U || !U.registerPage) return; var el = U.el, t = U.t; U.registerI18n({ en: { 'hl.sl.title': 'Services', 'hl.sl.lead': '{n} services, {ok} within their objective', 'hl.sl.lead.body': 'Objective: 99.5% of legitimate requests without an application or proxy error. {worst} has the least budget left ({budget}) {range}.', 'hl.sl.lead.body.all': 'Objective: 99.5% of legitimate requests without an application or proxy error, {range}.', 'hl.sl.lead.empty': 'No services seen yet', 'hl.sl.lead.empty.body': 'No Traefik requests with service data {range}.', 'hl.sl.cards': 'Service health', 'hl.sl.cards.hint': 'SLI is the share of legitimate requests answered without an application or proxy error.', 'hl.sl.sli': 'SLI', 'hl.sl.budget': 'Budget left', 'hl.sl.apdex': 'Apdex', 'hl.sl.p95': 'p95', 'hl.sl.rps': 'peak req/s', 'hl.sl.burn': 'Burn 1h', 'hl.sl.req': '{n} requests', 'hl.sl.bands': 'Latency bands', 'hl.sl.bands.hint': 'p50, p95 and p99 of the total time, the backend time and the proxy overhead (ms), for the busiest services.', 'hl.sl.band.total': 'Total', 'hl.sl.band.origin': 'Backend', 'hl.sl.band.overhead': 'Proxy', 'hl.sl.radar': 'Profile', 'hl.sl.radar.hint': 'Each axis is scaled to the best service: availability, Apdex, speed (p95), retries and traffic.', 'hl.sl.ax.avail': 'Availability', 'hl.sl.ax.apdex': 'Apdex', 'hl.sl.ax.speed': 'Speed', 'hl.sl.ax.retry': 'No retries', 'hl.sl.ax.traffic': 'Traffic', 'hl.sl.err': 'Could not load the services.', 'hl.sl.retry': 'Try again', 'hl.sl.empty': 'Nothing to show for this range.' }, 'pt-BR': { 'hl.sl.title': 'Serviços', 'hl.sl.lead': '{n} serviços, {ok} dentro do objetivo', 'hl.sl.lead.body': 'Objetivo: 99,5% das requisições legítimas sem erro de aplicação ou de proxy. {worst} tem o menor orçamento restante ({budget}) {range}.', 'hl.sl.lead.body.all': 'Objetivo: 99,5% das requisições legítimas sem erro de aplicação ou de proxy, {range}.', 'hl.sl.lead.empty': 'Nenhum serviço visto ainda', 'hl.sl.lead.empty.body': 'Nenhuma requisição do Traefik com dados de serviço {range}.', 'hl.sl.cards': 'Saúde dos serviços', 'hl.sl.cards.hint': 'O SLI é a parcela das requisições legítimas respondidas sem erro de aplicação ou de proxy.', 'hl.sl.sli': 'SLI', 'hl.sl.budget': 'Orçamento restante', 'hl.sl.apdex': 'Apdex', 'hl.sl.p95': 'p95', 'hl.sl.rps': 'pico req/s', 'hl.sl.burn': 'Consumo 1h', 'hl.sl.req': '{n} requisições', 'hl.sl.bands': 'Faixas de latência', 'hl.sl.bands.hint': 'p50, p95 e p99 do tempo total, do tempo no backend e da sobrecarga do proxy (ms), nos serviços mais ocupados.', 'hl.sl.band.total': 'Total', 'hl.sl.band.origin': 'Backend', 'hl.sl.band.overhead': 'Proxy', 'hl.sl.radar': 'Perfil', 'hl.sl.radar.hint': 'Cada eixo é relativo ao melhor serviço: disponibilidade, Apdex, rapidez (p95), retentativas e tráfego.', 'hl.sl.ax.avail': 'Disponibilidade', 'hl.sl.ax.apdex': 'Apdex', 'hl.sl.ax.speed': 'Rapidez', 'hl.sl.ax.retry': 'Sem retentativas', 'hl.sl.ax.traffic': 'Tráfego', 'hl.sl.err': 'Não foi possível carregar os serviços.', 'hl.sl.retry': 'Tentar de novo', 'hl.sl.empty': 'Nada para mostrar neste período.' } }); function clear(n) { while (n.firstChild) n.removeChild(n.firstChild); } function ms(v) { return v >= 1000 ? (v / 1000).toFixed(v >= 10000 ? 0 : 1) + ' s' : (v >= 10 ? Math.round(v) : v.toFixed(1)) + ' ms'; } function pct1(v) { return (v * 100).toFixed(v >= 0.9995 ? 2 : 1) + '%'; } function tone(s) { return s.budget_left <= 0.1 || s.burn_1h >= 6 ? 'danger' : s.budget_left <= 0.5 || s.burn_1h >= 2 ? 'warn' : 'ok'; } function card(s) { var tn = tone(s); var spark = U.charts && U.charts.sparkline && s.spark && s.spark.length > 1 ? U.charts.sparkline(s.spark) : null; var stat = function (label, value, key) { var l = el('span', { class: 'hl-sl' }, label); if (key && U.help && U.glossary && U.glossary.has(key)) U.help(l, key); return el('div', { class: 'hl-st' }, el('span', { class: 'hl-sv num' }, value), l); }; return el('article', { class: 'hl-card tone-' + tn }, el('header', null, el('h3', { class: 'hl-name' }, s.alias), el('span', { class: 'hl-svc mono' }, s.svc)), el('div', { class: 'hl-big num' }, pct1(s.sli), el('small', null, t('hl.sl.sli'))), el('div', { class: 'hl-bar', role: 'img', 'aria-label': t('hl.sl.budget') + ' ' + U.fmt.pct(s.budget_left) }, el('i', { style: { width: Math.round(s.budget_left * 100) + '%' } })), el('div', { class: 'hl-stats' }, stat(t('hl.sl.budget'), U.fmt.pct(s.budget_left), 'term.error_budget'), stat(t('hl.sl.apdex'), s.apdex.toFixed(2), 'term.apdex'), stat(t('hl.sl.p95'), ms(s.p95.total)), stat(t('hl.sl.rps'), s.rps_peak.toFixed(2))), spark ? el('div', { class: 'hl-spark' }, spark) : null, el('footer', null, t('hl.sl.req', { n: U.fmt.num(s.req) }))); } var inst = null; function create(root, ctx) { var seq = 0, alive = true, data = null, c = ctx; var grid = el('div', { class: 'grid-12 hl-page' }); var lead = el('div', { class: 'span-12' }); var pc = U.ui.panel({ title: t('hl.sl.cards'), hint: t('hl.sl.cards.hint'), loading: true, cls: 'span-12' }); var pb = U.ui.panel({ title: t('hl.sl.bands'), hint: t('hl.sl.bands.hint'), variant: 'chart', loading: true, cls: 'span-8' }); var pr = U.ui.panel({ title: t('hl.sl.radar'), hint: t('hl.sl.radar.hint'), variant: 'chart', loading: true, cls: 'span-4' }); [lead, pc, pb, pr].forEach(function (n) { grid.appendChild(n); }); root.appendChild(grid); function bands(list) { var box = el('div', { class: 'hl-bands' }); var mx = 0; list.slice(0, 8).forEach(function (s) { ['p50', 'p95', 'p99'].forEach(function (q) { ['total', 'origin', 'overhead'].forEach(function (k) { if (s[q][k] > mx) mx = s[q][k]; }); }); }); list.slice(0, 8).forEach(function (s) { var g = el('div', { class: 'hl-bgrp' }, el('h4', null, s.alias)); ['p50', 'p95', 'p99'].forEach(function (q) { var v = s[q]; var line = el('div', { class: 'hl-brow' }, el('span', { class: 'hl-bq' }, q)); [['total', 'hl.sl.band.total', '--viz-1'], ['origin', 'hl.sl.band.origin', '--viz-3'], ['overhead', 'hl.sl.band.overhead', '--viz-5']].forEach(function (p) { var w = mx ? Math.max(v[p[0]] > 0 ? 1.5 : 0, v[p[0]] / mx * 100) : 0; var i = el('i', { style: { width: w + '%', background: 'var(' + p[2] + ')' } }); i.title = t(p[1]) + ' ' + ms(v[p[0]]); line.appendChild(el('span', { class: 'hl-btrack' }, i, el('b', { class: 'num' }, ms(v[p[0]])))); }); g.appendChild(line); }); box.appendChild(g); }); var lg = el('div', { class: 'hl-legend' }); [['hl.sl.band.total', '--viz-1'], ['hl.sl.band.origin', '--viz-3'], ['hl.sl.band.overhead', '--viz-5']].forEach(function (p) { lg.appendChild(el('span', null, el('i', { style: { background: 'var(' + p[1] + ')' } }), t(p[0]))); }); box.appendChild(lg); return box; } function radar(list) { var top = list.slice(0, 5); if (!(U.charts && U.charts.radar) || top.length < 1) return U.ui.empty(t('hl.sl.empty')); var maxReq = 0, minP = Infinity; top.forEach(function (s) { if (s.req > maxReq) maxReq = s.req; if (s.p95.total > 0 && s.p95.total < minP) minP = s.p95.total; }); var axes = [{ key: 'avail', label: t('hl.sl.ax.avail') }, { key: 'apdex', label: t('hl.sl.ax.apdex') }, { key: 'speed', label: t('hl.sl.ax.speed') }, { key: 'retry', label: t('hl.sl.ax.retry') }, { key: 'traffic', label: t('hl.sl.ax.traffic') }]; var series = top.map(function (s) { return { label: s.alias, values: [s.sli * 100, s.apdex * 100, s.p95.total > 0 ? Math.min(100, minP / s.p95.total * 100) : 100, Math.max(0, 100 - s.retries_pct * 10), maxReq ? s.req / maxReq * 100 : 0] }; }); return U.charts.radar(axes, series, { max: 100, title: t('hl.sl.radar'), format: function (v) { return Math.round(v) + ''; } }); } function paint() { clear(lead); [pc, pb, pr].forEach(function (p) { clear(p.body); }); if (!data) return; var range = U.rangeLabel({ inline: true }); if (!data.length) { lead.appendChild(U.ui.lead(t('hl.sl.lead.empty'), t('hl.sl.lead.empty.body', { range: range }), 'neutral')); [pc, pb, pr].forEach(function (p) { p.body.appendChild(U.ui.empty(t('hl.sl.empty'))); }); return; } var ok = data.filter(function (s) { return s.budget_left > 0; }).length; var worst = data.slice().sort(function (a, b) { return a.budget_left - b.budget_left; })[0]; lead.appendChild(U.ui.lead(t('hl.sl.lead', { n: data.length, ok: ok }), worst.budget_left >= 1 ? t('hl.sl.lead.body.all', { range: range }) : t('hl.sl.lead.body', { worst: worst.alias, budget: U.fmt.pct(worst.budget_left), range: range }), ok === data.length ? 'ok' : 'warn')); var cards = el('div', { class: 'hl-cards' }); data.forEach(function (s) { cards.appendChild(card(s)); }); pc.body.appendChild(cards); pb.body.appendChild(bands(data)); pr.body.appendChild(radar(data)); } function load() { var my = ++seq; var p = Object.assign({}, U.rangeParams()); if (c.domain && c.domain !== 'all') p.host = c.domain; U.api('/api/v1/services', p).then(function (r) { if (alive && my === seq) { data = r || []; paint(); } }, function () { if (!alive || my !== seq || data) return; clear(lead); var b = el('button', { type: 'button', class: 'btn' }, t('hl.sl.retry')); b.addEventListener('click', load); lead.appendChild(el('div', { class: 'state-error' }, el('strong', null, t('hl.sl.err')), b)); }); } load(); return { update: function (cx) { c = cx; load(); }, destroy: function () { alive = false; seq++; clear(root); } }; } U.registerPage({ id: 'slo', group: 'monitor', titleKey: 'hl.sl.title', icon: '', mount: function (node, ctx) { if (inst) inst.destroy(); inst = create(node, ctx || {}); }, update: function (ctx) { if (inst) inst.update(ctx); }, unmount: function () { if (inst) { inst.destroy(); inst = null; } } }); })();