rapi

package
v1.63.7 Latest Latest
Warning

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

Go to latest
Published: Apr 3, 2024 License: Apache-2.0 Imports: 23 Imported by: 2

Documentation

Overview

Copyright 2022 Fortio Authors.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Remote API to trigger load tests package (REST API).

Index

Constants

View Source
const (
	JSONExtension = ".json"
	DataDir       = "data/"
)
View Source
const (
	RestRunURI    = "rest/run"
	RestStatusURI = "rest/status"
	RestStopURI   = "rest/stop"
	RestDNS       = "rest/dns"
	ModeGRPC      = "grpc"
)

Variables

View Source
var (

	// Default percentiles when not otherwise specified.
	DefaultPercentileList []float64
)

Functions

func AddDataHandler added in v1.35.0

func AddDataHandler(mux *http.ServeMux, baseurl, uipath, datadir string)

func AddHandlers

func AddHandlers(ahook bincommon.FortioHook, mux *http.ServeMux, baseurl, uiPath, datadir string)

AddHandlers adds the REST Api handlers for run, status and stop. uiPath must end with a /.

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

func FormValue(r *http.Request, json map[string]interface{}, key string) string

FormValue gets the value from the query arguments/url parameter or from the provided map (json data).

func GetConfigAtPath

func GetConfigAtPath(path string, data []byte) (map[string]interface{}, error)

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

func GetDataURL(r *http.Request) string

GetDataURL gives the url of the data/ dir either using configured `-base-url` and ui path from the incoming Host header.

func ID2URL added in v1.35.0

func ID2URL(r *http.Request, id string) string

func LogAndFilterDataRequest added in v1.35.0

func LogAndFilterDataRequest(h http.Handler) http.Handler

LogAndFilterDataRequest logs the data request.

func NextRunID added in v1.35.0

func NextRunID() int64

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 RemoveRun

func RemoveRun(id int64)

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

func RunMetrics() (int, int64)

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 SaveJSON

func SaveJSON(name string, json []byte) string

SaveJSON save Json bytes to give file name (.json) in data-path dir.

func SendTSVDataIndex

func SendTSVDataIndex(urlPrefix string, w http.ResponseWriter)

format for gcloud transfer https://cloud.google.com/storage/transfer/create-url-list

func SetDataDir

func SetDataDir(datadir string)

func StopByRunID

func StopByRunID(runid int64, wait bool) (int, string)

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

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 StateEnum added in v1.35.0

type StateEnum int
const (
	StateUnknown StateEnum = iota
	StatePending
	StateRunning
	StateStopping
	StateStopped
)

func (StateEnum) String added in v1.35.0

func (se StateEnum) String() string

type Status added in v1.35.0

type Status struct {
	RunID         int64
	State         StateEnum
	RunnerOptions *periodic.RunnerOptions
	// contains filtered or unexported fields
}

func GetRun added in v1.35.0

func GetRun(id int64) *Status

type StatusMap added in v1.35.0

type StatusMap map[int64]*Status

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
}

Jump to

Keyboard shortcuts

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