Documentation
¶
Overview ¶
Package discovery registers remote dashboard contributors found through a service discovery backend. A service that serves its contract intents with contract/server, and registers itself in discovery under the dashboard tag, shows up in the dashboard with no code on the dashboard's side.
Index ¶
Constants ¶
const APIKeyMetadata = "forge-api-key" //nolint:gosec // G101: a metadata key name, not a credential
APIKeyMetadata is the instance metadata key whose value, when present, is sent as a bearer token on every request the dashboard makes to that service.
const DefaultTag = "forge-dashboard-contributor"
DefaultTag is the discovery tag a service registers under to be picked up as a dashboard contributor.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶ added in v1.12.0
type Config struct {
// Tag is the discovery tag to look for. Empty means DefaultTag.
Tag string
// PollInterval is how often discovery is reconciled. Zero means a minute.
PollInterval time.Duration
// Register adds a remote contributor from its fetched manifest.
Register func(m *contract.ContractManifest, endpoint contract.RemoteEndpoint) error
// Unregister removes a remote contributor by name.
Unregister func(name string)
// Logger receives registration events. Nil means a no-op logger.
Logger forge.Logger
}
Config wires the integration to the dashboard. Register and Unregister are required; the dashboard extension supplies its own remote registration so validation, forwarding and status bookkeeping stay in one place.
type DiscoveryService ¶
type DiscoveryService interface {
// ListServices returns the names of all registered services.
ListServices(ctx context.Context) ([]string, error)
// DiscoverWithTags discovers service instances matching name + tags.
DiscoverWithTags(ctx context.Context, serviceName string, tags []string) ([]*ServiceInstance, error)
}
DiscoveryService is the interface the dashboard needs from a discovery service. This decouples the dashboard from the discovery extension's separate Go module, allowing the integration to work with any discovery provider that satisfies this contract.
type Integration ¶
type Integration struct {
// contains filtered or unexported fields
}
Integration polls a discovery service for instances carrying the dashboard tag and keeps the contract registry in step: new instances are registered, changed manifests are re-registered, and departed instances are removed.
Several healthy instances of one service all serve the same contributor, so only one of them is registered at a time. When that one departs, another takes over in the same poll.
func NewIntegration ¶
func NewIntegration(d DiscoveryService, cfg Config) *Integration
NewIntegration creates a discovery integration. Call Start to begin polling.
func (*Integration) IgnoreLocalService ¶ added in v1.6.2
func (i *Integration) IgnoreLocalService(serviceID string)
IgnoreLocalService skips a service ID when scanning discovery. Start calls it for the host's own ID when the discovery service can report one.
func (*Integration) Reconcile ¶ added in v1.12.0
func (i *Integration) Reconcile(ctx context.Context)
Reconcile runs one pass: it drops contributors whose instance has gone, refreshes the ones still present, and registers new ones. Start runs it on every tick; it is exported so a caller can force a pass.
func (*Integration) Start ¶
func (i *Integration) Start(ctx context.Context)
Start reconciles once, then keeps polling until ctx is done or Stop is called.
func (*Integration) Stop ¶
func (i *Integration) Stop()
Stop ends polling. Safe to call more than once.
func (*Integration) Tracked ¶ added in v1.12.0
func (i *Integration) Tracked() []string
Tracked returns the contributor names currently registered through discovery, sorted.
type LocalServiceIDProvider ¶ added in v1.6.2
type LocalServiceIDProvider interface {
LocalServiceID() string
}
LocalServiceIDProvider is the optional interface a discovery service implements when it can report the host process's own service ID, so the dashboard never tries to register itself as a remote contributor.
type ServiceInstance ¶
type ServiceInstance struct {
ID string
Name string
Address string
Port int
Tags []string
Metadata map[string]string
Status string // "passing", "warning", "critical", "unknown"
}
ServiceInstance mirrors the minimal fields the dashboard needs from a discovered service. This matches discovery/backends.ServiceInstance without importing the external module.
func (*ServiceInstance) GetMetadata ¶
func (si *ServiceInstance) GetMetadata(key string) (string, bool)
GetMetadata retrieves metadata by key.
func (*ServiceInstance) IsHealthy ¶
func (si *ServiceInstance) IsHealthy() bool
IsHealthy returns true if the service status is "passing".
func (*ServiceInstance) URL ¶
func (si *ServiceInstance) URL(scheme string) string
URL returns the full URL for the service instance.