Help us shape the future of Go! Take the 2026 Go Developer Survey

gcplogging

package
v1.9.0 Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2026 License: MIT Imports: 44 Imported by: 0

README

Cloud Logging

Parity grade: B · SDK cloud.google.com/go/logging@v1.20.0 · last audited 2026-10-21 (b1f3fa139)

Coverage

Metric Value
PARITY entries audited 40 (35 ok, 3 partial, 2 gap)
Feature families 7 (3 ok, 4 partial)
Known gaps 7
Deferred items 0
Resource leaks clean
Known gaps
  • Linked datasets (CreateLink, GetLink, ListLinks, DeleteLink) and CopyLogEntries return UNIMPLEMENTED.
  • Sinks on folders, organizations and billing accounts are stored, but include_children aggregation is not applied: only entries written to that parent's own logs are routed.
  • Sink destinations are not checked for existence at create time, and a missing destination only logs a warning when an entry is exported.
  • Cloud Storage export appends to the hourly object immediately instead of batching with the live service's delay; BigQuery tables use a fixed schema with JSON columns instead of the live typed schema, and partitioned tables are plain tables.
  • CMEK keys and settings are stored only; nothing is encrypted and the key is not validated against Cloud KMS.
  • Error messages and the edge cases of the live service (entry timestamp bounds, quota errors, SaveStatus details) were not verified against it; ListLogEntries default page size and Tail buffer_window behaviour are approximations.
  • Bucket index_configs, restricted_fields and analytics_enabled are stored but have no effect on queries.

More

Documentation

Index

Constants

View Source
const DefaultPort = 8131

DefaultPort is the dedicated gRPC listener's default TCP port.

Variables

View Source
var ErrNilAppContext = errors.New("gcplogging: nil app context")

ErrNilAppContext is returned when Init is called with a nil AppContext.

View Source
var ErrObjectNotFound = errors.New("object not found")

ErrObjectNotFound is returned by an ObjectStore when a bucket or object does not exist.

Functions

This section is empty.

Types

type ConfigProvider

type ConfigProvider interface {
	GetGCPLoggingSettings() Settings
}

ConfigProvider extracts Cloud Logging configuration from the AppContext Config.

type Handler

type Handler struct {
	Backend *InMemoryBackend

	Port int
	// contains filtered or unexported fields
}

Handler serves the Cloud Logging gRPC API (and its REST transcoding) on a dedicated listener.

func NewHandler

func NewHandler(backend *InMemoryBackend) *Handler

NewHandler creates a Handler; callers override Port from Settings.

func (*Handler) Addr

func (h *Handler) Addr() string

Addr returns the bound listener address, or "" before StartWorker.

func (*Handler) ExtractOperation

func (h *Handler) ExtractOperation(*echo.Context) string

ExtractOperation is unused: requests never reach the shared router.

func (*Handler) ExtractResource

func (h *Handler) ExtractResource(*echo.Context) string

ExtractResource is unused: requests never reach the shared router.

func (*Handler) GetSupportedOperations

func (h *Handler) GetSupportedOperations() []string

GetSupportedOperations lists the supported gRPC methods.

func (*Handler) Handler

func (h *Handler) Handler() echo.HandlerFunc

Handler returns a 404 handler; the real API is on the dedicated port.

func (*Handler) MatchPriority

func (h *Handler) MatchPriority() int

MatchPriority is irrelevant because RouteMatcher never matches.

func (*Handler) Name

func (h *Handler) Name() string

Name returns the service name.

func (*Handler) Reset

func (h *Handler) Reset()

Reset clears all in-memory state.

func (*Handler) Restore

func (h *Handler) Restore(ctx context.Context, data []byte) error

Restore implements persistence.Persistable by delegating to the backend.

func (*Handler) RouteMatcher

func (h *Handler) RouteMatcher() service.Matcher

RouteMatcher never matches: Cloud Logging runs on its own listener.

func (*Handler) Shutdown

func (h *Handler) Shutdown(ctx context.Context)

Shutdown stops the gRPC server, forcing a close after a short grace period.

func (*Handler) Snapshot

func (h *Handler) Snapshot(ctx context.Context) []byte

Snapshot implements persistence.Persistable by delegating to the backend.

func (*Handler) StartWorker

func (h *Handler) StartWorker(ctx context.Context) error

StartWorker binds the dedicated listener synchronously so a port conflict is returned to the caller.

type InMemoryBackend

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

InMemoryBackend holds all Cloud Logging state under one lock.

func NewInMemoryBackend

func NewInMemoryBackend() *InMemoryBackend

NewInMemoryBackend creates an empty backend.

func (*InMemoryBackend) CreateBucket

CreateBucket adds a user-defined log bucket.

func (*InMemoryBackend) CreateExclusion

CreateExclusion adds a log exclusion under the parent.

func (*InMemoryBackend) CreateLogMetric

CreateLogMetric stores a log-based metric.

func (*InMemoryBackend) CreateSink

CreateSink adds a sink under the parent.

func (*InMemoryBackend) CreateView

CreateView adds a view to a bucket.

func (*InMemoryBackend) DeleteBucket

func (b *InMemoryBackend) DeleteBucket(name string) error

DeleteBucket marks a bucket DELETE_REQUESTED; it can be undeleted for seven days.

func (*InMemoryBackend) DeleteExclusion

func (b *InMemoryBackend) DeleteExclusion(name string) error

DeleteExclusion removes an exclusion.

func (*InMemoryBackend) DeleteLog

func (b *InMemoryBackend) DeleteLog(logName string) error

DeleteLog removes every entry of the log from all buckets of its parent.

func (*InMemoryBackend) DeleteLogMetric

func (b *InMemoryBackend) DeleteLogMetric(name string) error

DeleteLogMetric removes a metric.

func (*InMemoryBackend) DeleteSink

func (b *InMemoryBackend) DeleteSink(name string) error

DeleteSink removes a sink.

func (*InMemoryBackend) DeleteView

func (b *InMemoryBackend) DeleteView(name string) error

DeleteView removes a view.

func (*InMemoryBackend) GetBucket

func (b *InMemoryBackend) GetBucket(name string) (*loggingpb.LogBucket, error)

GetBucket returns one bucket.

func (*InMemoryBackend) GetCmekSettings

func (b *InMemoryBackend) GetCmekSettings(name string) (*loggingpb.CmekSettings, error)

GetCmekSettings returns the stored CMEK settings, or empty defaults.

func (*InMemoryBackend) GetExclusion

func (b *InMemoryBackend) GetExclusion(name string) (*loggingpb.LogExclusion, error)

GetExclusion returns one exclusion.

func (*InMemoryBackend) GetLogMetric

func (b *InMemoryBackend) GetLogMetric(name string) (*loggingpb.LogMetric, error)

GetLogMetric returns one metric.

func (*InMemoryBackend) GetSettings

func (b *InMemoryBackend) GetSettings(name string) (*loggingpb.Settings, error)

GetSettings returns the stored settings, or defaults.

func (*InMemoryBackend) GetSink

func (b *InMemoryBackend) GetSink(name string) (*loggingpb.LogSink, error)

GetSink returns one sink.

func (*InMemoryBackend) GetView

func (b *InMemoryBackend) GetView(name string) (*loggingpb.LogView, error)

GetView returns one view.

func (*InMemoryBackend) ListBuckets

ListBuckets returns the buckets of a location ("-" lists every location), ordered by name.

func (*InMemoryBackend) ListExclusions

ListExclusions returns the parent's exclusions ordered by name.

func (*InMemoryBackend) ListLogEntries

ListLogEntries returns matching entries ordered by timestamp, paged.

func (*InMemoryBackend) ListLogMetrics

ListLogMetrics returns the parent's metrics ordered by name.

func (*InMemoryBackend) ListLogs

func (b *InMemoryBackend) ListLogs(req *loggingpb.ListLogsRequest) ([]string, string, error)

ListLogs returns the names of logs that hold entries under the given resources.

func (*InMemoryBackend) ListMonitoredResourceDescriptors

func (b *InMemoryBackend) ListMonitoredResourceDescriptors(
	token string, size int32,
) ([]*monitoredres.MonitoredResourceDescriptor, string, error)

ListMonitoredResourceDescriptors pages the static catalog of monitored resource types.

func (*InMemoryBackend) ListSinks

ListSinks returns the parent's sinks ordered by name.

func (*InMemoryBackend) ListViews

ListViews returns a bucket's views ordered by name.

func (*InMemoryBackend) MetricPoints

func (b *InMemoryBackend) MetricPoints(name string) ([]MetricPoint, error)

MetricPoints returns the accumulated series of a log-based metric ([PARENT]/metrics/[ID]).

func (*InMemoryBackend) Reset

func (b *InMemoryBackend) Reset()

Reset clears all state; exporter wiring is kept.

func (*InMemoryBackend) Restore

func (b *InMemoryBackend) Restore(ctx context.Context, data []byte) error

Restore loads backend state from a snapshot.

func (*InMemoryBackend) SetObjectStore

func (b *InMemoryBackend) SetObjectStore(s ObjectStore)

SetObjectStore wires Cloud Storage sink destinations.

func (*InMemoryBackend) SetPublisher

func (b *InMemoryBackend) SetPublisher(p Publisher)

SetPublisher wires Pub/Sub sink destinations.

func (*InMemoryBackend) SetTableStore

func (b *InMemoryBackend) SetTableStore(s TableStore)

SetTableStore wires BigQuery sink destinations.

func (*InMemoryBackend) Snapshot

func (b *InMemoryBackend) Snapshot(ctx context.Context) []byte

Snapshot serialises buckets with their entries, sinks, exclusions, views, metrics and settings.

func (*InMemoryBackend) Tail

Tail streams new matching entries to send until the client goes away or the server stops.

func (*InMemoryBackend) UndeleteBucket

func (b *InMemoryBackend) UndeleteBucket(name string) error

UndeleteBucket restores a bucket that is pending deletion.

func (*InMemoryBackend) UpdateBucket

UpdateBucket applies the masked fields to a bucket.

func (*InMemoryBackend) UpdateCmekSettings

UpdateCmekSettings stores the key used for new log buckets; the key is not validated against Cloud KMS.

func (*InMemoryBackend) UpdateExclusion

UpdateExclusion applies the masked fields of the request exclusion.

func (*InMemoryBackend) UpdateLogMetric

UpdateLogMetric replaces a metric, creating it when it does not exist.

func (*InMemoryBackend) UpdateSettings

UpdateSettings stores organization or folder defaults; disable_default_sink disables the _Default sink.

func (*InMemoryBackend) UpdateSink

UpdateSink applies the masked fields of the request sink.

func (*InMemoryBackend) UpdateView

UpdateView applies the masked fields to a view.

func (*InMemoryBackend) WriteLogEntries

func (b *InMemoryBackend) WriteLogEntries(ctx context.Context, req *loggingpb.WriteLogEntriesRequest) error

WriteLogEntries stores entries, routes them through sinks, updates log-based metrics and feeds tails.

type MetricPoint

type MetricPoint struct {
	Labels       map[string]string
	BucketCounts []int64
	Count        int64
	Sum          float64
	SumSqDev     float64
}

MetricPoint is the accumulated value of one label combination of a log-based metric.

type ObjectStore

type ObjectStore interface {
	// ReadObject returns the object content or an error wrapping ErrObjectNotFound.
	ReadObject(bucket, name string) ([]byte, error)
	WriteObject(bucket, name string, data []byte, contentType string) error
}

ObjectStore is the slice of Cloud Storage that sink export needs.

type Provider

type Provider struct{}

Provider implements service.Provider for Google Cloud Logging. It serves gRPC and REST on its own listener (see Handler.StartWorker) and never matches on the shared AWS router.

func (*Provider) Init

Init creates the backend and handler; the port is bound in StartWorker.

func (*Provider) Name

func (p *Provider) Name() string

Name returns the service provider name.

type Publisher

type Publisher interface {
	Publish(topic string, data []byte, attrs map[string]string) error
}

Publisher publishes one message to a Pub/Sub topic (projects/P/topics/T).

type Settings

type Settings struct {
	Port int `` //nolint:lll // config struct tags are intentionally verbose
	/* 182-byte string literal not displayed */
}

Settings holds service-level configuration, embedded in the root CLI command as CLI.GCPLogging.

func DefaultSettings

func DefaultSettings() Settings

DefaultSettings returns the settings used when no ConfigProvider is available.

type TableStore

type TableStore interface {
	// EnsureTable creates the table with the schema when it does not exist.
	EnsureTable(project, dataset, table string, schema []map[string]any) error
	InsertRows(project, dataset, table string, rows []map[string]any) error
}

TableStore is the slice of BigQuery that sink export needs.

Jump to

Keyboard shortcuts

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