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 {
|
for _, o := range options {
|
||||||
o(opts)
|
o(opts)
|
||||||
}
|
}
|
||||||
|
|
||||||
pods, err := k.getMatchingPods()
|
pods, err := k.getMatchingPods()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
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) {
|
func (k *kubernetes) Logs(s *runtime.Service, options ...runtime.LogsOption) (runtime.LogStream, error) {
|
||||||
klo := newLog(k.client, s.Name, options...)
|
klo := newLog(k.client, s.Name, options...)
|
||||||
stream, err := klo.Stream()
|
|
||||||
if err != nil {
|
if !klo.options.Stream {
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
// If requested, also read existing records and stream those too
|
|
||||||
if klo.options.Count > 0 {
|
|
||||||
go func() {
|
|
||||||
records, err := klo.Read()
|
records, err := klo.Read()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorf("Failed to get logs for service '%v' from k8s: %v", s.Name, err)
|
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
|
kstream := &kubeStream{
|
||||||
// and might cause out of order log retrieval at the receiving end.
|
stream: make(chan runtime.LogRecord),
|
||||||
// A better approach would probably to suppor this inside the `klog.Stream` method.
|
stop: make(chan bool),
|
||||||
|
}
|
||||||
|
go func() {
|
||||||
for _, record := range records {
|
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
|
return stream, nil
|
||||||
}
|
}
|
||||||
@ -398,6 +400,7 @@ func (k *kubeStream) Stop() error {
|
|||||||
return nil
|
return nil
|
||||||
default:
|
default:
|
||||||
close(k.stop)
|
close(k.stop)
|
||||||
|
close(k.stream)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user