feat(machine-logs): add server side of journal logs (#282)

* Add server side of journal logs

This add the server side and grpc methods to get a journal logs from a
machine. It repurposes ServiceLogEntry for these logs to keep the
changes somewhat to a minimum. And it lets us re-use the merging of the
various logs. In the protobufs ContainerLog has been renamed to just Log
and LogEntry, as these are now also used for journal logs.

It does api.LogOptions in more places to reduce the various logOpts that
were used.

It does not yet plumb it through to the uc client, that needs a follow
up pr. Following logs is also not yet implemented.

Signed-off-by: Miek Gieben <miek@miek.nl>

* Fix test too

Signed-off-by: Miek Gieben <miek@miek.nl>

* remove entire comment

Signed-off-by: Miek Gieben <miek@miek.nl>

* Implement the follow option, untested mind you

Signed-off-by: Miek Gieben <miek@miek.nl>

* update debug line

Signed-off-by: Miek Gieben <miek@miek.nl>

* internal/jounal: First batch of PR comments

Signed-off-by: Miek Gieben <miek@miek.nl>

* internal/journal: code review comments

Signed-off-by: Miek Gieben <miek@miek.nl>

* Manually apply suggestion

Signed-off-by: Miek Gieben <miek@miek.nl>

* apply comment manually

Signed-off-by: Miek Gieben <miek@miek.nl>

* internal/journal: add unit test

Signed-off-by: Miek Gieben <miek@miek.nl>

* Use testify

Signed-off-by: Miek Gieben <miek@miek.nl>

* -amFix scanner.Err checking

Signed-off-by: Miek Gieben <miek@miek.nl>

* Implement code review comments

Signed-off-by: Miek Gieben <miek@miek.nl>

---------

Signed-off-by: Miek Gieben <miek@miek.nl>
This commit is contained in:
Miek Gieben
2026-04-08 18:51:52 +10:00
committed by GitHub
parent 4b34c42b76
commit cef047221c
19 changed files with 1204 additions and 862 deletions
+14 -14
View File
@@ -18,31 +18,31 @@ const (
type LogStreamType int
// LogStreamTypeFromProto converts a protobuf ContainerLogEntry.StreamType to the internal LogStreamType.
func LogStreamTypeFromProto(s pb.ContainerLogEntry_StreamType) LogStreamType {
// LogStreamTypeFromProto converts a protobuf LogEntry.StreamType to the internal LogStreamType.
func LogStreamTypeFromProto(s pb.LogEntry_StreamType) LogStreamType {
switch s {
case pb.ContainerLogEntry_STDOUT:
case pb.LogEntry_STDOUT:
return LogStreamStdout
case pb.ContainerLogEntry_STDERR:
case pb.LogEntry_STDERR:
return LogStreamStderr
case pb.ContainerLogEntry_HEARTBEAT:
case pb.LogEntry_HEARTBEAT:
return LogStreamHeartbeat
default:
return LogStreamUnknown
}
}
// LogStreamTypeToProto converts LogStreamType to protobuf ContainerLogEntry.StreamType.
func LogStreamTypeToProto(s LogStreamType) pb.ContainerLogEntry_StreamType {
// LogStreamTypeToProto converts LogStreamType to protobuf LogEntry.StreamType.
func LogStreamTypeToProto(s LogStreamType) pb.LogEntry_StreamType {
switch s {
case LogStreamStdout:
return pb.ContainerLogEntry_STDOUT
return pb.LogEntry_STDOUT
case LogStreamStderr:
return pb.ContainerLogEntry_STDERR
return pb.LogEntry_STDERR
case LogStreamHeartbeat:
return pb.ContainerLogEntry_HEARTBEAT
return pb.LogEntry_HEARTBEAT
default:
return pb.ContainerLogEntry_UNKNOWN
return pb.LogEntry_UNKNOWN
}
}
@@ -61,7 +61,7 @@ type ServiceLogsOptions struct {
type ServiceLogEntry struct {
// Metadata may not be set if an error occurred (Err is not nil).
Metadata ServiceLogEntryMetadata
ContainerLogEntry
LogEntry
}
// ServiceLogEntryMetadata contains metadata about the source of a log entry.
@@ -73,8 +73,8 @@ type ServiceLogEntryMetadata struct {
MachineName string
}
// ContainerLogEntry represents a single log entry from a container.
type ContainerLogEntry struct {
// LogEntry represents a single log entry from a container or a service.
type LogEntry struct {
Stream LogStreamType
Timestamp time.Time
Message []byte