Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pkg/api/ci.go
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ func nextCIStreamBackoff(current time.Duration) time.Duration {

func logLineIdentity(line *civ1.LogLine) string {
sum := sha256.Sum256([]byte(line.GetBody()))
return fmt.Sprintf("%s:%d:%d:%d:%s", line.GetStepId(), line.GetTimestampMs(), line.GetLineNumber(), line.GetStream(), hex.EncodeToString(sum[:]))
return fmt.Sprintf("%s:%d:%d:%d:%s", line.GetStepKey(), line.GetTimestampMs(), line.GetLineNumber(), line.GetStream(), hex.EncodeToString(sum[:]))
}

type logLineDedupe struct {
Expand Down
2 changes: 1 addition & 1 deletion pkg/api/ci_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -738,7 +738,7 @@ func TestIsTransientConnectError(t *testing.T) {

func testLogLine(stepID string, lineNumber uint32, body string) *civ1.LogLine {
return &civ1.LogLine{
StepId: stepID,
StepKey: stepID,
TimestampMs: int64(lineNumber),
LineNumber: lineNumber,
Stream: 0,
Expand Down
6 changes: 5 additions & 1 deletion pkg/cmd/ci/logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,8 @@ type logLineEvent struct {
TimestampMs int64 `json:"timestamp_ms"`
Stream string `json:"stream"`
StepKey string `json:"step_key"`
StepID string `json:"step_id"`
StepName string `json:"step_name"`
LineNumber uint32 `json:"line_number"`
Body string `json:"body"`
}
Expand Down Expand Up @@ -311,7 +313,9 @@ func logLineEventFromLine(line *civ1.LogLine) logLineEvent {
Timestamp: formatLogTimestamp(line),
TimestampMs: line.GetTimestampMs(),
Stream: logStreamName(line.GetStream()),
StepKey: line.GetStepId(),
StepKey: line.GetStepKey(),
StepID: line.GetStepId(),
StepName: line.GetStepName(),
LineNumber: line.GetLineNumber(),
Body: line.GetBody(),
}
Expand Down
27 changes: 18 additions & 9 deletions pkg/cmd/ci/logs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -859,7 +859,7 @@ func TestPrintLogLinesTimestamps(t *testing.T) {
func TestPrintLogLinesJSON(t *testing.T) {
largeBody := strings.Repeat("x", 5000) + ` "quoted" \ slash`
lines := []*civ1.LogLine{
testCmdLogLine("step-1", 7, 123, 1, largeBody),
testCmdLogLine("step-1", 7, 123, 1, largeBody, "build", "Build"),
}

var out bytes.Buffer
Expand All @@ -877,6 +877,8 @@ func TestPrintLogLinesJSON(t *testing.T) {
"timestamp_ms": float64(123),
"stream": "stderr",
"step_key": "step-1",
"step_id": "build",
"step_name": "Build",
"line_number": float64(7),
"body": largeBody,
})
Expand Down Expand Up @@ -1036,14 +1038,21 @@ func TestStreamLogTargetWithFollowUXJSONEmitsStatusLineAndEnd(t *testing.T) {
}
}

func testCmdLogLine(stepID string, lineNumber uint32, timestampMs int64, stream uint32, body string) *civ1.LogLine {
return &civ1.LogLine{
StepId: stepID,
func testCmdLogLine(stepKey string, lineNumber uint32, timestampMs int64, stream uint32, body string, metadata ...string) *civ1.LogLine {
line := &civ1.LogLine{
StepKey: stepKey,
TimestampMs: timestampMs,
LineNumber: lineNumber,
Stream: stream,
Body: body,
}
if len(metadata) > 0 {
line.StepId = metadata[0]
}
if len(metadata) > 1 {
line.StepName = metadata[1]
}
return line
}

func decodeLogEvents(t *testing.T, output string) []map[string]any {
Expand All @@ -1068,13 +1077,13 @@ func decodeLogEvents(t *testing.T, output string) []map[string]any {
func assertLogLineEvent(t *testing.T, got map[string]any, want map[string]any) {
t.Helper()

assertEventFields(t, got, want)
if _, ok := got["step_id"]; ok {
t.Fatalf("line event should not include step_id: %#v", got)
if _, ok := want["step_id"]; !ok {
want["step_id"] = ""
}
if _, ok := got["step_name"]; ok {
t.Fatalf("line event should not include step_name: %#v", got)
if _, ok := want["step_name"]; !ok {
want["step_name"] = ""
}
assertEventFields(t, got, want)
}

func assertEventFields(t *testing.T, got map[string]any, want map[string]any) {
Expand Down
Loading
Loading