Fixing micro logs being follow by default against k8s (#1866)

This commit is contained in:
Janos Dobronszki 2020-07-23 09:50:38 +02:00 committed by GitHub
parent a3a7434f2c
commit fbdf1f2c1c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 17 deletions

View File

@ -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

View File

@ -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
}