1
0
mirror of https://github.com/amir20/dozzle.git synced 2025-12-21 21:33:18 +01:00

fix: fixes std stream when type is unknown. see #2243 (#2247)

* fix: fixes std stream when type is unknown. see #2243

* fixes tests
This commit is contained in:
Amir Raminfar
2023-06-08 10:23:02 -07:00
committed by GitHub
parent 8912339044
commit 7477b1aecc
5 changed files with 24 additions and 16 deletions

View File

@@ -19,7 +19,7 @@ export interface LogEvent {
readonly id: number; readonly id: number;
readonly l: string; readonly l: string;
readonly p: Position; readonly p: Position;
readonly s: number; readonly s: "stdout" | "stderr" | "unknown";
} }
export abstract class LogEntry<T extends string | JSONObject> implements HasComponent { export abstract class LogEntry<T extends string | JSONObject> implements HasComponent {
@@ -151,9 +151,15 @@ export function asLogEntry(event: LogEvent): LogEntry<string | JSONObject> {
new Date(event.ts), new Date(event.ts),
event.l, event.l,
event.p, event.p,
event.s === 1 ? "stdout" : "stderr" event.s === "unknown" ? "stderr" : event.s ?? "stderr"
); );
} else { } else {
return new ComplexLogEntry(event.m, event.id, new Date(event.ts), event.l, event.s === 1 ? "stdout" : "stderr"); return new ComplexLogEntry(
event.m,
event.id,
new Date(event.ts),
event.l,
event.s === "unknown" ? "stderr" : event.s ?? "stderr"
);
} }
} }

View File

@@ -30,7 +30,8 @@ type dockerClient struct {
type StdType int type StdType int
const ( const (
STDOUT StdType = 1 << iota UNKNOWN StdType = 1 << iota
STDOUT
STDERR STDERR
) )
const STDALL = STDOUT | STDERR const STDALL = STDOUT | STDERR
@@ -38,13 +39,13 @@ const STDALL = STDOUT | STDERR
func (s StdType) String() string { func (s StdType) String() string {
switch s { switch s {
case STDOUT: case STDOUT:
return "out" return "stdout"
case STDERR: case STDERR:
return "err" return "stderr"
case STDALL: case STDALL:
return "all" return "all"
default: default:
return "" return "unknown"
} }
} }

View File

@@ -98,15 +98,16 @@ func (g *eventGenerator) consume() {
switch std { switch std {
case "OUT": case "OUT":
stdType = STDOUT stdType = STDOUT
message = message[3:]
case "ERR": case "ERR":
stdType = STDERR stdType = STDERR
message = message[3:]
default: default:
log.Panicf("unknown std type [%s] with message [%s]", std, message) log.Debugf("unknown std type [%s] with message [%s]", std, message)
stdType = UNKNOWN
} }
message = message[3:] logEvent := &LogEvent{Id: h.Sum32(), Message: message, Stream: stdType.String()}
logEvent := &LogEvent{Id: h.Sum32(), Message: message, StdType: stdType}
if index := strings.IndexAny(message, " "); index != -1 { if index := strings.IndexAny(message, " "); index != -1 {
logId := message[:index] logId := message[:index]

View File

@@ -46,7 +46,7 @@ type LogEvent struct {
Id uint32 `json:"id,omitempty"` Id uint32 `json:"id,omitempty"`
Level string `json:"l,omitempty"` Level string `json:"l,omitempty"`
Position LogPosition `json:"p,omitempty"` Position LogPosition `json:"p,omitempty"`
StdType StdType `json:"s,omitempty"` Stream string `json:"s,omitempty"`
} }
func (l *LogEvent) HasLevel() bool { func (l *LogEvent) HasLevel() bool {

View File

@@ -76,8 +76,8 @@ HTTP/1.1 200 OK
Connection: close Connection: close
Content-Type: application/ld+json; charset=UTF-8 Content-Type: application/ld+json; charset=UTF-8
{"m":"INFO Testing logs...","ts":1589396137772,"id":1122614848,"l":"info","s":1} {"m":"INFO Testing logs...","ts":1589396137772,"id":1122614848,"l":"info","s":"stdout"}
{"m":"INFO Testing logs...","ts":1589396137772,"id":1543246723,"l":"info","s":2} {"m":"INFO Testing logs...","ts":1589396137772,"id":1543246723,"l":"info","s":"stderr"}
/* snapshot: Test_handler_streamEvents_error */ /* snapshot: Test_handler_streamEvents_error */
HTTP/1.1 200 OK HTTP/1.1 200 OK
@@ -160,7 +160,7 @@ Connection: keep-alive
Content-Type: text/event-stream Content-Type: text/event-stream
X-Accel-Buffering: no X-Accel-Buffering: no
data: {"m":"INFO Testing logs...","ts":0,"id":852638900,"l":"info","s":1} data: {"m":"INFO Testing logs...","ts":0,"id":852638900,"l":"info","s":"stdout"}
event: container-stopped event: container-stopped
data: end of stream data: end of stream
@@ -186,7 +186,7 @@ Connection: keep-alive
Content-Type: text/event-stream Content-Type: text/event-stream
X-Accel-Buffering: no X-Accel-Buffering: no
data: {"m":"INFO Testing logs...","ts":1589396137772,"id":3373215946,"l":"info","s":1} data: {"m":"INFO Testing logs...","ts":1589396137772,"id":3373215946,"l":"info","s":"stdout"}
id: 1589396137772 id: 1589396137772
event: container-stopped event: container-stopped