Skip to content

Commit 4047af3

Browse files
committed
logging: add timestamps to entries
If a timestamp doesn't exist on the Log Entry, the Logging service inserts a timestamp based on the time it receives the message. Local and network queuing / latency may cause logs to be delivered in an order different from the originating source. Attaching a timestamp at Entry creation time makes avoids this problem. Queuing / latency on the client side or on the network may mean that the Log Entries are received by the service in a different order than the client.
1 parent 941b86c commit 4047af3

3 files changed

Lines changed: 34 additions & 49 deletions

File tree

packages/logging/src/entry.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ var isCircular = require('is-circular');
8585
function Entry(metadata, data) {
8686
this.metadata = metadata;
8787
this.data = data;
88+
this.timestamp = new Date();
8889
}
8990

9091
/**

packages/logging/system-test/logging.js

Lines changed: 27 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -315,36 +315,38 @@ describe('Logging', function() {
315315
});
316316

317317
it('should write multiple entries to a log', function(done) {
318-
log.write(logEntries, options, function(err) {
319-
assert.ifError(err);
318+
logEntries.forEach(function(entry) {
319+
log.write(entry, options, function(err) {
320+
assert.ifError(err);
321+
});
322+
});
320323

321-
setTimeout(function() {
322-
log.getEntries({
323-
pageSize: logEntries.length
324-
}, function(err, entries) {
325-
assert.ifError(err);
324+
setTimeout(function() {
325+
log.getEntries({
326+
pageSize: logEntries.length
327+
}, function(err, entries) {
328+
assert.ifError(err);
326329

327-
assert.deepEqual(entries.map(prop('data')).reverse(), [
328-
'log entry 1',
329-
{
330+
assert.deepEqual(entries.map(prop('data')).reverse(), [
331+
'log entry 1',
332+
{
333+
delegate: 'my_username'
334+
},
335+
{
336+
nonValue: null,
337+
boolValue: true,
338+
arrayValue: [ 1, 2, 3 ]
339+
},
340+
{
341+
nested: {
330342
delegate: 'my_username'
331-
},
332-
{
333-
nonValue: null,
334-
boolValue: true,
335-
arrayValue: [ 1, 2, 3 ]
336-
},
337-
{
338-
nested: {
339-
delegate: 'my_username'
340-
}
341343
}
342-
]);
344+
}
345+
]);
343346

344-
done();
345-
});
346-
}, WRITE_CONSISTENCY_DELAY_MS);
347-
});
347+
done();
348+
});
349+
}, WRITE_CONSISTENCY_DELAY_MS);
348350
});
349351

350352
it('should write an entry with primitive values', function(done) {

packages/logging/test/log.js

Lines changed: 6 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
var assert = require('assert');
2020
var extend = require('extend');
2121
var GrpcServiceObject = require('@google-cloud/common').GrpcServiceObject;
22+
var prop = require('propprop');
2223
var proxyquire = require('proxyquire');
2324
var util = require('@google-cloud/common').util;
2425

@@ -137,34 +138,15 @@ describe('Log', function() {
137138
var SEVERITY = 'severity';
138139

139140
it('should assign severity to a single entry', function() {
140-
assert.deepEqual(
141-
Log.assignSeverityToEntries_(ENTRIES[0], SEVERITY),
142-
[
143-
extend(true, {}, ENTRIES[0], {
144-
metadata: {
145-
severity: SEVERITY
146-
}
147-
})
148-
]
149-
);
141+
assert.deepEqual(Log.assignSeverityToEntries_(ENTRIES[0], SEVERITY)
142+
.map(prop('metadata')),
143+
[{severity: SEVERITY}]);
150144
});
151145

152146
it('should assign severity property to multiple entries', function() {
153147
assert.deepEqual(
154-
Log.assignSeverityToEntries_(ENTRIES, SEVERITY),
155-
[
156-
extend(true, {}, ENTRIES[0], {
157-
metadata: {
158-
severity: SEVERITY
159-
}
160-
}),
161-
extend(true, {}, ENTRIES[1], {
162-
metadata: {
163-
severity: SEVERITY
164-
}
165-
})
166-
]
167-
);
148+
Log.assignSeverityToEntries_(ENTRIES, SEVERITY).map(prop('metadata')),
149+
[{severity: SEVERITY}, {severity: SEVERITY}]);
168150
});
169151

170152
it('should not affect original array', function() {

0 commit comments

Comments
 (0)