Documentation
¶
Overview ¶
Package rapi provides a remote API to trigger load tests package (REST API).
Index ¶
- Constants
- Variables
- func AddDataHandler(mux *http.ServeMux, baseurl, uipath, datadir string)
- func AddHandlers(mux *http.ServeMux, baseurl, uiPath, datadir string)
- func CallHook(httpopts *fhttp.HTTPOptions, ro *periodic.RunnerOptions)
- func DataList() (dataList []string)
- func Error(w http.ResponseWriter, msg string, err error)
- func FormValue(r *http.Request, json map[string]interface{}, key string) string
- func GetConfigAtPath(path string, data []byte) (map[string]interface{}, error)
- func GetDataDir() string
- func GetDataURL(r *http.Request) string
- func ID2URL(r *http.Request, id string) string
- func LogAndFilterDataRequest(h http.Handler) http.Handler
- func NextRunID() int64
- func RESTDNSHandler(w http.ResponseWriter, r *http.Request)
- func RESTRunHandler(w http.ResponseWriter, r *http.Request)
- func RESTStatusHandler(w http.ResponseWriter, r *http.Request)
- func RESTStopHandler(w http.ResponseWriter, r *http.Request)
- func RemoveRun(id int64)
- func Run(w http.ResponseWriter, r *http.Request, jd map[string]interface{}, ...) (periodic.HasRunnerResult, string, []byte, error)
- func RunMetrics() (int, int64)
- func SaveJSON(name string, json []byte) string
- func SendTSVDataIndex(urlPrefix string, w http.ResponseWriter)
- func SetDataDir(datadir string)
- func SetHook(h bincommon.FortioHook)
- func StopByRunID(runid int64, wait bool) (int, string)
- func UpdateRun(ro *periodic.RunnerOptions) *periodic.Aborter
- type AsyncReply
- type DNSReply
- type StateEnum
- type Status
- type StatusMap
- type StatusReply
Constants ¶
const ( JSONExtension = ".json" DataDir = "data/" )
const ( RestRunURI = "rest/run" RestStatusURI = "rest/status" RestStopURI = "rest/stop" RestDNS = "rest/dns" ModeGRPC = "grpc" )
Variables ¶
var ( // DefaultPercentileList is the default percentiles when not otherwise specified. DefaultPercentileList []float64 )
Functions ¶
func AddDataHandler ¶ added in v1.35.0
func AddHandlers ¶
AddHandlers adds the REST API handlers for run, status and stop. uiPath must end with a /.
func CallHook ¶ added in v1.69.0
func CallHook(httpopts *fhttp.HTTPOptions, ro *periodic.RunnerOptions)
CallHook is the hook used to allow Fortiotel or other hook to be called to modify options before the run starts.
func DataList ¶
func DataList() (dataList []string)
DataList returns the .json files/entries in data dir.
func Error ¶
func Error(w http.ResponseWriter, msg string, err error)
Error writes serialized ServerReply marked as error, to the writer.
func FormValue ¶
FormValue gets the value from the query arguments/URL parameter or from the provided map (JSON data).
func GetConfigAtPath ¶
GetConfigAtPath deserializes the bytes as JSON and extracts the map at the given path (only supports simple expression): . is all the JSON .foo.bar.blah will extract that part of the tree.
func GetDataDir ¶
func GetDataDir() string
func GetDataURL ¶ added in v1.35.0
GetDataURL gives the url of the data/ dir either using configured `-base-url` and ui path from the incoming Host header.
func LogAndFilterDataRequest ¶ added in v1.35.0
LogAndFilterDataRequest logs the data request.
func RESTDNSHandler ¶ added in v1.54.0
func RESTDNSHandler(w http.ResponseWriter, r *http.Request)
func RESTRunHandler ¶
func RESTRunHandler(w http.ResponseWriter, r *http.Request)
RESTRunHandler is API version of UI submit handler. TODO: refactor common option/args/flag parsing between uihandler.go and this.
func RESTStatusHandler ¶
func RESTStatusHandler(w http.ResponseWriter, r *http.Request)
RESTStatusHandler will print the state of the runs.
func RESTStopHandler ¶
func RESTStopHandler(w http.ResponseWriter, r *http.Request)
RESTStopHandler is the API to stop a given run by runid or all the runs if unspecified/0.
func Run ¶
func Run(w http.ResponseWriter, r *http.Request, jd map[string]interface{}, runner, url string, ro *periodic.RunnerOptions, httpopts *fhttp.HTTPOptions, htmlMode bool, ) (periodic.HasRunnerResult, string, []byte, error)
Run executes the run (can be called async or not, writer is nil for async mode). API is a bit awkward to be compatible with both this new now main REST code but also the old one in ui/uihandler.go.
func RunMetrics ¶ added in v1.53.0
RunMetrics returns the number of currently running runs as well as the total runs so far. acquire the lock once (per scrape) for all stats.
func SendTSVDataIndex ¶
func SendTSVDataIndex(urlPrefix string, w http.ResponseWriter)
SendTSVDataIndex is the index format for gcloud transfer https://cloud.google.com/storage/transfer/create-url-list
func SetDataDir ¶
func SetDataDir(datadir string)
func SetHook ¶ added in v1.69.0
func SetHook(h bincommon.FortioHook)
SetHook is called by main() to set the hook for fortiotel.
func StopByRunID ¶
StopByRunID stops all the runs if passed 0 or the runid provided. if wait is true, waits for the run to actually end (single only).
func UpdateRun ¶ added in v1.35.0
func UpdateRun(ro *periodic.RunnerOptions) *periodic.Aborter
UpdateRun must be called exactly once for each runner. Responsible for normalization (abort channel setup) and making sure the options object returned in status is same as the actual one. Note that the Aborter/Stop field is being "moved" into the runner when making the concrete runner and cleared from the original options object so we need to keep our own copy of the aborter pointer. See newPeriodicRunner. Note this is arguably not the best behavior design/could be changed.
Types ¶
type AsyncReply ¶ added in v1.35.0
type AsyncReply struct {
jrpc.ServerReply
RunID int64
Count int
// Object ID to retrieve results (only usable if save=on).
// Also returned when using stop as long as exactly 1 run is stopped.
ResultID string
// Result URL, constructed from the ResultID and the incoming request URL, if available.
ResultURL string
}
AsyncReply is returned when async=on is passed.
type DNSReply ¶ added in v1.54.0
type DNSReply struct {
jrpc.ServerReply
Name string
IPv4 []string
IPv6 []string
}
type Status ¶ added in v1.35.0
type Status struct {
RunID int64
State StateEnum
RunnerOptions *periodic.RunnerOptions
// contains filtered or unexported fields
}
type StatusMap ¶ added in v1.35.0
func GetAllRuns ¶ added in v1.35.0
func GetAllRuns() StatusMap
GetAllRuns returns a copy of the status map (note maps are always reference types, so no copy is done when returning the map value).
type StatusReply ¶ added in v1.35.0
type StatusReply struct {
jrpc.ServerReply
Statuses StatusMap
}