Documentation
¶
Overview ¶
Package collector renders the external dbg-collector's config, manages its Docker lifecycle, and persists local state so `dbg collector` can install, inspect, and remove a collector that monitors a developer's local Postgres.
The collector itself is the Rust dbg-collector image; this package never talks to a database or the control plane directly. It only prepares config + secrets and drives Docker. Secrets are referenced in collector.toml as ${ENV} placeholders and supplied to the container via a 0600 env-file, never inlined into the TOML or onto the docker argv.
Index ¶
- Constants
- func ClearSecrets(agentID string)
- func ConfigPath() (string, error)
- func Dir() (string, error)
- func DockerAvailable() error
- func EnvPath() (string, error)
- func ImageForVersion(version string) string
- func IsLoopback(host string) bool
- func LoadSecrets(agentID string) (secret, dbPassword string, err error)
- func PinnedRef(ref string) (string, error)
- func RemoveState() error
- func SaveState(s *State) error
- func StoreSecrets(agentID, secret, dbPassword string) error
- func WriteConfig(path, contents string) error
- func WriteEnvFile(path, secret, dbPassword string) error
- type Auth
- type Commands
- type Component
- type Config
- type Connect
- type Dbgorilla
- type Endpoints
- type Provider
- type Runner
- func (r Runner) ImageRef() string
- func (r Runner) Logs(follow bool, tail string) error
- func (r Runner) Remove() error
- func (r Runner) Restart() error
- func (r Runner) Run() error
- func (r Runner) RunCommandString() string
- func (r Runner) Running() (exists bool, running bool, err error)
- func (r Runner) Start() error
- func (r Runner) Stop() error
- type State
- type Target
- type Topology
Constants ¶
const ( SecretEnv = "DBG_SERVER_SECRET" DBPasswordEnv = "COLLECTOR_DB_PASSWORD" // DockerHostInternal is the hostname that resolves to the Docker host from // inside a container (native on Docker Desktop; on Linux we add an // --add-host mapping to host-gateway). DockerHostInternal = "host.docker.internal" )
Env var names the rendered collector.toml references and the env-file supplies. The collector expands ${VAR} references at load time.
const DefaultContainerName = "dbg-collector"
DefaultContainerName is the stable name for the local collector container.
const DefaultImage = "dbgorillapublic.azurecr.io/dbg-collector:0.1.0@sha256:4874dfe63453d9335e17c37405e640b09d91090f8b78b46bbbb4adbe5337c77a"
DefaultImage is the published GA collector image, pinned by digest for reproducibility. Bump this on each release (see the collector repo's "Releasing" docs). Override with `dbg collector install --image`. Used as the fallback when the deployment advertises no preferred version.
const ImageRepo = "dbgorillapublic.azurecr.io/dbg-collector"
ImageRepo is the published collector repository, used to build an image ref from a deployment-advertised preferred version (`<ImageRepo>:<version>`).
Variables ¶
This section is empty.
Functions ¶
func ClearSecrets ¶
func ClearSecrets(agentID string)
ClearSecrets removes both keychain entries (best-effort).
func ConfigPath ¶
ConfigPath / EnvPath / statePath are the on-disk artifact locations.
func Dir ¶
Dir returns the per-user collector directory (~/.config/dbgorilla/collector), creating it 0700 if needed.
func DockerAvailable ¶
func DockerAvailable() error
DockerAvailable returns nil when a usable Docker engine is reachable.
func ImageForVersion ¶
ImageForVersion returns the image ref for a deployment-blessed version string.
func IsLoopback ¶
IsLoopback reports whether host refers to the local loopback interface, in which case it must be rewritten to host.docker.internal for the containerized collector to reach a database running on the host.
func LoadSecrets ¶
LoadSecrets reads the collector secret and DB password from the keychain.
func PinnedRef ¶
PinnedRef ensures ref is pinned to an immutable digest before we run it. If ref already carries an @sha256 digest (e.g. the built-in DefaultImage) it is returned unchanged. Otherwise — a deployment-blessed version like "<repo>:0.2.0" or a bare --image tag — the image is pulled and its repo digest resolved, yielding "<ref>@sha256:...". This keeps a centrally rolled-out version as reproducible and tamper-evident as a hard-pinned default (a tag is mutable; a digest is not).
func StoreSecrets ¶
StoreSecrets persists the collector secret and DB password in the OS keychain, keyed by agent id.
func WriteConfig ¶
WriteConfig writes the rendered collector.toml atomically. It is 0644 (not 0600) because it is bind-mounted into the collector container, which runs as a non-root user with a read-only rootfs and must be able to read it. The file holds no secrets — only ${ENV} references — so world-readable is safe.
func WriteEnvFile ¶
WriteEnvFile materializes the secrets into a 0600 env-file that `docker run --env-file` reads. Called on install and on start; the file is the only place plaintext secrets land on disk.
Types ¶
type Auth ¶
type Auth struct {
Method string `toml:"method"`
User string `toml:"user"`
Password string `toml:"password"`
}
Auth is [component.auth].
type Component ¶
type Component struct {
Name string `toml:"name"`
Engine string `toml:"engine"`
Provider Provider `toml:"provider"`
Auth Auth `toml:"auth"`
Connect Connect `toml:"connect"`
}
Component is one [[component]] to monitor.
type Config ¶
type Config struct {
Dbgorilla Dbgorilla `toml:"dbgorilla"`
Component []Component `toml:"component"`
Topology Topology `toml:"topology"`
Commands Commands `toml:"commands"`
}
Config mirrors the dbg-collector collector.toml schema. Only the subset this CLI generates is modelled (postgres / self_hosted / password).
type Connect ¶
type Connect struct {
Host string `toml:"host"`
Port int `toml:"port"`
Databases []string `toml:"databases,omitempty"`
SSLMode string `toml:"ssl_mode"`
}
Connect is [component.connect].
type Dbgorilla ¶
type Dbgorilla struct {
AgentID string `toml:"agent_id"`
TenantID string `toml:"tenant_id"`
Secret string `toml:"secret"`
OpampBaseURL string `toml:"opamp_base_url,omitempty"`
OtlpBaseURL string `toml:"otlp_base_url,omitempty"`
KeycloakBaseURL string `toml:"keycloak_base_url,omitempty"`
}
Dbgorilla is the [dbgorilla] block: identity plus optional endpoint overrides. Empty *_base_url fields fall back to the collector's built-in production defaults, so local-dev-against-prod needs none of them.
type Endpoints ¶
Endpoints carries optional explicit endpoint overrides (Phase 1: from the provisioning response; Phase 2: from the .well-known discovery document). Leave fields empty to use the collector's production defaults.
type Provider ¶
type Provider struct {
Type string `toml:"type"`
}
Provider is [component.provider]. self_hosted carries no extra fields.
type Runner ¶
type Runner struct {
Name string
Image string
ConfigPath string
EnvFilePath string
// CACertPath, when set, is a PEM CA bundle mounted into the container and
// pointed at via SSL_CERT_FILE so the collector trusts a private/internal
// CA (e.g. on-prem or internal deployments). Note: this replaces the
// system trust bundle inside the container, so it is intended for
// deployments whose endpoints all chain to this CA.
CACertPath string
}
Runner drives the collector container's lifecycle via the docker CLI.
func (Runner) Logs ¶
Logs streams container logs to stdout/stderr. When follow is true it blocks until interrupted.
func (Runner) RunCommandString ¶
RunCommandString returns the printable `docker run ...` invocation, for dry-run output. Secrets are not on argv (they ride --env-file), so this is safe to display.
type State ¶
type State struct {
AgentID string `json:"agent_id"`
TenantID string `json:"tenant_id"`
Domain string `json:"domain"`
ContainerName string `json:"container_name"`
Image string `json:"image"`
ConfigPath string `json:"config_path"`
EnvFilePath string `json:"env_file_path"`
CACertPath string `json:"ca_cert_path,omitempty"`
TargetName string `json:"target_name"`
CreatedAt time.Time `json:"created_at"`
}
State records the installed collector so status/stop/uninstall work across CLI invocations. It holds no secrets.