Class: Capsium::Reactor::Introspection
- Inherits:
-
Object
- Object
- Capsium::Reactor::Introspection
- Defined in:
- lib/capsium/reactor/introspection.rb,
sig/capsium/reactor/introspection.rbs
Overview
Monitoring HTTP API reports (ARCHITECTURE.md section 7): /api/v1/introspect/* aggregates every mounted package, plus reactor-level /introspect/* and per-package /package/:id/* endpoints resolved by package name.
Constant Summary collapse
- METADATA_PATH =
"/api/v1/introspect/metadata"- ROUTES_PATH =
"/api/v1/introspect/routes"- CONTENT_HASHES_PATH =
"/api/v1/introspect/content-hashes"- CONTENT_VALIDITY_PATH =
"/api/v1/introspect/content-validity"- PATHS =
[METADATA_PATH, ROUTES_PATH, CONTENT_HASHES_PATH, CONTENT_VALIDITY_PATH].freeze
- STATUS_PATH =
"/introspect/status"- CONFIG_PATH =
"/introspect/config"- METRICS_PATH =
"/introspect/metrics"- REACTOR_PATHS =
[STATUS_PATH, CONFIG_PATH, METRICS_PATH].freeze
- PACKAGE_MOUNT =
Per-package endpoints: "/package/
/status|metadata|logs". PACKAGE_MOUNT is the mount point (WEBrick longest-prefix matching routes all "/package/..." requests to the reactor); the name resolves against every mounted package, anything else is a 404. "/package"- PACKAGE_PATH_PATTERN =
%r{\A/package/(?<name>[^/]+)/(?<report>status|metadata|logs)\z}- DEFAULT_LOG_LINES =
100- MAX_LOG_LINES =
1000
Instance Attribute Summary collapse
-
#packages ⇒ Array[Package]
readonly
Returns the value of attribute packages.
Instance Method Summary collapse
-
#config_report ⇒ Hash[Symbol, untyped]
Reactor configuration; secrets are never exposed.
- #content_hashes_report ⇒ Hash[Symbol, untyped]
- #content_validity_report ⇒ Hash[Symbol, untyped]
- #endpoint?(path) ⇒ Boolean
-
#initialize(packages, reactor: nil) ⇒ Introspection
constructor
The packages this reactor serves (one per mount; ARCHITECTURE.md section 7 introspection aggregates all of them).
- #metadata_report ⇒ Hash[Symbol, untyped]
- #metrics_report ⇒ Hash[Symbol, untyped]
-
#package ⇒ Package
The first mounted package (the single-package view).
-
#report_for(path, params: {}) ⇒ Hash[Symbol, untyped]?
The report body for an endpoint, or nil when the path is not an endpoint or the package name does not match (404).
- #routes_report ⇒ Hash[Symbol, untyped]
- #status_report ⇒ Hash[Symbol, untyped]
Constructor Details
#initialize(packages, reactor: nil) ⇒ Introspection
The packages this reactor serves (one per mount; ARCHITECTURE.md section 7 introspection aggregates all of them).
43 44 45 46 |
# File 'lib/capsium/reactor/introspection.rb', line 43 def initialize(packages, reactor: nil) @packages = packages @reactor = reactor end |
Instance Attribute Details
#packages ⇒ Array[Package] (readonly)
Returns the value of attribute packages.
39 40 41 |
# File 'lib/capsium/reactor/introspection.rb', line 39 def packages @packages end |
Instance Method Details
#config_report ⇒ Hash[Symbol, untyped]
Reactor configuration; secrets are never exposed.
102 103 104 105 106 107 108 109 110 |
# File 'lib/capsium/reactor/introspection.rb', line 102 def config_report { port: @reactor.port, storeDir: store_dir, cacheControl: @reactor.cache_control, authEnabled: @reactor.authenticator.enabled?, registry: registry_location } end |
#content_hashes_report ⇒ Hash[Symbol, untyped]
85 86 87 88 89 90 |
# File 'lib/capsium/reactor/introspection.rb', line 85 def content_hashes_report entries = @packages.map do |pkg| { package: pkg.name, hash: content_hash(pkg) } end { contentHashes: entries } end |
#content_validity_report ⇒ Hash[Symbol, untyped]
92 93 94 |
# File 'lib/capsium/reactor/introspection.rb', line 92 def content_validity_report { contentValidity: @packages.map { |pkg| content_validity_entry(pkg) } } end |
#endpoint?(path) ⇒ Boolean
51 52 53 54 |
# File 'lib/capsium/reactor/introspection.rb', line 51 def endpoint?(path) PATHS.include?(path) || package_endpoint?(path) || (!@reactor.nil? && REACTOR_PATHS.include?(path)) end |
#metadata_report ⇒ Hash[Symbol, untyped]
71 72 73 |
# File 'lib/capsium/reactor/introspection.rb', line 71 def { packages: @packages.map { |pkg| (pkg) } } end |
#metrics_report ⇒ Hash[Symbol, untyped]
112 |
# File 'lib/capsium/reactor/introspection.rb', line 112 def metrics_report = @reactor.metrics.snapshot.merge(uptime: uptime) |
#package ⇒ Package
The first mounted package (the single-package view).
49 |
# File 'lib/capsium/reactor/introspection.rb', line 49 def package = @packages.first |
#report_for(path, params: {}) ⇒ Hash[Symbol, untyped]?
The report body for an endpoint, or nil when the path is not an endpoint or the package name does not match (404).
58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/capsium/reactor/introspection.rb', line 58 def report_for(path, params: {}) case path when METADATA_PATH then when ROUTES_PATH then routes_report when CONTENT_HASHES_PATH then content_hashes_report when CONTENT_VALIDITY_PATH then content_validity_report when STATUS_PATH then status_report when CONFIG_PATH then config_report when METRICS_PATH then metrics_report else package_report_for(path, params) end end |
#routes_report ⇒ Hash[Symbol, untyped]
75 76 77 78 79 80 81 82 83 |
# File 'lib/capsium/reactor/introspection.rb', line 75 def routes_report entries = @packages.map do |pkg| routes = pkg.routes.config.routes.map do |route| { method: route.http_method || "GET", path: route.path } end { package: pkg.name, routes: routes } end { routes: entries } end |
#status_report ⇒ Hash[Symbol, untyped]
96 97 98 |
# File 'lib/capsium/reactor/introspection.rb', line 96 def status_report { status: "running", uptime: uptime, packagesLoaded: @packages.size } end |