accessdata

package
v0.0.0-...-d72b2cd Latest Latest
Warning

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

Go to latest
Published: Mar 21, 2023 License: BSD-3-Clause Imports: 7 Imported by: 2

Documentation

Overview

Example (CreateOperator)
op, err := createOperator(Operator{})
fmt.Printf("test: createOperator({}) -> [%v] [err:%v]\n", translateOperator(op), err)

op, err = createOperator(Operator{Name: " ", Value: "static"})
fmt.Printf("test: createOperator(\"static\") -> [%v] [err:%v]\n", translateOperator(op), err)

op, err = createOperator(Operator{Name: "static", Value: "value"})
fmt.Printf("test: createOperator(\"static\") -> [%v] [err:%v]\n", translateOperator(op), err)

op, err = createOperator(Operator{Name: "", Value: "%TRAFFIC__%"})
fmt.Printf("test: createOperator(\"TRAFFIC__\") -> [%v] [err:%v]\n", translateOperator(op), err)

op, err = createOperator(Operator{Name: "", Value: "%REQ("})
fmt.Printf("test: createOperator(\"REQ(static)\") -> [%v] [err:%v]\n", translateOperator(op), err)

op, err = createOperator(Operator{Name: "", Value: "%REQ(test"})
fmt.Printf("test: createOperator(\"REQ(static)\") -> [%v] [err:%v]\n", translateOperator(op), err)

//op, err = createOperator(Operator{Name: "", Value: "%REQ()%"})
//fmt.Printf("test: createOperator(\"REQ(static)\") -> [%v] [err:%v]\n", translateOperator(op), err)

op, err = createOperator(Operator{Name: "", Value: "%REQ(static)%"})
fmt.Printf("test: createOperator(\"REQ(static)\") -> [%v] [err:%v]\n", translateOperator(op), err)

op, err = createOperator(Operator{Name: "new-name", Value: "%REQ(static)%"})
fmt.Printf("test: createOperator(\"REQ(static)\") -> [%v] [err:%v]\n", translateOperator(op), err)

op, err = createOperator(Operator{Name: "", Value: "%TRAFFIC%"})
fmt.Printf("test: createOperator(\"TRAFFIC\") -> [%v] [err:%v]\n", translateOperator(op), err)

op, err = createOperator(Operator{Name: "new-name", Value: "%TRAFFIC%"})
fmt.Printf("test: createOperator(\"TRAFFIC\") -> [%v] [err:%v]\n", translateOperator(op), err)
Output:

test: createOperator({}) -> [{<empty> <empty>}] [err:invalid operator: value is empty ]
test: createOperator("static") -> [{<empty> <empty>}] [err:invalid operator: name is empty [static]]
test: createOperator("static") -> [{static value}] [err:<nil>]
test: createOperator("TRAFFIC__") -> [{<empty> <empty>}] [err:invalid operator: value not found or invalid %TRAFFIC__%]
test: createOperator("REQ(static)") -> [{<empty> <empty>}] [err:invalid operator: value not found or invalid %REQ(]
test: createOperator("REQ(static)") -> [{<empty> <empty>}] [err:invalid operator: value not found or invalid %REQ(test]
test: createOperator("REQ(static)") -> [{static %REQ(static)%}] [err:<nil>]
test: createOperator("REQ(static)") -> [{new-name %REQ(static)%}] [err:<nil>]
test: createOperator("TRAFFIC") -> [{traffic %TRAFFIC%}] [err:<nil>]
test: createOperator("TRAFFIC") -> [{new-name %TRAFFIC%}] [err:<nil>]

Index

Examples

Constants

View Source
const (
	EgressTraffic  = "egress"
	IngressTraffic = "ingress"
	PingTraffic    = "ping"

	PingName           = "ping"
	TimeoutName        = "timeout"
	FailoverName       = "failover"
	ProxyName          = "proxy"
	RetryName          = "retry"
	RetryRateLimitName = "retryRateLimit"
	RetryRateBurstName = "retryBurst"
	RateLimitName      = "rateLimit"
	RateBurstName      = "burst"
	ControllerName     = "name"
)
View Source
const (
	OperatorPrefix         = "%"
	RequestReferencePrefix = "%REQ("

	RequestIdHeaderName    = "X-REQUEST-ID"
	FromRouteHeaderName    = "FROM-ROUTE"
	UserAgentHeaderName    = "USER-AGENT"
	ForwardedForHeaderName = "X-FORWARDED-FOR"

	TrafficOperator        = "%TRAFFIC%"      // ingress, egress, ping
	StartTimeOperator      = "%START_TIME%"   // start time
	DurationOperator       = "%DURATION%"     // Total duration in milliseconds of the request from the start time to the last byte out.
	DurationStringOperator = "%DURATION_STR%" // Time package formatted

	OriginRegionOperator     = "%REGION%"      // origin region
	OriginZoneOperator       = "%ZONE%"        // origin zone
	OriginSubZoneOperator    = "%SUB_ZONE%"    // origin sub zone
	OriginServiceOperator    = "%SERVICE%"     // origin service
	OriginInstanceIdOperator = "%INSTANCE_ID%" // origin instance id

	RouteNameOperator       = "%ROUTE_NAME%"
	TimeoutDurationOperator = "%TIMEOUT_DURATION%"
	RateLimitOperator       = "%RATE_LIMIT%"
	RateBurstOperator       = "%RATE_BURST%"
	RetryOperator           = "%RETRY"
	RetryRateLimitOperator  = "%RETRY_RATE_LIMIT%"
	RetryRateBurstOperator  = "%RETRY_RATE_BURST%"
	FailoverOperator        = "%FAILOVER%"
	ProxyOperator           = "%PROXY%"

	ResponseStatusCodeOperator    = "%STATUS_CODE%"    // HTTP status code
	ResponseBytesReceivedOperator = "%BYTES_RECEIVED%" // bytes received
	ResponseBytesSentOperator     = "%BYTES_SENT%"     // bytes sent
	StatusFlagsOperator           = "%STATUS_FLAGS%"   // status flags

	RequestProtocolOperator = "%PROTOCOL%" // HTTP Protocol
	RequestMethodOperator   = "%METHOD%"   // HTTP method
	RequestUrlOperator      = "%URL%"
	RequestPathOperator     = "%PATH%"
	RequestHostOperator     = "%HOST%"

	RequestIdOperator           = "%X-REQUEST-ID%"    // X-REQUEST-ID request header value
	RequestFromRouteOperator    = "%FROM-ROUTE%"      // request from route name
	RequestUserAgentOperator    = "%USER-AGENT%"      // user agent request header value
	RequestAuthorityOperator    = "%AUTHORITY%"       // authority request header value
	RequestForwardedForOperator = "%X-FORWARDED-FOR%" // client IP address (X-FORWARDED-FOR request header value)

	GRPCStatusOperator       = "%GRPC_STATUS(X)%"     // gRPC status code formatted according to the optional parameter X, which can be CAMEL_STRING, SNAKE_STRING and NUMBER. X-REQUEST-ID request header value
	GRPCStatusNumberOperator = "%GRPC_STATUS_NUMBER%" // gRPC status code.

)

Variables

This section is empty.

Functions

func FmtTimestamp

func FmtTimestamp(t time.Time) string

func IsDirectOperator

func IsDirectOperator(op Operator) bool

func IsEmpty

func IsEmpty(s string) bool

func IsRequestOperator

func IsRequestOperator(op Operator) bool

func IsStringValue

func IsStringValue(op Operator) bool

func RequestOperatorHeaderName

func RequestOperatorHeaderName(op Operator) string

func WriteJson

func WriteJson(items []Operator, data *Entry) string

func WriteText

func WriteText(items []Operator, data *Entry) string

Types

type Accessor

type Accessor func(entry *Entry)

Accessor - function type

type Entry

type Entry struct {
	Traffic   string
	Start     time.Time
	Duration  time.Duration
	CtrlState map[string]string

	// Request
	Url      string
	Path     string
	Host     string
	Protocol string
	Method   string
	Header   http.Header

	// Response
	StatusCode    int
	BytesSent     int64
	BytesReceived int64
	StatusFlags   string
}

Entry - struct for all access logging accessdata

func NewEgressEntry

func NewEgressEntry(start time.Time, duration time.Duration, req *http.Request, resp *http.Response, statusFlags string, controllerState map[string]string) *Entry

NewEgressEntry - create an Entry for egress traffic

func NewEmptyEntry

func NewEmptyEntry() *Entry

func NewEntry

func NewEntry(traffic string, start time.Time, duration time.Duration, req *http.Request, resp *http.Response, statusFlags string, controllerState map[string]string) *Entry

func NewIngressEntry

func NewIngressEntry(start time.Time, duration time.Duration, req *http.Request, resp *http.Response, statusFlags string, controllerState map[string]string) *Entry

NewIngressEntry - create an Entry for ingress traffic

func (*Entry) AddRequest

func (l *Entry) AddRequest(req *http.Request)

func (*Entry) AddResponse

func (l *Entry) AddResponse(resp *http.Response)

func (*Entry) AddUrl

func (l *Entry) AddUrl(uri string)

func (*Entry) String

func (l *Entry) String() string

func (*Entry) Value

func (l *Entry) Value(value string) string

type Formatter

type Formatter interface {
	Format(items []Operator, data *Entry) string
}

Formatter - template parameter for formatting

type JsonFormatter

type JsonFormatter struct{}

func (JsonFormatter) Format

func (JsonFormatter) Format(items []Operator, data *Entry) string

type Operator

type Operator struct {
	Name  string
	Value string
}

Operator - configuration of logging entries

func CreateOperators

func CreateOperators(operators []string) ([]Operator, error)

func InitOperators

func InitOperators(operators []Operator) ([]Operator, error)

type TextFormatter

type TextFormatter struct{}

func (TextFormatter) Format

func (TextFormatter) Format(items []Operator, data *Entry) string

Jump to

Keyboard shortcuts

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