reqlog

package
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2026 License: Apache-2.0 Imports: 4 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package reqlog records every API call and data-plane request as a structured entry (FR-CORE-061) and keeps the most recent ones in memory for the admin API (FR-CORE-045).

Index

Constants

View Source
const MaxBody = 16 << 10

MaxBody is how much of a body an entry keeps.

Variables

This section is empty.

Functions

This section is empty.

Types

type Bodies added in v0.6.0

type Bodies struct {
	Request  *Body `json:"requestBody,omitempty"`
	Response *Body `json:"responseBody,omitempty"`
}

Bodies are the bodies of one API call.

type Body added in v0.6.0

type Body struct {
	ContentType string `json:"contentType,omitempty"`
	// Size is the body's length in bytes: what the handler read of a
	// request, or wrote of a response.
	Size int64 `json:"size"`
	// Text is the first MaxBody bytes; empty when Binary.
	Text      string `json:"text,omitempty"`
	Truncated bool   `json:"truncated,omitempty"`
	// Binary is set when the kept bytes are not UTF-8 text.
	Binary bool `json:"binary,omitempty"`
}

Body is the start of a request or response body.

func NewBody added in v0.6.0

func NewBody(contentType string, head []byte, size int64) *Body

NewBody returns the body of size bytes that starts with head, keeping at most MaxBody bytes of it as text.

type Capture added in v0.6.0

type Capture struct {
	// contains filtered or unexported fields
}

Capture collects the first MaxBody bytes written to it and counts the rest.

func (*Capture) Body added in v0.6.0

func (c *Capture) Body(contentType string) *Body

Body returns what was written as a Body, or nil when nothing was.

func (*Capture) Write added in v0.6.0

func (c *Capture) Write(p []byte) (int, error)

type Detail added in v0.6.0

type Detail struct {
	Entry
	Bodies
}

Detail is an entry with its bodies.

type Entry

type Entry struct {
	// ID numbers the entries of one process from 1, in the order added.
	ID       int64     `json:"id"`
	Time     time.Time `json:"time"`
	Service  string    `json:"service"`
	Protocol string    `json:"protocol"` // http, grpc, dns, postgres, tcp, udp
	Method   string    `json:"method"`
	// Resource is the resource acted on: the one whose permission an API
	// call checked first, the answering DNS zone, the Cloud SQL instance or
	// the Cloud NAT gateway.
	Resource  string `json:"resource,omitempty"`
	Principal string `json:"principal,omitempty"`
	// Status is protocol-specific: the HTTP status, gRPC code or DNS
	// rcode; for connections (postgres, NAT) 0 when admitted and 1 when
	// refused, with the reason in Code.
	Status    int     `json:"status"`
	Code      string  `json:"code,omitempty"`
	LatencyMS float64 `json:"latencyMs"`
	// LB is the load balancer's trace of a data-plane request.
	LB *LBTrace `json:"lb,omitempty"`
	// NAT is the NAT egress proxy's trace of an internet egress attempt.
	NAT *NATTrace `json:"nat,omitempty"`
	// Bodies are the API call's request and response bodies. They are left
	// out of Entries and of the event stream, and read with Get.
	Bodies *Bodies `json:"-"`
}

Entry is one logged request.

type LBTrace added in v0.6.0

type LBTrace struct {
	Host string `json:"host"`
	// Path is the path and query as the client sent them.
	Path        string `json:"path"`
	TargetProxy string `json:"targetProxy,omitempty"`
	URLMap      string `json:"urlMap,omitempty"`
	// Match is the URL map rule that matched: "routeRule", "pathRule",
	// "pathMatcherDefault" or "urlMapDefault"; empty when the URL map is
	// missing or invalid.
	Match       string `json:"match,omitempty"`
	PathMatcher string `json:"pathMatcher,omitempty"`
	// Priority is the matched route rule's; Paths the matched path rule's.
	Priority *int64   `json:"priority,omitempty"`
	Paths    []string `json:"paths,omitempty"`
	// Redirect is the Location of a redirect the load balancer answered.
	Redirect string `json:"redirect,omitempty"`
	// Backend is the backend service or bucket path, Endpoint the
	// endpoint (ip:port, or the bucket) that answered.
	Backend  string `json:"backend,omitempty"`
	Endpoint string `json:"endpoint,omitempty"`
	// CacheStatus is Cloud CDN's {cdn_cache_status}: hit, miss,
	// revalidated, uncacheable, or disabled when the backend has no CDN.
	CacheStatus      string  `json:"cacheStatus,omitempty"`
	StatusDetails    string  `json:"statusDetails,omitempty"`
	BackendLatencyMS float64 `json:"backendLatencyMs,omitempty"`
}

LBTrace is how a load balancer served one request: the forwarding rule is the Entry's Resource.

type Log

type Log struct {
	// contains filtered or unexported fields
}

Log is a bounded ring buffer of entries that also writes to a logger.

func New

func New(size int, log *slog.Logger) *Log

New returns a log keeping the last size entries.

func (*Log) Add

func (l *Log) Add(e Entry)

Add records e, numbering it. A nil Log discards it.

func (*Log) Clear

func (l *Log) Clear()

Clear drops all entries. IDs keep counting, so an ID never names two entries.

func (*Log) Entries

func (l *Log) Entries(service string) []Entry

Entries returns the retained entries, oldest first, optionally filtered by service.

func (*Log) Get added in v0.6.0

func (l *Log) Get(id int64) (Detail, bool)

Get returns the retained entry numbered id, with its bodies.

func (*Log) OnAdd added in v0.2.0

func (l *Log) OnAdd(fn func(Entry))

OnAdd sets a function called with every entry added. Set it before the Log is used.

type NATTrace added in v0.6.0

type NATTrace struct {
	Network    string `json:"network"`
	Subnetwork string `json:"subnetwork,omitempty"`
	// VM is the workload holding the source address, e.g. a GKE node.
	VM       string `json:"vm,omitempty"`
	SrcIP    string `json:"srcIp"`
	SrcPort  int    `json:"srcPort"`
	DestIP   string `json:"destIp"`
	DestPort int    `json:"destPort"`
	// NatIP and NatPort are the translated source, when one was allocated.
	NatIP   string `json:"natIp,omitempty"`
	NatPort int    `json:"natPort,omitempty"`
	// Request is the first line the offline sink received.
	Request string `json:"request,omitempty"`
}

NATTrace is one connection the NAT egress proxy saw leave a VPC network: translated, dropped or answered by the offline sink (the Entry's Code). The Cloud NAT gateway, or the network when no NAT covers the source, is the Entry's Resource. Fields follow Cloud NAT's log (FR-NAT-004).

Jump to

Keyboard shortcuts

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