discovery

package
v0.0.6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 8, 2026 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SourceStandalone = "standalone"
	SourceCompose    = "compose"
)

Variables

View Source
var ErrNotFound = errors.New("app not found")

Functions

func InferRuntime

func InferRuntime(appCommand string) string

InferRuntime guesses the app's language from its launch command (best-effort).

func InferRuntimeFromImage

func InferRuntimeFromImage(image string) string

InferRuntimeFromImage guesses the app's language from its container image name (best-effort; conservative — a bespoke image name yields "unknown").

func TranslateMountPath

func TranslateMountPath(mounts map[string]string, containerPath string) (string, bool)

TranslateMountPath maps a container-internal path to its host path via a bind-mount table (exact destination match or destination-prefix match). Container paths are always slash-separated (Linux containers).

Types

type ActorType

type ActorType struct {
	Type  string `json:"type"`
	Count int    `json:"count"`
}

type Component

type Component struct {
	Name    string `json:"name"`
	Type    string `json:"type"`
	Version string `json:"version,omitempty"`
}

type ComposeEnv

type ComposeEnv struct {
	Projects map[string]ComposeProject
	// PathProject maps each host resource/config dir found on a sidecar to its
	// compose project name.
	PathProject map[string]string
}

ComposeEnv is the compose network/mount context from the last scan. The reconciler uses it to translate store addresses to host-reachable ones.

func (ComposeEnv) ProjectForPath

func (e ComposeEnv) ProjectForPath(p string) (string, bool)

ProjectForPath returns the compose project owning p (p equal to, or nested under, one of the scanned host resource dirs).

type ComposeProject

type ComposeProject struct {
	// ServicePorts maps service name -> container port -> published host port.
	ServicePorts map[string]map[int]int
	// Mounts maps container destination -> host source, merged across the
	// project's daprd sidecars (first destination wins). Used for SQLite
	// connection-path translation.
	Mounts map[string]string
}

ComposeProject is the host-reachable view of one compose project.

type ComposeSource

type ComposeSource struct {
	// contains filtered or unexported fields
}

ComposeSource discovers Dapr sidecars running in compose-managed containers. A nil runner (no docker/podman) degrades to an empty, error-free scan.

func NewComposeSource

func NewComposeSource(run containerruntime.Runner) *ComposeSource

func (*ComposeSource) Env

func (s *ComposeSource) Env() ComposeEnv

Env returns the compose endpoint/mount context from the last successful scan.

func (*ComposeSource) Scanner

func (s *ComposeSource) Scanner() Scanner

Scanner returns the compose scan as a discovery.Scanner.

type Health

type Health string

Health represents the health status of an instance

const (
	HealthHealthy   Health = "healthy"
	HealthStarting  Health = "starting"
	HealthUnhealthy Health = "unhealthy"
	HealthUnknown   Health = "unknown"
)

func CheckHealth

func CheckHealth(ctx context.Context, client *http.Client, httpPort int) Health

CheckHealth probes a sidecar's /v1.0/healthz endpoint.

type Instance

type Instance struct {
	AppID              string         `json:"appId"`
	Health             Health         `json:"health"`
	Runtime            string         `json:"runtime"`            // e.g. "go", "python", "node", "dotnet", "java", "rust", "unknown"
	IsAspire           bool           `json:"isAspire,omitempty"` // true when the app is .NET Aspire-managed
	Source             string         `json:"source"`             // "standalone" | "compose"
	ComposeProject     string         `json:"composeProject,omitempty"`
	ComposeService     string         `json:"composeService,omitempty"`
	DaprdContainerID   string         `json:"daprdContainerId,omitempty"`
	DaprdContainerName string         `json:"daprdContainerName,omitempty"`
	AppContainerID     string         `json:"appContainerId,omitempty"`
	AppContainerName   string         `json:"appContainerName,omitempty"`
	SidecarReachable   bool           `json:"sidecarReachable"`
	HTTPPort           int            `json:"httpPort"`
	GRPCPort           int            `json:"grpcPort"`
	AppPort            int            `json:"appPort"`
	DaprdPID           int            `json:"daprdPid"`
	AppPID             int            `json:"appPid"` // 0 = unknown
	CLIPID             int            `json:"cliPid"`
	Age                string         `json:"age"`     // human, e.g. "14m"
	Created            string         `json:"created"` // local time string
	RunTemplate        string         `json:"runTemplate"`
	ResourcePaths      []string       `json:"resourcePaths"`
	ConfigPath         string         `json:"configPath"`
	AppLogPath         string         `json:"appLogPath"`
	DaprdLogPath       string         `json:"daprdLogPath"`
	AppLogFormat       string         `json:"appLogFormat,omitempty"`   // "" / "plain" / "dcp"
	DaprdLogFormat     string         `json:"daprdLogFormat,omitempty"` // "" / "plain" / "dcp"
	Command            string         `json:"command"`
	RuntimeVersion     string         `json:"runtimeVersion"` // from metadata; "" if unavailable
	MetadataOK         bool           `json:"metadataOk"`     // false if /v1.0/metadata failed
	Actors             []ActorType    `json:"actors,omitempty"`
	Subscriptions      []Subscription `json:"subscriptions,omitempty"`
	Components         []Component    `json:"components,omitempty"`
	EnabledFeatures    []string       `json:"enabledFeatures,omitempty"`
	Placement          string         `json:"placement,omitempty"`
}

Instance represents a running application instance with Dapr

type Metadata

type Metadata struct {
	ID              string
	RuntimeVersion  string
	AppPID          int
	CLIPID          int
	AppCommand      string
	AppLogPath      string
	DaprdLogPath    string
	RunTemplate     string
	Actors          []ActorType
	Subscriptions   []Subscription
	Components      []Component
	EnabledFeatures []string
	Placement       string
}

func FetchMetadata

func FetchMetadata(ctx context.Context, client *http.Client, httpPort int) (Metadata, error)

FetchMetadata queries a sidecar's /v1.0/metadata endpoint.

type ScanResult

type ScanResult struct {
	AppID         string
	HTTPPort      int
	GRPCPort      int
	AppPort       int
	DaprdPID      int
	CLIPID        int
	Created       time.Time
	RunTemplate   string
	ResourcePaths []string
	ConfigPath    string
	Command       string

	// Source is SourceStandalone (process table) or SourceCompose (containers).
	Source             string
	ComposeProject     string
	ComposeService     string
	DaprdContainerID   string
	DaprdContainerName string
	AppContainerID     string
	AppContainerName   string
	AppImage           string
	// SidecarReachable is false only for compose sidecars whose HTTP port is
	// not published to the host (metadata/health enrichment impossible).
	SidecarReachable bool
}

type Scanner

type Scanner func() ([]ScanResult, error)

func Merge

func Merge(scanners ...Scanner) Scanner

Merge combines scanners into one. A failing scanner is logged and skipped so one source (e.g. docker being absent) never hides the others; the merged scan errors only when every scanner fails.

func StandaloneScanner

func StandaloneScanner() Scanner

StandaloneScanner returns a Scanner that reads running Dapr sidecars from the local process table via the Dapr CLI standalone.List function.

type Service

type Service interface {
	List(ctx context.Context) ([]Instance, error)
	Get(ctx context.Context, appID string) (Instance, error)
}

func New

func New(scan Scanner, client *http.Client) Service

type SubRule

type SubRule struct {
	Match string `json:"match,omitempty"`
	Path  string `json:"path,omitempty"`
}

type Subscription

type Subscription struct {
	PubsubName      string    `json:"pubsubName"`
	Topic           string    `json:"topic"`
	Rules           []SubRule `json:"rules,omitempty"`
	DeadLetterTopic string    `json:"deadLetterTopic,omitempty"`
	Type            string    `json:"type,omitempty"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL