routeexample

package
v0.1.95 Latest Latest
Warning

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

Go to latest
Published: Sep 20, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package routeexample is the built-in cheapest_healthy routing strategy: it sends a virtual model's traffic to the cheapest (or fastest) target whose recent error rate is acceptable, learning target health from the attempt outcomes GoModel reports. It doubles as the reference implementation of a pluginapi.RouteStrategy plugin.

Index

Constants

View Source
const (
	// PreferCheapest picks the healthy candidate with the lowest input price.
	PreferCheapest = "cheapest"
	// PreferFastest picks the healthy candidate with the lowest median latency.
	PreferFastest = "fastest"

	// DefaultMaxErrorRate is the error-rate ceiling above which a target is
	// treated as unhealthy.
	DefaultMaxErrorRate = 0.2
	// WindowSize is how many recent outcomes per target are remembered.
	WindowSize = 50
)
View Source
const Name = "cheapest_healthy"

Name is the manifest name of the plugin.

Variables

This section is empty.

Functions

func New

func New() pluginapi.Plugin

New returns an unconfigured plugin; call Init before use.

Types

type Plugin

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

Plugin is one cheapest_healthy instance. Health is tracked per target across every virtual model that uses the instance.

func (*Plugin) Close

func (p *Plugin) Close(context.Context) error

Close releases nothing.

func (*Plugin) Init

Init has no instance-scoped settings.

func (*Plugin) Manifest

func (p *Plugin) Manifest() pluginapi.Manifest

Manifest describes the plugin and its per-virtual-model form.

func (*Plugin) OnAttemptEnd

func (p *Plugin) OnAttemptEnd(outcome pluginapi.RouteOutcome)

OnAttemptEnd records the outcome in the target's sliding window.

func (*Plugin) Select

Select keeps a healthy session target, otherwise picks among the healthy candidates by price or latency. When every candidate is unhealthy it chooses among all of them, so the strategy fails open rather than declining.

Jump to

Keyboard shortcuts

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