Documentation
¶
Overview ¶
Package gcpserve holds the pieces GCP emulators share to serve user workloads from containers.
Index ¶
- Constants
- func AcquirePort(ctx context.Context, pool PortPool, label string) (int, error)
- func CloudRunJobResource(project, job, location string) *monitoredres.MonitoredResource
- func CloudRunResource(project, service, revision, location string) *monitoredres.MonitoredResource
- func LogName(project, id string) string
- func Proxy(port int, rt http.RoundTripper) *httputil.ReverseProxy
- func ReleasePort(pool PortPool, port int)
- func StreamLogs(ctx context.Context, rt any, id string, t LogTarget, sink LogSink) error
- func WaitReady(ctx context.Context, port int) error
- type LazyRuntime
- type LogCapture
- func (c *LogCapture) Follow(ctx context.Context, rt any, id string, t LogTarget) StopFunc
- func (c *LogCapture) Request(ctx context.Context, t LogTarget, r *http.Request, rec *RequestRecorder, ...)
- func (c *LogCapture) SetSink(s LogSink)
- func (c *LogCapture) Start(ctx context.Context, rt any, id string, t LogTarget)
- func (c *LogCapture) Wait()
- type LogSink
- type LogTarget
- type PortPool
- type RequestRecorder
- type Runner
- type StopFunc
Constants ¶
const ( StreamStdout = "stdout" StreamStderr = "stderr" )
Container output streams, named as in the Cloud Run log ids.
const ProbeUserAgent = "gopherstack-readiness-probe"
ProbeUserAgent identifies readiness probes sent to workload containers.
Variables ¶
This section is empty.
Functions ¶
func AcquirePort ¶
AcquirePort takes a host port from pool, or a free loopback port when pool is nil.
func CloudRunJobResource ¶
func CloudRunJobResource(project, job, location string) *monitoredres.MonitoredResource
CloudRunJobResource returns the cloud_run_job resource that Cloud Run job tasks log under.
func CloudRunResource ¶
func CloudRunResource(project, service, revision, location string) *monitoredres.MonitoredResource
CloudRunResource returns the cloud_run_revision resource that Cloud Run and 2nd-gen functions log under.
func LogName ¶
LogName returns projects/{project}/logs/{id} with id URL-escaped, as the Logging API expects.
func Proxy ¶
func Proxy(port int, rt http.RoundTripper) *httputil.ReverseProxy
Proxy reverse-proxies to the container published on the loopback port, preserving the inbound Host.
func ReleasePort ¶
ReleasePort returns port to pool; a nil pool or zero port is a no-op.
func StreamLogs ¶
StreamLogs follows container id's output and writes each line to sink until the container goes away or ctx ends. rt must implement container.LogStreamer.
Types ¶
type LazyRuntime ¶
type LazyRuntime struct {
// contains filtered or unexported fields
}
LazyRuntime connects to the container runtime on first use and retries while it is unreachable.
func NewLazyRuntime ¶
func NewLazyRuntime(log *slog.Logger, lockName string) *LazyRuntime
NewLazyRuntime returns a LazyRuntime whose lock is named lockName.
func (*LazyRuntime) Get ¶
func (l *LazyRuntime) Get() (Runner, error)
Get returns the connected runtime, dialing it if needed.
type LogCapture ¶
type LogCapture struct {
// contains filtered or unexported fields
}
LogCapture forwards workload output and request logs to a LogSink once one is wired.
func NewLogCapture ¶
func NewLogCapture(lockName string) *LogCapture
NewLogCapture returns a LogCapture whose lock is named lockName.
func (*LogCapture) Follow ¶
Follow is Start for a workload whose output must be complete before it is removed: the returned stop waits up to drain for the stream to end on its own (the container has exited), then cancels it. It is a no-op without a sink.
func (*LogCapture) Request ¶
func (c *LogCapture) Request( ctx context.Context, t LogTarget, r *http.Request, rec *RequestRecorder, took time.Duration, )
Request writes the request log for a finished request; a no-op without a sink.
func (*LogCapture) SetSink ¶
func (c *LogCapture) SetSink(s LogSink)
SetSink wires the destination; nil disables capture.
func (*LogCapture) Start ¶
Start follows container id's output in the background until the container is removed or ctx ends.
func (*LogCapture) Wait ¶
func (c *LogCapture) Wait()
Wait blocks until every capture goroutine has finished; call after the containers are removed.
type LogSink ¶
type LogSink interface {
WriteLogEntries(ctx context.Context, req *loggingpb.WriteLogEntriesRequest) error
}
LogSink receives log entries; *gcplogging.InMemoryBackend satisfies it.
type LogTarget ¶
type LogTarget struct {
Resource *monitoredres.MonitoredResource
Labels map[string]string
Project string
}
LogTarget says which monitored resource a workload's log entries belong to.
func (LogTarget) LineEntry ¶
LineEntry builds the entry for one output line: textPayload for plain text, jsonPayload for a JSON object.
type RequestRecorder ¶
type RequestRecorder struct {
// contains filtered or unexported fields
}
RequestRecorder remembers the status and response size of a proxied request without wrapping the ResponseWriter.
func NewRequestRecorder ¶
func NewRequestRecorder() *RequestRecorder
NewRequestRecorder returns an empty recorder; Attach it to the proxy before serving.
func (*RequestRecorder) Attach ¶
func (r *RequestRecorder) Attach(p *httputil.ReverseProxy)
Attach records p's upstream status and body size and its error responses.
func (*RequestRecorder) Size ¶
func (r *RequestRecorder) Size() int64
Size returns the response bytes read from the upstream.
func (*RequestRecorder) Status ¶
func (r *RequestRecorder) Status() int
Status returns the recorded status, 200 when the handler wrote nothing.