| OLD | NEW |
| 1 // Copyright 2015 The LUCI Authors. All rights reserved. | 1 // Copyright 2015 The LUCI Authors. All rights reserved. |
| 2 // Use of this source code is governed under the Apache License, Version 2.0 | 2 // Use of this source code is governed under the Apache License, Version 2.0 |
| 3 // that can be found in the LICENSE file. | 3 // that can be found in the LICENSE file. |
| 4 | 4 |
| 5 package main | 5 package main |
| 6 | 6 |
| 7 import ( | 7 import ( |
| 8 "fmt" |
| 8 "time" | 9 "time" |
| 9 | 10 |
| 10 "github.com/luci/luci-go/common/clock/clockflag" | 11 "github.com/luci/luci-go/common/clock/clockflag" |
| 11 "github.com/luci/luci-go/common/errors" | 12 "github.com/luci/luci-go/common/errors" |
| 12 "github.com/luci/luci-go/common/flag/multiflag" | 13 "github.com/luci/luci-go/common/flag/multiflag" |
| 13 "github.com/luci/luci-go/logdog/client/butler/output" | 14 "github.com/luci/luci-go/logdog/client/butler/output" |
| 14 out "github.com/luci/luci-go/logdog/client/butler/output/logdog" | 15 out "github.com/luci/luci-go/logdog/client/butler/output/logdog" |
| 15 ) | 16 ) |
| 16 | 17 |
| 17 func init() { | 18 func init() { |
| 18 registerOutputFactory(new(logdogOutputFactory)) | 19 registerOutputFactory(new(logdogOutputFactory)) |
| 19 } | 20 } |
| 20 | 21 |
| 21 // logdogOutputFactory for publishing logs using a LogDog Coordinator host. | 22 // logdogOutputFactory for publishing logs using a LogDog Coordinator host. |
| 22 type logdogOutputFactory struct { | 23 type logdogOutputFactory struct { |
| 23 » host string | 24 » service string |
| 24 prefixExpiration clockflag.Duration | 25 prefixExpiration clockflag.Duration |
| 25 | 26 |
| 26 track bool | 27 track bool |
| 27 } | 28 } |
| 28 | 29 |
| 29 var _ outputFactory = (*logdogOutputFactory)(nil) | 30 var _ outputFactory = (*logdogOutputFactory)(nil) |
| 30 | 31 |
| 31 func (f *logdogOutputFactory) option() multiflag.Option { | 32 func (f *logdogOutputFactory) option() multiflag.Option { |
| 32 opt := newOutputOption("logdog", "Output to a LogDog Coordinator instanc
e.", f) | 33 opt := newOutputOption("logdog", "Output to a LogDog Coordinator instanc
e.", f) |
| 33 | 34 |
| 34 flags := opt.Flags() | 35 flags := opt.Flags() |
| 35 » flags.StringVar(&f.host, "host", "", | 36 » flags.StringVar(&f.service, "service", "", |
| 36 » » "The LogDog Coordinator host name.") | 37 » » "Optional service within <host> to use. Will be referenced as <s
ervice>-dot-<host>.") |
| 37 flags.Var(&f.prefixExpiration, "prefix-expiration", | 38 flags.Var(&f.prefixExpiration, "prefix-expiration", |
| 38 "Amount of time after registration that the prefix will be activ
e. If omitted, the service "+ | 39 "Amount of time after registration that the prefix will be activ
e. If omitted, the service "+ |
| 39 "default will be used. This should exceed the expected l
ifetime of the job by a fair margin.") | 40 "default will be used. This should exceed the expected l
ifetime of the job by a fair margin.") |
| 40 | 41 |
| 41 // TODO(dnj): Default to false when mandatory debugging is finished. | 42 // TODO(dnj): Default to false when mandatory debugging is finished. |
| 42 flags.BoolVar(&f.track, "track", true, | 43 flags.BoolVar(&f.track, "track", true, |
| 43 "Track each sent message and dump at the end. This adds CPU/memo
ry overhead.") | 44 "Track each sent message and dump at the end. This adds CPU/memo
ry overhead.") |
| 44 | 45 |
| 45 return opt | 46 return opt |
| 46 } | 47 } |
| 47 | 48 |
| 48 func (f *logdogOutputFactory) configOutput(a *application) (output.Output, error
) { | 49 func (f *logdogOutputFactory) configOutput(a *application) (output.Output, error
) { |
| 49 auth, err := a.authenticator(a) | 50 auth, err := a.authenticator(a) |
| 50 if err != nil { | 51 if err != nil { |
| 51 return nil, errors.Annotate(err).Reason("failed to instantiate a
uthenticator").Err() | 52 return nil, errors.Annotate(err).Reason("failed to instantiate a
uthenticator").Err() |
| 52 } | 53 } |
| 53 | 54 |
| 55 host := a.coordinatorHost |
| 56 if host == "" { |
| 57 return nil, errors.New("logdog output requires a Coordinator hos
t (-coordinator-host)") |
| 58 } |
| 59 if f.service != "" { |
| 60 host = fmt.Sprintf("%s-dot-%s", f.service, host) |
| 61 } |
| 62 |
| 54 cfg := out.Config{ | 63 cfg := out.Config{ |
| 55 Auth: auth, | 64 Auth: auth, |
| 56 » » Host: f.host, | 65 » » Host: host, |
| 57 Project: a.project, | 66 Project: a.project, |
| 58 Prefix: a.prefix, | 67 Prefix: a.prefix, |
| 59 PrefixExpiration: time.Duration(f.prefixExpiration), | 68 PrefixExpiration: time.Duration(f.prefixExpiration), |
| 60 SourceInfo: []string{ | 69 SourceInfo: []string{ |
| 61 "LogDog Butler", | 70 "LogDog Butler", |
| 62 }, | 71 }, |
| 63 PublishContext: a.ncCtx, | 72 PublishContext: a.ncCtx, |
| 64 RPCTimeout: 30 * time.Second, | 73 RPCTimeout: 30 * time.Second, |
| 65 Track: f.track, | 74 Track: f.track, |
| 66 } | 75 } |
| 67 return cfg.Register(a) | 76 return cfg.Register(a) |
| 68 } | 77 } |
| 69 | 78 |
| 70 func (f *logdogOutputFactory) scopes() []string { return out.Scopes() } | 79 func (f *logdogOutputFactory) scopes() []string { return out.Scopes() } |
| OLD | NEW |