mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2024-11-26 20:01:02 +00:00
ability to limit log size, defaults to 5mb
This commit is contained in:
parent
2da1728c70
commit
56b6eb1b0c
3 changed files with 27 additions and 4 deletions
|
@ -42,8 +42,9 @@ func NewClientUpdater(client client.Client) UpdateFunc {
|
|||
}
|
||||
}
|
||||
|
||||
func NewClientLogger(client client.Client, id int64, rc io.ReadCloser, wc io.WriteCloser) LoggerFunc {
|
||||
func NewClientLogger(client client.Client, id int64, rc io.ReadCloser, wc io.WriteCloser, limit int64) LoggerFunc {
|
||||
var once sync.Once
|
||||
var size int64
|
||||
return func(line *build.Line) {
|
||||
// annoying hack to only start streaming once the first line is written
|
||||
once.Do(func() {
|
||||
|
@ -55,8 +56,14 @@ func NewClientLogger(client client.Client, id int64, rc io.ReadCloser, wc io.Wri
|
|||
}()
|
||||
})
|
||||
|
||||
if size > limit {
|
||||
return
|
||||
}
|
||||
|
||||
linejson, _ := json.Marshal(line)
|
||||
wc.Write(linejson)
|
||||
wc.Write([]byte{'\n'})
|
||||
|
||||
size += int64(len(line.Out))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -86,6 +86,18 @@ var AgentCmd = cli.Command{
|
|||
Name: "debug",
|
||||
Usage: "start the agent in debug mode",
|
||||
},
|
||||
cli.DurationFlag{
|
||||
EnvVar: "DRONE_TIMEOUT",
|
||||
Name: "timeout",
|
||||
Usage: "drone timeout due to log inactivity",
|
||||
Value: time.Minute * 5,
|
||||
},
|
||||
cli.IntFlag{
|
||||
EnvVar: "DRONE_MAX_LOGS",
|
||||
Name: "max-log-size",
|
||||
Usage: "drone maximum log size in megabytes",
|
||||
Value: 5,
|
||||
},
|
||||
cli.StringSliceFlag{
|
||||
EnvVar: "DRONE_PLUGIN_PRIVILEGED",
|
||||
Name: "privileged",
|
||||
|
@ -157,9 +169,11 @@ func start(c *cli.Context) {
|
|||
drone: client,
|
||||
docker: docker,
|
||||
config: config{
|
||||
timeout: c.Duration("timeout"),
|
||||
namespace: c.String("namespace"),
|
||||
privileged: c.StringSlice("privileged"),
|
||||
pull: c.Bool("pull"),
|
||||
logs: int64(c.Int("max-log-size")) * 1000000,
|
||||
},
|
||||
}
|
||||
for {
|
||||
|
|
|
@ -17,6 +17,8 @@ type config struct {
|
|||
namespace string
|
||||
privileged []string
|
||||
pull bool
|
||||
logs int64
|
||||
timeout time.Duration
|
||||
}
|
||||
|
||||
type pipeline struct {
|
||||
|
@ -46,10 +48,10 @@ func (r *pipeline) run() error {
|
|||
|
||||
a := agent.Agent{
|
||||
Update: agent.NewClientUpdater(r.drone),
|
||||
Logger: agent.NewClientLogger(r.drone, w.Job.ID, rc, wc),
|
||||
Logger: agent.NewClientLogger(r.drone, w.Job.ID, rc, wc, r.config.logs),
|
||||
Engine: engine,
|
||||
Timeout: time.Minute * 15,
|
||||
Platform: r.config.platform,
|
||||
Timeout: r.config.timeout,
|
||||
Platform: "linux/amd64",
|
||||
Namespace: r.config.namespace,
|
||||
Escalate: r.config.privileged,
|
||||
Pull: r.config.pull,
|
||||
|
|
Loading…
Reference in a new issue