fluent-plugin-google-cloud 0.7.21 → 0.7.22
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 +19 -3
- data/fluent-plugin-google-cloud.gemspec +3 -1
- data/lib/fluent/plugin/monitoring.rb +98 -4
- data/lib/fluent/plugin/out_google_cloud.rb +56 -36
- data/test/plugin/base_test.rb +31 -2
- data/test/plugin/constants.rb +5 -0
- data/test/plugin/test_out_google_cloud.rb +56 -47
- data/test/plugin/test_out_google_cloud_grpc.rb +56 -47
- metadata +30 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: c0d3db1dc87f350081fd9b15fb276f5bb362216d7e3baee3fbfc65811185e178
|
|
4
|
+
data.tar.gz: f4dfa81c6a56eb92799ce59f391dd3a252ff0efd1f157f7c80df097b92731a58
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 86f7fe07dfdfdfbb4fa787e99671a5b1e6f550cd8fc83da05aaf5bcd098bcff5e1bda4bb4cbd19397c2cbe2f97fb19e5a6eaf91da87839b819ce440c4ba4f6d6
|
|
7
|
+
data.tar.gz: 8c15a973178e824aadaced186a7635f73b5f24cd13b281b7fb2c83cf2432c495d8ee15a8363bff66518432100b918a88ca0a8a736fb0eeccf22c4693790cf6b7
|
data/Gemfile.lock
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
PATH
|
|
2
2
|
remote: .
|
|
3
3
|
specs:
|
|
4
|
-
fluent-plugin-google-cloud (0.7.
|
|
4
|
+
fluent-plugin-google-cloud (0.7.22)
|
|
5
5
|
fluentd (= 1.6.3)
|
|
6
6
|
google-api-client (= 0.30.8)
|
|
7
7
|
google-cloud-logging (= 1.6.6)
|
|
@@ -45,7 +45,7 @@ GEM
|
|
|
45
45
|
representable (~> 3.0)
|
|
46
46
|
retriable (>= 2.0, < 4.0)
|
|
47
47
|
signet (~> 0.10)
|
|
48
|
-
google-cloud-core (1.3.
|
|
48
|
+
google-cloud-core (1.3.2)
|
|
49
49
|
google-cloud-env (~> 1.0)
|
|
50
50
|
google-cloud-env (1.2.1)
|
|
51
51
|
faraday (~> 0.11)
|
|
@@ -55,6 +55,14 @@ GEM
|
|
|
55
55
|
google-gax (~> 1.7)
|
|
56
56
|
googleapis-common-protos-types (>= 1.0.2)
|
|
57
57
|
stackdriver-core (~> 1.3)
|
|
58
|
+
google-cloud-monitoring (0.29.5)
|
|
59
|
+
google-gax (~> 1.3)
|
|
60
|
+
googleapis-common-protos-types (>= 1.0.2)
|
|
61
|
+
google-cloud-trace (0.35.0)
|
|
62
|
+
concurrent-ruby (~> 1.1)
|
|
63
|
+
google-cloud-core (~> 1.2)
|
|
64
|
+
google-gax (~> 1.7)
|
|
65
|
+
stackdriver-core (~> 1.3)
|
|
58
66
|
google-gax (1.7.1)
|
|
59
67
|
google-protobuf (~> 3.2)
|
|
60
68
|
googleapis-common-protos (>= 1.3.5, < 2.0)
|
|
@@ -89,8 +97,14 @@ GEM
|
|
|
89
97
|
mocha (1.9.0)
|
|
90
98
|
metaclass (~> 0.0.1)
|
|
91
99
|
msgpack (1.3.1)
|
|
92
|
-
multi_json (1.
|
|
100
|
+
multi_json (1.14.1)
|
|
93
101
|
multipart-post (2.1.1)
|
|
102
|
+
opencensus (0.5.0)
|
|
103
|
+
opencensus-stackdriver (0.3.0)
|
|
104
|
+
concurrent-ruby (~> 1.0)
|
|
105
|
+
google-cloud-monitoring (~> 0.29.2)
|
|
106
|
+
google-cloud-trace (~> 0.33)
|
|
107
|
+
opencensus (~> 0.5)
|
|
94
108
|
os (1.0.1)
|
|
95
109
|
parser (2.6.5.0)
|
|
96
110
|
ast (~> 2.4.0)
|
|
@@ -149,6 +163,8 @@ PLATFORMS
|
|
|
149
163
|
DEPENDENCIES
|
|
150
164
|
fluent-plugin-google-cloud!
|
|
151
165
|
mocha (= 1.9.0)
|
|
166
|
+
opencensus (= 0.5.0)
|
|
167
|
+
opencensus-stackdriver (= 0.3.0)
|
|
152
168
|
prometheus-client (< 0.10)
|
|
153
169
|
rake (= 10.5.0)
|
|
154
170
|
rubocop (= 0.39.0)
|
|
@@ -10,7 +10,7 @@ eos
|
|
|
10
10
|
gem.homepage =
|
|
11
11
|
'https://github.com/GoogleCloudPlatform/fluent-plugin-google-cloud'
|
|
12
12
|
gem.license = 'Apache-2.0'
|
|
13
|
-
gem.version = '0.7.
|
|
13
|
+
gem.version = '0.7.22'
|
|
14
14
|
gem.authors = ['Stackdriver Agents Team']
|
|
15
15
|
gem.email = ['stackdriver-agents@google.com']
|
|
16
16
|
gem.required_ruby_version = Gem::Requirement.new('>= 2.2')
|
|
@@ -29,6 +29,8 @@ eos
|
|
|
29
29
|
gem.add_runtime_dependency 'json', '2.2.0'
|
|
30
30
|
|
|
31
31
|
gem.add_development_dependency 'mocha', '1.9.0'
|
|
32
|
+
gem.add_development_dependency 'opencensus', '0.5.0'
|
|
33
|
+
gem.add_development_dependency 'opencensus-stackdriver', '0.3.0'
|
|
32
34
|
# Keep this the same as in
|
|
33
35
|
# https://github.com/fluent/fluent-plugin-prometheus/blob/master/fluent-plugin-prometheus.gemspec
|
|
34
36
|
gem.add_development_dependency 'prometheus-client', '< 0.10'
|
|
@@ -31,11 +31,33 @@ module Monitoring
|
|
|
31
31
|
end
|
|
32
32
|
end
|
|
33
33
|
|
|
34
|
+
# OpenCensus implementation of counters.
|
|
35
|
+
class OpenCensusCounter < BaseCounter
|
|
36
|
+
def initialize(recorder, measure)
|
|
37
|
+
raise ArgumentError, 'measure must not be nil' if measure.nil?
|
|
38
|
+
@recorder = recorder
|
|
39
|
+
@measure = measure
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def increment(by: 1, labels: {})
|
|
43
|
+
tag_map = OpenCensus::Tags::TagMap.new(
|
|
44
|
+
labels.map { |k, v| [k.to_s, v.to_s] }.to_h)
|
|
45
|
+
@recorder.record(@measure.create_measurement(value: by, tags: tag_map))
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
|
|
34
49
|
# Base class for the monitoring registry.
|
|
35
50
|
class BaseMonitoringRegistry
|
|
51
|
+
def initialize(_project_id, _monitored_resource)
|
|
52
|
+
end
|
|
53
|
+
|
|
36
54
|
def counter(_name, _labels, _docstring)
|
|
37
55
|
nil
|
|
38
56
|
end
|
|
57
|
+
|
|
58
|
+
def export
|
|
59
|
+
nil
|
|
60
|
+
end
|
|
39
61
|
end
|
|
40
62
|
|
|
41
63
|
# Prometheus implementation of the monitoring registry, that uses the default
|
|
@@ -45,7 +67,8 @@ module Monitoring
|
|
|
45
67
|
'prometheus'
|
|
46
68
|
end
|
|
47
69
|
|
|
48
|
-
def initialize
|
|
70
|
+
def initialize(_project_id, _monitored_resource)
|
|
71
|
+
super
|
|
49
72
|
require 'prometheus/client'
|
|
50
73
|
@registry = Prometheus::Client.registry
|
|
51
74
|
end
|
|
@@ -58,20 +81,91 @@ module Monitoring
|
|
|
58
81
|
end
|
|
59
82
|
end
|
|
60
83
|
|
|
84
|
+
# OpenCensus implementation of the monitoring registry.
|
|
85
|
+
class OpenCensusMonitoringRegistry < BaseMonitoringRegistry
|
|
86
|
+
def self.name
|
|
87
|
+
'opencensus'
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
def initialize(project_id, monitored_resource)
|
|
91
|
+
super
|
|
92
|
+
require 'opencensus'
|
|
93
|
+
require 'opencensus-stackdriver'
|
|
94
|
+
@log = $log # rubocop:disable Style/GlobalVars
|
|
95
|
+
@recorder = OpenCensus::Stats.ensure_recorder
|
|
96
|
+
@exporter = OpenCensus::Stats::Exporters::Stackdriver.new(
|
|
97
|
+
project_id: project_id,
|
|
98
|
+
metric_prefix: 'agent.googleapis.com/agent',
|
|
99
|
+
resource_type: monitored_resource.type,
|
|
100
|
+
resource_labels: monitored_resource.labels)
|
|
101
|
+
OpenCensus.configure do |c|
|
|
102
|
+
c.stats.exporter = @exporter
|
|
103
|
+
end
|
|
104
|
+
@log.debug "OpenCensus config=#{OpenCensus.config}"
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
def counter(name, labels, docstring)
|
|
108
|
+
name = OpenCensusMonitoringRegistry.translate_metric_name(name)
|
|
109
|
+
measure = OpenCensus::Stats::MeasureRegistry.get(name)
|
|
110
|
+
if measure.nil?
|
|
111
|
+
measure = OpenCensus::Stats.create_measure_int(
|
|
112
|
+
name: name,
|
|
113
|
+
unit: OpenCensus::Stats::Measure::UNIT_NONE,
|
|
114
|
+
description: docstring
|
|
115
|
+
)
|
|
116
|
+
end
|
|
117
|
+
OpenCensus::Stats.create_and_register_view(
|
|
118
|
+
name: name,
|
|
119
|
+
measure: measure,
|
|
120
|
+
aggregation: OpenCensus::Stats.create_sum_aggregation,
|
|
121
|
+
description: docstring,
|
|
122
|
+
columns: labels.map(&:to_s)
|
|
123
|
+
)
|
|
124
|
+
OpenCensusCounter.new(@recorder, measure)
|
|
125
|
+
end
|
|
126
|
+
|
|
127
|
+
def export
|
|
128
|
+
@exporter.export @recorder.views_data
|
|
129
|
+
end
|
|
130
|
+
|
|
131
|
+
class << self
|
|
132
|
+
# Translate the internal metrics to the curated metrics in Stackdriver.
|
|
133
|
+
# The Prometheus metrics are collected by Google Kubernetes Engine's
|
|
134
|
+
# monitoring, so we can't redefine them.
|
|
135
|
+
def translate_metric_name(name)
|
|
136
|
+
case name
|
|
137
|
+
when :stackdriver_successful_requests_count,
|
|
138
|
+
:stackdriver_failed_requests_count
|
|
139
|
+
:request_count
|
|
140
|
+
when :stackdriver_ingested_entries_count,
|
|
141
|
+
:stackdriver_dropped_entries_count
|
|
142
|
+
:log_entry_count
|
|
143
|
+
when :stackdriver_retried_entries_count
|
|
144
|
+
:log_entry_retry_count
|
|
145
|
+
else
|
|
146
|
+
name
|
|
147
|
+
end
|
|
148
|
+
end
|
|
149
|
+
end
|
|
150
|
+
end
|
|
151
|
+
|
|
61
152
|
# Factory that is used to create a monitoring registry based on
|
|
62
153
|
# the monitoring solution name.
|
|
63
154
|
class MonitoringRegistryFactory
|
|
64
155
|
@known_registry_types = {
|
|
65
156
|
PrometheusMonitoringRegistry.name =>
|
|
66
|
-
PrometheusMonitoringRegistry
|
|
157
|
+
PrometheusMonitoringRegistry,
|
|
158
|
+
OpenCensusMonitoringRegistry.name =>
|
|
159
|
+
OpenCensusMonitoringRegistry
|
|
67
160
|
}
|
|
68
161
|
|
|
69
162
|
def self.supports_monitoring_type(name)
|
|
70
163
|
@known_registry_types.key?(name)
|
|
71
164
|
end
|
|
72
165
|
|
|
73
|
-
def self.create(name)
|
|
74
|
-
|
|
166
|
+
def self.create(name, project_id, monitored_resource)
|
|
167
|
+
registry = @known_registry_types[name] || BaseMonitoringRegistry
|
|
168
|
+
registry.new(project_id, monitored_resource)
|
|
75
169
|
end
|
|
76
170
|
end
|
|
77
171
|
end
|
|
@@ -64,6 +64,18 @@ module Google
|
|
|
64
64
|
end
|
|
65
65
|
end
|
|
66
66
|
|
|
67
|
+
# FluentLogger exposes the Fluent logger to the gRPC library.
|
|
68
|
+
module FluentLogger
|
|
69
|
+
def logger
|
|
70
|
+
$log # rubocop:disable Style/GlobalVars
|
|
71
|
+
end
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
# Define a gRPC module-level logger method before grpc/logconfig.rb loads.
|
|
75
|
+
module GRPC
|
|
76
|
+
extend FluentLogger
|
|
77
|
+
end
|
|
78
|
+
|
|
67
79
|
module Fluent
|
|
68
80
|
# fluentd output plugin for the Stackdriver Logging API
|
|
69
81
|
class GoogleCloudOutput < BufferedOutput
|
|
@@ -238,7 +250,7 @@ module Fluent
|
|
|
238
250
|
|
|
239
251
|
Fluent::Plugin.register_output('google_cloud', self)
|
|
240
252
|
|
|
241
|
-
helpers :server
|
|
253
|
+
helpers :server, :timer
|
|
242
254
|
|
|
243
255
|
PLUGIN_NAME = 'Fluentd Google Cloud Logging plugin'.freeze
|
|
244
256
|
|
|
@@ -497,41 +509,6 @@ module Fluent
|
|
|
497
509
|
end
|
|
498
510
|
end
|
|
499
511
|
|
|
500
|
-
# If monitoring is enabled, register metrics in the default registry
|
|
501
|
-
# and store metric objects for future use.
|
|
502
|
-
if @enable_monitoring
|
|
503
|
-
unless Monitoring::MonitoringRegistryFactory.supports_monitoring_type(
|
|
504
|
-
@monitoring_type)
|
|
505
|
-
@log.warn "monitoring_type '#{@monitoring_type}' is unknown; "\
|
|
506
|
-
'there will be no metrics'
|
|
507
|
-
end
|
|
508
|
-
registry = Monitoring::MonitoringRegistryFactory.create @monitoring_type
|
|
509
|
-
@successful_requests_count = registry.counter(
|
|
510
|
-
:stackdriver_successful_requests_count,
|
|
511
|
-
[:grpc, :code],
|
|
512
|
-
'A number of successful requests to the Stackdriver Logging API')
|
|
513
|
-
@failed_requests_count = registry.counter(
|
|
514
|
-
:stackdriver_failed_requests_count,
|
|
515
|
-
[:grpc, :code],
|
|
516
|
-
'A number of failed requests to the Stackdriver Logging '\
|
|
517
|
-
'API, broken down by the error code')
|
|
518
|
-
@ingested_entries_count = registry.counter(
|
|
519
|
-
:stackdriver_ingested_entries_count,
|
|
520
|
-
[:grpc, :code],
|
|
521
|
-
'A number of log entries ingested by Stackdriver Logging')
|
|
522
|
-
@dropped_entries_count = registry.counter(
|
|
523
|
-
:stackdriver_dropped_entries_count,
|
|
524
|
-
[:grpc, :code],
|
|
525
|
-
'A number of log entries dropped by the Stackdriver output plugin')
|
|
526
|
-
@retried_entries_count = registry.counter(
|
|
527
|
-
:stackdriver_retried_entries_count,
|
|
528
|
-
[:grpc, :code],
|
|
529
|
-
'The number of log entries that failed to be ingested by '\
|
|
530
|
-
'the Stackdriver output plugin due to a transient error '\
|
|
531
|
-
'and were retried')
|
|
532
|
-
@ok_code = @use_grpc ? GRPC::Core::StatusCodes::OK : 200
|
|
533
|
-
end
|
|
534
|
-
|
|
535
512
|
# Alert on old authentication configuration.
|
|
536
513
|
unless @auth_method.nil? && @private_key_email.nil? &&
|
|
537
514
|
@private_key_path.nil? && @private_key_passphrase.nil?
|
|
@@ -564,6 +541,44 @@ module Fluent
|
|
|
564
541
|
# to get it from Metadata Agent.
|
|
565
542
|
@resource ||= determine_agent_level_monitored_resource_via_legacy
|
|
566
543
|
|
|
544
|
+
# If monitoring is enabled, register metrics in the default registry
|
|
545
|
+
# and store metric objects for future use.
|
|
546
|
+
if @enable_monitoring
|
|
547
|
+
unless Monitoring::MonitoringRegistryFactory.supports_monitoring_type(
|
|
548
|
+
@monitoring_type)
|
|
549
|
+
@log.warn "monitoring_type '#{@monitoring_type}' is unknown; "\
|
|
550
|
+
'there will be no metrics'
|
|
551
|
+
end
|
|
552
|
+
@registry = Monitoring::MonitoringRegistryFactory
|
|
553
|
+
.create(@monitoring_type, @project_id, @resource)
|
|
554
|
+
# Export metrics every 60 seconds.
|
|
555
|
+
timer_execute(:export_metrics, 60) { @registry.export }
|
|
556
|
+
@successful_requests_count = @registry.counter(
|
|
557
|
+
:stackdriver_successful_requests_count,
|
|
558
|
+
[:grpc, :code],
|
|
559
|
+
'A number of successful requests to the Stackdriver Logging API')
|
|
560
|
+
@failed_requests_count = @registry.counter(
|
|
561
|
+
:stackdriver_failed_requests_count,
|
|
562
|
+
[:grpc, :code],
|
|
563
|
+
'A number of failed requests to the Stackdriver Logging '\
|
|
564
|
+
'API, broken down by the error code')
|
|
565
|
+
@ingested_entries_count = @registry.counter(
|
|
566
|
+
:stackdriver_ingested_entries_count,
|
|
567
|
+
[:grpc, :code],
|
|
568
|
+
'A number of log entries ingested by Stackdriver Logging')
|
|
569
|
+
@dropped_entries_count = @registry.counter(
|
|
570
|
+
:stackdriver_dropped_entries_count,
|
|
571
|
+
[:grpc, :code],
|
|
572
|
+
'A number of log entries dropped by the Stackdriver output plugin')
|
|
573
|
+
@retried_entries_count = @registry.counter(
|
|
574
|
+
:stackdriver_retried_entries_count,
|
|
575
|
+
[:grpc, :code],
|
|
576
|
+
'The number of log entries that failed to be ingested by '\
|
|
577
|
+
'the Stackdriver output plugin due to a transient error '\
|
|
578
|
+
'and were retried')
|
|
579
|
+
@ok_code = @use_grpc ? GRPC::Core::StatusCodes::OK : 200
|
|
580
|
+
end
|
|
581
|
+
|
|
567
582
|
# Set regexp that we should match tags against later on. Using a list
|
|
568
583
|
# instead of a map to ensure order.
|
|
569
584
|
@tag_regexp_list = []
|
|
@@ -621,6 +636,9 @@ module Fluent
|
|
|
621
636
|
|
|
622
637
|
def shutdown
|
|
623
638
|
super
|
|
639
|
+
# Export metrics on shutdown. This is a best-effort attempt, and it might
|
|
640
|
+
# fail, for instance if there was a recent write to the same time series.
|
|
641
|
+
@registry.export unless @registry.nil?
|
|
624
642
|
end
|
|
625
643
|
|
|
626
644
|
def write(chunk)
|
|
@@ -2047,6 +2065,8 @@ module Fluent
|
|
|
2047
2065
|
end
|
|
2048
2066
|
|
|
2049
2067
|
def init_api_client
|
|
2068
|
+
# Set up the logger for the auto-generated Google Cloud APIs.
|
|
2069
|
+
Google::Apis.logger = @log
|
|
2050
2070
|
if @use_grpc
|
|
2051
2071
|
uri = URI.parse(@logging_api_url)
|
|
2052
2072
|
host = uri.host
|
data/test/plugin/base_test.rb
CHANGED
|
@@ -20,6 +20,15 @@ require 'prometheus/client'
|
|
|
20
20
|
|
|
21
21
|
require_relative 'constants'
|
|
22
22
|
|
|
23
|
+
module Monitoring
|
|
24
|
+
# Prevent OpenCensus from writing to the network.
|
|
25
|
+
class OpenCensusMonitoringRegistry
|
|
26
|
+
def export
|
|
27
|
+
nil
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
|
|
23
32
|
# Unit tests for Google Cloud Logging plugin
|
|
24
33
|
module BaseTest
|
|
25
34
|
include Constants
|
|
@@ -903,7 +912,7 @@ module BaseTest
|
|
|
903
912
|
# [] returns nil for any index.
|
|
904
913
|
[ENABLE_SPLIT_LOGS_BY_TAG_CONFIG, log_entry_count, dynamic_log_names, []]
|
|
905
914
|
].each do |(config, request_count, request_log_names, entry_log_names)|
|
|
906
|
-
|
|
915
|
+
clear_metrics
|
|
907
916
|
setup_logging_stubs do
|
|
908
917
|
@logs_sent = []
|
|
909
918
|
d = create_driver(config + ENABLE_PROMETHEUS_CONFIG, 'test', true)
|
|
@@ -2144,8 +2153,9 @@ module BaseTest
|
|
|
2144
2153
|
DATAPROC_REGION)
|
|
2145
2154
|
end
|
|
2146
2155
|
|
|
2147
|
-
def
|
|
2156
|
+
def clear_metrics
|
|
2148
2157
|
Prometheus::Client.registry.instance_variable_set('@metrics', {})
|
|
2158
|
+
OpenCensus::Stats.ensure_recorder.clear_stats
|
|
2149
2159
|
end
|
|
2150
2160
|
|
|
2151
2161
|
# Metadata Agent.
|
|
@@ -2723,6 +2733,25 @@ module BaseTest
|
|
|
2723
2733
|
assert_equal(expected_value, metric_value)
|
|
2724
2734
|
end
|
|
2725
2735
|
|
|
2736
|
+
def assert_opencensus_metric_value(metric_name, expected_value, labels = {})
|
|
2737
|
+
metric_name = Monitoring::OpenCensusMonitoringRegistry
|
|
2738
|
+
.translate_metric_name(metric_name)
|
|
2739
|
+
labels = labels.map { |k, v| [k.to_s, v.to_s] }.to_h
|
|
2740
|
+
stats_recorder = OpenCensus::Stats.ensure_recorder
|
|
2741
|
+
view_data = stats_recorder.view_data metric_name
|
|
2742
|
+
assert_not_nil(view_data)
|
|
2743
|
+
# For now assume all metrics are counters.
|
|
2744
|
+
assert_kind_of(OpenCensus::Stats::Aggregation::Sum,
|
|
2745
|
+
view_data.view.aggregation)
|
|
2746
|
+
assert_true(view_data.view.measure.int64?)
|
|
2747
|
+
tag_values = view_data.view.columns.map { |column| labels[column] }
|
|
2748
|
+
metric_value = 0
|
|
2749
|
+
if view_data.data.key? tag_values
|
|
2750
|
+
metric_value = view_data.data[tag_values].value
|
|
2751
|
+
end
|
|
2752
|
+
assert_equal(expected_value, metric_value)
|
|
2753
|
+
end
|
|
2754
|
+
|
|
2726
2755
|
# Defined in specific gRPC or REST files.
|
|
2727
2756
|
def expected_operation_message2
|
|
2728
2757
|
_undefined
|
data/test/plugin/constants.rb
CHANGED
|
@@ -283,6 +283,11 @@ module Constants
|
|
|
283
283
|
monitoring_type prometheus
|
|
284
284
|
).freeze
|
|
285
285
|
|
|
286
|
+
ENABLE_OPENCENSUS_CONFIG = %(
|
|
287
|
+
enable_monitoring true
|
|
288
|
+
monitoring_type opencensus
|
|
289
|
+
).freeze
|
|
290
|
+
|
|
286
291
|
ENABLE_METADATA_AGENT_CONFIG = %(
|
|
287
292
|
enable_metadata_agent true
|
|
288
293
|
).freeze
|
|
@@ -73,7 +73,7 @@ class GoogleCloudOutputTest < Test::Unit::TestCase
|
|
|
73
73
|
|
|
74
74
|
def test_partial_success
|
|
75
75
|
setup_gce_metadata_stubs
|
|
76
|
-
|
|
76
|
+
clear_metrics
|
|
77
77
|
# The API Client should not retry this and the plugin should consume
|
|
78
78
|
# the exception.
|
|
79
79
|
root_error_code = PARTIAL_SUCCESS_RESPONSE_BODY['error']['code']
|
|
@@ -98,7 +98,7 @@ class GoogleCloudOutputTest < Test::Unit::TestCase
|
|
|
98
98
|
|
|
99
99
|
def test_non_api_error
|
|
100
100
|
setup_gce_metadata_stubs
|
|
101
|
-
|
|
101
|
+
clear_metrics
|
|
102
102
|
# The API Client should not retry this and the plugin should consume
|
|
103
103
|
# the exception.
|
|
104
104
|
root_error_code = PARSE_ERROR_RESPONSE_BODY['error']['code']
|
|
@@ -141,56 +141,65 @@ class GoogleCloudOutputTest < Test::Unit::TestCase
|
|
|
141
141
|
# TODO: The code in the non-gRPC and gRPC tests is nearly identical.
|
|
142
142
|
# Refactor and remove duplication.
|
|
143
143
|
# TODO: Use status codes instead of int literals.
|
|
144
|
-
def
|
|
144
|
+
def test_metrics
|
|
145
145
|
setup_gce_metadata_stubs
|
|
146
146
|
[
|
|
147
|
-
|
|
148
|
-
[
|
|
149
|
-
|
|
150
|
-
[
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
(
|
|
166
|
-
|
|
147
|
+
[ENABLE_PROMETHEUS_CONFIG, method(:assert_prometheus_metric_value)],
|
|
148
|
+
[ENABLE_OPENCENSUS_CONFIG, method(:assert_opencensus_metric_value)]
|
|
149
|
+
].each do |config, assert_metric_value|
|
|
150
|
+
[
|
|
151
|
+
# Single successful request.
|
|
152
|
+
[200, 1, 1, [1, 0, 1, 0, 0]],
|
|
153
|
+
# Several successful requests.
|
|
154
|
+
[200, 2, 1, [2, 0, 2, 0, 0]],
|
|
155
|
+
# Single successful request with several entries.
|
|
156
|
+
[200, 1, 2, [1, 0, 2, 0, 0]],
|
|
157
|
+
# Single failed request that causes logs to be dropped.
|
|
158
|
+
[401, 1, 1, [0, 1, 0, 1, 0]],
|
|
159
|
+
# Single failed request that escalates without logs being dropped with
|
|
160
|
+
# several entries.
|
|
161
|
+
[500, 1, 2, [0, 0, 0, 0, 2]]
|
|
162
|
+
].each do |code, request_count, entry_count, metric_values|
|
|
163
|
+
clear_metrics
|
|
164
|
+
# TODO: Do this as part of setup_logging_stubs.
|
|
165
|
+
stub_request(:post, WRITE_LOG_ENTRIES_URI)
|
|
166
|
+
.to_return(status: code, body: 'Some Message')
|
|
167
|
+
(1..request_count).each do
|
|
168
|
+
d = create_driver(config)
|
|
169
|
+
(1..entry_count).each do |i|
|
|
170
|
+
d.emit('message' => log_entry(i.to_s))
|
|
171
|
+
end
|
|
172
|
+
# rubocop:disable Lint/HandleExceptions
|
|
173
|
+
begin
|
|
174
|
+
d.run
|
|
175
|
+
rescue Google::Apis::AuthorizationError
|
|
176
|
+
rescue Google::Apis::ServerError
|
|
177
|
+
end
|
|
178
|
+
# rubocop:enable Lint/HandleExceptions
|
|
167
179
|
end
|
|
168
|
-
|
|
169
|
-
begin
|
|
170
|
-
d.run
|
|
171
|
-
rescue Google::Apis::AuthorizationError
|
|
172
|
-
rescue Google::Apis::ServerError
|
|
173
|
-
end
|
|
174
|
-
# rubocop:enable Lint/HandleExceptions
|
|
175
|
-
end
|
|
176
|
-
successful_requests_count, failed_requests_count,
|
|
180
|
+
successful_requests_count, failed_requests_count,
|
|
177
181
|
ingested_entries_count, dropped_entries_count,
|
|
178
182
|
retried_entries_count = metric_values
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
183
|
+
assert_metric_value.call(:stackdriver_successful_requests_count,
|
|
184
|
+
successful_requests_count,
|
|
185
|
+
grpc: false, code: 200)
|
|
186
|
+
assert_metric_value.call(:stackdriver_ingested_entries_count,
|
|
187
|
+
ingested_entries_count,
|
|
188
|
+
grpc: false, code: 200)
|
|
189
|
+
assert_metric_value.call(:stackdriver_retried_entries_count,
|
|
190
|
+
retried_entries_count,
|
|
191
|
+
grpc: false, code: code)
|
|
192
|
+
# Skip failure assertions when code indicates success, because the
|
|
193
|
+
# assertion will fail in the case when a single metric contains time
|
|
194
|
+
# series with success and failure events.
|
|
195
|
+
next if code == 200
|
|
196
|
+
assert_metric_value.call(:stackdriver_failed_requests_count,
|
|
197
|
+
failed_requests_count,
|
|
198
|
+
grpc: false, code: code)
|
|
199
|
+
assert_metric_value.call(:stackdriver_dropped_entries_count,
|
|
200
|
+
dropped_entries_count,
|
|
201
|
+
grpc: false, code: code)
|
|
202
|
+
end
|
|
194
203
|
end
|
|
195
204
|
end
|
|
196
205
|
|
|
@@ -86,7 +86,7 @@ class GoogleCloudOutputGRPCTest < Test::Unit::TestCase
|
|
|
86
86
|
|
|
87
87
|
def test_partial_success
|
|
88
88
|
setup_gce_metadata_stubs
|
|
89
|
-
|
|
89
|
+
clear_metrics
|
|
90
90
|
setup_logging_stubs(
|
|
91
91
|
GRPC::PermissionDenied.new('User not authorized.',
|
|
92
92
|
PARTIAL_SUCCESS_GRPC_METADATA)) do
|
|
@@ -117,7 +117,7 @@ class GoogleCloudOutputGRPCTest < Test::Unit::TestCase
|
|
|
117
117
|
|
|
118
118
|
def test_non_api_error
|
|
119
119
|
setup_gce_metadata_stubs
|
|
120
|
-
|
|
120
|
+
clear_metrics
|
|
121
121
|
setup_logging_stubs(
|
|
122
122
|
GRPC::InvalidArgument.new('internal client error',
|
|
123
123
|
PARSE_ERROR_GRPC_METADATA)) do
|
|
@@ -171,57 +171,66 @@ class GoogleCloudOutputGRPCTest < Test::Unit::TestCase
|
|
|
171
171
|
# TODO: The code in the non-gRPC and gRPC tests is nearly identical.
|
|
172
172
|
# Refactor and remove duplication.
|
|
173
173
|
# TODO: Use status codes instead of int literals.
|
|
174
|
-
def
|
|
174
|
+
def test_metrics
|
|
175
175
|
setup_gce_metadata_stubs
|
|
176
176
|
[
|
|
177
|
-
|
|
178
|
-
[
|
|
179
|
-
|
|
180
|
-
[
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
177
|
+
[ENABLE_PROMETHEUS_CONFIG, method(:assert_prometheus_metric_value)],
|
|
178
|
+
[ENABLE_OPENCENSUS_CONFIG, method(:assert_opencensus_metric_value)]
|
|
179
|
+
].each do |config, assert_metric_value|
|
|
180
|
+
[
|
|
181
|
+
# Single successful request.
|
|
182
|
+
[false, 0, 1, 1, [1, 0, 1, 0, 0]],
|
|
183
|
+
# Several successful requests.
|
|
184
|
+
[false, 0, 2, 1, [2, 0, 2, 0, 0]],
|
|
185
|
+
# Single successful request with several entries.
|
|
186
|
+
[false, 0, 1, 2, [1, 0, 2, 0, 0]],
|
|
187
|
+
# Single failed request that causes logs to be dropped.
|
|
188
|
+
[true, 16, 1, 1, [0, 1, 0, 1, 0]],
|
|
189
|
+
# Single failed request that escalates without logs being dropped with
|
|
190
|
+
# several entries.
|
|
191
|
+
[true, 13, 1, 2, [0, 0, 0, 0, 2]]
|
|
192
|
+
].each do |should_fail, code, request_count, entry_count, metric_values|
|
|
193
|
+
clear_metrics
|
|
194
|
+
(1..request_count).each do
|
|
195
|
+
setup_logging_stubs(
|
|
196
|
+
if should_fail
|
|
197
|
+
GRPC::BadStatus.new_status_exception(code, 'SomeMessage')
|
|
198
|
+
end) do
|
|
199
|
+
d = create_driver(USE_GRPC_CONFIG + config, 'test')
|
|
200
|
+
(1..entry_count).each do |i|
|
|
201
|
+
d.emit('message' => log_entry(i.to_s))
|
|
202
|
+
end
|
|
203
|
+
# rubocop:disable Lint/HandleExceptions
|
|
204
|
+
begin
|
|
205
|
+
d.run
|
|
206
|
+
rescue GRPC::BadStatus
|
|
207
|
+
end
|
|
208
|
+
# rubocop:enable Lint/HandleExceptions
|
|
198
209
|
end
|
|
199
|
-
# rubocop:disable Lint/HandleExceptions
|
|
200
|
-
begin
|
|
201
|
-
d.run
|
|
202
|
-
rescue GRPC::BadStatus
|
|
203
|
-
end
|
|
204
|
-
# rubocop:enable Lint/HandleExceptions
|
|
205
210
|
end
|
|
206
|
-
|
|
207
|
-
successful_requests_count, failed_requests_count,
|
|
211
|
+
successful_requests_count, failed_requests_count,
|
|
208
212
|
ingested_entries_count, dropped_entries_count,
|
|
209
213
|
retried_entries_count = metric_values
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
214
|
+
assert_metric_value.call(:stackdriver_successful_requests_count,
|
|
215
|
+
successful_requests_count,
|
|
216
|
+
grpc: true, code: 0)
|
|
217
|
+
assert_metric_value.call(:stackdriver_ingested_entries_count,
|
|
218
|
+
ingested_entries_count,
|
|
219
|
+
grpc: true, code: 0)
|
|
220
|
+
assert_metric_value.call(:stackdriver_retried_entries_count,
|
|
221
|
+
retried_entries_count,
|
|
222
|
+
grpc: true, code: code)
|
|
223
|
+
# Skip failure assertions when code indicates success, because the
|
|
224
|
+
# assertion will fail in the case when a single metric contains time
|
|
225
|
+
# series with success and failure events.
|
|
226
|
+
next if code == 0
|
|
227
|
+
assert_metric_value.call(:stackdriver_failed_requests_count,
|
|
228
|
+
failed_requests_count,
|
|
229
|
+
grpc: true, code: code)
|
|
230
|
+
assert_metric_value.call(:stackdriver_dropped_entries_count,
|
|
231
|
+
dropped_entries_count,
|
|
232
|
+
grpc: true, code: code)
|
|
233
|
+
end
|
|
225
234
|
end
|
|
226
235
|
end
|
|
227
236
|
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: fluent-plugin-google-cloud
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.7.
|
|
4
|
+
version: 0.7.22
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Stackdriver Agents Team
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2019-10-
|
|
11
|
+
date: 2019-10-19 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: fluentd
|
|
@@ -136,6 +136,34 @@ dependencies:
|
|
|
136
136
|
- - '='
|
|
137
137
|
- !ruby/object:Gem::Version
|
|
138
138
|
version: 1.9.0
|
|
139
|
+
- !ruby/object:Gem::Dependency
|
|
140
|
+
name: opencensus
|
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
|
142
|
+
requirements:
|
|
143
|
+
- - '='
|
|
144
|
+
- !ruby/object:Gem::Version
|
|
145
|
+
version: 0.5.0
|
|
146
|
+
type: :development
|
|
147
|
+
prerelease: false
|
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
149
|
+
requirements:
|
|
150
|
+
- - '='
|
|
151
|
+
- !ruby/object:Gem::Version
|
|
152
|
+
version: 0.5.0
|
|
153
|
+
- !ruby/object:Gem::Dependency
|
|
154
|
+
name: opencensus-stackdriver
|
|
155
|
+
requirement: !ruby/object:Gem::Requirement
|
|
156
|
+
requirements:
|
|
157
|
+
- - '='
|
|
158
|
+
- !ruby/object:Gem::Version
|
|
159
|
+
version: 0.3.0
|
|
160
|
+
type: :development
|
|
161
|
+
prerelease: false
|
|
162
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
163
|
+
requirements:
|
|
164
|
+
- - '='
|
|
165
|
+
- !ruby/object:Gem::Version
|
|
166
|
+
version: 0.3.0
|
|
139
167
|
- !ruby/object:Gem::Dependency
|
|
140
168
|
name: prometheus-client
|
|
141
169
|
requirement: !ruby/object:Gem::Requirement
|