Fixing micro logs
being follow by default against k8s (#1866)
This commit is contained in:
parent
a3a7434f2c
commit
fbdf1f2c1c
@ -102,7 +102,6 @@ func (k *klog) Read(options ...log.ReadOption) ([]log.Record, error) {
|
||||
for _, o := range options {
|
||||
o(opts)
|
||||
}
|
||||
|
||||
pods, err := k.getMatchingPods()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
@ -350,25 +350,27 @@ func (k *kubernetes) Init(opts ...runtime.Option) error {
|
||||
|
||||
func (k *kubernetes) Logs(s *runtime.Service, options ...runtime.LogsOption) (runtime.LogStream, error) {
|
||||
klo := newLog(k.client, s.Name, options...)
|
||||
stream, err := klo.Stream()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
// If requested, also read existing records and stream those too
|
||||
if klo.options.Count > 0 {
|
||||
go func() {
|
||||
|
||||
if !klo.options.Stream {
|
||||
records, err := klo.Read()
|
||||
if err != nil {
|
||||
log.Errorf("Failed to get logs for service '%v' from k8s: %v", s.Name, err)
|
||||
return
|
||||
return nil, err
|
||||
}
|
||||
// @todo: this might actually not run before podLogStream starts
|
||||
// and might cause out of order log retrieval at the receiving end.
|
||||
// A better approach would probably to suppor this inside the `klog.Stream` method.
|
||||
kstream := &kubeStream{
|
||||
stream: make(chan runtime.LogRecord),
|
||||
stop: make(chan bool),
|
||||
}
|
||||
go func() {
|
||||
for _, record := range records {
|
||||
stream.Chan() <- record
|
||||
kstream.Chan() <- record
|
||||
}
|
||||
}()
|
||||
return kstream, nil
|
||||
}
|
||||
stream, err := klo.Stream()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return stream, nil
|
||||
}
|
||||
@ -398,6 +400,7 @@ func (k *kubeStream) Stop() error {
|
||||
return nil
|
||||
default:
|
||||
close(k.stop)
|
||||
close(k.stream)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user