Documentation
¶
Overview ¶
Package observability runs forge's local Grafana stack and renders the dashboard and alert rules that ship with the CLI.
Index ¶
- Constants
- Variables
- func DashboardJSON() ([]byte, error)
- func DefaultStateDir() (string, error)
- func Export(dir string, o RulesOptions, force bool) ([]string, error)
- func RemoveTarget(dir, name string) error
- func RenderRules(o RulesOptions) ([]byte, error)
- func WriteState(dir string) (string, error)
- func WriteTarget(dir string, t Target) error
- type ContainerState
- type Ports
- type RulesOptions
- type Stack
- type Target
- type TargetHealth
Constants ¶
const ( // DashboardFile is the exported Forge Service dashboard. DashboardFile = "forge-service-dashboard.json" // RulesFile is the exported Prometheus rule file. RulesFile = "forge-rules.yaml" )
const ( // Image is the all-in-one Grafana, Tempo, Loki, Prometheus and collector image. Image = "grafana/otel-lgtm:0.36.0" // ContainerName is the one long-lived stack container. ContainerName = "forge-lgtm" // VolumeName holds the stack's data across recreates. VolumeName = "forge-lgtm-data" // NetworkName is the user network the stack runs on. Dev containers // join it so they reach the stack, and it them, by container name. NetworkName = "forge-observability" )
Variables ¶
var ( // ErrInvalidSLO reports an availability objective outside (0, 100). ErrInvalidSLO = errors.New("observability: slo must be greater than 0 and less than 100") // ErrInvalidP95 reports a latency threshold that is not positive. ErrInvalidP95 = errors.New("observability: p95 threshold must be positive") )
var ( // ErrPortInUse reports a host port another process holds. ErrPortInUse = errors.New("observability: port in use") // ErrNotReady reports a stack that didn't finish starting in time. ErrNotReady = errors.New("observability: stack did not become ready") )
var ErrExists = errors.New("observability: file exists")
ErrExists reports an export target that already exists.
var ErrInvalidTarget = errors.New("observability: invalid target")
ErrInvalidTarget reports a --target value that isn't name=host:port.
Functions ¶
func DashboardJSON ¶
DashboardJSON returns the Forge Service dashboard. The same build always produces the same bytes, which the examples drift test relies on.
func DefaultStateDir ¶
DefaultStateDir is where the CLI keeps the files it mounts into the stack.
func Export ¶
func Export(dir string, o RulesOptions, force bool) ([]string, error)
Export writes the dashboard and the rule file into dir and returns their paths. It renders and checks everything before it writes anything.
func RemoveTarget ¶
RemoveTarget deletes a target file. A missing file is not an error.
func RenderRules ¶
func RenderRules(o RulesOptions) ([]byte, error)
RenderRules renders the Prometheus rule file for o.
func WriteState ¶
WriteState writes the generated files into dir and returns a hash of their contents. Target files are left alone and are not part of the hash, because Prometheus reads them live.
func WriteTarget ¶
WriteTarget writes a file_sd file for t. It writes a temporary file and renames it, so Prometheus never reads half a file.
Types ¶
type ContainerState ¶
ContainerState is what docker reports about the stack's container.
type Ports ¶
Ports are the host ports the stack publishes on 127.0.0.1.
func ParsePorts ¶
ParsePorts reads the forge.ports container label.
func (Ports) GrafanaURL ¶
GrafanaURL is where Grafana answers on the host.
func (Ports) PrometheusURL ¶
PrometheusURL is where Prometheus answers on the host.
type RulesOptions ¶
type RulesOptions struct {
// SLO is the availability objective in percent, for example 99.9.
SLO float64
// P95Threshold is the latency above which ForgeHighLatencyP95 fires.
P95Threshold time.Duration
}
RulesOptions sets the objective and threshold the alert rules use.
func DefaultRulesOptions ¶
func DefaultRulesOptions() RulesOptions
DefaultRulesOptions is a 99.9% objective and a one second p95.
type Stack ¶
type Stack struct {
Runner execx.Runner
Dir string // state directory, see DefaultStateDir
Name string // container name, ContainerName when empty
Volume string // data volume, VolumeName when empty
Network string // user network, NetworkName when empty
Image string // Image when empty
Ports Ports
Out io.Writer // progress lines, discarded when nil
ReadyTimeout time.Duration // 90s when zero
PollInterval time.Duration // 1s when zero
// PortFree reports whether a host port is free. It checks 127.0.0.1 when nil.
PortFree func(ctx context.Context, port int) bool
}
Stack runs grafana/otel-lgtm as one long-lived container with the files from WriteState mounted into it.
func (*Stack) Down ¶
Down removes the container. With purge it also removes the data volume and the state directory.
type Target ¶
type Target struct {
Name string // becomes the job label
Address string // host:port as seen from inside the container
// Rewritten is true when ParseTarget replaced a loopback host with
// host.docker.internal.
Rewritten bool
}
Target is one app Prometheus scrapes.
func ParseTarget ¶
ParseTarget reads name=host:port. A loopback host means the developer's machine, which the container reaches as host.docker.internal.
type TargetHealth ¶
TargetHealth is one scrape target as Prometheus sees it.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Command syncexamples rewrites the dashboard and rules in examples/observability from the copies the forge CLI embeds.
|
Command syncexamples rewrites the dashboard and rules in examples/observability from the copies the forge CLI embeds. |