@@ -62,6 +62,12 @@ func TestLogMapping(t *testing.T) {
6262 testSpanID := pcommon .SpanID ([8 ]byte {
6363 0 , 0 , 0 , 0 , 0 , 0 , 0 , 1 ,
6464 })
65+ testInt64RequestSize := int64 (4611686018427387904 ) // 2 ^ 62 + 1
66+ testInt64ResponseSize := int64 (4611686018427387905 ) // 2 ^ 62 + 2
67+ testInt64CacheFillBytes := int64 (4611686018427387906 ) // 2 ^ 62 + 3
68+ testStringRequestSize := "4611686018427387904" // 2 ^ 62 + 1
69+ testStringResponseSize := "4611686018427387905" // 2 ^ 62 + 2
70+ testStringCacheFillBytes := "4611686018427387906" // 2 ^ 62 + 3
6571 logName := "projects/fakeprojectid/logs/default-log"
6672
6773 testCases := []struct {
@@ -266,6 +272,108 @@ func TestLogMapping(t *testing.T) {
266272 },
267273 maxEntrySize : defaultMaxEntrySize ,
268274 },
275+ {
276+ name : "log with json and httpRequest with integer values, empty monitoredresource" ,
277+ log : func () plog.LogRecord {
278+ log := plog .NewLogRecord ()
279+ log .Body ().SetEmptyMap ().PutStr ("message" , "hello!" )
280+ httpRequest := log .Attributes ().PutEmptyMap (HTTPRequestAttributeKey )
281+ httpRequest .PutStr ("requestMethod" , "GET" )
282+ httpRequest .PutStr ("requestURL" , "https://www.example.com" )
283+ httpRequest .PutInt ("requestSize" , testInt64RequestSize )
284+ httpRequest .PutInt ("status" , 200 )
285+ httpRequest .PutInt ("responseSize" , testInt64ResponseSize )
286+ httpRequest .PutStr ("userAgent" , "test" )
287+ httpRequest .PutStr ("remoteIP" , "192.168.0.1" )
288+ httpRequest .PutStr ("serverIP" , "192.168.0.2" )
289+ httpRequest .PutStr ("referer" , "https://www.example2.com" )
290+ httpRequest .PutBool ("cacheHit" , false )
291+ httpRequest .PutBool ("cacheValidatedWithOriginServer" , false )
292+ httpRequest .PutInt ("cacheFillBytes" , testInt64CacheFillBytes )
293+ httpRequest .PutStr ("protocol" , "HTTP/2" )
294+ return log
295+ },
296+ mr : func () * monitoredrespb.MonitoredResource {
297+ return nil
298+ },
299+ expectedEntries : []* logpb.LogEntry {
300+ {
301+ LogName : logName ,
302+ Timestamp : timestamppb .New (testObservedTime ),
303+ Payload : & logpb.LogEntry_JsonPayload {JsonPayload : & structpb.Struct {Fields : map [string ]* structpb.Value {
304+ "message" : {Kind : & structpb.Value_StringValue {StringValue : "hello!" }},
305+ }}},
306+ HttpRequest : & logtypepb.HttpRequest {
307+ RequestMethod : "GET" ,
308+ UserAgent : "test" ,
309+ Referer : "https://www.example2.com" ,
310+ RequestUrl : "https://www.example.com" ,
311+ Protocol : "HTTP/1.1" ,
312+ RequestSize : testInt64RequestSize ,
313+ Status : 200 ,
314+ ResponseSize : testInt64ResponseSize ,
315+ ServerIp : "192.168.0.2" ,
316+ RemoteIp : "192.168.0.1" ,
317+ CacheHit : false ,
318+ CacheValidatedWithOriginServer : false ,
319+ CacheFillBytes : testInt64CacheFillBytes ,
320+ CacheLookup : false ,
321+ },
322+ },
323+ },
324+ maxEntrySize : defaultMaxEntrySize ,
325+ },
326+ {
327+ name : "log with json and httpRequest with string values, empty monitoredresource" ,
328+ log : func () plog.LogRecord {
329+ log := plog .NewLogRecord ()
330+ log .Body ().SetEmptyMap ().PutStr ("message" , "hello!" )
331+ httpRequest := log .Attributes ().PutEmptyMap (HTTPRequestAttributeKey )
332+ httpRequest .PutStr ("requestMethod" , "GET" )
333+ httpRequest .PutStr ("requestURL" , "https://www.example.com" )
334+ httpRequest .PutStr ("requestSize" , testStringRequestSize )
335+ httpRequest .PutInt ("status" , 200 )
336+ httpRequest .PutStr ("responseSize" , testStringResponseSize )
337+ httpRequest .PutStr ("userAgent" , "test" )
338+ httpRequest .PutStr ("remoteIP" , "192.168.0.1" )
339+ httpRequest .PutStr ("serverIP" , "192.168.0.2" )
340+ httpRequest .PutStr ("referer" , "https://www.example2.com" )
341+ httpRequest .PutBool ("cacheHit" , false )
342+ httpRequest .PutBool ("cacheValidatedWithOriginServer" , false )
343+ httpRequest .PutStr ("cacheFillBytes" , testStringCacheFillBytes )
344+ httpRequest .PutStr ("protocol" , "HTTP/2" )
345+ return log
346+ },
347+ mr : func () * monitoredrespb.MonitoredResource {
348+ return nil
349+ },
350+ expectedEntries : []* logpb.LogEntry {
351+ {
352+ LogName : logName ,
353+ Timestamp : timestamppb .New (testObservedTime ),
354+ Payload : & logpb.LogEntry_JsonPayload {JsonPayload : & structpb.Struct {Fields : map [string ]* structpb.Value {
355+ "message" : {Kind : & structpb.Value_StringValue {StringValue : "hello!" }},
356+ }}},
357+ HttpRequest : & logtypepb.HttpRequest {
358+ RequestMethod : "GET" ,
359+ UserAgent : "test" ,
360+ Referer : "https://www.example2.com" ,
361+ RequestUrl : "https://www.example.com" ,
362+ Protocol : "HTTP/1.1" ,
363+ RequestSize : testInt64RequestSize ,
364+ Status : 200 ,
365+ ResponseSize : testInt64ResponseSize ,
366+ ServerIp : "192.168.0.2" ,
367+ RemoteIp : "192.168.0.1" ,
368+ CacheHit : false ,
369+ CacheValidatedWithOriginServer : false ,
370+ CacheFillBytes : testInt64CacheFillBytes ,
371+ CacheLookup : false ,
372+ },
373+ },
374+ },
375+ maxEntrySize : defaultMaxEntrySize ,
376+ },
269377 {
270378 name : "log with httpRequest attribute unsupported type" ,
271379 log : func () plog.LogRecord {
0 commit comments