Documentation
¶
Overview ¶
Package jev provides a partitioned TypeSafe Jev System One API with deterministic answers, failure modes and a per-partition request log.
A Jev policy appends /v1/systemone to its base URL, so a scenario points the policy at
http://testbench:3019/<partition>/<mode>
or, for a policy that requires HTTPS, at https://testbench:3020/<partition>/<mode>: the same service over TLS, sharing its partitions.
where <partition> is a scenario-unique name and <mode> selects the service's behaviour: ok, error, slow, ratelimit-once, overloaded-once, ratelimit-always, invalid-json or missing-answer.
Answers default to a low noul probability, a zero score and evenly spread choice options. A marker in the text Jev is asked about sets a question's answer:
jev:<key>=0.95 a noul probability jev:<key>=2@0.5 a score and its confidence jev:<key>=code@0.9 a choice, the rest spread over the other options jev:<key>=a:0.35,b:0.35,c:0.3 a choice distribution
Every request is recorded, including those answered with an error, and GET /<partition>/test/requests reports them with their count.
Index ¶
Constants ¶
const ( EnvTLSCert = "TESTBENCH_JEV_TLS_CERT" EnvTLSKey = "TESTBENCH_JEV_TLS_KEY" )
EnvTLSCert and EnvTLSKey name the variables holding the PEM certificate and key the service serves HTTPS with on TLSPort. When both are unset only the plain HTTP port is served.
const ( // DefaultNoul is the probability a noul question answers. DefaultNoul = 0.05 // DefaultScore is the scale position a score question answers. DefaultScore = 0.0 // DefaultConfidence is the confidence reported with every score and choice answer. DefaultConfidence = 0.9 )
Default answers for questions a request carries no marker for.
const ( // ModeOK answers every question. ModeOK = "ok" // ModeError answers 500. ModeError = "error" // ModeSlow answers after the slow delay, so a short policy timeout expires first. ModeSlow = "slow" // ModeRateLimitOnce answers the partition's first request with 429 and every later one normally. ModeRateLimitOnce = "ratelimit-once" // ModeOverloadedOnce answers the partition's first request with 529 and every later one normally. ModeOverloadedOnce = "overloaded-once" // ModeRateLimitAlways answers every request with 429. ModeRateLimitAlways = "ratelimit-always" // ModeInvalidJSON answers 200 with a body that is not JSON. ModeInvalidJSON = "invalid-json" // ModeMissingAnswer answers every question except the first, in key order. ModeMissingAnswer = "missing-answer" )
Modes, the path segment after the partition.
const APIKey = "test-jev-key"
APIKey is the only key the service accepts, as "Authorization: Bearer <APIKey>".
const Port = 3019
Port is the container port used by the testbench.
const StatusOverloaded = 529
StatusOverloaded is the status Jev uses when it is overloaded.
const SystemOnePath = "/v1/systemone"
SystemOnePath is the Jev endpoint the policies call, appended to their base URL.
const TLSPort = 3020
TLSPort is the port the same service answers on over HTTPS, for a policy that refuses a plain HTTP Jev endpoint on a host that is not loopback.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Request ¶
type Request struct {
Mode string `json:"mode"`
Authorization string `json:"authorization"`
Model string `json:"model"`
State json.RawMessage `json:"state"`
QuestionKeys []string `json:"questionKeys"`
Questions json.RawMessage `json:"questions"`
}
Request is one recorded call to the System One endpoint.
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service implements testbench.Service and testbench.Partitioned.
func (*Service) OverTLS ¶
OverTLS returns the service served over HTTPS on TLSPort with the supplied PEM certificate and key. It shares this service's partitions, so a call made over HTTPS is read back from /test/requests on either port.
func (*Service) PartitionKey ¶
PartitionKey returns the partitioning strategy used by this stateful service.