Documentation

Index

Constants

View Source
const (
	CheckRequest = 1 + iota
	QuotaRequest
	ReportRequest
)
View Source
const (
	OK                  = 0
	CANCELLED           = 1
	UNKNOWN             = 2
	INVALID_ARGUMENT    = 3
	DEADLINE_EXCEEDED   = 4
	NOT_FOUND           = 5
	ALREADY_EXISTS      = 6
	PERMISSION_DENIED   = 7
	UNAUTHENTICATED     = 16
	RESOURCE_EXHAUSTED  = 8
	FAILED_PRECONDITION = 9
	ABORTED             = 10
	OUT_OF_RANGE        = 11
	UNIMPLEMENTED       = 12
	INTERNAL            = 13
	UNAVAILABLE         = 14
	DATA_LOSS           = 15
)
View Source
const (
	// Path with filtering for ESPv2 stats.
	ESpv2FiltersStatsPath = "/stats?format=json&usedonly&filter=http.ingress_http.(path_matcher|backend_auth|service_control|backend_routing)"
)

Variables

This section is empty.

Functions

func AggregateReport

func AggregateReport(pb *scpb.ReportRequest, n int64)

AggregateReport aggregates N report body into one, as all metric values * N, and its LowEntries appended N times.

func CheckAPIKey

func CheckAPIKey(t *testing.T, scCheck *ServiceRequest, wantApiKey string, desc string)

func CheckScRequest

func CheckScRequest(t *testing.T, scRequests []*ServiceRequest, wantScRequests []interface{}, desc string)

func CommonArgs

func CommonArgs() []string

func CreateCheck

func CreateCheck(er *ExpectedCheck) scpb.CheckRequest

func CreateReport

func CreateReport(er *ExpectedReport) scpb.ReportRequest

CreateReport makes a service_controller.proto ReportRequest out of an ExpectedReport

func DoWithHeaders

func DoWithHeaders(url, method, message string, headers map[string]string) (http.Header, []byte, error)

DoWithHeaders performs a GET/POST/PUT/DELETE/PATCH request to a specified url with given headers and message(if provided)

func ESPv2Version

func ESPv2Version() string

func Elapsed

func Elapsed(what string) func()

func FetchStats

func FetchStats(adminPort uint16) (StatCounters, StatHistograms, error)

func HttpResponseCodeToStatusCode

func HttpResponseCodeToStatusCode(code int) int

func ProtoDiff

func ProtoDiff(x, y proto.Message) string

ProtoDiff returns git diff style line-by-line diff between marshalled proto. Lines prefixed with '-' are missing in y and lines prefixed with '+' are extra in y.

func RpcStatusDeterministicJsonFormat

func RpcStatusDeterministicJsonFormat(jsonBytes []byte) string

RpcStatusDeterministicJsonFormat converts the unordered json format of rpcStatus to an ordered one.

func StringDiff

func StringDiff(x, y string) string

StringDiff returns git diff style line-by-line diff between two strings. Lines prefixed with '-' are missing in y and lines prefixed with '+' are extra in y.

func UnmarshalCheckRequest

func UnmarshalCheckRequest(data []byte) (*scpb.CheckRequest, error)

UnmarshalCheckRequest returns proto CheckRequest given data.

func UnmarshalQuotaRequest

func UnmarshalQuotaRequest(data []byte) (*scpb.AllocateQuotaRequest, error)

UnmarshalQuotaRequest returns proto AllocateQuotaRequest given data.

func UnmarshalReportRequest

func UnmarshalReportRequest(data []byte) (*scpb.ReportRequest, error)

UnmarshalReportRequest returns proto ReportRequest given data.

func VerifyCheck

func VerifyCheck(body []byte, ec *ExpectedCheck) error

VerifyCheck verify if the response body is the expected CheckRequest. If the verification fails, it returns an error.

func VerifyQuota

func VerifyQuota(body []byte, er *ExpectedQuota) error

VerifyQuota verify if the response body is the expected AllocateQuotaRequest. If the verification fails, it returns an error.

func VerifyReport

func VerifyReport(body []byte, er *ExpectedReport) error

VerifyReport verify if the response body is the expected ReportRequest. If the verification fails, it returns an error.

func VerifyReportRequestOperationLabel

func VerifyReportRequestOperationLabel(body []byte, label, value string) error

VerifyReportRequestOperationLabel verifies whether a ReportRequest has the correct value for the label specified

func VerifyServiceControlResp

func VerifyServiceControlResp(desc string, wantScRequests []interface{}, scRequests []*ServiceRequest) error

Types

type ComputedQuantiles

type ComputedQuantiles struct {
	Name   string  `json:"name"`
	Values []Point `json:"values"`
}

ComputedQuantiles is the struct to represent the computed quantile for each histogram.

type ExpectedCheck

type ExpectedCheck struct {
	Version                string
	ServiceName            string
	ServiceConfigID        string
	ConsumerID             string
	OperationName          string
	CallerIp               string
	AndroidCertFingerprint string
	AndroidPackageName     string
	ApiKey                 string
	IosBundleID            string
	Referer                string
}

type ExpectedQuota

type ExpectedQuota struct {
	ConsumerID      string
	MethodName      string
	QuotaMetrics    map[string]int64
	QuotaMode       scpb.QuotaOperation_QuotaMode
	ServiceConfigID string
	ServiceName     string
}

type ExpectedReport

type ExpectedReport struct {
	Aggregate         int64
	Version           string
	ServiceName       string
	ServiceConfigID   string
	ApiVersion        string
	ApiMethod         string
	ApiName           string
	ApiKey            string
	ProducerProjectID string
	ConsumerProjectID string
	URL               string
	Location          string
	HttpMethod        string
	LogMessage        string
	RequestMsgCounts  int64
	ResponseMsgCounts int64
	ResponseCode      int
	Referer           string
	StatusCode        string
	ErrorCause        string
	ErrorType         string
	FrontendProtocol  string
	BackendProtocol   string
	Platform          string
	JwtAuth           string
	RequestHeaders    string
	ResponseHeaders   string
	JwtPayloads       string
}

type Histogram

type Histogram struct {
	// Cq represents computed_quantiles.
	Cq []ComputedQuantiles `json:"computed_quantiles,omitempty"`
	// Sq represents supported_quantiles.
	Sq []interface{} `json:"supported_quantiles,omitempty"`
}

Histogram is the struct which is an optional part of StatsData.

type MetricCreator

type MetricCreator int
const (
	MTProducer MetricCreator = 1 + iota
	MTConsumer
	MTProducerByConsumer
	MTProducerUnderGrpcStream
	MTConsumerUnderGrpcStream
)

type MetricValueInfo

type MetricValueInfo struct {
	MetricCreator   MetricCreator
	MetricValueType MetricValueType
	// Whether to use this metric when creating a ExpectedReport
	ShouldInit bool
}

type MetricValueType

type MetricValueType int
const (
	Int64 MetricValueType = 1 + iota
	Distribution
)

type Point

type Point struct {
	Cumulative float64 `json:"cumulative,omitempty"`
	Interval   float64 `json:"interval,omitempty"`
}

Point is the struct to decode the values of computed_quantiles.

type RetryServiceHandler

type RetryServiceHandler struct {
	RequestCount  int32
	SleepTimes    int32
	SleepLengthMs int32
}

func (*RetryServiceHandler) ServeHTTP

func (h *RetryServiceHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)

type ServiceRequest

type ServiceRequest struct {
	ReqType   ServiceRequestType
	ReqHeader http.Header
	ReqBody   []byte
}

type ServiceRequestType

type ServiceRequestType int

type StatCounters

type StatCounters map[string]int

type StatHistograms

type StatHistograms map[string][]float64

type Stats

type Stats struct {
	Stat []StatsData `json:"stats"`
}

Stats is the struct to decode envoy admin json raw data.

type StatsData

type StatsData struct {
	MetricName  string    `json:"name,omitempty"`
	MetricValue float64   `json:"value,omitempty"`
	Bar         Histogram `json:"histograms,omitempty"`
}

StatsData is the struct to decode the stats data, which may include the metric name and value, and metrics' histogram.