Documentation
¶
Overview ¶
Package services pkg/services/duration.go c2-vis-appsvc
Duration is a time.Duration wrapper that JSON-marshals as a Go duration string ("2m", "30s", "100ms") and unmarshals from either a string or a number (nanoseconds). Standard time.Duration's JSON support is asymmetric — it marshals as a number but won't unmarshal a string, so config files using human-readable durations fail to parse without a wrapper like this.
Mirrored from pkg/visor/visorconfig.Duration so the deployment services can use it without importing the whole visorconfig package (which would broaden their dependency surface for one type).
Package services pkg/services/loglevel.go c2-vis-appsvc
Per-service log levels.
Every service block may carry its own "log_level". Historically each service applied it by calling the package-global logging.SetLevel, which is fine for a single-service binary (`skywire svc ar`) but wrong under `skywire svc run`, where several services share one process: the last service constructed decided the level for every other service, so a per-service log_level was misleading and one block set to "debug" turned on debug logging for the whole process.
NewLogger keeps the single-service behavior exactly as it was and gives each service its own independently-leveled logger when the process hosts more than one.
Package services pkg/services/run.go c2-vis-appsvc
errgroup-style supervisor for a parsed services.File. Brought into its own file so the registry primitives in services.go stay small and easy to read.
Package services pkg/services/services.go c2-vis-appsvc
Multi-service-in-one-process runner for Skywire deployment services. Each service registers a Factory that decodes its block from a JSON services.json and returns a Service that runs until ctx cancels or a fatal error.
Goal: collapse the nine deployment-side containers exercised by CI e2e (dmsg-discovery, dmsg-server, transport-discovery, service-discovery, address-resolver, route-finder, transport-setup, stun-server, setup-node) down to a single binary invocation (`skywire svc run --config services.json`) so CI e2e doesn't have to wrangle nine Dockerfiles. uptime-tracker and network-monitor are out of scope — UT is being subsumed by TPD, NM is intentionally disabled in the production deployment. Production deployments unchanged — the existing per-service cobra subcommands stay and build their own Service via the same Factory.
Topology choice: each service gets its own HTTP listener (no path multiplexing). In-process topology stays identical to the multi-container topology, so the e2e suite exercises the same code paths whether it runs collapsed or not.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewLogger ¶
NewLogger returns the logger a service should log through, given the "log_level" from its own config block and the tag it logs under.
An empty level leaves everything alone. An unparseable one is reported at warn — naming the offending string and the level actually used — and falls back to info, so a typo in a config file can no longer put a production service into debug without saying so.
When this process hosts a single service, the level is applied to the process-global master logger as before, so library packages (dmsg, httpauth, the stores) are quieted along with the service. When several services share the process, the level applies to the returned logger only; Run separately picks the shared global level from all the blocks.
func Register ¶
Register installs a Factory for the given service type. Called from each service package's init(); duplicate registrations panic (programmer error, caught at process startup).
func RegisteredTypes ¶
func RegisteredTypes() []string
RegisteredTypes returns the sorted list of currently-registered service types. Used by the cobra subcommand's error messages and `skywire svc run --list` output.
func Run ¶
Run dispatches every block in file to its registered Factory and supervises the resulting Services. Returns when:
- ctx is canceled (returns nil)
- SIGINT/SIGTERM is received (returns nil; ctx is canceled internally so all services unwind cleanly)
- any service's Run returns an error (returns the first error; other services are then canceled and joined)
Each service runs in its own goroutine and shares the same ctx. Services log under their Block.Label() so an operator looking at merged stdout can tell two instances of the same service type apart.
Types ¶
type Block ¶
type Block struct {
Type string
Name string
Raw json.RawMessage
// LogLevel is the block's optional "log_level", read here so the
// supervisor can pick a shared level for the library packages
// before any service is built. Each factory still reads its own.
LogLevel string
}
Block is one service entry. UnmarshalJSON pulls the type marker out and stashes the full block bytes on Raw for the factory.
func (*Block) Label ¶
Label returns the operator-visible name for this block, falling back to the type when no explicit name was set. Used in log prefixes so an operator running multiple instances of the same service type can tell them apart.
func (*Block) UnmarshalJSON ¶
UnmarshalJSON captures both the typed fields ("type", optional "name") and the full block bytes, so factories can re-decode the block into their own config struct. Forward-compatible: extra service-specific fields live alongside "type" / "name" in the same object and reach the factory via Raw.
type Duration ¶
Duration is a JSON-friendly wrapper around time.Duration.
func (Duration) MarshalJSON ¶
MarshalJSON renders as a Go-style duration string ("2m").
func (Duration) Std ¶
Std returns the wrapped value as the standard time.Duration so callers don't have to repeat the type assertion.
func (*Duration) UnmarshalJSON ¶
UnmarshalJSON accepts either a duration string ("2m", "5s") or a raw number (nanoseconds, matching time.Duration's MarshalJSON default).
type Factory ¶
Factory builds a Service from a raw block in services.json. The block is the full JSON object the operator wrote (including the "type" field, which factories typically ignore — the registry has already used it to dispatch).
type File ¶
type File struct {
Services []Block `json:"services"`
}
File is the on-disk shape of services.json.
{
"services": [
{ "type": "dmsg-discovery", ... },
{ "type": "dmsg-server", ... }
]
}
Each Block carries its full original JSON so the per-service factory can decode into its own typed config struct without losing fields the framework doesn't know about.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package ar pkg/services/ar/ar.go c2-vis-appsvc
|
Package ar pkg/services/ar/ar.go c2-vis-appsvc |
|
Package dmsgdisc pkg/services/dmsgdisc/config.go c2-vis-appsvc
|
Package dmsgdisc pkg/services/dmsgdisc/config.go c2-vis-appsvc |
|
Package dmsgsrv pkg/services/dmsgsrv/dmsgsrv.go c2-vis-appsvc
|
Package dmsgsrv pkg/services/dmsgsrv/dmsgsrv.go c2-vis-appsvc |
|
Package noop pkg/services/noop/noop.go c2-vis-appsvc
|
Package noop pkg/services/noop/noop.go c2-vis-appsvc |
|
Package rf pkg/services/rf/rf.go c2-vis-appsvc
|
Package rf pkg/services/rf/rf.go c2-vis-appsvc |
|
Package sd pkg/services/sd/config.go c2-vis-appsvc
|
Package sd pkg/services/sd/config.go c2-vis-appsvc |
|
Package sn pkg/services/sn/sn.go c2-vis-appsvc
|
Package sn pkg/services/sn/sn.go c2-vis-appsvc |
|
Package stun pkg/services/stun/stun.go c2-vis-appsvc
|
Package stun pkg/services/stun/stun.go c2-vis-appsvc |
|
Package tpd pkg/services/tpd/config.go c2-vis-appsvc
|
Package tpd pkg/services/tpd/config.go c2-vis-appsvc |
|
Package tps pkg/services/tps/tps.go c2-vis-appsvc
|
Package tps pkg/services/tps/tps.go c2-vis-appsvc |
|
Package visor pkg/services/visor/visor.go c2-vis-appsvc
|
Package visor pkg/services/visor/visor.go c2-vis-appsvc |