mirror of
https://github.com/go-micro/go-micro.git
synced 2025-06-12 22:07:47 +02:00
Runtime logs (#1447)
* Runtime logs * Slightly broken * Pushing for diff * Log trailing works locally * LogsOptions * Comments and streamcount support for local logs * Adding kubernetes logs * Fixing k8s logs * K8s fixes * StreamCount is now nuked * PR comments * PR comments again * Fix typo
This commit is contained in:
@ -301,6 +301,53 @@ func (k *kubernetes) Init(opts ...runtime.Option) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
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() {
|
||||
records, err := klo.Read()
|
||||
if err != nil {
|
||||
logger.Errorf("Failed to get logs for service '%v' from k8s: %v", err)
|
||||
return
|
||||
}
|
||||
// @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.
|
||||
for _, record := range records {
|
||||
stream.Chan() <- record
|
||||
}
|
||||
}()
|
||||
}
|
||||
return stream, nil
|
||||
}
|
||||
|
||||
type kubeStream struct {
|
||||
// the k8s log stream
|
||||
stream chan runtime.LogRecord
|
||||
// the stop chan
|
||||
stop chan bool
|
||||
}
|
||||
|
||||
func (k *kubeStream) Chan() chan runtime.LogRecord {
|
||||
return k.stream
|
||||
}
|
||||
|
||||
func (k *kubeStream) Stop() error {
|
||||
select {
|
||||
case <-k.stop:
|
||||
return nil
|
||||
default:
|
||||
close(k.stop)
|
||||
close(k.stream)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Creates a service
|
||||
func (k *kubernetes) Create(s *runtime.Service, opts ...runtime.CreateOption) error {
|
||||
k.Lock()
|
||||
|
Reference in New Issue
Block a user