fluent-plugin-google-cloud 0.7.15 → 0.7.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile.lock +36 -38
- data/fluent-plugin-google-cloud.gemspec +20 -15
- data/lib/fluent/plugin/monitoring.rb +5 -1
- data/lib/fluent/plugin/out_google_cloud.rb +27 -5
- data/lib/fluent/plugin/statusz.rb +106 -10
- data/test/plugin/base_test.rb +158 -188
- data/test/plugin/constants.rb +71 -6
- data/test/plugin/test_out_google_cloud.rb +72 -63
- data/test/plugin/test_out_google_cloud_grpc.rb +41 -98
- metadata +40 -40
data/test/plugin/base_test.rb
CHANGED
@@ -39,6 +39,14 @@ module BaseTest
|
|
39
39
|
# home var, which is used to find $HOME/.gcloud/...
|
40
40
|
ENV.delete('HOME')
|
41
41
|
|
42
|
+
# Unregister Prometheus metrics.
|
43
|
+
registry = Prometheus::Client.registry
|
44
|
+
registry.unregister(:stackdriver_successful_requests_count)
|
45
|
+
registry.unregister(:stackdriver_failed_requests_count)
|
46
|
+
registry.unregister(:stackdriver_ingested_entries_count)
|
47
|
+
registry.unregister(:stackdriver_dropped_entries_count)
|
48
|
+
registry.unregister(:stackdriver_retried_entries_count)
|
49
|
+
|
42
50
|
setup_auth_stubs
|
43
51
|
@logs_sent = []
|
44
52
|
end
|
@@ -142,6 +150,24 @@ module BaseTest
|
|
142
150
|
end
|
143
151
|
end
|
144
152
|
|
153
|
+
def test_configure_ignores_unknown_monitoring_type
|
154
|
+
# Verify that driver creation succeeds when monitoring type is not
|
155
|
+
# "prometheus" (in which case, we simply don't record metrics),
|
156
|
+
# and that the counters are set to nil.
|
157
|
+
setup_gce_metadata_stubs
|
158
|
+
create_driver(CONFIG_UNKNOWN_MONITORING_TYPE)
|
159
|
+
assert_nil(Prometheus::Client.registry.get(
|
160
|
+
:stackdriver_successful_requests_count))
|
161
|
+
assert_nil(Prometheus::Client.registry.get(
|
162
|
+
:stackdriver_failed_requests_count))
|
163
|
+
assert_nil(Prometheus::Client.registry.get(
|
164
|
+
:stackdriver_ingested_entries_count))
|
165
|
+
assert_nil(Prometheus::Client.registry.get(
|
166
|
+
:stackdriver_dropped_entries_count))
|
167
|
+
assert_nil(Prometheus::Client.registry.get(
|
168
|
+
:stackdriver_retried_entries_count))
|
169
|
+
end
|
170
|
+
|
145
171
|
def test_metadata_loading
|
146
172
|
setup_gce_metadata_stubs
|
147
173
|
d = create_driver
|
@@ -330,12 +356,12 @@ module BaseTest
|
|
330
356
|
d.run
|
331
357
|
end
|
332
358
|
verify_log_entries(1, COMPUTE_PARAMS, 'jsonPayload') do |entry, i|
|
333
|
-
fields =
|
359
|
+
fields = entry['jsonPayload']
|
334
360
|
assert_equal 4, fields.size, entry
|
335
|
-
verify_default_log_entry_text(
|
336
|
-
assert_equal 'test',
|
337
|
-
assert_equal 5000,
|
338
|
-
|
361
|
+
verify_default_log_entry_text(fields['msg'], i, entry)
|
362
|
+
assert_equal 'test', fields['tag2'], entry
|
363
|
+
assert_equal 5000, fields['data'], entry
|
364
|
+
assert_nil fields['some_null_field'], entry
|
339
365
|
end
|
340
366
|
end
|
341
367
|
|
@@ -448,22 +474,17 @@ module BaseTest
|
|
448
474
|
d.run
|
449
475
|
end
|
450
476
|
verify_log_entries(1, COMPUTE_PARAMS, 'jsonPayload') do |entry|
|
451
|
-
fields =
|
477
|
+
fields = entry['jsonPayload']
|
452
478
|
assert_equal 7, fields.size, entry
|
453
|
-
assert_equal message,
|
454
|
-
|
455
|
-
assert_equal message,
|
456
|
-
|
457
|
-
|
458
|
-
|
459
|
-
|
460
|
-
|
461
|
-
assert_equal message,
|
462
|
-
['mixed_key']))['{"some_key"=>["a", "b", "c"]}']), entry
|
463
|
-
assert_equal message, get_string(get_fields(get_struct(fields \
|
464
|
-
['symbol_key']))['some_symbol']), entry
|
465
|
-
assert_equal message, get_string(get_fields(get_struct(fields \
|
466
|
-
['nil_key']))['']), entry
|
479
|
+
assert_equal message, fields['int_key']['1'], entry
|
480
|
+
assert_equal message, fields['int_array_key']['[1, 2, 3, 4]'], entry
|
481
|
+
assert_equal message, fields['string_array_key']['["a", "b", "c"]'], entry
|
482
|
+
assert_equal message, fields['hash_key']['{"some_key"=>"some_value"}'],
|
483
|
+
entry
|
484
|
+
assert_equal message,
|
485
|
+
fields['mixed_key']['{"some_key"=>["a", "b", "c"]}'], entry
|
486
|
+
assert_equal message, fields['symbol_key']['some_symbol'], entry
|
487
|
+
assert_equal message, fields['nil_key'][''], entry
|
467
488
|
end
|
468
489
|
end
|
469
490
|
|
@@ -497,7 +518,7 @@ module BaseTest
|
|
497
518
|
d.run
|
498
519
|
end
|
499
520
|
verify_log_entries(6, COMPUTE_PARAMS, 'jsonPayload') do |entry|
|
500
|
-
fields =
|
521
|
+
fields = entry['jsonPayload']
|
501
522
|
assert !fields.key?('tag2'), 'Did not expect tag2'
|
502
523
|
assert !fields.key?('data'), 'Did not expect data'
|
503
524
|
assert !fields.key?('some_null_field'), 'Did not expect some_null_field'
|
@@ -530,7 +551,7 @@ module BaseTest
|
|
530
551
|
d.run
|
531
552
|
end
|
532
553
|
verify_log_entries(2, COMPUTE_PARAMS, 'jsonPayload') do |entry|
|
533
|
-
fields =
|
554
|
+
fields = entry['jsonPayload']
|
534
555
|
assert !fields.key?('tag2'), 'Did not expect tag2'
|
535
556
|
assert !fields.key?('data'), 'Did not expect data'
|
536
557
|
assert !fields.key?('some_null_field'), 'Did not expect some_null_field'
|
@@ -594,15 +615,14 @@ module BaseTest
|
|
594
615
|
end
|
595
616
|
else
|
596
617
|
verify_log_entries(1, COMPUTE_PARAMS, 'jsonPayload') do |entry|
|
597
|
-
json_payload =
|
618
|
+
json_payload = entry['jsonPayload']
|
598
619
|
assert_equal 1, json_payload.size, entry
|
599
|
-
fields =
|
600
|
-
get_struct(json_payload[test_params[:field_name]]))
|
620
|
+
fields = json_payload[test_params[:field_name]]
|
601
621
|
assert_equal 4, fields.size, entry
|
602
|
-
assert_equal 'test log entry 0',
|
603
|
-
assert_equal 'test',
|
604
|
-
assert_equal 5000,
|
605
|
-
|
622
|
+
assert_equal 'test log entry 0', fields['msg'], entry
|
623
|
+
assert_equal 'test', fields['tag2'], entry
|
624
|
+
assert_equal 5000, fields['data'], entry
|
625
|
+
assert_nil fields['some_null_field'], entry
|
606
626
|
end
|
607
627
|
end
|
608
628
|
end
|
@@ -622,12 +642,12 @@ module BaseTest
|
|
622
642
|
d.run
|
623
643
|
end
|
624
644
|
verify_log_entries(6, COMPUTE_PARAMS, 'jsonPayload') do |entry|
|
625
|
-
fields =
|
645
|
+
fields = entry['jsonPayload']
|
626
646
|
assert_equal 4, fields.size, entry
|
627
|
-
assert_equal 'test log entry 0',
|
628
|
-
assert_equal 'test',
|
629
|
-
assert_equal 5000,
|
630
|
-
|
647
|
+
assert_equal 'test log entry 0', fields['msg'], entry
|
648
|
+
assert_equal 'test', fields['tag2'], entry
|
649
|
+
assert_equal 5000, fields['data'], entry
|
650
|
+
assert_nil fields['some_null_field'], entry
|
631
651
|
end
|
632
652
|
end
|
633
653
|
|
@@ -676,12 +696,12 @@ module BaseTest
|
|
676
696
|
end
|
677
697
|
verify_log_entries(2, CONTAINER_FROM_METADATA_PARAMS, 'jsonPayload') \
|
678
698
|
do |entry|
|
679
|
-
fields =
|
699
|
+
fields = entry['jsonPayload']
|
680
700
|
assert_equal 4, fields.size, entry
|
681
|
-
assert_equal 'test log entry 0',
|
682
|
-
assert_equal 'test',
|
683
|
-
assert_equal 5000,
|
684
|
-
|
701
|
+
assert_equal 'test log entry 0', fields['msg'], entry
|
702
|
+
assert_equal 'test', fields['tag2'], entry
|
703
|
+
assert_equal 5000, fields['data'], entry
|
704
|
+
assert_nil fields['some_null_field'], entry
|
685
705
|
end
|
686
706
|
end
|
687
707
|
|
@@ -692,22 +712,26 @@ module BaseTest
|
|
692
712
|
setup_gce_metadata_stubs
|
693
713
|
json_string = '{"msg": "test log entry 0", "tag2": "test", ' \
|
694
714
|
'"data": 5000, "some_null_field": null}'
|
695
|
-
|
696
|
-
|
697
|
-
|
698
|
-
d
|
715
|
+
PRESERVED_KEYS_TIMESTAMP_FIELDS.each do |timestamp_fields|
|
716
|
+
setup_logging_stubs do
|
717
|
+
@logs_sent = []
|
718
|
+
d = create_driver(DETECT_JSON_CONFIG)
|
719
|
+
%w(message log msg).each do |field|
|
720
|
+
d.emit(PRESERVED_KEYS_MAP.merge(
|
721
|
+
field => json_string).merge(timestamp_fields))
|
722
|
+
end
|
723
|
+
d.run
|
724
|
+
end
|
725
|
+
expected_params = COMPUTE_PARAMS.merge(
|
726
|
+
labels: COMPUTE_PARAMS[:labels].merge(LABELS_MESSAGE))
|
727
|
+
verify_log_entries(3, expected_params, 'jsonPayload') do |entry|
|
728
|
+
fields = entry['jsonPayload']
|
729
|
+
assert_equal 4, fields.size, entry
|
730
|
+
assert_equal 'test log entry 0', fields['msg'], entry
|
731
|
+
assert_equal 'test', fields['tag2'], entry
|
732
|
+
assert_equal 5000, fields['data'], entry
|
733
|
+
assert_nil fields['some_null_field'], entry
|
699
734
|
end
|
700
|
-
d.run
|
701
|
-
end
|
702
|
-
expected_params = COMPUTE_PARAMS.merge(
|
703
|
-
labels: COMPUTE_PARAMS[:labels].merge(LABELS_MESSAGE))
|
704
|
-
verify_log_entries(3, expected_params, 'jsonPayload') do |entry|
|
705
|
-
fields = get_fields(entry['jsonPayload'])
|
706
|
-
assert_equal 4, fields.size, entry
|
707
|
-
assert_equal 'test log entry 0', get_string(fields['msg']), entry
|
708
|
-
assert_equal 'test', get_string(fields['tag2']), entry
|
709
|
-
assert_equal 5000, get_number(fields['data']), entry
|
710
|
-
assert_equal null_value, fields['some_null_field'], entry
|
711
735
|
end
|
712
736
|
end
|
713
737
|
|
@@ -961,19 +985,15 @@ module BaseTest
|
|
961
985
|
d.run
|
962
986
|
verify_log_entries(emit_index, COMPUTE_PARAMS) do |entry, i|
|
963
987
|
verify_default_log_entry_text(entry['textPayload'], i, entry)
|
964
|
-
|
965
|
-
|
966
|
-
|
967
|
-
|
968
|
-
|
969
|
-
|
970
|
-
|
971
|
-
|
972
|
-
|
973
|
-
# See http://wikipedia.org/wiki/Double-precision_floating-point_format.
|
974
|
-
assert_in_delta expected_ts.tv_nsec,
|
975
|
-
entry['timestamp']['nanos'], 600, entry
|
976
|
-
end
|
988
|
+
actual_timestamp = timestamp_parse(entry['timestamp'])
|
989
|
+
assert_equal actual_timestamp['seconds'], expected_ts.tv_sec, entry
|
990
|
+
# Fluentd v0.14 onwards supports nanosecond timestamp values.
|
991
|
+
# Added in 600 ns delta to avoid flaky tests introduced
|
992
|
+
# due to rounding error in double-precision floating-point numbers
|
993
|
+
# (to account for the missing 9 bits of precision ~ 512 ns).
|
994
|
+
# See http://wikipedia.org/wiki/Double-precision_floating-point_format.
|
995
|
+
assert_in_delta expected_ts.tv_nsec, actual_timestamp['nanos'],
|
996
|
+
600, entry
|
977
997
|
end
|
978
998
|
end
|
979
999
|
end
|
@@ -989,9 +1009,9 @@ module BaseTest
|
|
989
1009
|
d.run
|
990
1010
|
end
|
991
1011
|
verify_log_entries(1, COMPUTE_PARAMS, 'jsonPayload') do |entry|
|
992
|
-
fields =
|
1012
|
+
fields = entry['jsonPayload']
|
993
1013
|
assert_equal 2, fields.size, entry
|
994
|
-
assert_equal 'not-a-hash',
|
1014
|
+
assert_equal 'not-a-hash', fields['timestamp'], entry
|
995
1015
|
end
|
996
1016
|
end
|
997
1017
|
|
@@ -1082,10 +1102,10 @@ module BaseTest
|
|
1082
1102
|
params[:labels]['foo.googleapis.com/bar'] = 'value2'
|
1083
1103
|
params[:labels]['label3'] = 'value3'
|
1084
1104
|
verify_log_entries(1, params, 'jsonPayload') do |entry, i|
|
1085
|
-
fields =
|
1105
|
+
fields = entry['jsonPayload']
|
1086
1106
|
assert_equal 2, fields.size, entry
|
1087
|
-
verify_default_log_entry_text(
|
1088
|
-
assert_equal 'value4',
|
1107
|
+
verify_default_log_entry_text(fields['message'], i, entry)
|
1108
|
+
assert_equal 'value4', fields['not_a_label'], entry
|
1089
1109
|
end
|
1090
1110
|
end
|
1091
1111
|
|
@@ -1171,8 +1191,9 @@ module BaseTest
|
|
1171
1191
|
) { |_, oldval, newval| oldval.merge(newval) }
|
1172
1192
|
verify_log_entries(1, expected_params) do |entry, i|
|
1173
1193
|
verify_default_log_entry_text(entry['textPayload'], i, entry)
|
1174
|
-
|
1175
|
-
assert_equal
|
1194
|
+
actual_timestamp = timestamp_parse(entry['timestamp'])
|
1195
|
+
assert_equal K8S_SECONDS_EPOCH, actual_timestamp['seconds'], entry
|
1196
|
+
assert_equal K8S_NANOS, actual_timestamp['nanos'], entry
|
1176
1197
|
assert_equal 'ERROR', entry['severity'], entry
|
1177
1198
|
end
|
1178
1199
|
end
|
@@ -1189,13 +1210,14 @@ module BaseTest
|
|
1189
1210
|
end
|
1190
1211
|
verify_log_entries(1, CONTAINER_FROM_METADATA_PARAMS,
|
1191
1212
|
'jsonPayload') do |entry|
|
1192
|
-
fields =
|
1213
|
+
fields = entry['jsonPayload']
|
1193
1214
|
assert_equal 3, fields.size, entry
|
1194
|
-
assert_equal 'test log entry 0',
|
1195
|
-
assert_equal 'test',
|
1196
|
-
assert_equal 5000,
|
1197
|
-
|
1198
|
-
assert_equal
|
1215
|
+
assert_equal 'test log entry 0', fields['msg'], entry
|
1216
|
+
assert_equal 'test', fields['tag2'], entry
|
1217
|
+
assert_equal 5000, fields['data'], entry
|
1218
|
+
actual_timestamp = timestamp_parse(entry['timestamp'])
|
1219
|
+
assert_equal K8S_SECONDS_EPOCH, actual_timestamp['seconds'], entry
|
1220
|
+
assert_equal K8S_NANOS, actual_timestamp['nanos'], entry
|
1199
1221
|
assert_equal 'WARNING', entry['severity'], entry
|
1200
1222
|
end
|
1201
1223
|
end
|
@@ -1212,13 +1234,14 @@ module BaseTest
|
|
1212
1234
|
end
|
1213
1235
|
verify_log_entries(1, CONTAINER_FROM_TAG_PARAMS,
|
1214
1236
|
'jsonPayload') do |entry|
|
1215
|
-
fields =
|
1237
|
+
fields = entry['jsonPayload']
|
1216
1238
|
assert_equal 3, fields.size, entry
|
1217
|
-
assert_equal 'test log entry 0',
|
1218
|
-
assert_equal 'test',
|
1219
|
-
assert_equal 5000,
|
1220
|
-
|
1221
|
-
assert_equal
|
1239
|
+
assert_equal 'test log entry 0', fields['msg'], entry
|
1240
|
+
assert_equal 'test', fields['tag2'], entry
|
1241
|
+
assert_equal 5000, fields['data'], entry
|
1242
|
+
actual_timestamp = timestamp_parse(entry['timestamp'])
|
1243
|
+
assert_equal K8S_SECONDS_EPOCH, actual_timestamp['seconds'], entry
|
1244
|
+
assert_equal K8S_NANOS, actual_timestamp['nanos'], entry
|
1222
1245
|
assert_equal 'WARNING', entry['severity'], entry
|
1223
1246
|
end
|
1224
1247
|
end
|
@@ -1356,7 +1379,7 @@ module BaseTest
|
|
1356
1379
|
verify_log_entries(1, COMPUTE_PARAMS, 'httpRequest') do |entry|
|
1357
1380
|
assert_equal http_request_message_with_absent_referer,
|
1358
1381
|
entry['httpRequest'], entry
|
1359
|
-
assert_nil
|
1382
|
+
assert_nil entry['jsonPayload']['httpRequest'], entry
|
1360
1383
|
end
|
1361
1384
|
end
|
1362
1385
|
end
|
@@ -1367,13 +1390,13 @@ module BaseTest
|
|
1367
1390
|
setup_logging_stubs do
|
1368
1391
|
d = create_driver
|
1369
1392
|
@logs_sent = []
|
1370
|
-
d.emit('httpRequest' =>
|
1393
|
+
d.emit('httpRequest' => HTTP_REQUEST_MESSAGE.merge('latency' => input))
|
1371
1394
|
d.run
|
1372
1395
|
end
|
1373
1396
|
verify_log_entries(1, COMPUTE_PARAMS, 'httpRequest') do |entry|
|
1374
|
-
assert_equal
|
1397
|
+
assert_equal HTTP_REQUEST_MESSAGE.merge('latency' => expected),
|
1375
1398
|
entry['httpRequest'], entry
|
1376
|
-
assert_nil
|
1399
|
+
assert_nil entry['jsonPayload']['httpRequest'], entry
|
1377
1400
|
end
|
1378
1401
|
end
|
1379
1402
|
end
|
@@ -1388,12 +1411,12 @@ module BaseTest
|
|
1388
1411
|
setup_logging_stubs do
|
1389
1412
|
d = create_driver
|
1390
1413
|
@logs_sent = []
|
1391
|
-
d.emit('httpRequest' =>
|
1414
|
+
d.emit('httpRequest' => HTTP_REQUEST_MESSAGE.merge('latency' => input))
|
1392
1415
|
d.run
|
1393
1416
|
end
|
1394
1417
|
verify_log_entries(1, COMPUTE_PARAMS, 'httpRequest') do |entry|
|
1395
|
-
assert_equal
|
1396
|
-
assert_nil
|
1418
|
+
assert_equal HTTP_REQUEST_MESSAGE, entry['httpRequest'], entry
|
1419
|
+
assert_nil entry['jsonPayload']['httpRequest'], entry
|
1397
1420
|
end
|
1398
1421
|
end
|
1399
1422
|
end
|
@@ -1432,7 +1455,7 @@ module BaseTest
|
|
1432
1455
|
custom_key: 'custom_source_location_key',
|
1433
1456
|
custom_key_config: \
|
1434
1457
|
CONFIG_CUSTOM_SOURCE_LOCATION_KEY_SPECIFIED,
|
1435
|
-
sample_value:
|
1458
|
+
sample_value: SOURCE_LOCATION_MESSAGE)
|
1436
1459
|
end
|
1437
1460
|
|
1438
1461
|
def test_log_entry_span_id_field
|
@@ -1490,8 +1513,8 @@ module BaseTest
|
|
1490
1513
|
def test_cascading_json_detection_with_log_entry_source_location_field
|
1491
1514
|
verify_cascading_json_detection_with_log_entry_fields(
|
1492
1515
|
'sourceLocation', DEFAULT_SOURCE_LOCATION_KEY,
|
1493
|
-
root_level_value:
|
1494
|
-
nested_level_value:
|
1516
|
+
root_level_value: SOURCE_LOCATION_MESSAGE,
|
1517
|
+
nested_level_value: SOURCE_LOCATION_MESSAGE2)
|
1495
1518
|
end
|
1496
1519
|
|
1497
1520
|
def test_cascading_json_detection_with_log_entry_span_id_field
|
@@ -1652,11 +1675,11 @@ module BaseTest
|
|
1652
1675
|
d.run
|
1653
1676
|
end
|
1654
1677
|
verify_log_entries(n, DOCKER_CONTAINER_PARAMS, 'jsonPayload') do |entry|
|
1655
|
-
fields =
|
1678
|
+
fields = entry['jsonPayload']
|
1656
1679
|
assert_equal 3, fields.size, entry
|
1657
|
-
assert_equal "test log entry #{n}",
|
1658
|
-
assert_equal 'test',
|
1659
|
-
assert_equal 5000,
|
1680
|
+
assert_equal "test log entry #{n}", fields['msg'], entry
|
1681
|
+
assert_equal 'test', fields['tag2'], entry
|
1682
|
+
assert_equal 5000, fields['data'], entry
|
1660
1683
|
end
|
1661
1684
|
assert_requested_metadata_agent_stub("container.#{DOCKER_CONTAINER_ID}")
|
1662
1685
|
end
|
@@ -1771,10 +1794,10 @@ module BaseTest
|
|
1771
1794
|
end
|
1772
1795
|
verify_log_entries(1, test_params[:expected_params],
|
1773
1796
|
'jsonPayload') do |entry|
|
1774
|
-
fields =
|
1797
|
+
fields = entry['jsonPayload']
|
1775
1798
|
assert_equal 2, fields.size, entry
|
1776
|
-
assert_equal 'test log entry 0',
|
1777
|
-
assert_equal K8S_STREAM,
|
1799
|
+
assert_equal 'test log entry 0', fields['log'], entry
|
1800
|
+
assert_equal K8S_STREAM, fields['stream'], entry
|
1778
1801
|
end
|
1779
1802
|
end
|
1780
1803
|
end
|
@@ -1868,10 +1891,10 @@ module BaseTest
|
|
1868
1891
|
end
|
1869
1892
|
verify_log_entries(1, test_params[:expected_params],
|
1870
1893
|
'jsonPayload') do |entry|
|
1871
|
-
fields =
|
1894
|
+
fields = entry['jsonPayload']
|
1872
1895
|
assert_equal 2, fields.size, entry
|
1873
|
-
assert_equal 'test log entry 0',
|
1874
|
-
assert_equal K8S_STREAM,
|
1896
|
+
assert_equal 'test log entry 0', fields['log'], entry
|
1897
|
+
assert_equal K8S_STREAM, fields['stream'], entry
|
1875
1898
|
end
|
1876
1899
|
end
|
1877
1900
|
end
|
@@ -1928,10 +1951,10 @@ module BaseTest
|
|
1928
1951
|
end
|
1929
1952
|
verify_log_entries(1, test_params[:expected_params],
|
1930
1953
|
'jsonPayload') do |entry|
|
1931
|
-
fields =
|
1954
|
+
fields = entry['jsonPayload']
|
1932
1955
|
assert_equal 2, fields.size, entry
|
1933
|
-
assert_equal 'test log entry 0',
|
1934
|
-
assert_equal K8S_STREAM,
|
1956
|
+
assert_equal 'test log entry 0', fields['log'], entry
|
1957
|
+
assert_equal K8S_STREAM, fields['stream'], entry
|
1935
1958
|
end
|
1936
1959
|
end
|
1937
1960
|
end
|
@@ -1951,10 +1974,10 @@ module BaseTest
|
|
1951
1974
|
verify_log_entries(1, DOCKER_CONTAINER_PARAMS_NO_STREAM) do |entry, i|
|
1952
1975
|
verify_default_log_entry_text(entry['textPayload'], i, entry)
|
1953
1976
|
# Timestamp in 'time' field from log entry should be set properly.
|
1977
|
+
actual_timestamp = timestamp_parse(entry['timestamp'])
|
1954
1978
|
assert_equal DOCKER_CONTAINER_SECONDS_EPOCH,
|
1955
|
-
|
1956
|
-
assert_equal DOCKER_CONTAINER_NANOS,
|
1957
|
-
entry['timestamp']['nanos'], entry
|
1979
|
+
actual_timestamp['seconds'], entry
|
1980
|
+
assert_equal DOCKER_CONTAINER_NANOS, actual_timestamp['nanos'], entry
|
1958
1981
|
end
|
1959
1982
|
assert_requested_metadata_agent_stub(
|
1960
1983
|
"#{DOCKER_CONTAINER_LOCAL_RESOURCE_ID_PREFIX}.#{DOCKER_CONTAINER_NAME}")
|
@@ -2381,8 +2404,9 @@ module BaseTest
|
|
2381
2404
|
end
|
2382
2405
|
verify_log_entries(n, expected_params) do |entry, i|
|
2383
2406
|
verify_default_log_entry_text(entry['textPayload'], i, entry)
|
2384
|
-
|
2385
|
-
assert_equal
|
2407
|
+
actual_timestamp = timestamp_parse(entry['timestamp'])
|
2408
|
+
assert_equal K8S_SECONDS_EPOCH, actual_timestamp['seconds'], entry
|
2409
|
+
assert_equal K8S_NANOS, actual_timestamp['nanos'], entry
|
2386
2410
|
assert_equal CONTAINER_SEVERITY, entry['severity'], entry
|
2387
2411
|
end
|
2388
2412
|
end
|
@@ -2394,13 +2418,13 @@ module BaseTest
|
|
2394
2418
|
# LogEntry info from. The values are lists of two elements: the name of
|
2395
2419
|
# the subfield in LogEntry object and the expected value of that field.
|
2396
2420
|
DEFAULT_HTTP_REQUEST_KEY => [
|
2397
|
-
'httpRequest',
|
2421
|
+
'httpRequest', HTTP_REQUEST_MESSAGE],
|
2398
2422
|
DEFAULT_LABELS_KEY => [
|
2399
2423
|
'labels', COMPUTE_PARAMS[:labels].merge(LABELS_MESSAGE)],
|
2400
2424
|
DEFAULT_OPERATION_KEY => [
|
2401
2425
|
'operation', OPERATION_MESSAGE],
|
2402
2426
|
DEFAULT_SOURCE_LOCATION_KEY => [
|
2403
|
-
'sourceLocation',
|
2427
|
+
'sourceLocation', SOURCE_LOCATION_MESSAGE]
|
2404
2428
|
}
|
2405
2429
|
end
|
2406
2430
|
|
@@ -2416,7 +2440,7 @@ module BaseTest
|
|
2416
2440
|
verify_log_entries(1, COMPUTE_PARAMS, destination_key,
|
2417
2441
|
check_exact_entry_labels) do |entry|
|
2418
2442
|
assert_equal payload_value, entry[destination_key], entry
|
2419
|
-
fields =
|
2443
|
+
fields = entry['jsonPayload']
|
2420
2444
|
assert_nil fields[payload_key], entry
|
2421
2445
|
end
|
2422
2446
|
end
|
@@ -2432,9 +2456,9 @@ module BaseTest
|
|
2432
2456
|
end
|
2433
2457
|
verify_log_entries(1, COMPUTE_PARAMS, destination_key) do |entry|
|
2434
2458
|
assert_equal payload_value, entry[destination_key], entry
|
2435
|
-
fields =
|
2436
|
-
request =
|
2437
|
-
assert_equal 'value',
|
2459
|
+
fields = entry['jsonPayload']
|
2460
|
+
request = fields[payload_key]
|
2461
|
+
assert_equal 'value', request['otherKey'], entry
|
2438
2462
|
end
|
2439
2463
|
end
|
2440
2464
|
|
@@ -2449,7 +2473,7 @@ module BaseTest
|
|
2449
2473
|
end
|
2450
2474
|
verify_log_entries(1, COMPUTE_PARAMS, 'jsonPayload') do |entry|
|
2451
2475
|
# The malformed field has been removed from the payload.
|
2452
|
-
assert_true
|
2476
|
+
assert_true entry['jsonPayload'].empty?, entry
|
2453
2477
|
# No additional labels.
|
2454
2478
|
assert_equal COMPUTE_PARAMS[:labels].size,
|
2455
2479
|
entry[destination_key].size, entry
|
@@ -2467,8 +2491,8 @@ module BaseTest
|
|
2467
2491
|
end
|
2468
2492
|
verify_log_entries(1, COMPUTE_PARAMS, 'jsonPayload') do |entry|
|
2469
2493
|
# Verify that we leave the malformed field as it is.
|
2470
|
-
field =
|
2471
|
-
assert_equal 'a_string',
|
2494
|
+
field = entry['jsonPayload'][payload_key]
|
2495
|
+
assert_equal 'a_string', field, entry
|
2472
2496
|
assert_false entry.key?(destination_key), entry
|
2473
2497
|
end
|
2474
2498
|
end
|
@@ -2484,7 +2508,7 @@ module BaseTest
|
|
2484
2508
|
end
|
2485
2509
|
|
2486
2510
|
verify_log_entries(1, COMPUTE_PARAMS, 'jsonPayload') do |entry|
|
2487
|
-
fields =
|
2511
|
+
fields = entry['jsonPayload']
|
2488
2512
|
assert_false fields.key?(payload_key), entry
|
2489
2513
|
if payload_key == DEFAULT_LABELS_KEY
|
2490
2514
|
# No additional labels.
|
@@ -2576,10 +2600,10 @@ module BaseTest
|
|
2576
2600
|
entry[log_entry_field], expected_value, default_value,
|
2577
2601
|
"Index #{index} failed. #{expected_value} is expected for " \
|
2578
2602
|
"#{log_entry_field} field."
|
2579
|
-
payload_fields =
|
2603
|
+
payload_fields = entry['jsonPayload']
|
2580
2604
|
assert_equal structured_log_entry.size, payload_fields.size
|
2581
2605
|
payload_fields.each do |key, value|
|
2582
|
-
assert_equal structured_log_entry[key],
|
2606
|
+
assert_equal structured_log_entry[key], value
|
2583
2607
|
end
|
2584
2608
|
end
|
2585
2609
|
end
|
@@ -2632,10 +2656,10 @@ module BaseTest
|
|
2632
2656
|
end
|
2633
2657
|
verify_log_entries(1, COMPUTE_PARAMS, 'jsonPayload', false) do |entry|
|
2634
2658
|
assert_equal input[:expected_field_value], entry[log_entry_field], input
|
2635
|
-
payload_fields =
|
2659
|
+
payload_fields = entry['jsonPayload']
|
2636
2660
|
assert_equal input[:expected_payload].size, payload_fields.size, input
|
2637
2661
|
payload_fields.each do |key, value|
|
2638
|
-
|
2662
|
+
assert_equal input[:expected_payload][key], value
|
2639
2663
|
end
|
2640
2664
|
end
|
2641
2665
|
end
|
@@ -2643,35 +2667,19 @@ module BaseTest
|
|
2643
2667
|
|
2644
2668
|
# Replace the 'referer' field with nil.
|
2645
2669
|
def http_request_message_with_nil_referer
|
2646
|
-
|
2670
|
+
HTTP_REQUEST_MESSAGE.merge('referer' => nil)
|
2647
2671
|
end
|
2648
2672
|
|
2649
2673
|
# Unset the 'referer' field.
|
2650
2674
|
def http_request_message_with_absent_referer
|
2651
|
-
|
2675
|
+
HTTP_REQUEST_MESSAGE.reject do |k, _|
|
2652
2676
|
k == 'referer'
|
2653
2677
|
end
|
2654
2678
|
end
|
2655
2679
|
|
2656
2680
|
# The conversions from user input to output.
|
2657
2681
|
def latency_conversion
|
2658
|
-
|
2659
|
-
'32 s' => { 'seconds' => 32 },
|
2660
|
-
'32s' => { 'seconds' => 32 },
|
2661
|
-
'0.32s' => { 'nanos' => 320_000_000 },
|
2662
|
-
' 123 s ' => { 'seconds' => 123 },
|
2663
|
-
'1.3442 s' => { 'seconds' => 1, 'nanos' => 344_200_000 },
|
2664
|
-
|
2665
|
-
# Test whitespace.
|
2666
|
-
# \t: tab. \r: carriage return. \n: line break.
|
2667
|
-
# \v: vertical whitespace. \f: form feed.
|
2668
|
-
"\t123.5\ts\t" => { 'seconds' => 123, 'nanos' => 500_000_000 },
|
2669
|
-
"\r123.5\rs\r" => { 'seconds' => 123, 'nanos' => 500_000_000 },
|
2670
|
-
"\n123.5\ns\n" => { 'seconds' => 123, 'nanos' => 500_000_000 },
|
2671
|
-
"\v123.5\vs\v" => { 'seconds' => 123, 'nanos' => 500_000_000 },
|
2672
|
-
"\f123.5\fs\f" => { 'seconds' => 123, 'nanos' => 500_000_000 },
|
2673
|
-
"\r123.5\ts\f" => { 'seconds' => 123, 'nanos' => 500_000_000 }
|
2674
|
-
}
|
2682
|
+
_undefined
|
2675
2683
|
end
|
2676
2684
|
|
2677
2685
|
# This module expects the methods below to be overridden.
|
@@ -2715,53 +2723,15 @@ module BaseTest
|
|
2715
2723
|
assert_equal(expected_value, metric_value)
|
2716
2724
|
end
|
2717
2725
|
|
2718
|
-
# Get the fields of the payload.
|
2719
|
-
def get_fields(_payload)
|
2720
|
-
_undefined
|
2721
|
-
end
|
2722
|
-
|
2723
|
-
# Get the value of a struct field.
|
2724
|
-
def get_struct(_field)
|
2725
|
-
_undefined
|
2726
|
-
end
|
2727
|
-
|
2728
|
-
# Get the value of a string field.
|
2729
|
-
def get_string(_field)
|
2730
|
-
_undefined
|
2731
|
-
end
|
2732
|
-
|
2733
|
-
# Get the value of a number field.
|
2734
|
-
def get_number(_field)
|
2735
|
-
_undefined
|
2736
|
-
end
|
2737
|
-
|
2738
|
-
# The null value.
|
2739
|
-
def null_value(_field)
|
2740
|
-
_undefined
|
2741
|
-
end
|
2742
|
-
|
2743
|
-
# Defined in specific gRPC or REST files.
|
2744
|
-
def http_request_message
|
2745
|
-
_undefined
|
2746
|
-
end
|
2747
|
-
|
2748
|
-
# Defined in specific gRPC or REST files.
|
2749
|
-
def source_location_message
|
2750
|
-
_undefined
|
2751
|
-
end
|
2752
|
-
|
2753
|
-
# Defined in specific gRPC or REST files.
|
2754
|
-
def source_location_message2
|
2755
|
-
_undefined
|
2756
|
-
end
|
2757
|
-
|
2758
2726
|
# Defined in specific gRPC or REST files.
|
2759
2727
|
def expected_operation_message2
|
2760
2728
|
_undefined
|
2761
2729
|
end
|
2762
2730
|
|
2731
|
+
# Parse timestamp and convert it to a hash with the "seconds" and "nanos" keys
|
2732
|
+
# if necessary.
|
2763
2733
|
# Defined in specific gRPC or REST files.
|
2764
|
-
def
|
2734
|
+
def timestamp_parse(_timestamp)
|
2765
2735
|
_undefined
|
2766
2736
|
end
|
2767
2737
|
|