Documentation ¶
Index ¶
- Constants
- func NoOpConsumerFn(consumer *ContainerLogConsumer) error
- func ShortenUrl(grafanaUrl, urlToShorten, bearerToken string) (string, error)
- type ConsumerConsumingFn
- type ConsumerLogConsumingFn
- type ContainerLogConsumer
- type FileLogHandler
- func (h FileLogHandler) GetLogLocation(_ map[string]*ContainerLogConsumer) (string, error)
- func (h FileLogHandler) GetTarget() LogTarget
- func (h *FileLogHandler) Handle(c *ContainerLogConsumer, content LogContent) error
- func (h *FileLogHandler) Init(c *ContainerLogConsumer) error
- func (h *FileLogHandler) Teardown() error
- type HandleLogTarget
- type InMemoryLogHandler
- func (h InMemoryLogHandler) GetLogLocation(_ map[string]*ContainerLogConsumer) (string, error)
- func (h InMemoryLogHandler) GetTarget() LogTarget
- func (h *InMemoryLogHandler) Handle(c *ContainerLogConsumer, content LogContent) error
- func (h *InMemoryLogHandler) Init(_ *ContainerLogConsumer) error
- func (h *InMemoryLogHandler) Teardown() error
- type LogContent
- type LogNotification
- type LogProducingContainer
- type LogStream
- func (m *LogStream) ConnectContainer(ctx context.Context, container LogProducingContainer, prefix string) error
- func (m *LogStream) ContainerLogs(name string) ([]string, error)
- func (m *LogStream) DisconnectContainer(container LogProducingContainer) error
- func (m *LogStream) FlushAndShutdown() error
- func (m *LogStream) FlushLogsToTargets() error
- func (m *LogStream) GetAllLogsAndConsume(preExecuteFn ConsumerConsumingFn, consumeLogFn ConsumerLogConsumingFn, ...) (loopErr error)
- func (m *LogStream) GetConsumers() map[string]*ContainerLogConsumer
- func (m *LogStream) PrintLogTargetsLocations()
- func (m *LogStream) SaveLogLocationInTestSummary()
- func (m *LogStream) SaveLogTargetsLocations(writer LogWriter)
- func (m *LogStream) Shutdown(context context.Context) error
- type LogTarget
- type LogWriter
- type LokiLogHandler
- func (h *LokiLogHandler) GetLogLocation(consumers map[string]*ContainerLogConsumer) (string, error)
- func (h LokiLogHandler) GetTarget() LogTarget
- func (h *LokiLogHandler) Handle(c *ContainerLogConsumer, content LogContent) error
- func (h *LokiLogHandler) Init(c *ContainerLogConsumer) error
- func (h *LokiLogHandler) Teardown() error
- type Option
Constants ¶
const NO_TEST = "no_test"
const (
ShorteningFailedErr = "failed to shorten Grafana URL"
)
Variables ¶
This section is empty.
Functions ¶
func NoOpConsumerFn ¶
func NoOpConsumerFn(consumer *ContainerLogConsumer) error
NoOpConsumerFn is a no-op consumer function
func ShortenUrl ¶ added in v1.23.0
Types ¶
type ConsumerConsumingFn ¶
type ConsumerConsumingFn = func(consumer *ContainerLogConsumer) error
type ConsumerLogConsumingFn ¶
type ConsumerLogConsumingFn = func(consumer *ContainerLogConsumer, log LogContent) error
type ContainerLogConsumer ¶
type ContainerLogConsumer struct {
// contains filtered or unexported fields
}
ContainerLogConsumer is a container log lines consumer
func (*ContainerLogConsumer) Accept ¶
func (g *ContainerLogConsumer) Accept(l testcontainers.Log)
Accept accepts the log message from particular container and saves it to the temp gob file
func (*ContainerLogConsumer) GetContainer ¶
func (g *ContainerLogConsumer) GetContainer() LogProducingContainer
GetContainer returns the container that this consumer is connected to
func (*ContainerLogConsumer) GetStartTime ¶
func (g *ContainerLogConsumer) GetStartTime() time.Time
GetStartTime returns the time of the first log line
func (*ContainerLogConsumer) MarkAsErrored ¶
func (g *ContainerLogConsumer) MarkAsErrored()
MarkAsErrored marks the consumer as errored (which makes it stop accepting logs)
func (*ContainerLogConsumer) ResetTempFile ¶
func (g *ContainerLogConsumer) ResetTempFile() error
ResetTempFile resets the temp file and gob encoder
type FileLogHandler ¶
type FileLogHandler struct {
// contains filtered or unexported fields
}
FileLogHandler saves logs to local files
func (FileLogHandler) GetLogLocation ¶
func (h FileLogHandler) GetLogLocation(_ map[string]*ContainerLogConsumer) (string, error)
func (FileLogHandler) GetTarget ¶
func (h FileLogHandler) GetTarget() LogTarget
func (*FileLogHandler) Handle ¶
func (h *FileLogHandler) Handle(c *ContainerLogConsumer, content LogContent) error
func (*FileLogHandler) Init ¶
func (h *FileLogHandler) Init(c *ContainerLogConsumer) error
func (*FileLogHandler) Teardown ¶
func (h *FileLogHandler) Teardown() error
type HandleLogTarget ¶
type HandleLogTarget interface { Handle(*ContainerLogConsumer, LogContent) error GetLogLocation(map[string]*ContainerLogConsumer) (string, error) GetTarget() LogTarget Init(*ContainerLogConsumer) error Teardown() error }
type InMemoryLogHandler ¶
type InMemoryLogHandler struct {
// contains filtered or unexported fields
}
InMemoryLogHandler stores logs in memory
func (InMemoryLogHandler) GetLogLocation ¶
func (h InMemoryLogHandler) GetLogLocation(_ map[string]*ContainerLogConsumer) (string, error)
func (InMemoryLogHandler) GetTarget ¶
func (h InMemoryLogHandler) GetTarget() LogTarget
func (*InMemoryLogHandler) Handle ¶
func (h *InMemoryLogHandler) Handle(c *ContainerLogConsumer, content LogContent) error
func (*InMemoryLogHandler) Init ¶
func (h *InMemoryLogHandler) Init(_ *ContainerLogConsumer) error
func (*InMemoryLogHandler) Teardown ¶
func (h *InMemoryLogHandler) Teardown() error
type LogContent ¶
LogContent is a representation of log that will be send to Loki
type LogNotification ¶
LogNotification notification about log line match for some container
type LogProducingContainer ¶
type LogProducingContainer interface { Name(ctx context.Context) (string, error) FollowOutput(consumer testcontainers.LogConsumer) StartLogProducer(ctx context.Context, timeout time.Duration) error StopLogProducer() error GetLogProducerErrorChannel() <-chan error IsRunning() bool GetContainerID() string Terminate(context.Context) error }
LogProducingContainer is a facade that needs to be implemented by any container that wants to be connected to LogStream
type LogStream ¶
type LogStream struct {
// contains filtered or unexported fields
}
LogStream is a test helper struct to monitor docker container logs for some patterns and push their logs into Loki for further analysis
func NewLogStream ¶
func NewLogStream(t *testing.T, loggingConfig *config.LoggingConfig, options ...Option) (*LogStream, error)
NewLogStream creates a new LogStream instance, with Loki client only if Loki log target is enabled (lazy init)
func (*LogStream) ConnectContainer ¶
func (m *LogStream) ConnectContainer(ctx context.Context, container LogProducingContainer, prefix string) error
ConnectContainer connects consumer to selected container, starts testcontainers.LogProducer and listens to it's failures in a detached goroutine
func (*LogStream) ContainerLogs ¶
ContainerLogs return all logs for particular container
func (*LogStream) DisconnectContainer ¶
func (m *LogStream) DisconnectContainer(container LogProducingContainer) error
DisconnectContainer disconnects particular container
func (*LogStream) FlushAndShutdown ¶
FlushAndShutdown flushes all logs to their targets and shuts down the log stream in a default sequence
func (*LogStream) FlushLogsToTargets ¶
FlushLogsToTargets flushes all logs for all consumers (containers) to their targets
func (*LogStream) GetAllLogsAndConsume ¶
func (m *LogStream) GetAllLogsAndConsume(preExecuteFn ConsumerConsumingFn, consumeLogFn ConsumerLogConsumingFn, postExecuteFn ConsumerConsumingFn) (loopErr error)
GetAllLogsAndConsume gets all logs for all consumers (containers) and consumes them using consumeLogFn
func (*LogStream) GetConsumers ¶
func (m *LogStream) GetConsumers() map[string]*ContainerLogConsumer
GetConsumers returns all consumers
func (*LogStream) PrintLogTargetsLocations ¶
func (m *LogStream) PrintLogTargetsLocations()
PrintLogTargetsLocations prints all log targets locations to stdout
func (*LogStream) SaveLogLocationInTestSummary ¶
func (m *LogStream) SaveLogLocationInTestSummary()
SaveLogTargetsLocations saves all log targets locations to test summary
func (*LogStream) SaveLogTargetsLocations ¶
SaveLogTargetsLocations saves all log targets given writer
type LokiLogHandler ¶
type LokiLogHandler struct {
// contains filtered or unexported fields
}
LokiLogHandler sends logs to Loki
func (*LokiLogHandler) GetLogLocation ¶
func (h *LokiLogHandler) GetLogLocation(consumers map[string]*ContainerLogConsumer) (string, error)
func (LokiLogHandler) GetTarget ¶
func (h LokiLogHandler) GetTarget() LogTarget
func (*LokiLogHandler) Handle ¶
func (h *LokiLogHandler) Handle(c *ContainerLogConsumer, content LogContent) error
func (*LokiLogHandler) Init ¶
func (h *LokiLogHandler) Init(c *ContainerLogConsumer) error
func (*LokiLogHandler) Teardown ¶
func (h *LokiLogHandler) Teardown() error
type Option ¶
type Option func(*LogStream)
func WithCustomLogHandler ¶
func WithCustomLogHandler(logTarget LogTarget, handler HandleLogTarget) Option
WithCustomLogHandler allows to override default log handler for particular log target