simplify runtime logs
This commit is contained in:
@@ -347,7 +347,7 @@ func (k *kubernetes) Init(opts ...runtime.Option) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (k *kubernetes) Logs(s *runtime.Service, options ...runtime.LogsOption) (runtime.LogStream, error) {
|
||||
func (k *kubernetes) Logs(s *runtime.Service, options ...runtime.LogsOption) (runtime.Logs, error) {
|
||||
klo := newLog(k.client, s.Name, options...)
|
||||
|
||||
if !klo.options.Stream {
|
||||
@@ -357,7 +357,7 @@ func (k *kubernetes) Logs(s *runtime.Service, options ...runtime.LogsOption) (ru
|
||||
return nil, err
|
||||
}
|
||||
kstream := &kubeStream{
|
||||
stream: make(chan runtime.LogRecord),
|
||||
stream: make(chan runtime.Log),
|
||||
stop: make(chan bool),
|
||||
}
|
||||
go func() {
|
||||
@@ -377,7 +377,7 @@ func (k *kubernetes) Logs(s *runtime.Service, options ...runtime.LogsOption) (ru
|
||||
|
||||
type kubeStream struct {
|
||||
// the k8s log stream
|
||||
stream chan runtime.LogRecord
|
||||
stream chan runtime.Log
|
||||
// the stop chan
|
||||
sync.Mutex
|
||||
stop chan bool
|
||||
@@ -388,7 +388,7 @@ func (k *kubeStream) Error() error {
|
||||
return k.err
|
||||
}
|
||||
|
||||
func (k *kubeStream) Chan() chan runtime.LogRecord {
|
||||
func (k *kubeStream) Chan() chan runtime.Log {
|
||||
return k.stream
|
||||
}
|
||||
|
||||
|
@@ -21,7 +21,7 @@ type klog struct {
|
||||
options runtime.LogsOptions
|
||||
}
|
||||
|
||||
func (k *klog) podLogStream(podName string, stream *kubeStream) error {
|
||||
func (k *klog) podLogs(podName string, stream *kubeStream) error {
|
||||
p := make(map[string]string)
|
||||
p["follow"] = "true"
|
||||
|
||||
@@ -51,7 +51,7 @@ func (k *klog) podLogStream(podName string, stream *kubeStream) error {
|
||||
return stream.Error()
|
||||
default:
|
||||
if s.Scan() {
|
||||
record := runtime.LogRecord{
|
||||
record := runtime.Log{
|
||||
Message: s.Text(),
|
||||
}
|
||||
select {
|
||||
@@ -101,7 +101,7 @@ func (k *klog) getMatchingPods() ([]string, error) {
|
||||
return matches, nil
|
||||
}
|
||||
|
||||
func (k *klog) Read() ([]runtime.LogRecord, error) {
|
||||
func (k *klog) Read() ([]runtime.Log, error) {
|
||||
pods, err := k.getMatchingPods()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -110,7 +110,7 @@ func (k *klog) Read() ([]runtime.LogRecord, error) {
|
||||
return nil, errors.NotFound("runtime.logs", "no such service")
|
||||
}
|
||||
|
||||
var records []runtime.LogRecord
|
||||
var records []runtime.Log
|
||||
|
||||
for _, pod := range pods {
|
||||
logParams := make(map[string]string)
|
||||
@@ -145,7 +145,7 @@ func (k *klog) Read() ([]runtime.LogRecord, error) {
|
||||
s := bufio.NewScanner(logs)
|
||||
|
||||
for s.Scan() {
|
||||
record := runtime.LogRecord{
|
||||
record := runtime.Log{
|
||||
Message: s.Text(),
|
||||
}
|
||||
// record.Metadata["pod"] = pod
|
||||
@@ -159,7 +159,7 @@ func (k *klog) Read() ([]runtime.LogRecord, error) {
|
||||
return records, nil
|
||||
}
|
||||
|
||||
func (k *klog) Stream() (runtime.LogStream, error) {
|
||||
func (k *klog) Stream() (runtime.Logs, error) {
|
||||
// find the matching pods
|
||||
pods, err := k.getMatchingPods()
|
||||
if err != nil {
|
||||
@@ -170,14 +170,14 @@ func (k *klog) Stream() (runtime.LogStream, error) {
|
||||
}
|
||||
|
||||
stream := &kubeStream{
|
||||
stream: make(chan runtime.LogRecord),
|
||||
stream: make(chan runtime.Log),
|
||||
stop: make(chan bool),
|
||||
}
|
||||
|
||||
// stream from the individual pods
|
||||
for _, pod := range pods {
|
||||
go func(podName string) {
|
||||
err := k.podLogStream(podName, stream)
|
||||
err := k.podLogs(podName, stream)
|
||||
if err != nil {
|
||||
log.Errorf("Error streaming from pod: %v", err)
|
||||
}
|
||||
|
Reference in New Issue
Block a user