Merge pull request #32996 from dperny/service-logs-support-details
Fix Ambigious Logs Format and Add Support for Details in Service Logs Upstream-commit: 7fd8a9382c0fd3f23002288e357b5612b869a974 Component: engine
This commit is contained in:
@@ -405,11 +405,11 @@ func (c *containerAdapter) logs(ctx context.Context, options api.LogSubscription
|
||||
apiOptions := &types.ContainerLogsOptions{
|
||||
Follow: options.Follow,
|
||||
|
||||
// TODO(stevvooe): Parse timestamp out of message. This
|
||||
// absolutely needs to be done before going to production with
|
||||
// this, at it is completely redundant.
|
||||
// Always say yes to Timestamps and Details. we make the decision
|
||||
// of whether to return these to the user or not way higher up the
|
||||
// stack.
|
||||
Timestamps: true,
|
||||
Details: false, // no clue what to do with this, let's just deprecate it.
|
||||
Details: true,
|
||||
}
|
||||
|
||||
if options.Since != nil {
|
||||
|
||||
@@ -523,10 +523,18 @@ func (r *controller) Logs(ctx context.Context, publisher exec.LogPublisher, opti
|
||||
stream = api.LogStreamStderr
|
||||
}
|
||||
|
||||
// parse the details out of the Attrs map
|
||||
attrs := []api.LogAttr{}
|
||||
for k, v := range msg.Attrs {
|
||||
attr := api.LogAttr{Key: k, Value: v}
|
||||
attrs = append(attrs, attr)
|
||||
}
|
||||
|
||||
if err := publisher.Publish(ctx, api.LogMessage{
|
||||
Context: msgctx,
|
||||
Timestamp: tsp,
|
||||
Stream: stream,
|
||||
Attrs: attrs,
|
||||
Data: msg.Line,
|
||||
}); err != nil {
|
||||
return errors.Wrap(err, "failed to publish log message")
|
||||
|
||||
@@ -430,9 +430,17 @@ func (c *Cluster) ServiceLogs(ctx context.Context, selector *backend.LogSelector
|
||||
if err != nil {
|
||||
m.Err = err
|
||||
}
|
||||
// copy over all of the details
|
||||
for _, d := range msg.Attrs {
|
||||
m.Attrs[d.Key] = d.Value
|
||||
}
|
||||
// we have the final say over context details (in case there
|
||||
// is a conflict (if the user added a detail with a context's
|
||||
// key for some reason))
|
||||
m.Attrs[contextPrefix+".node.id"] = msg.Context.NodeID
|
||||
m.Attrs[contextPrefix+".service.id"] = msg.Context.ServiceID
|
||||
m.Attrs[contextPrefix+".task.id"] = msg.Context.TaskID
|
||||
|
||||
switch msg.Stream {
|
||||
case swarmapi.LogStreamStdout:
|
||||
m.Source = "stdout"
|
||||
|
||||
Reference in New Issue
Block a user