Stream live server logs over SSE
This commit is contained in:
@@ -53,6 +53,21 @@ type LogStreamCursorResponse struct {
|
||||
LatestSeq uint64 `json:"latestSeq"`
|
||||
}
|
||||
|
||||
type LogStreamEventResponse struct {
|
||||
ServerInstanceID string `json:"serverInstanceId"`
|
||||
StreamID string `json:"streamId"`
|
||||
Source domain.LogStreamSource `json:"source"`
|
||||
StreamKey string `json:"streamKey"`
|
||||
LatestSeq uint64 `json:"latestSeq"`
|
||||
Entry LogEntryBody `json:"entry"`
|
||||
}
|
||||
|
||||
type LogStreamEventsReadyResponse struct {
|
||||
ServerInstanceID string `json:"serverInstanceId"`
|
||||
StreamCount int `json:"streamCount"`
|
||||
ServerTime time.Time `json:"serverTime"`
|
||||
}
|
||||
|
||||
func (request LogBatchIngestRequest) ToDomain() domain.LogBatchIngest {
|
||||
return domain.LogBatchIngest{
|
||||
RunEndpointID: request.RunEndpointID,
|
||||
@@ -99,6 +114,18 @@ func LogStreamCursorFromDomain(result domain.LogStreamCursorResult) LogStreamCur
|
||||
}
|
||||
}
|
||||
|
||||
func LogStreamEventFromDomain(event domain.LogStreamEvent) LogStreamEventResponse {
|
||||
event = domain.CopyLogStreamEvent(event)
|
||||
return LogStreamEventResponse{
|
||||
ServerInstanceID: event.ServerInstanceID,
|
||||
StreamID: event.Stream.ID,
|
||||
Source: event.Stream.Source,
|
||||
StreamKey: event.Stream.StreamKey,
|
||||
LatestSeq: event.LatestSeq,
|
||||
Entry: logEntryFromDomain(event.Entry),
|
||||
}
|
||||
}
|
||||
|
||||
func logEntriesToDomain(entries []LogEntryBody) []domain.LogEntry {
|
||||
if entries == nil {
|
||||
return nil
|
||||
@@ -117,20 +144,24 @@ func logEntriesToDomain(entries []LogEntryBody) []domain.LogEntry {
|
||||
return out
|
||||
}
|
||||
|
||||
func logEntryFromDomain(entry domain.LogEntry) LogEntryBody {
|
||||
return LogEntryBody{
|
||||
Seq: entry.Seq,
|
||||
Timestamp: entry.Timestamp,
|
||||
Level: entry.Level,
|
||||
Line: entry.Line,
|
||||
Fields: copyStringMap(entry.Fields),
|
||||
Redacted: entry.Redacted,
|
||||
}
|
||||
}
|
||||
|
||||
func logEntriesFromDomain(entries []domain.LogEntry) []LogEntryBody {
|
||||
if entries == nil {
|
||||
return nil
|
||||
}
|
||||
out := make([]LogEntryBody, len(entries))
|
||||
for i, entry := range entries {
|
||||
out[i] = LogEntryBody{
|
||||
Seq: entry.Seq,
|
||||
Timestamp: entry.Timestamp,
|
||||
Level: entry.Level,
|
||||
Line: entry.Line,
|
||||
Fields: copyStringMap(entry.Fields),
|
||||
Redacted: entry.Redacted,
|
||||
}
|
||||
out[i] = logEntryFromDomain(entry)
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user