Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rework log streaming and related functions #1802

Merged
merged 49 commits into from
Jun 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
a0cf979
fix logging
anbraten Jun 2, 2023
c4ddf20
store to db
anbraten Jun 2, 2023
60cec1d
Merge branch 'master' into fix-log
6543 Jun 2, 2023
5789aee
Merge branch 'master' into fix-log
6543 Jun 3, 2023
bd17843
Merge branch 'master' into fix-log
6543 Jun 3, 2023
bc96707
Merge remote-tracking branch 'upstream/master' into fix-log
anbraten Jun 3, 2023
5e4d5bd
Merge branch 'fix-log' of github.com:anbraten/woodpecker into fix-log
anbraten Jun 3, 2023
7a30a53
update model and add migration
anbraten Jun 4, 2023
bba6e02
refactor log code
anbraten Jun 4, 2023
7a64b24
Merge branch 'master' into fix-log
anbraten Jun 4, 2023
d35daa7
update ui
anbraten Jun 4, 2023
120a0e7
Merge branch 'fix-log' of github.com:anbraten/woodpecker into fix-log
anbraten Jun 4, 2023
8a101de
adjust api endpoints and ui
anbraten Jun 4, 2023
474724d
rename
anbraten Jun 4, 2023
dd3e1fd
finish store & bump proto version ...
6543 Jun 4, 2023
ea13eb0
new entity will get new table so we dont need to rename on migration
6543 Jun 4, 2023
b22c4ee
cleanup + fixing
6543 Jun 4, 2023
7b1890a
fix
6543 Jun 4, 2023
faa70be
fix
6543 Jun 4, 2023
ae3c9fc
steps get an UUID from pipeline.Compiler
6543 Jun 4, 2023
a07234f
workflow need a uuid to atm ... show they have one in future too?
6543 Jun 4, 2023
fae1e52
for logs:
6543 Jun 4, 2023
716503d
gen cods
6543 Jun 4, 2023
5d4f34a
document issue
6543 Jun 4, 2023
553b67e
Merge branch 'master' into fix-log
6543 Jun 4, 2023
46ca1ae
clean unused
6543 Jun 4, 2023
0d0bdef
adjust cli
6543 Jun 4, 2023
92d09b5
Merge branch 'master' into fix-log
6543 Jun 4, 2023
b578311
adjust log streaming code so use stepID
6543 Jun 4, 2023
0db1ac9
update swagger doc
6543 Jun 5, 2023
88c91a2
add check back
6543 Jun 5, 2023
2d5c497
fix
6543 Jun 5, 2023
6412306
fix tests
6543 Jun 5, 2023
08d75c6
migration
6543 Jun 5, 2023
ff498e1
migration timeout
6543 Jun 5, 2023
5c290f9
migration takes a long time
6543 Jun 5, 2023
762e5de
make cli work
6543 Jun 5, 2023
fcee178
fix webui log display
6543 Jun 5, 2023
e4d806d
a todo got resolved
6543 Jun 5, 2023
0b5c32e
cleanup code
6543 Jun 5, 2023
0f82a4f
fix web logstream
6543 Jun 5, 2023
1be3243
clean
6543 Jun 5, 2023
dab2e5d
Update server/store/datastore/log.go
6543 Jun 5, 2023
21b4989
Update server/logging/logging.go
6543 Jun 5, 2023
e0ff996
Merge branch 'master' into fix-log
6543 Jun 5, 2023
9eb0273
move migration into new pull: #1828
6543 Jun 5, 2023
7ae0308
OrderBy_ID
6543 Jun 5, 2023
6c06e4b
Merge branch 'master' into fix-log
6543 Jun 6, 2023
d31fe9a
Merge branch 'master' into fix-log
6543 Jun 6, 2023
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
5 changes: 2 additions & 3 deletions agent/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,8 @@ func (r *Runner) createLogger(_ context.Context, logger zerolog.Logger, uploads

loglogger.Debug().Msg("log stream opened")

limitedPart := io.LimitReader(part, maxLogsUpload)
logStream := rpc.NewLineWriter(r.client, work.ID, step.Alias, secrets...)
if _, err := io.Copy(logStream, limitedPart); err != nil {
logStream := rpc.NewLineWriter(r.client, step.UUID, secrets...)
if _, err := io.Copy(logStream, part); err != nil {
log.Error().Err(err).Msg("copy limited logStream part")
}

Expand Down
14 changes: 7 additions & 7 deletions agent/rpc/client_grpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -278,14 +278,14 @@ func (c *client) Update(ctx context.Context, id string, state rpc.State) (err er
}

// Log writes the pipeline log entry.
func (c *client) Log(ctx context.Context, id string, line *rpc.Line) (err error) {
func (c *client) Log(ctx context.Context, logEntry *rpc.LogEntry) (err error) {
req := new(proto.LogRequest)
req.Id = id
req.Line = new(proto.Line)
req.Line.Out = line.Out
req.Line.Pos = int32(line.Pos)
req.Line.Step = line.Step
req.Line.Time = line.Time
req.LogEntry = new(proto.LogEntry)
req.LogEntry.StepUuid = logEntry.StepUUID
req.LogEntry.Data = logEntry.Data
req.LogEntry.Line = int32(logEntry.Line)
req.LogEntry.Time = logEntry.Time
req.LogEntry.Type = int32(logEntry.Type)
for {
_, err = c.client.Log(ctx, req)
if err == nil {
Expand Down
8 changes: 0 additions & 8 deletions agent/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,6 @@ import (
"github.com/woodpecker-ci/woodpecker/shared/utils"
)

// TODO: Implement log streaming.
// Until now we need to limit the size of the logs and files that we upload.
// The maximum grpc payload size is 4194304. So we need to set these limits below the maximum.
const (
maxLogsUpload = 2000000 // this is per step
maxFileUpload = 1000000
)

type Runner struct {
client rpc.Peer
filter rpc.Filter
Expand Down
2 changes: 1 addition & 1 deletion cli/exec/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ var defaultLogger = pipeline.LogFunc(func(step *backendTypes.Step, rc multipart.
return err
}

logStream := NewLineWriter(step.Alias)
logStream := NewLineWriter(step.Alias, step.UUID)
_, err = io.Copy(logStream, part)
return err
})
60 changes: 22 additions & 38 deletions cli/exec/line.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,60 +19,44 @@ import (
"os"
"strings"
"time"
)

// Identifies the type of line in the logs.
const (
LineStdout int = iota
LineStderr
LineExitCode
LineMetadata
LineProgress
"github.com/woodpecker-ci/woodpecker/pipeline/rpc"
)

// Line is a line of console output.
type Line struct {
Step string `json:"step,omitempty"`
Time int64 `json:"time,omitempty"`
Type int `json:"type,omitempty"`
Pos int `json:"pos,omitempty"`
Out string `json:"out,omitempty"`
}

// LineWriter sends logs to the client.
type LineWriter struct {
name string
num int
now time.Time
rep *strings.Replacer
lines []*Line
stepName string
stepUUID string
num int
now time.Time
rep *strings.Replacer
lines []*rpc.LogEntry
}

// NewLineWriter returns a new line reader.
func NewLineWriter(name string) *LineWriter {
w := new(LineWriter)
w.name = name
w.num = 0
w.now = time.Now().UTC()

return w
func NewLineWriter(stepName, stepUUID string) *LineWriter {
return &LineWriter{
stepName: stepName,
stepUUID: stepUUID,
now: time.Now().UTC(),
}
}

func (w *LineWriter) Write(p []byte) (n int, err error) {
out := string(p)
data := string(p)
if w.rep != nil {
out = w.rep.Replace(out)
data = w.rep.Replace(data)
}

line := &Line{
Out: out,
Step: w.name,
Pos: w.num,
Time: int64(time.Since(w.now).Seconds()),
Type: LineStdout,
line := &rpc.LogEntry{
Data: data,
StepUUID: w.stepUUID,
Line: w.num,
Time: int64(time.Since(w.now).Seconds()),
Type: rpc.LogEntryStdout,
}

fmt.Fprintf(os.Stderr, "[%s:L%d:%ds] %s", w.name, w.num, int64(time.Since(w.now).Seconds()), out)
fmt.Fprintf(os.Stderr, "[%s:L%d:%ds] %s", w.stepName, w.num, int64(time.Since(w.now).Seconds()), data)

w.num++

Expand Down
6 changes: 3 additions & 3 deletions cli/pipeline/logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import (
var pipelineLogsCmd = &cli.Command{
Name: "logs",
Usage: "show pipeline logs",
ArgsUsage: "<repo/name> [pipeline] [step]",
ArgsUsage: "<repo/name> [pipeline] [stepID]",
Action: pipelineLogs,
Flags: common.GlobalFlags,
}
Expand All @@ -54,13 +54,13 @@ func pipelineLogs(c *cli.Context) error {
return err
}

logs, err := client.PipelineLogs(owner, name, number, step)
logs, err := client.StepLogEntries(owner, name, number, step)
if err != nil {
return err
}

for _, log := range logs {
fmt.Print(log.Output)
fmt.Print(string(log.Data))
}

return nil
Expand Down
169 changes: 103 additions & 66 deletions cmd/server/docs/docs.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading