dash 4.2.0 → 4.2.1

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e8fe407ebe24b10effd6d4236b4e9035f6a01362098e6b23a97d5fc120c6e9b5
4
- data.tar.gz: f10f2b259bd849dde14c9bdf2982571f20cbafe201141a4a4a797eac14ce25ee
3
+ metadata.gz: 96cc4535760fa6be551d5bf0d9eda09b2b6b4b10ea2a24a76b1ac9365421893b
4
+ data.tar.gz: 43fbc526438ddb2f27f7bb966043b3efc2dd10a202d611c2bbaee1350d85de69
5
5
  SHA512:
6
- metadata.gz: dcf7d8731f2526798b9e601a9c75c81c728fd7a203a5191fad0eb61473ac2cf474c53de4c0efb83e640610ba3674969d58bc8f8033f7e46f5595bfdc43a83373
7
- data.tar.gz: 00a5d2988465fdaf6b5df1e0beca380b92ab20ccc61a00cda1fdab9030c44b1c50e9e763a4736d1e649dfc99d3c2020a173ceff58df25118a0522f03b1778771
6
+ metadata.gz: c1286f146277ace7cfb1c48da59c41faab42a6fd914be96e17364d56b1815b733cab5d04641a0f11e011df2cbd16e23196036ced7585c949b8d33a520ac2922c
7
+ data.tar.gz: 35899091e6dbe7d1995cf920deb6cd5cbee46d95b35ce483ab747fbfccc03d9028aa7c8838d216f05c07d9177b0d0440e92c8b519b7d4acf36457d3a2fe7d556
@@ -156,7 +156,7 @@ class Dash::Autoscale::Controller
156
156
  entry = Entry.new(role: role, state: Dash::Autoscale::RoleState.from(state.dig("roles", role.name)))
157
157
  entry.evaluation = Dash::Autoscale::Evaluation.new(role: role, now: now, state: entry.state, pause: Dash::Autoscale::Pause.from(pauses[role.name]),
158
158
  observation: quietly { Dash::Autoscale::Observation.take(role) }, reader: @reader)
159
- entry.decision = entry.evaluation.decide
159
+ entry.decision = quietly { entry.evaluation.decide }
160
160
  entry
161
161
  rescue StandardError => e
162
162
  entry.evaluation = nil
@@ -0,0 +1,48 @@
1
+ # A window of request queue times as dash-proxy reports it per target (`list --json`,
2
+ # `target_details[].queue`): cumulative counts per finite upper bound in milliseconds, and
3
+ # the total, whose excess over the last bound is the +Inf bucket. Merging sums the counts,
4
+ # so the quantile of a merge is the fleet's, not an average of percentiles.
5
+ class Dash::Autoscale::Histogram
6
+ attr_reader :buckets, :count
7
+
8
+ # `buckets`: [ [ upper bound ms, cumulative count ], ... ] in ascending bound order.
9
+ def initialize(buckets:, count:)
10
+ @buckets, @count = buckets, count
11
+ end
12
+
13
+ def self.merge(histograms)
14
+ return new(buckets: [], count: 0) if histograms.empty?
15
+
16
+ bounds = histograms.first.bounds
17
+ histograms.each do |histogram|
18
+ next if histogram.bounds == bounds
19
+
20
+ raise ArgumentError, "histograms with different bucket bounds cannot be merged: #{bounds} and #{histogram.bounds}"
21
+ end
22
+
23
+ counts = histograms.map { |histogram| histogram.buckets.map(&:last) }.transpose.map(&:sum)
24
+ new(buckets: bounds.zip(counts), count: histograms.sum(&:count))
25
+ end
26
+
27
+ def bounds
28
+ buckets.map(&:first)
29
+ end
30
+
31
+ # Prometheus' histogram_quantile, as dash-proxy computes its own p95: find the bucket the
32
+ # rank falls in and interpolate linearly inside it. A rank past the last finite bound
33
+ # reports that bound, there being nothing above it to interpolate towards.
34
+ def quantile(q)
35
+ return 0.0 if count.zero?
36
+
37
+ rank = q * count
38
+ lower_bound, lower_count = 0.0, 0
39
+
40
+ buckets.each do |bound, cumulative|
41
+ return lower_bound + (bound - lower_bound) * (rank - lower_count) / (cumulative - lower_count) if cumulative >= rank
42
+
43
+ lower_bound, lower_count = bound.to_f, cumulative
44
+ end
45
+
46
+ lower_bound
47
+ end
48
+ end
@@ -1,13 +1,18 @@
1
1
  # One reading of a signal or a guard: the number, when it was read, or the error that kept
2
2
  # it from being read. A reader never raises out of a tick - a failure is a Sample with an
3
3
  # error, and the policy holds the role with `missing_data`.
4
- Dash::Autoscale::Sample = Struct.new(:value, :at, :error, keyword_init: true) do
4
+ #
5
+ # `detail` is what a source can say about how it got the number (the proxy signal: the
6
+ # unit, the window, which hosts answered); it rides along in `to_h`, so a decision, a
7
+ # record and `dash autoscale signal --json` carry it.
8
+ Dash::Autoscale::Sample = Struct.new(:value, :at, :error, :detail, keyword_init: true) do
5
9
  # No number to act on: an error, nothing read, or a NaN/Inf a query returned.
6
10
  def missing?
7
11
  !error.nil? || !value.is_a?(Numeric) || (value.is_a?(Float) && !value.finite?)
8
12
  end
9
13
 
10
14
  def to_h
11
- { value: (value unless missing?), at: at, error: error.respond_to?(:message) ? error.message : error }
15
+ hash = { value: (value unless missing?), at: at, error: error.respond_to?(:message) ? error.message : error }
16
+ detail.nil? ? hash : hash.merge(detail: detail)
12
17
  end
13
18
  end
@@ -0,0 +1,49 @@
1
+ # Web request queue time in milliseconds: the 95th percentile of the last minute across
2
+ # every container of the role on every host, from the windows each host's dash-proxy keeps
3
+ # per target (Dash::Diagnostics::ProxyQueue). The buckets are merged before the percentile
4
+ # is read, so a host weighs by its traffic.
5
+ #
6
+ # No requests in the window is a queue time of 0, so an idle role can scale in. A host
7
+ # that cannot be read is named in the detail and the rest still answer (the tick's
8
+ # Observation holds the role anyway when a baseline host is unreadable); no host answering
9
+ # is a missing sample.
10
+ class Dash::Autoscale::Signal::Proxy < Dash::Autoscale::Signal
11
+ QUANTILE = 0.95
12
+
13
+ # `queue` reads the role's windows; tests hand it a fake.
14
+ def initialize(config, connections, role: nil, queue: ->(role) { Dash::Diagnostics::ProxyQueue.new(role: role).to_h })
15
+ super(config, connections, role: role)
16
+ @queue = queue
17
+ end
18
+
19
+ def sample(at: Time.now.utc)
20
+ @detail = nil
21
+ super.tap { |sample| sample.detail = @detail }
22
+ end
23
+
24
+ private
25
+ def read(_at)
26
+ hosts = @queue.call(role)[:hosts]
27
+ answered = hosts.reject { |host| host[:error] }
28
+ targets = answered.flat_map { |host| host[:targets] }
29
+ fleet = histogram(targets)
30
+
31
+ @detail = { unit: "ms", window_seconds: targets.filter_map { |target| target[:window_seconds] }.first, requests: fleet.count,
32
+ measured_by: { app: targets.sum { |target| target[:app].to_i }, proxy: targets.sum { |target| target[:proxy].to_i } },
33
+ hosts: hosts.map { |host| host[:error] ? host.slice(:host, :error) : host_detail(host) } }
34
+
35
+ raise "no dash-proxy of #{role.name} answered: #{hosts.map { |host| "#{host[:host]} (#{host[:error]})" }.join(", ")}" if answered.empty?
36
+
37
+ fleet.quantile(QUANTILE).round(1)
38
+ end
39
+
40
+ def host_detail(host)
41
+ histogram = histogram(host[:targets])
42
+
43
+ { host: host[:host], targets: host[:targets].size, requests: histogram.count, p95_ms: histogram.quantile(QUANTILE).round(1) }
44
+ end
45
+
46
+ def histogram(targets)
47
+ Dash::Autoscale::Histogram.merge(targets.map { |target| Dash::Autoscale::Histogram.new(buckets: target[:buckets], count: target[:requests]) })
48
+ end
49
+ end
@@ -1,18 +1,20 @@
1
1
  # A role's `scale.signal` as the controller reads it: one number per tick, from Redis
2
2
  # (Sidekiq), Postgres (pgbus) or Prometheus, through the process's
3
- # Dash::Autoscale::Connections. A reader never raises out of a tick: a failure becomes a
4
- # Sample with its error, and the policy holds the role. Only a configuration error (a
5
- # missing gem, a secret that resolves to nothing) goes through, for the operator to fix.
3
+ # Dash::Autoscale::Connections, or from the role's own dash-proxies over SSH (proxy). A
4
+ # reader never raises out of a tick: a failure becomes a Sample with its error, and the
5
+ # policy holds the role. Only a configuration error (a missing gem, a secret that resolves
6
+ # to nothing) goes through, for the operator to fix.
6
7
  class Dash::Autoscale::Signal
7
- attr_reader :config, :connections
8
+ attr_reader :config, :connections, :role
8
9
 
9
10
  def self.for(role, connections)
10
- { "sidekiq" => Sidekiq, "pgbus" => Pgbus, "prometheus" => Prometheus }.fetch(role.scale.signal.source).new(role.scale.signal, connections)
11
+ { "sidekiq" => Sidekiq, "pgbus" => Pgbus, "prometheus" => Prometheus, "proxy" => Proxy }
12
+ .fetch(role.scale.signal.source).new(role.scale.signal, connections, role: role)
11
13
  end
12
14
 
13
15
  # `config` is the role's Dash::Configuration::Role::Scale::Signal.
14
- def initialize(config, connections)
15
- @config, @connections = config, connections
16
+ def initialize(config, connections, role: nil)
17
+ @config, @connections, @role = config, connections, role
16
18
  end
17
19
 
18
20
  def sample(at: Time.now.utc)
@@ -249,10 +249,12 @@ class Dash::Cli::Autoscale < Dash::Cli::Base
249
249
  say "#{sample[:role]}: #{signal[:source]} could not be read from #{sample[:from]}: #{signal[:error] || "no value"}", :red
250
250
  else
251
251
  position = sample[:position] == "inside" ? "inside the band" : "#{sample[:position]} the band"
252
- say "#{sample[:role]}: #{signal[:source]} #{signal[:value]}, #{position} (up above #{band[:up_above]} for #{band[:up_for]}s, " \
252
+ say "#{sample[:role]}: #{signal[:source]} #{signal[:value]}#{signal.dig(:detail, :unit)}, #{position} (up above #{band[:up_above]} for #{band[:up_for]}s, " \
253
253
  "down below #{band[:down_below]} for #{band[:down_for]}s), read from #{sample[:from]} in #{signal[:latency_ms]}ms"
254
254
  end
255
255
 
256
+ print_signal_detail(signal[:detail]) if signal[:detail]
257
+
256
258
  sample[:guards].each do |guard|
257
259
  name = "hold_when/#{guard[:index]} #{guard[:source]}"
258
260
  reading = guard[:value].nil? ? "#{name}: #{guard[:error] || "no value"}" : "#{name} #{guard[:value]}#{" > #{guard[:above]}" if guard[:holding]}"
@@ -260,6 +262,22 @@ class Dash::Cli::Autoscale < Dash::Cli::Base
260
262
  end
261
263
  end
262
264
 
265
+ # A proxy signal's traffic, when a host answered, and each host's share of it or error.
266
+ def print_signal_detail(detail)
267
+ if detail[:hosts].any? { |host| host[:error].nil? }
268
+ say " #{detail[:requests]} requests#{" in the last #{detail[:window_seconds]}s" if detail[:window_seconds]}, queue time from the app " \
269
+ "#{detail.dig(:measured_by, :app)}, from dash-proxy's connection wait #{detail.dig(:measured_by, :proxy)}"
270
+ end
271
+
272
+ detail[:hosts].each do |host|
273
+ if host[:error]
274
+ say " #{host[:host]}: did not answer: #{host[:error]}", :yellow
275
+ else
276
+ say " #{host[:host]}: #{host[:requests]} requests, p95 #{host[:p95_ms]}#{detail[:unit]}"
277
+ end
278
+ end
279
+ end
280
+
263
281
  def print_simulation(simulation)
264
282
  simulation[:roles].each do |role|
265
283
  say "#{role[:role]}: #{role[:ticks]} #{"tick".pluralize(role[:ticks])}, #{role[:replayed]} replayed"
@@ -61,7 +61,8 @@ autoscale:
61
61
  # `rediss://` cannot go through `via` (the certificate cannot be verified through a
62
62
  # tunnel). Postgres reads run in a read-only transaction. `token` is an optional bearer
63
63
  # token for Prometheus. The controller's Gemfile needs `redis-client` for Redis and `pg` for
64
- # Postgres; dash does not depend on either.
64
+ # Postgres; dash does not depend on either. A `proxy` signal needs none of these: it reads
65
+ # the role's own dash-proxies over SSH.
65
66
  autoscale:
66
67
  provider:
67
68
  ...
@@ -719,6 +719,13 @@ proxy:
719
719
  # This is a per-service deploy setting even though it reads like metrics
720
720
  # configuration — where the metrics are served and who may read them are
721
721
  # proxy-wide and live under `run/metrics_port` and `run/metrics_allow_ips`.
722
+ #
723
+ # Excluded paths also stay out of the per-container queue time window the
724
+ # `proxy` autoscale signal reads (see `scale/signal` in dash docs role), so a
725
+ # load balancer probing `/up` every second does not drag its p95 down. Per
726
+ # container, the metrics carry `kamal_proxy_target_queue_seconds` and
727
+ # `kamal_proxy_target_upstream_ttfb_seconds` (histograms) and
728
+ # `kamal_proxy_target_in_flight`, labelled `service` and `target`.
722
729
  exclude_metrics_paths:
723
730
  - /up
724
731
 
@@ -837,7 +844,7 @@ proxy:
837
844
  # below already embeds its ghcr.io host
838
845
  repository: ghcr.io/zoolutions/dash-proxy # Container repository for the
839
846
  # dash-proxy image (this is the default)
840
- version: v1.1.0.4 # Version tag of the dash-proxy image to use.
847
+ version: v1.1.0.6 # Version tag of the dash-proxy image to use.
841
848
  # Defaults to the minimum version this gem
842
849
  # requires - only pin it to roll forward early,
843
850
  # never below the default
@@ -226,6 +226,41 @@ servers:
226
226
  # least pgbus's `drain_timeout`.
227
227
  # - `prometheus`: the value of one PromQL `query` (`autoscale/prometheus`), the
228
228
  # largest when it returns several series. An empty result is a missing sample.
229
+ # - `proxy`: web request queue time in **milliseconds**, how long a request waited
230
+ # before the app started on it. The 95th percentile over the last 60 seconds across
231
+ # every container of the role on every host, read from each host's dash-proxy over
232
+ # SSH (`dash-proxy list --json`), so it needs no `autoscale/` block, only a role that
233
+ # runs the proxy. No requests in the window reads as 0, so an idle role scales in. A
234
+ # host that cannot be read is left out and named; none answering is a missing
235
+ # sample. Judoscale's web defaults make a sound start: `up/above: 50`,
236
+ # `down/below: 25`.
237
+ #
238
+ # dash-proxy takes the queue time from the app's `Server-Timing: queue;dur=<ms>`
239
+ # response header when the app sends one, and stamps every request with
240
+ # `X-Dash-Request-Start: t=<unix ms>` from the app host's own clock to compute it
241
+ # from. In a Rails app:
242
+ #
243
+ # # config/initializers/queue_time.rb
244
+ # class QueueTime
245
+ # def initialize(app) = @app = app
246
+ #
247
+ # def call(env)
248
+ # started = env["HTTP_X_DASH_REQUEST_START"].to_s[/t=(\d+)/, 1]
249
+ # queue = [ (Time.now.to_f * 1000).round - started.to_i, 0 ].max if started
250
+ # status, headers, body = @app.call(env)
251
+ # headers["server-timing"] = [ headers["server-timing"], "queue;dur=#{queue}" ].compact.join(", ") if queue
252
+ # [ status, headers, body ]
253
+ # end
254
+ # end
255
+ # Rails.application.config.middleware.insert_before 0, QueueTime
256
+ #
257
+ # Without that header dash-proxy times its own wait for a connection to the
258
+ # container, which is a queue time only when `proxy/target/max_conns` caps the
259
+ # connections at the app's thread count; otherwise it stays near 0 whatever the
260
+ # backlog, and `dash doctor` warns. A deploy starts every container's window empty,
261
+ # so the first minute after one reads low, and a container that stops answering
262
+ # records nothing (its in-flight count in `dash-proxy list --json` and the
263
+ # `kamal_proxy_target_in_flight` metric shows it).
229
264
  #
230
265
  # A role with a `schedule` and no `signal` keeps returning to its floor a step at a time.
231
266
  #
@@ -1,5 +1,5 @@
1
1
  class Dash::Configuration::Proxy::Run
2
- MINIMUM_VERSION = "v1.1.0.4"
2
+ MINIMUM_VERSION = "v1.1.0.6"
3
3
  DEFAULT_HTTP_PORT = 80
4
4
  DEFAULT_HTTPS_PORT = 443
5
5
  DEFAULT_LOG_MAX_SIZE = "10m"
@@ -430,6 +430,13 @@ class Dash::Configuration::Proxy
430
430
  self.class.new config: config, proxy_config: other.proxy_config.deep_merge(proxy_config), role_name: role_name, secrets: secrets, load_balanced: load_balanced?
431
431
  end
432
432
 
433
+ # `target/max_conns`, which makes dash-proxy's wait for a connection a queue time. 0 is
434
+ # dash-proxy's unlimited, so it is no cap.
435
+ def target_max_conns
436
+ max_conns = proxy_config.dig("target", "max_conns")
437
+ max_conns unless max_conns.to_i.zero?
438
+ end
439
+
433
440
  private
434
441
  def target_list(targets)
435
442
  Array(targets).map { |target| "#{target}:#{app_port}" }.join(",")
@@ -1,13 +1,16 @@
1
1
  # The `scale.signal` entry: the one number the controller scales a role on. `sidekiq` and
2
2
  # `pgbus` are the age in seconds of the oldest job waiting across `queues`; `prometheus` is
3
- # whatever its `query` returns (the largest value of a vector). See Dash::Autoscale::Signal.
3
+ # whatever its `query` returns (the largest value of a vector); `proxy` is the fleet p95 of
4
+ # web request queue time in milliseconds, read from each host's dash-proxy. See
5
+ # Dash::Autoscale::Signal.
4
6
  class Dash::Configuration::Role::Scale::Signal
5
- SOURCES = %w[ sidekiq pgbus prometheus ]
7
+ SOURCES = %w[ sidekiq pgbus prometheus proxy ]
6
8
  KEYS = %w[ source queues prefix query ]
7
9
  NAME = /\A[A-Za-z0-9_.:-]+\z/
8
10
  DEFAULT_PGBUS_PREFIX = "pgbus_"
9
11
 
10
- # The autoscale/<connection> block each source reads through.
12
+ # The autoscale/<connection> block each source reads through. `proxy` has none: it reads
13
+ # each host's dash-proxy over SSH, as `dash doctor` does.
11
14
  CONNECTIONS = { "sidekiq" => "redis", "pgbus" => "postgres", "prometheus" => "prometheus" }.freeze
12
15
 
13
16
  attr_reader :source, :queues, :prefix, :query
@@ -27,11 +30,11 @@ class Dash::Configuration::Role::Scale::Signal
27
30
  end
28
31
 
29
32
  def queues?
30
- source != "prometheus"
33
+ %w[ sidekiq pgbus ].include?(source)
31
34
  end
32
35
 
33
36
  def connection
34
- CONNECTIONS.fetch(source)
37
+ CONNECTIONS[source]
35
38
  end
36
39
 
37
40
  def to_h
@@ -40,9 +43,6 @@ class Dash::Configuration::Role::Scale::Signal
40
43
 
41
44
  private
42
45
  def validate_source!
43
- if source == "proxy"
44
- error "source", "proxy (web queue time) comes with Phase 4 (zoolutions/dash#180), use #{SOURCES.to_sentence(last_word_connector: " or ")}"
45
- end
46
46
  error "source", "must be #{SOURCES.to_sentence(last_word_connector: " or ")}, not #{source}" unless SOURCES.include?(source)
47
47
  end
48
48
 
@@ -70,7 +70,7 @@ class Dash::Configuration::Role::Scale::Signal
70
70
  end
71
71
 
72
72
  def parse_query(query)
73
- if queues?
73
+ unless source == "prometheus"
74
74
  error "query", "is only used with prometheus" unless query.nil?
75
75
  return
76
76
  end
@@ -585,13 +585,18 @@ class Dash::Configuration
585
585
  end
586
586
 
587
587
  # A signal or guard reads through its autoscale/<connection> block; without one the
588
- # controller would hold the role with missing_data forever instead of failing here.
588
+ # controller would hold the role with missing_data forever instead of failing here. A
589
+ # proxy signal reads the role's own dash-proxy instead, so the role has to run one.
589
590
  def ensure_signal_sources_are_configured
590
591
  scaled_roles.select { |role| role.scale.signal? }.each do |role|
592
+ if role.scale.signal.source == "proxy" && !role.running_proxy?
593
+ raise Dash::ConfigurationError, "servers/#{role.name}/scale/signal: proxy reads the role's dash-proxy, which #{role.name} does not run (proxy: true on the role)"
594
+ end
595
+
591
596
  readers = [ [ "signal", role.scale.signal ] ] + role.scale.guards.each_with_index.map { |guard, index| [ "hold_when/#{index}", guard ] }
592
597
 
593
598
  readers.each do |key, reader|
594
- next if autoscale.source?(reader.connection)
599
+ next if reader.connection.nil? || autoscale.source?(reader.connection)
595
600
 
596
601
  raise Dash::ConfigurationError, "servers/#{role.name}/scale/#{key}: #{reader.source} reads #{reader.connection.capitalize}, " \
597
602
  "set autoscale/#{reader.connection} (see dash docs autoscale)"
@@ -23,10 +23,34 @@ class Dash::Diagnostics::Doctor::SignalChecks
23
23
  sample = Dash::Diagnostics::AutoscaleSignal.new(role: role, connections: connections).to_h
24
24
  from = "from this machine (#{sample[:from]})"
25
25
 
26
- [ source_result(role.name, sample[:signal], from),
26
+ [ sample[:signal][:detail] && !sample[:signal][:error] ? proxy_result(role, sample[:signal], from) : source_result(role.name, sample[:signal], from),
27
27
  *sample[:guards].map { |guard| guard_result("#{role.name} hold_when/#{guard[:index]}", guard, from) } ]
28
28
  end
29
29
 
30
+ # A proxy signal answers with how it got its number: how much traffic, from which hosts,
31
+ # and whether the app or dash-proxy timed it. A host that did not answer warns; so does
32
+ # a queue time that is only dash-proxy's wait for a connection with nothing capping the
33
+ # connections, since that wait stays near 0 whatever the app's backlog.
34
+ def proxy_result(role, read, from)
35
+ detail = read[:detail]
36
+ answered, failed = detail[:hosts].partition { |host| host[:error].nil? }
37
+ window = " in the last #{detail[:window_seconds]}s" if detail[:window_seconds]
38
+ traffic = if detail[:requests].zero?
39
+ "no requests#{window}"
40
+ else
41
+ "p95 of #{detail[:requests]} requests#{window} on #{answered.size} #{"host".pluralize(answered.size)}"
42
+ end
43
+
44
+ warnings = failed.map { |host| "#{host[:host]} did not answer: #{host[:error]}" }
45
+ if detail[:requests].positive? && detail.dig(:measured_by, :app).zero? && role.proxy.target_max_conns.nil?
46
+ warnings << "every request was timed by dash-proxy's wait for a connection, which stays near 0 without proxy/target/max_conns: " \
47
+ "send Server-Timing: queue;dur=<ms> from the app or set max_conns to its thread count (dash docs role)"
48
+ end
49
+
50
+ result role.name, warnings.empty? ? :ok : :warn,
51
+ [ "#{read[:source]} answered #{read[:value]}#{detail[:unit]} (#{traffic}) in #{read[:latency_ms]}ms, #{from}", *warnings ].join("; ")
52
+ end
53
+
30
54
  def source_result(target, read, from)
31
55
  if read[:error]
32
56
  result target, :fail, "#{read[:source]} did not answer #{from}: #{read[:error]}"
@@ -0,0 +1,40 @@
1
+ # What each host's dash-proxy measured of a role's request queue time: per target, the
2
+ # trailing window `dash-proxy list --json` reports (v1.1.0.5 on) under `target_details`.
3
+ # Read over SSH like Dash::Diagnostics::ProxyServices; the proxy signal
4
+ # (Dash::Autoscale::Signal::Proxy) merges it into the fleet's p95.
5
+ #
6
+ # A host whose proxy cannot be read, does not route the role, or predates the window is
7
+ # that host's error; the other hosts still answer.
8
+ class Dash::Diagnostics::ProxyQueue < Dash::Diagnostics::Base
9
+ # The role's targets in one `dash-proxy list --json` output, active and rollout slots
10
+ # alike (both serve requests). Buckets are [ [ upper bound ms, cumulative count ], ... ].
11
+ #
12
+ # dash-proxy omits empty lists, so a service with no targets has neither `targets` nor
13
+ # `target_details`; only targets without details is a proxy older than the window.
14
+ def self.targets(output, service:, host:)
15
+ routed = Dash::Commands::Proxy::Services.parse(output)[service] or raise "dash-proxy on #{host} routes no #{service}"
16
+ details = routed.fetch("target_details") do
17
+ raise "dash-proxy on #{host} reports no queue window (it predates v1.1.0.5), run dash proxy reboot" if Array(routed["targets"]).any?
18
+
19
+ []
20
+ end
21
+
22
+ details.map do |target|
23
+ queue = target.fetch("queue")
24
+
25
+ { address: target["address"], slot: target["slot"], state: target["state"], in_flight: target["in_flight"],
26
+ window_seconds: queue["window_seconds"], requests: queue.fetch("requests"), p95_ms: queue["p95_ms"], max_ms: queue["max_ms"], app: queue["app"], proxy: queue["proxy"],
27
+ buckets: queue.fetch("buckets").map { |bucket| [ bucket.fetch("le_ms"), bucket.fetch("count") ] } }
28
+ end
29
+ end
30
+
31
+ def initialize(role:)
32
+ @role = role
33
+ end
34
+
35
+ private
36
+ def snapshot
37
+ { role: @role.name,
38
+ hosts: per_host(@role.hosts) { |backend, host| { targets: self.class.targets(backend.capture_with_info(*DASH.proxy(host).list(json: true)), service: @role.container_prefix, host: host) } } }
39
+ end
40
+ end
@@ -2,9 +2,11 @@ class Dash::Mcp::Tools::SignalSampleTool < Dash::Mcp::BaseTool
2
2
  tool_name "signal_sample"
3
3
  title "Signal sample"
4
4
  description <<~DESC
5
- One live sample of a scaled role's autoscale signal (scale.signal: sidekiq or pgbus queue age in seconds, or a Prometheus
6
- query) and of each of its saturation guards (scale.hold_when), read from the machine dash mcp runs on, each with its latency:
7
- the source, value, time and error of the signal, where it sits against the role's band (above, inside, below) and the band
5
+ One live sample of a scaled role's autoscale signal (scale.signal: sidekiq or pgbus queue age in seconds, a Prometheus
6
+ query, or proxy: the fleet p95 of web request queue time in ms over the last 60s, read from each host's dash-proxy) and of
7
+ each of its saturation guards (scale.hold_when), read from the machine dash mcp runs on, each with its latency: the source,
8
+ value, time and error of the signal (a proxy signal adds detail: the unit, the requests, whether the app or dash-proxy timed
9
+ them, and each host's share or error), where it sits against the role's band (above, inside, below) and the band
8
10
  itself (up.above, up.for, down.below, down.for); per guard its index, source, bound, value, error and whether it is holding
9
11
  a scale-out. The fields match the signal and guards inputs of the controller's decisions, so a sample compares directly
10
12
  with autoscale_explain and autoscale_decisions. Reads only. configured is false for a role without a signal.
data/lib/dash/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Dash
2
- VERSION = "4.2.0"
2
+ VERSION = "4.2.1"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dash
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.2.0
4
+ version: 4.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mikael Henriksson
@@ -185,6 +185,7 @@ files:
185
185
  - lib/dash/autoscale/duration.rb
186
186
  - lib/dash/autoscale/evaluation.rb
187
187
  - lib/dash/autoscale/guard.rb
188
+ - lib/dash/autoscale/histogram.rb
188
189
  - lib/dash/autoscale/lease.rb
189
190
  - lib/dash/autoscale/lease_held.rb
190
191
  - lib/dash/autoscale/lease_lost.rb
@@ -209,6 +210,7 @@ files:
209
210
  - lib/dash/autoscale/signal.rb
210
211
  - lib/dash/autoscale/signal/pgbus.rb
211
212
  - lib/dash/autoscale/signal/prometheus.rb
213
+ - lib/dash/autoscale/signal/proxy.rb
212
214
  - lib/dash/autoscale/signal/sidekiq.rb
213
215
  - lib/dash/autoscale/simulation.rb
214
216
  - lib/dash/autoscale/state_store.rb
@@ -398,6 +400,7 @@ files:
398
400
  - lib/dash/diagnostics/lock.rb
399
401
  - lib/dash/diagnostics/logs.rb
400
402
  - lib/dash/diagnostics/pool.rb
403
+ - lib/dash/diagnostics/proxy_queue.rb
401
404
  - lib/dash/diagnostics/proxy_services.rb
402
405
  - lib/dash/diagnostics/redactor.rb
403
406
  - lib/dash/diagnostics/reports.rb