Skip to content

Commit c91d82d

Browse files
committed
Add spans and drop large size high volume trace logs
Signed-off-by: Kirtana Ashok <[email protected]>
1 parent 523fe7b commit c91d82d

3 files changed

Lines changed: 27 additions & 8 deletions

File tree

cmd/containerd-shim-runhcs-v1/exec_hcs.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ func newHcsExec(
4848
"eid": id, // Init exec ID is always same as Task ID
4949
"bundle": bundle,
5050
"wcow": isWCOW,
51-
}).Debug("newHcsExec")
51+
}).Trace("newHcsExec")
5252

5353
he := &hcsExec{
5454
events: events,

internal/gcs/bridge.go

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,11 @@ import (
1616
"time"
1717

1818
"github.com/sirupsen/logrus"
19+
"go.opencensus.io/trace"
1920
"golang.org/x/sys/windows"
2021

2122
"github.com/Microsoft/hcsshim/internal/log"
23+
"github.com/Microsoft/hcsshim/internal/oc"
2224
)
2325

2426
const (
@@ -258,6 +260,9 @@ func (brdg *bridge) recvLoopRoutine() {
258260
}
259261

260262
func readMessage(r io.Reader) (int64, msgType, []byte, error) {
263+
_, span := oc.StartSpan(context.Background(), "bridge receive read message", oc.WithClientSpanKind)
264+
defer span.End()
265+
261266
var h [hdrSize]byte
262267
_, err := io.ReadFull(r, h[:])
263268
if err != nil {
@@ -266,6 +271,10 @@ func readMessage(r io.Reader) (int64, msgType, []byte, error) {
266271
typ := msgType(binary.LittleEndian.Uint32(h[hdrOffType:]))
267272
n := binary.LittleEndian.Uint32(h[hdrOffSize:])
268273
id := int64(binary.LittleEndian.Uint64(h[hdrOffID:]))
274+
span.AddAttributes(
275+
trace.StringAttribute("type", typ.String()),
276+
trace.Int64Attribute("message-id", id))
277+
269278
if n < hdrSize || n > maxMsgSize {
270279
return 0, 0, nil, fmt.Errorf("invalid message size %d", n)
271280
}
@@ -298,7 +307,8 @@ func (brdg *bridge) recvLoop() error {
298307
brdg.log.WithFields(logrus.Fields{
299308
"payload": string(b),
300309
"type": typ.String(),
301-
"message-id": id}).Debug("bridge receive")
310+
"message-id": id}).Trace("bridge receive")
311+
302312
switch typ & msgTypeMask {
303313
case msgTypeResponse:
304314
// Find the request associated with this response.
@@ -372,19 +382,27 @@ func (brdg *bridge) sendLoop() {
372382
}
373383

374384
func (brdg *bridge) writeMessage(buf *bytes.Buffer, enc *json.Encoder, typ msgType, id int64, req interface{}) error {
385+
var err error
386+
_, span := oc.StartSpan(context.Background(), "bridge send", oc.WithClientSpanKind)
387+
defer span.End()
388+
defer func() { oc.SetSpanStatus(span, err) }()
389+
span.AddAttributes(
390+
trace.StringAttribute("type", typ.String()),
391+
trace.Int64Attribute("message-id", id))
392+
375393
// Prepare the buffer with the message.
376394
var h [hdrSize]byte
377395
binary.LittleEndian.PutUint32(h[hdrOffType:], uint32(typ))
378396
binary.LittleEndian.PutUint64(h[hdrOffID:], uint64(id))
379397
buf.Write(h[:])
380-
err := enc.Encode(req)
398+
err = enc.Encode(req)
381399
if err != nil {
382400
return fmt.Errorf("bridge encode: %w", err)
383401
}
384402
// Update the message header with the size.
385403
binary.LittleEndian.PutUint32(buf.Bytes()[hdrOffSize:], uint32(buf.Len()))
386404

387-
if brdg.log.Logger.GetLevel() >= logrus.DebugLevel {
405+
if brdg.log.Logger.GetLevel() > logrus.DebugLevel {
388406
b := buf.Bytes()[hdrSize:]
389407
switch typ {
390408
// container environment vars are in rpCreate for linux; rpcExecuteProcess for windows
@@ -399,7 +417,7 @@ func (brdg *bridge) writeMessage(buf *bytes.Buffer, enc *json.Encoder, typ msgTy
399417
brdg.log.WithFields(logrus.Fields{
400418
"payload": string(b),
401419
"type": typ.String(),
402-
"message-id": id}).Debug("bridge send")
420+
"message-id": id}).Trace("bridge send")
403421
}
404422

405423
// Write the message.

internal/guest/bridge/bridge.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ func (b *Bridge) ListenAndServe(bridgeIn io.ReadCloser, bridgeOut io.WriteCloser
310310
trace.StringAttribute("cid", base.ContainerID))
311311

312312
entry := log.G(ctx)
313-
if entry.Logger.GetLevel() >= logrus.DebugLevel {
313+
if entry.Logger.GetLevel() > logrus.DebugLevel {
314314
s := string(message)
315315
switch header.Type {
316316
case prot.ComputeSystemCreateV1:
@@ -320,7 +320,7 @@ func (b *Bridge) ListenAndServe(bridgeIn io.ReadCloser, bridgeOut io.WriteCloser
320320
entry.WithError(err).Warning("could not scrub bridge payload")
321321
}
322322
}
323-
entry.WithField("message", s).Debug("request read message")
323+
entry.WithField("message", s).Trace("request read message")
324324
}
325325
requestChan <- &Request{
326326
Context: ctx,
@@ -384,7 +384,8 @@ func (b *Bridge) ListenAndServe(bridgeIn io.ReadCloser, bridgeOut io.WriteCloser
384384

385385
s := trace.FromContext(resp.ctx)
386386
if s != nil {
387-
log.G(resp.ctx).WithField("message", string(responseBytes)).Debug("request write response")
387+
log.G(resp.ctx).WithField("message", string(responseBytes)).Trace("request write response")
388+
s.AddAttributes(trace.StringAttribute("response-message-type", resp.header.Type.String()))
388389
s.End()
389390
}
390391
}

0 commit comments

Comments
 (0)