diff --git a/queue/channel_test.go b/queue/channel_test.go index d0fbb88..98cd1c6 100644 --- a/queue/channel_test.go +++ b/queue/channel_test.go @@ -64,7 +64,7 @@ func (n *nilStorer) StoreResources(_ []logging.Resource, count int) (*logging.St } func TestChannelQueue(t *testing.T) { - q, err := queue.NewChannelQueue() + q, err := queue.NewChannelQueue(queue.WithMetrics(&nilMetrics{})) assert.Nil(t, err) assert.NotNil(t, q) diff --git a/queue/deliverer.go b/queue/deliverer.go index d30a70d..174150d 100644 --- a/queue/deliverer.go +++ b/queue/deliverer.go @@ -234,13 +234,19 @@ func ProcessMessage(rfcLogMessage syslog.Message, m Metrics) (*logging.Resource, } msg = wrapResource("logproxy-wrapped", rfcLogMessage) + err = json.Unmarshal([]byte(*logMessage), &dhp) if err == nil { if dhp.TransactionID != "" { msg.TransactionID = dhp.TransactionID } if dhp.LogData.Message != "" { - msg.LogData.Message = dhp.LogData.Message + if !Base64Pattern.MatchString(dhp.LogData.Message) { // Encode + msg.LogData.Message = base64.StdEncoding.EncodeToString([]byte(dhp.LogData.Message)) + m.IncEnhancedEncodedMessage() + } else { // Already base64 encoded + msg.LogData.Message = dhp.LogData.Message + } } if dhp.ApplicationInstance != "" { msg.ApplicationInstance = dhp.ApplicationInstance diff --git a/queue/deliverer_test.go b/queue/deliverer_test.go index 77f1f32..f2779c1 100644 --- a/queue/deliverer_test.go +++ b/queue/deliverer_test.go @@ -2,6 +2,7 @@ package queue_test import ( "bytes" + "encoding/base64" "io" "os" "regexp" @@ -34,7 +35,7 @@ func TestCustomJSONInProcessMessage(t *testing.T) { assert.Nilf(t, err, "Expected Parse() to succeed") resource, err := queue.ProcessMessage(msg, &nilMetrics{}) assert.Nilf(t, err, "Expected ProcessMessage() to succeed") - assert.Equal(t, `Log message`, resource.LogData.Message) + assert.Equal(t, base64.StdEncoding.EncodeToString([]byte(`Log message`)), resource.LogData.Message) } @@ -116,7 +117,8 @@ func TestProcessMessage(t *testing.T) { assert.Equal(t, "com.philips.MyLoggingClass%28%29", resource.ServiceName) assert.Equal(t, "%40396f1a94-86f3-470b-784c-17cc%3D%3D", resource.ServerName) assert.Equal(t, "FATAL%7C", resource.Severity) - assert.Equal(t, payload, resource.LogData.Message) + encoded := base64.StdEncoding.EncodeToString([]byte(payload)) + assert.Equal(t, encoded, resource.LogData.Message) assert.Equal(t, "logproxy%24,", resource.OriginatingUser) msg, err = parser.Parse([]byte(nonDHPMessage)) @@ -174,7 +176,7 @@ func TestResourceWorker(t *testing.T) { assert.Nilf(t, err, "Expected NewDeliverer() to succeed") deliverer.Debug = true - q, _ := queue.NewChannelQueue() + q, _ := queue.NewChannelQueue(queue.WithMetrics(&nilMetrics{})) done, _ := q.Start() go deliverer.ResourceWorker(q, done, nil) @@ -230,7 +232,7 @@ func TestDroppedMessages(t *testing.T) { assert.Nilf(t, err, "Expected NewDeliverer() to succeed") deliverer.Debug = true - q, _ := queue.NewChannelQueue() + q, _ := queue.NewChannelQueue(queue.WithMetrics(&nilMetrics{})) done, _ := q.Start() go deliverer.ResourceWorker(q, done, nil)