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 once sync.Once
|
||||||
|
var size int64
|
||||||
return func(line *build.Line) {
|
return func(line *build.Line) {
|
||||||
// annoying hack to only start streaming once the first line is written
|
// annoying hack to only start streaming once the first line is written
|
||||||
once.Do(func() {
|
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)
|
linejson, _ := json.Marshal(line)
|
||||||
wc.Write(linejson)
|
wc.Write(linejson)
|
||||||
wc.Write([]byte{'\n'})
|
wc.Write([]byte{'\n'})
|
||||||
|
|
||||||
|
size += int64(len(line.Out))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -86,6 +86,18 @@ var AgentCmd = cli.Command{
|
||||||
Name: "debug",
|
Name: "debug",
|
||||||
Usage: "start the agent in debug mode",
|
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{
|
cli.StringSliceFlag{
|
||||||
EnvVar: "DRONE_PLUGIN_PRIVILEGED",
|
EnvVar: "DRONE_PLUGIN_PRIVILEGED",
|
||||||
Name: "privileged",
|
Name: "privileged",
|
||||||
|
@ -157,9 +169,11 @@ func start(c *cli.Context) {
|
||||||
drone: client,
|
drone: client,
|
||||||
docker: docker,
|
docker: docker,
|
||||||
config: config{
|
config: config{
|
||||||
|
timeout: c.Duration("timeout"),
|
||||||
namespace: c.String("namespace"),
|
namespace: c.String("namespace"),
|
||||||
privileged: c.StringSlice("privileged"),
|
privileged: c.StringSlice("privileged"),
|
||||||
pull: c.Bool("pull"),
|
pull: c.Bool("pull"),
|
||||||
|
logs: int64(c.Int("max-log-size")) * 1000000,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
for {
|
for {
|
||||||
|
|
|
@ -17,6 +17,8 @@ type config struct {
|
||||||
namespace string
|
namespace string
|
||||||
privileged []string
|
privileged []string
|
||||||
pull bool
|
pull bool
|
||||||
|
logs int64
|
||||||
|
timeout time.Duration
|
||||||
}
|
}
|
||||||
|
|
||||||
type pipeline struct {
|
type pipeline struct {
|
||||||
|
@ -46,10 +48,10 @@ func (r *pipeline) run() error {
|
||||||
|
|
||||||
a := agent.Agent{
|
a := agent.Agent{
|
||||||
Update: agent.NewClientUpdater(r.drone),
|
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,
|
Engine: engine,
|
||||||
Timeout: time.Minute * 15,
|
Timeout: r.config.timeout,
|
||||||
Platform: r.config.platform,
|
Platform: "linux/amd64",
|
||||||
Namespace: r.config.namespace,
|
Namespace: r.config.namespace,
|
||||||
Escalate: r.config.privileged,
|
Escalate: r.config.privileged,
|
||||||
Pull: r.config.pull,
|
Pull: r.config.pull,
|
||||||
|
|
Loading…
Add table
Reference in a new issue