Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion src/internal/syslog/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ func (s *Server) parseListener(res *syslog.Result) {
if !ok {
s.invalidIngress.Add(1)
s.loggr.Printf("invalid message format: not rfc5424")
return
}

env, err := s.convertToEnvelope(msg)
Expand All @@ -229,9 +230,18 @@ func (s *Server) convertToEnvelope(msg *rfc5424.SyslogMessage) (*loggregator_v2.
return nil, fmt.Errorf("missing app name in syslog message")
}

var timestamp int64
if msg.Timestamp != nil {
timestamp = msg.Timestamp.UnixNano()
} else {
// RFC5424 §6.2.3 allows the TIMESTAMP to be the NILVALUE "-", in which
// case the parser leaves it nil. Fall back to the time of receipt.
timestamp = time.Now().UnixNano()
}

env := &loggregator_v2.Envelope{
SourceId: *sourceID,
Timestamp: msg.Timestamp.UnixNano(),
Timestamp: timestamp,
InstanceId: instanceId,
Tags: map[string]string{},
}
Expand Down
25 changes: 25 additions & 0 deletions src/internal/syslog/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,31 @@ var _ = Describe("Server", func() {
}).Should(Equal(5.0))
})

// RFC5424 allows the TIMESTAMP to be the NILVALUE "-", which leaves
// msg.Timestamp nil. The server must accept it and use the receive time.
It("accepts a message with a nil timestamp", func() {
before := time.Now()
body := `<14>1 - test-hostname test-app-id [APP/2] - - just a test`
_, err := fmt.Fprintf(clientConn, "%d %s", len(body), body)
Expect(err).ToNot(HaveOccurred())

Expect(server.Stream(context.Background(), &loggregator_v2.EgressBatchRequest{})()).Should(ContainElement(
SatisfyAll(
HaveField("SourceId", "test-app-id"),
HaveField("InstanceId", "2"),
HaveField("Timestamp", BeNumerically(">=", before.UnixNano())),
HaveField("Timestamp", BeNumerically("<=", time.Now().UnixNano())),
HaveField("Message", &loggregator_v2.Envelope_Log{
Log: &loggregator_v2.Log{
Payload: []byte("just a test"),
Type: loggregator_v2.Log_OUT,
},
}),
),
))
Expect(spyRegistry.GetMetric("invalid_ingress", nil).Value()).To(Equal(0.0))
})

DescribeTable("message streaming",
func(msg string, expected *loggregator_v2.Envelope) {
_, err := fmt.Fprint(clientConn, msg)
Expand Down
Loading