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
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 0f2aed0c799baf6303990c4977ebde10a7e8d2536ea4a8b85cc68abcd7a41d9d
4
+ data.tar.gz: 314d72133f21851aa9c462504925dbe9bdf0ca133bedbb86b906c2a4205d6ebe
5
+ SHA512:
6
+ metadata.gz: 2283a2c05c42093fcf930700b56c5e20b36bb096feb6149bfb56338d4170cd7e22242fab9f48a408d9afa919843f33a136c3db609db94c79b096f7682dc1a72a
7
+ data.tar.gz: 69832b6196948bc8d1fef57041f9a11b6796405d0679ebc6f435fdf6a21851c1de2432449fea4e05606af9246cd2c68d8bab8ea83c09f59ee6d3909ed89c148c
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Evo Tech Builder
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,22 @@
1
+ # boto-rb-management-ui
2
+
3
+ The Boto management UI: the panel of a solution's services and the monitor, on
4
+ its own port. It is a companion of `boto run`, so the gem only needs to be in
5
+ the solution's Gemfile.
6
+
7
+ ## Installation
8
+
9
+ ```ruby
10
+ gem "boto-rb-management-ui"
11
+ ```
12
+
13
+ Then run `bin/boto bundle`. With the gem in the bundle, `bin/dev` opens the
14
+ panel at http://127.0.0.1:3900.
15
+
16
+ In production it runs as a service of its own (`boto deploy prepare
17
+ management-ui`), behind Basic auth, with the monitor's database.
18
+
19
+ ## Documentation
20
+
21
+ Options, the production variables and how the panel runs:
22
+ [Running a solution](https://evotechbuilder.github.io/boto-rb/guide/running/).
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ Boto::Migration.define do
4
+ create_table :boto_monitor_instances, timestamps: false do |t|
5
+ t.string :service, size: 128, null: false
6
+ t.string :instance, size: 128, null: false
7
+ t.integer :process, null: false
8
+ t.string :boto_version, size: 32, null: false
9
+ t.time :started_at, null: false
10
+ t.time :last_seen_at, null: false
11
+ t.integer :in_flight, null: false
12
+ t.index %i[service instance process], unique: true
13
+ end
14
+ end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ # One row per minute and label combination. Labels that do not apply to the kind stay null, so the
4
+ # uniqueness is kept by the store inside a transaction (nulls never collide in a unique index).
5
+ Boto::Migration.define do
6
+ create_table :boto_monitor_series, timestamps: false do |t|
7
+ t.string :service, size: 128, null: false
8
+ t.time :minute, null: false
9
+ t.string :kind, size: 16, null: false
10
+ t.string :verb, size: 16
11
+ t.string :route, size: 512
12
+ t.integer :status
13
+ t.string :name, size: 512
14
+ t.string :result, size: 64
15
+ t.integer :count, null: false
16
+ t.float :sum, null: false
17
+ t.text :buckets, null: false
18
+ t.index %i[service minute]
19
+ end
20
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ Boto::Migration.define do
4
+ create_table :boto_monitor_errors, timestamps: false do |t|
5
+ t.string :service, size: 128, null: false
6
+ t.string :fingerprint, size: 600, null: false
7
+ t.string :class_name, size: 256
8
+ t.string :message, size: 1000
9
+ t.string :location, size: 512
10
+ t.string :verb, size: 16
11
+ t.string :route, size: 512
12
+ t.integer :count, null: false
13
+ t.time :first_at, null: false
14
+ t.time :last_at, null: false
15
+ t.text :backtrace, null: false
16
+ t.string :trace_id, size: 32
17
+ t.index %i[service fingerprint], unique: true
18
+ end
19
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ Boto::Migration.define do
4
+ create_table :boto_monitor_traces, timestamps: false do |t|
5
+ t.string :service, size: 128, null: false
6
+ t.string :trace_id, size: 32, null: false
7
+ t.string :parent_id, size: 16
8
+ t.time :received_at, null: false
9
+ t.time :started_at, null: false
10
+ t.string :verb, size: 16
11
+ t.string :route, size: 512
12
+ t.string :path, size: 512
13
+ t.integer :status
14
+ t.float :duration, null: false
15
+ t.string :reason, size: 16, null: false
16
+ t.text :spans, null: false
17
+ t.index %i[service received_at]
18
+ end
19
+ end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Last runtime of each instance in each minute; a batch in the same minute overwrites the row.
4
+ Boto::Migration.define do
5
+ create_table :boto_monitor_runtime, timestamps: false do |t|
6
+ t.string :service, size: 128, null: false
7
+ t.string :instance, size: 128, null: false
8
+ t.integer :process, null: false
9
+ t.time :minute, null: false
10
+ t.float :cpu
11
+ t.bigint :memory
12
+ t.bigint :memory_limit
13
+ t.float :cpu_limit
14
+ t.string :memory_source, size: 64
15
+ t.bigint :gc_count
16
+ t.integer :pool_size
17
+ t.integer :pool_in_use
18
+ t.integer :in_flight
19
+ t.bigint :dropped
20
+ t.index %i[service minute]
21
+ t.index %i[service instance process minute], unique: true
22
+ end
23
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ Boto::Migration.define do
4
+ create_table :boto_monitor_n_plus_ones, timestamps: false do |t|
5
+ t.string :service, size: 128, null: false
6
+ t.string :fingerprint, size: 1530, null: false
7
+ t.string :verb, size: 16
8
+ t.string :route, size: 512
9
+ t.text :sql, null: false
10
+ t.integer :count, null: false
11
+ t.integer :max_repeats, null: false
12
+ t.time :first_at, null: false
13
+ t.time :last_at, null: false
14
+ t.string :trace_id, size: 32
15
+ t.index %i[service fingerprint], unique: true
16
+ end
17
+ end
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Browser data: the series of pages and browser calls get their labels, and the browser errors share the errors
4
+ # table with source "browser". The unique index now has the source, so a server and a browser error with the same
5
+ # fingerprint stay apart. Existing rows get source "server".
6
+ Boto::Migration.define do
7
+ execute "DROP INDEX boto_monitor_errors_service_fingerprint_index"
8
+
9
+ alter_table :boto_monitor_series do |t|
10
+ t.add :metric, :string, size: 16
11
+ t.add :ref, :string, size: 128
12
+ t.add :operation, :string, size: 512
13
+ end
14
+
15
+ alter_table :boto_monitor_errors do |t|
16
+ t.add :source, :string, size: 16, null: false, default: "server"
17
+ t.add :browsers, :text
18
+ t.index %i[service source fingerprint], unique: true
19
+ end
20
+
21
+ down do
22
+ execute "DROP INDEX boto_monitor_errors_service_source_fingerprint_index"
23
+ execute "CREATE UNIQUE INDEX boto_monitor_errors_service_fingerprint_index " \
24
+ "ON boto_monitor_errors (service, fingerprint)"
25
+ execute "ALTER TABLE boto_monitor_errors DROP COLUMN browsers"
26
+ execute "ALTER TABLE boto_monitor_errors DROP COLUMN source"
27
+ execute "ALTER TABLE boto_monitor_series DROP COLUMN operation"
28
+ execute "ALTER TABLE boto_monitor_series DROP COLUMN ref"
29
+ execute "ALTER TABLE boto_monitor_series DROP COLUMN metric"
30
+ end
31
+ end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ # The SSE stream sums of each route in each minute. The reasons and the duration buckets are JSON text, as the
4
+ # buckets of the series. Like the series, there is no unique index: two workers may insert the same key at once,
5
+ # and the queries sum the rows of a key.
6
+ Boto::Migration.define do
7
+ create_table :boto_monitor_streams, timestamps: false do |t|
8
+ t.string :service, size: 128, null: false
9
+ t.time :minute, null: false
10
+ t.string :route, size: 512, null: false
11
+ t.bigint :opened, null: false
12
+ t.bigint :resumed, null: false
13
+ t.bigint :events_sent, null: false
14
+ t.bigint :serialization_failures, null: false
15
+ t.bigint :write_failures, null: false
16
+ t.bigint :overflows, null: false
17
+ t.text :rejected, null: false
18
+ t.text :closed, null: false
19
+ t.bigint :duration_count, null: false
20
+ t.float :duration_sum, null: false
21
+ t.text :duration_buckets, null: false
22
+ t.index %i[service minute]
23
+ end
24
+ end
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ # The streams open in each process: the last batch of the process wins, and the panel sums the live processes.
4
+ Boto::Migration.define do
5
+ alter_table :boto_monitor_instances do |t|
6
+ t.add :streams_open, :integer
7
+ end
8
+
9
+ down do
10
+ execute "ALTER TABLE boto_monitor_instances DROP COLUMN streams_open"
11
+ end
12
+ end
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "boto/management_ui"
4
+
5
+ Boto::CLI::Companion.define(:management_ui) do |companion|
6
+ companion.port env: "BOTO_MANAGEMENT_PORT", default: 3900
7
+ companion.app { |context| Boto::ManagementUi::App.new(context) }
8
+ end
@@ -0,0 +1,84 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "monitor"
4
+
5
+ module Boto
6
+ module ManagementUi
7
+ # The management UI as a Rack app on its own port. `boto run` serves it beside the solution (a companion), and
8
+ # `boto deploy` mounts it in production with no apps of its own, only the monitor. The ingest takes the agents'
9
+ # batches with the monitor token; in production the rest sits behind Basic auth.
10
+ class App
11
+ INGEST_PATH = "/ingest"
12
+ TEXT_TYPE = "text/plain; charset=utf-8"
13
+ UNAUTHORIZED_BODY = "Unauthorized"
14
+
15
+ # context: the run (its apps are the spas and the panel's services); setup: the environment, read at boot.
16
+ def initialize(context, setup: Setup.new(env_name: context.env_name))
17
+ setup.check!
18
+ @setup = setup
19
+ @lock = ::Monitor.new
20
+ @auth = PasswordAuth.new(users: setup.users) if setup.production?
21
+ @retention_days = setup.retention_days
22
+ @spas = Spas.new(apps: context.apps.merge(context.frontends))
23
+ @panel = Panel.new(context: context, env_name: context.env_name, base: "", retention: @retention_days,
24
+ monitor_api: -> { monitor_api })
25
+ end
26
+
27
+ def call(env)
28
+ return ingest.call(env) if env["PATH_INFO"] == INGEST_PATH
29
+ return unauthorized unless authorized?(env)
30
+
31
+ @spas.call(env) || @panel.call(env)
32
+ end
33
+
34
+ # The store is opened on first use, so a run that serves no request never touches the database.
35
+ def start
36
+ start_in_process
37
+ @spas.start
38
+ start_retention if @setup.production?
39
+ end
40
+
41
+ def stop
42
+ @retention&.stop
43
+ @spas.stop
44
+ Boto::Telemetry::Delivery::InProcess.unregister(@receiver) if @receiver
45
+ end
46
+
47
+ private
48
+
49
+ def authorized?(env) = @auth.nil? || !@auth.call(env).nil?
50
+
51
+ def unauthorized
52
+ [401, { "content-type" => TEXT_TYPE, "www-authenticate" => @auth.challenge }, [UNAUTHORIZED_BODY]]
53
+ end
54
+
55
+ def store = @lock.synchronize { @store ||= @setup.store }
56
+
57
+ def ingest
58
+ @lock.synchronize do
59
+ @ingest ||= Monitor::Ingest.new(store: store, token: @setup.token, public: @setup.public_ingest?)
60
+ end
61
+ end
62
+
63
+ def monitor_api
64
+ @lock.synchronize do
65
+ @monitor_api ||= Monitor::Api.new(queries: Monitor::Queries.new(store: store))
66
+ end
67
+ end
68
+
69
+ # The agent hands batches over in this process when the telemetry gem is loaded; without it, nothing is sent.
70
+ def start_in_process
71
+ return unless defined?(Boto::Telemetry::Delivery::InProcess)
72
+
73
+ @receiver = InProcessReceiver.new(store: store)
74
+ Boto::Telemetry::Delivery::InProcess.register(@receiver)
75
+ end
76
+
77
+ def start_retention
78
+ days = @retention_days
79
+ @retention = Monitor::Retention.new(store: store, metrics_days: days[:metrics],
80
+ traces_days: days[:traces]).start
81
+ end
82
+ end
83
+ end
84
+ end
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Boto
4
+ module ManagementUi
5
+ # What a running app declares, read from its plugins and endpoints. Plugins are found by plugin_name, so the
6
+ # panel never needs the gem that defines them.
7
+ module AppTraits
8
+ TELEMETRY = :telemetry
9
+ DATABASE = :database
10
+ GATEWAY = :gateway
11
+ BROWSER_BASE = "/"
12
+
13
+ module_function
14
+
15
+ def plugin(app, name)
16
+ app.plugins.find { |plugin| plugin.class.plugin_name == name }
17
+ end
18
+
19
+ def telemetry?(app) = !plugin(app, TELEMETRY).nil?
20
+
21
+ def database?(app) = !plugin(app, DATABASE).nil?
22
+
23
+ def gateway_plugin(app) = plugin(app, GATEWAY)
24
+
25
+ def streams?(app) = app.endpoints.any?(&:events?)
26
+
27
+ # A spa is an app whose telemetry takes the browser's beacons (telemetry browser: on); the meta is nil when off.
28
+ def spa?(app)
29
+ telemetry = plugin(app, TELEMETRY)
30
+ telemetry.respond_to?(:browser_meta) && !telemetry.browser_meta(base: BROWSER_BASE).nil?
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,36 @@
1
+ // Network: one fetch per JSON, with the period of the buttons. Errors reject, and the caller shows them.
2
+ function load(path) {
3
+ var url = base + path + "?period=" + encodeURIComponent(state.period);
4
+ return fetch(url, { headers: { accept: "application/json" } }).then(function (response) {
5
+ if (!response.ok) throw new Error(response.status + " " + path);
6
+ return response.json();
7
+ });
8
+ }
9
+
10
+ function servicePath(name) { return "/services/" + encodeURIComponent(name || state.service); }
11
+
12
+ // Only the latest navigation writes to the panel: a slow response for an old choice is dropped.
13
+ function show(promise, render) {
14
+ var mine = ++sequence;
15
+ promise.then(function (value) {
16
+ if (mine === sequence) render(value);
17
+ }, function (error) {
18
+ if (mine === sequence) fill(content, note(MESSAGES.failed + ": " + error.message));
19
+ });
20
+ }
21
+
22
+ function setField(name, text) {
23
+ var node = $("[data-field='" + name + "']", root);
24
+ if (node) node.textContent = text;
25
+ }
26
+
27
+ function fillSource(solution) {
28
+ var fleet = plural(solution.services, "serviço");
29
+ if (!production) {
30
+ setField("fleet", "Mesmo processo · " + fleet);
31
+ return;
32
+ }
33
+ setField("fleet", "Recebendo de " + fleet + " · " + plural(solution.instances, "instância"));
34
+ setField("last-batch", ago(solution.last_batch_at));
35
+ }
36
+
@@ -0,0 +1,212 @@
1
+ // ---------- Chart helpers ----------
2
+
3
+ function column(rows, key) { return rows.map(function (item) { return item[key]; }); }
4
+
5
+ function scaled(values, factor) { return values.map(function (value) { return value == null ? null : value * factor; }); }
6
+
7
+ function lastOf(values) {
8
+ for (var i = values.length - 1; i >= 0; i--) {
9
+ if (values[i] != null) return values[i];
10
+ }
11
+ return null;
12
+ }
13
+
14
+ function line(name, color, values, options) {
15
+ return Object.assign({ name: name, color: color, values: values }, options);
16
+ }
17
+
18
+ // Builds what the drawing needs: the largest value (the axis top) and the text of the current point.
19
+ function chartConfig(spec) {
20
+ var config = Object.assign({ limit: null, tick: spec.format }, spec);
21
+ config.max = scaleMax(config);
22
+ config.limitLabel = config.limit == null ? null : "limite " + config.format(config.limit);
23
+ config.now = config.series.map(function (item) { return item.name + " " + valueText(config, lastOf(item.values)); }).join(" · ");
24
+ return config;
25
+ }
26
+
27
+ function scaleMax(config) {
28
+ var values = config.series.reduce(function (all, item) { return all.concat(item.values); }, [0, config.limit]);
29
+ var max = Math.max.apply(null, values.filter(function (value) { return value != null; }));
30
+ return max > 0 ? max : 1;
31
+ }
32
+
33
+ function valueText(config, value) { return value == null ? "—" : config.format(value); }
34
+
35
+ function hasValues(config) {
36
+ return config.series.some(function (item) { return item.values.some(function (value) { return value != null; }); });
37
+ }
38
+
39
+ function requestsChart(charts) {
40
+ var rows = charts.requests;
41
+ return chartConfig({
42
+ title: "Requests por segundo", step: charts.step, times: column(rows, "at"),
43
+ series: [line("total", COLORS.total, column(rows, "per_second"), { fill: "#fdf2f1" }),
44
+ line("5xx", COLORS.errors, column(rows, "errors_per_second"), { bars: true })],
45
+ format: function (value) { return fmt(value, 1) + " req/s"; },
46
+ tick: function (value) { return fmt(value, 0); }
47
+ });
48
+ }
49
+
50
+ function latencyChart(charts) {
51
+ var rows = charts.latency;
52
+ return chartConfig({
53
+ title: "Latência", step: charts.step, times: column(rows, "at"),
54
+ series: [line("p50", COLORS.p50, scaled(column(rows, "p50"), 1000)),
55
+ line("p95", COLORS.p95, scaled(column(rows, "p95"), 1000)),
56
+ line("p99", COLORS.p99, scaled(column(rows, "p99"), 1000))],
57
+ format: function (value) { return fmt(value, 0) + " ms"; }
58
+ });
59
+ }
60
+
61
+ function usageChart(title, rows, step, format) {
62
+ return chartConfig({
63
+ title: title, step: step, times: column(rows, "at"),
64
+ series: [line("uso", COLORS.usage, column(rows, "usage"), { fill: "#e0ecff" })],
65
+ limit: lastOf(column(rows, "limit")), format: format
66
+ });
67
+ }
68
+
69
+ function chartsRow(configs) {
70
+ return el("div", { className: "charts" }, configs.map(chartBox));
71
+ }
72
+
73
+ function chartBox(config) {
74
+ var plot = el("div", { className: "chart__plot", "data-plot": "" });
75
+ plot.chartConfig = config;
76
+ return el("div", { className: "chart" }, [
77
+ el("div", { className: "chart__title" }, [el("span", null, config.title), el("span", { className: "chart__now" }, config.now)]),
78
+ el("div", { className: "chart__legend" }, legend(config)),
79
+ plot
80
+ ]);
81
+ }
82
+
83
+ function legend(config) {
84
+ var items = config.series.map(function (item) {
85
+ return el("span", null, [el("i", { style: "background:" + item.color }), item.name]);
86
+ });
87
+ if (config.limitLabel) items.push(el("span", null, [el("i", { className: "dash" }), config.limitLabel]));
88
+ return items;
89
+ }
90
+
91
+ function drawAll(scope) {
92
+ $$("[data-plot]", scope).forEach(function (plot) { drawChart(plot, plot.chartConfig); });
93
+ }
94
+
95
+ function drawChart(plot, config) {
96
+ var width = plot.clientWidth;
97
+ if (!width) return;
98
+ fill(plot, hasValues(config) ? chartParts(config, width) : note(MESSAGES.noData));
99
+ }
100
+
101
+ function plotScale(config, width) {
102
+ var span = width - CHART.left - CHART.right;
103
+ var count = config.times.length;
104
+ var base = CHART.height - CHART.bottom;
105
+ return {
106
+ base: base,
107
+ right: width - CHART.right,
108
+ x: function (i) { return CHART.left + (count > 1 ? i * span / (count - 1) : span / 2); },
109
+ y: function (value) { return CHART.top + (base - CHART.top) * (1 - value / config.max); },
110
+ index: function (px) { return Math.max(0, Math.min(count - 1, Math.round((px - CHART.left) / span * (count - 1)))); }
111
+ };
112
+ }
113
+
114
+ function chartParts(config, width) {
115
+ var scale = plotScale(config, width);
116
+ var node = svg("svg", { viewBox: "0 0 " + width + " " + CHART.height, width: width, height: CHART.height });
117
+ var cursor = svg("line", { "class": "cursor", y1: CHART.top, y2: scale.base, visibility: "hidden" });
118
+ var dots = config.series.map(function (item) {
119
+ return svg("circle", { r: 3.5, fill: "#ffffff", stroke: item.color, "stroke-width": 2, visibility: "hidden" });
120
+ });
121
+ var tip = el("div", { className: "tooltip", hidden: true });
122
+ drawAxes(node, config, scale);
123
+ config.series.forEach(function (item) { drawSeries(node, item, scale); });
124
+ append(node, [cursor, dots]);
125
+ attachHover(node, config, scale, { cursor: cursor, dots: dots, tip: tip, width: width });
126
+ return [node, tip];
127
+ }
128
+
129
+ function drawAxes(node, config, scale) {
130
+ [0, config.max / 2, config.max].forEach(function (value) {
131
+ var y = scale.y(value);
132
+ append(node, [
133
+ svg("line", { "class": "grid", x1: CHART.left, x2: scale.right, y1: y, y2: y }),
134
+ svg("text", { "class": "axis", x: CHART.left - 4, y: y + 3, "text-anchor": "end" }, config.tick(value))
135
+ ]);
136
+ });
137
+ var last = config.times.length - 1;
138
+ [0, Math.floor(last / 2), last].filter(function (i, pos, all) { return all.indexOf(i) === pos; }).forEach(function (i) {
139
+ var anchor = i === 0 ? "start" : i === last ? "end" : "middle";
140
+ append(node, svg("text", { "class": "axis", x: scale.x(i), y: CHART.height - 4, "text-anchor": anchor }, clock(config.times[i])));
141
+ });
142
+ if (config.limit != null) {
143
+ var limitY = scale.y(config.limit);
144
+ append(node, svg("line", { x1: CHART.left, x2: scale.right, y1: limitY, y2: limitY, stroke: COLORS.limit, "stroke-dasharray": "4 4" }));
145
+ }
146
+ }
147
+
148
+ function drawSeries(node, item, scale) {
149
+ var known = [];
150
+ item.values.forEach(function (value, i) { if (value != null) known.push([i, value]); });
151
+ if (!known.length) return;
152
+ if (item.bars) {
153
+ append(node, known.map(function (point) {
154
+ return svg("rect", { x: scale.x(point[0]) - 1.2, width: 2.4, y: scale.y(point[1]), height: scale.base - scale.y(point[1]), fill: item.color });
155
+ }));
156
+ return;
157
+ }
158
+ var points = known.map(function (point) { return scale.x(point[0]) + "," + scale.y(point[1]); });
159
+ if (item.fill) {
160
+ var first = scale.x(known[0][0]);
161
+ var last = scale.x(known[known.length - 1][0]);
162
+ append(node, svg("polygon", { points: [first + "," + scale.base].concat(points, [last + "," + scale.base]).join(" "), fill: item.fill }));
163
+ }
164
+ append(node, svg("polyline", { points: points.join(" "), fill: "none", stroke: item.color, "stroke-width": 2, "vector-effect": "non-scaling-stroke" }));
165
+ }
166
+
167
+ function attachHover(node, config, scale, marks) {
168
+ node.addEventListener("mousemove", function (event) {
169
+ showPoint(config, scale, marks, scale.index(event.clientX - node.getBoundingClientRect().left));
170
+ });
171
+ node.addEventListener("mouseleave", function () { hidePoint(marks); });
172
+ }
173
+
174
+ function showPoint(config, scale, marks, i) {
175
+ var x = scale.x(i);
176
+ marks.cursor.setAttribute("x1", x);
177
+ marks.cursor.setAttribute("x2", x);
178
+ marks.cursor.setAttribute("visibility", "visible");
179
+ config.series.forEach(function (item, k) {
180
+ var value = item.values[i];
181
+ marks.dots[k].setAttribute("cx", x);
182
+ marks.dots[k].setAttribute("cy", scale.y(value == null ? 0 : value));
183
+ marks.dots[k].setAttribute("visibility", value == null || item.bars ? "hidden" : "visible");
184
+ });
185
+ fillTip(marks.tip, config, i);
186
+ marks.tip.hidden = false;
187
+ var left = x + 12;
188
+ if (left + marks.tip.offsetWidth > marks.width) left = x - marks.tip.offsetWidth - 12;
189
+ marks.tip.style.left = left + "px";
190
+ }
191
+
192
+ function hidePoint(marks) {
193
+ marks.cursor.setAttribute("visibility", "hidden");
194
+ marks.dots.forEach(function (dot) { dot.setAttribute("visibility", "hidden"); });
195
+ marks.tip.hidden = true;
196
+ }
197
+
198
+ function fillTip(tip, config, i) {
199
+ fill(tip, [
200
+ el("b", null, clock(config.times[i])), " ", el("span", { className: "muted" }, pointLabel(config.step)),
201
+ config.series.map(function (item) {
202
+ return el("div", { className: "row" }, [
203
+ el("i", { style: "background:" + item.color }), item.name + ": ", el("b", null, valueText(config, item.values[i]))
204
+ ]);
205
+ })
206
+ ]);
207
+ }
208
+
209
+ function pointLabel(step) {
210
+ return step === MINUTE_STEP ? "média do minuto" : "média de " + fmt(step / MINUTE_STEP, 0) + " min";
211
+ }
212
+