fluent-plugin-google-cloud 0.10.9 → 0.13.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: cfb8318e26804ad6f09d4e16777e3bbef7448a671f6a81dc3c2c2e30fd5e8a92
4
- data.tar.gz: 4410e23d39d9dacf8fad1b9053be2fc9da055c37e3be1fcd13916a04f0ae3758
3
+ metadata.gz: d9e2068fdf6e41a45b160c309d16a3fa0dd58ef555f19c76c93e798f0da03815
4
+ data.tar.gz: f9902899c11ecf784433b7437d9efcd0ebda4ff812aeaee7edb6e7aeffbc6d66
5
5
  SHA512:
6
- metadata.gz: f28ea72b58f2ed3d8eedea65b002fad2dda4ffc8a62b4b0a5c5c26fd54e04a058d680ea9745199fa8dcfbae5b1b984400a3cae5e88332b563453eb0c6415967e
7
- data.tar.gz: 2992d107c0617ba61f6637d6f0e57d997b6b19068d9c67bbd7794adef43489a8bf7dc133601ddfe59d1a150f47ce6b41388fb0decbded25a4d49b35dfabf2b00
6
+ metadata.gz: 39777bfde0e2c738c2d50506660604209e0860bd89a6669acfa1cc94bae5696d6bfae1089f17c7b197fa807ff6db8caac5e278a94b3c7db35b44366cf31c8d40
7
+ data.tar.gz: 71ded0ece74b31da78d665862a1fcd54c9ef0407c6b0f6bbd4eff26cfbe49072d8f17d84c9c86af8a97b14a3c380756df2578f88eb3beefacce2278724e02be5
data/Gemfile.lock CHANGED
@@ -1,25 +1,31 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- fluent-plugin-google-cloud (0.10.9)
5
- fluentd (= 1.11.2)
6
- google-api-client (= 0.30.8)
7
- google-cloud-logging (= 1.6.6)
8
- google-protobuf (= 3.15.8)
9
- googleapis-common-protos (= 1.3.10)
10
- googleauth (= 0.9.0)
11
- grpc (= 1.31.1)
12
- json (= 2.2.0)
4
+ fluent-plugin-google-cloud (0.13.1)
5
+ fluentd (= 1.13.3)
6
+ google-api-client (= 0.53.0)
7
+ google-cloud-logging (= 2.3.2)
8
+ google-cloud-monitoring-v3 (= 0.10.0)
9
+ google-protobuf (= 3.22.1)
10
+ googleapis-common-protos (= 1.4.0)
11
+ googleauth (= 1.3.0)
12
+ grpc (= 1.53.0)
13
+ json (= 2.6.3)
13
14
  opencensus (= 0.5.0)
14
- opencensus-stackdriver (= 0.3.2)
15
+ opencensus-stackdriver (= 0.4.1)
15
16
 
16
17
  GEM
17
18
  remote: https://rubygems.org/
18
19
  specs:
19
- addressable (2.7.0)
20
- public_suffix (>= 2.0.2, < 5.0)
20
+ activesupport (7.0.6)
21
+ concurrent-ruby (~> 1.0, >= 1.0.2)
22
+ i18n (>= 1.6, < 2)
23
+ minitest (>= 5.1)
24
+ tzinfo (~> 2.0)
25
+ addressable (2.8.4)
26
+ public_suffix (>= 2.0.2, < 6.0)
21
27
  ast (2.4.2)
22
- concurrent-ruby (1.1.8)
28
+ concurrent-ruby (1.2.2)
23
29
  cool.io (1.7.1)
24
30
  coveralls (0.8.23)
25
31
  json (>= 1.8, < 3)
@@ -30,135 +36,153 @@ GEM
30
36
  crack (0.4.5)
31
37
  rexml
32
38
  declarative (0.0.20)
33
- docile (1.3.5)
34
- faraday (0.17.4)
35
- multipart-post (>= 1.2, < 3)
36
- fluentd (1.11.2)
39
+ docile (1.4.0)
40
+ faraday (2.7.10)
41
+ faraday-net_http (>= 2.0, < 3.1)
42
+ ruby2_keywords (>= 0.0.4)
43
+ faraday-net_http (3.0.2)
44
+ faraday-retry (2.2.0)
45
+ faraday (~> 2.0)
46
+ fluentd (1.13.3)
47
+ bundler
37
48
  cool.io (>= 1.4.5, < 2.0.0)
38
- http_parser.rb (>= 0.5.1, < 0.7.0)
49
+ http_parser.rb (>= 0.5.1, < 0.8.0)
39
50
  msgpack (>= 1.3.1, < 2.0.0)
40
- serverengine (>= 2.0.4, < 3.0.0)
51
+ serverengine (>= 2.2.2, < 3.0.0)
41
52
  sigdump (~> 0.2.2)
42
53
  strptime (>= 0.2.2, < 1.0.0)
43
54
  tzinfo (>= 1.0, < 3.0)
44
55
  tzinfo-data (~> 1.0)
56
+ webrick (>= 1.4.2, < 1.8.0)
45
57
  yajl-ruby (~> 1.0)
46
- gapic-common (0.3.4)
47
- google-protobuf (~> 3.12, >= 3.12.2)
48
- googleapis-common-protos (>= 1.3.9, < 2.0)
49
- googleapis-common-protos-types (>= 1.0.4, < 2.0)
50
- googleauth (~> 0.9)
51
- grpc (~> 1.25)
52
- google-api-client (0.30.8)
58
+ gapic-common (0.19.1)
59
+ faraday (>= 1.9, < 3.a)
60
+ faraday-retry (>= 1.0, < 3.a)
61
+ google-protobuf (~> 3.14)
62
+ googleapis-common-protos (>= 1.3.12, < 2.a)
63
+ googleapis-common-protos-types (>= 1.3.1, < 2.a)
64
+ googleauth (~> 1.0)
65
+ grpc (~> 1.36)
66
+ gems (1.2.0)
67
+ google-api-client (0.53.0)
68
+ google-apis-core (~> 0.1)
69
+ google-apis-generator (~> 0.1)
70
+ google-apis-core (0.11.0)
53
71
  addressable (~> 2.5, >= 2.5.1)
54
- googleauth (>= 0.5, < 0.10.0)
55
- httpclient (>= 2.8.1, < 3.0)
72
+ googleauth (>= 0.16.2, < 2.a)
73
+ httpclient (>= 2.8.1, < 3.a)
56
74
  mini_mime (~> 1.0)
57
75
  representable (~> 3.0)
58
- retriable (>= 2.0, < 4.0)
59
- signet (~> 0.10)
76
+ retriable (>= 2.0, < 4.a)
77
+ rexml
78
+ webrick
79
+ google-apis-discovery_v1 (0.14.0)
80
+ google-apis-core (>= 0.11.0, < 2.a)
81
+ google-apis-generator (0.12.0)
82
+ activesupport (>= 5.0)
83
+ gems (~> 1.2)
84
+ google-apis-core (>= 0.11.0, < 2.a)
85
+ google-apis-discovery_v1 (~> 0.5)
86
+ thor (>= 0.20, < 2.a)
60
87
  google-cloud-core (1.6.0)
61
88
  google-cloud-env (~> 1.0)
62
89
  google-cloud-errors (~> 1.0)
63
- google-cloud-env (1.5.0)
64
- faraday (>= 0.17.3, < 2.0)
65
- google-cloud-errors (1.1.0)
66
- google-cloud-logging (1.6.6)
67
- concurrent-ruby (~> 1.1)
68
- google-cloud-core (~> 1.2)
69
- google-gax (~> 1.7)
70
- googleapis-common-protos-types (>= 1.0.2)
71
- stackdriver-core (~> 1.3)
72
- google-cloud-monitoring (0.38.0)
73
- google-gax (~> 1.8)
74
- googleapis-common-protos (>= 1.3.9, < 2.0)
75
- googleapis-common-protos-types (>= 1.0.4, < 2.0)
76
- google-cloud-trace (0.41.0)
90
+ google-cloud-env (1.6.0)
91
+ faraday (>= 0.17.3, < 3.0)
92
+ google-cloud-errors (1.3.1)
93
+ google-cloud-logging (2.3.2)
77
94
  concurrent-ruby (~> 1.1)
78
95
  google-cloud-core (~> 1.5)
79
- google-cloud-trace-v1 (~> 0.0)
80
- google-cloud-trace-v2 (~> 0.0)
96
+ google-cloud-logging-v2 (~> 0.0)
81
97
  stackdriver-core (~> 1.3)
82
- google-cloud-trace-v1 (0.3.0)
83
- gapic-common (~> 0.3)
98
+ google-cloud-logging-v2 (0.10.1)
99
+ gapic-common (>= 0.19.1, < 2.a)
100
+ google-cloud-errors (~> 1.0)
101
+ google-cloud-monitoring-v3 (0.10.0)
102
+ gapic-common (>= 0.16.0, < 2.a)
84
103
  google-cloud-errors (~> 1.0)
85
- google-cloud-trace-v2 (0.3.0)
86
- gapic-common (~> 0.3)
104
+ google-cloud-trace-v2 (0.6.1)
105
+ gapic-common (>= 0.19.1, < 2.a)
87
106
  google-cloud-errors (~> 1.0)
88
- google-gax (1.8.1)
89
- google-protobuf (~> 3.9)
90
- googleapis-common-protos (>= 1.3.9, < 2.0)
91
- googleauth (~> 0.9)
92
- grpc (~> 1.24)
93
- rly (~> 0.2.3)
94
- google-protobuf (3.15.8)
95
- googleapis-common-protos (1.3.10)
96
- google-protobuf (~> 3.11)
97
- googleapis-common-protos-types (>= 1.0.5, < 2.0)
107
+ google-protobuf (3.22.1)
108
+ googleapis-common-protos (1.4.0)
109
+ google-protobuf (~> 3.14)
110
+ googleapis-common-protos-types (~> 1.2)
98
111
  grpc (~> 1.27)
99
- googleapis-common-protos-types (1.0.6)
112
+ googleapis-common-protos-types (1.6.0)
100
113
  google-protobuf (~> 3.14)
101
- googleauth (0.9.0)
102
- faraday (~> 0.12)
114
+ googleauth (1.3.0)
115
+ faraday (>= 0.17.3, < 3.a)
103
116
  jwt (>= 1.4, < 3.0)
104
117
  memoist (~> 0.16)
105
118
  multi_json (~> 1.11)
106
119
  os (>= 0.9, < 2.0)
107
- signet (~> 0.7)
108
- grpc (1.31.1)
109
- google-protobuf (~> 3.12)
120
+ signet (>= 0.16, < 2.a)
121
+ grpc (1.53.0)
122
+ google-protobuf (~> 3.21)
110
123
  googleapis-common-protos-types (~> 1.0)
111
124
  hashdiff (1.0.1)
112
- http_parser.rb (0.6.0)
125
+ http_parser.rb (0.7.0)
113
126
  httpclient (2.8.3)
114
- json (2.2.0)
115
- jwt (2.2.3)
127
+ i18n (1.14.1)
128
+ concurrent-ruby (~> 1.0)
129
+ json (2.6.3)
130
+ jwt (2.7.1)
116
131
  memoist (0.16.2)
117
132
  metaclass (0.0.4)
118
- mini_mime (1.1.0)
133
+ mini_mime (1.1.2)
134
+ minitest (5.18.1)
119
135
  mocha (1.9.0)
120
136
  metaclass (~> 0.0.1)
121
- msgpack (1.4.2)
137
+ msgpack (1.7.1)
122
138
  multi_json (1.15.0)
123
- multipart-post (2.1.1)
124
139
  opencensus (0.5.0)
125
- opencensus-stackdriver (0.3.2)
140
+ opencensus-stackdriver (0.4.1)
126
141
  concurrent-ruby (~> 1.0)
127
- google-cloud-monitoring (~> 0.32)
128
- google-cloud-trace (~> 0.35)
142
+ google-cloud-env (~> 1.3)
143
+ google-cloud-monitoring-v3 (~> 0.1)
144
+ google-cloud-trace-v2 (~> 0.1)
129
145
  opencensus (~> 0.5)
130
- os (1.1.1)
131
- parser (2.7.2.0)
146
+ os (1.1.4)
147
+ parallel (1.23.0)
148
+ parser (3.2.2.3)
132
149
  ast (~> 2.4.1)
133
- power_assert (2.0.0)
134
- powerpack (0.1.3)
150
+ racc
151
+ power_assert (2.0.3)
135
152
  prometheus-client (0.9.0)
136
153
  quantile (~> 0.2.1)
137
- public_suffix (4.0.6)
154
+ public_suffix (5.0.3)
138
155
  quantile (0.2.1)
139
- rainbow (2.2.2)
140
- rake
141
- rake (10.5.0)
142
- representable (3.1.1)
156
+ racc (1.7.1)
157
+ rainbow (3.1.1)
158
+ rake (13.0.6)
159
+ regexp_parser (2.8.1)
160
+ representable (3.2.0)
143
161
  declarative (< 0.1.0)
144
162
  trailblazer-option (>= 0.1.1, < 0.2.0)
145
163
  uber (< 0.2.0)
146
164
  retriable (3.1.2)
147
165
  rexml (3.2.5)
148
- rly (0.2.3)
149
- rubocop (0.39.0)
150
- parser (>= 2.3.0.7, < 3.0)
151
- powerpack (~> 0.1)
152
- rainbow (>= 1.99.1, < 3.0)
166
+ rubocop (1.48.1)
167
+ json (~> 2.3)
168
+ parallel (~> 1.10)
169
+ parser (>= 3.2.0.0)
170
+ rainbow (>= 2.2.2, < 4.0)
171
+ regexp_parser (>= 1.8, < 3.0)
172
+ rexml (>= 3.2.5, < 4.0)
173
+ rubocop-ast (>= 1.26.0, < 2.0)
153
174
  ruby-progressbar (~> 1.7)
154
- unicode-display_width (~> 1.0, >= 1.0.1)
155
- ruby-progressbar (1.11.0)
156
- serverengine (2.2.3)
175
+ unicode-display_width (>= 2.4.0, < 3.0)
176
+ rubocop-ast (1.29.0)
177
+ parser (>= 3.2.1.0)
178
+ ruby-progressbar (1.13.0)
179
+ ruby2_keywords (0.0.5)
180
+ serverengine (2.3.2)
157
181
  sigdump (~> 0.2.2)
158
- sigdump (0.2.4)
159
- signet (0.15.0)
160
- addressable (~> 2.3)
161
- faraday (>= 0.17.3, < 2.0)
182
+ sigdump (0.2.5)
183
+ signet (0.17.0)
184
+ addressable (~> 2.8)
185
+ faraday (>= 0.17.5, < 3.a)
162
186
  jwt (>= 1.5, < 3.0)
163
187
  multi_json (~> 1.10)
164
188
  simplecov (0.16.1)
@@ -174,21 +198,22 @@ GEM
174
198
  tins (~> 1.0)
175
199
  test-unit (3.3.3)
176
200
  power_assert
177
- thor (1.1.0)
178
- tins (1.28.0)
201
+ thor (1.2.2)
202
+ tins (1.32.1)
179
203
  sync
180
- trailblazer-option (0.1.1)
181
- tzinfo (2.0.4)
204
+ trailblazer-option (0.1.2)
205
+ tzinfo (2.0.6)
182
206
  concurrent-ruby (~> 1.0)
183
- tzinfo-data (1.2021.1)
207
+ tzinfo-data (1.2023.3)
184
208
  tzinfo (>= 1.0.0)
185
209
  uber (0.1.0)
186
- unicode-display_width (1.7.0)
187
- webmock (3.6.2)
188
- addressable (>= 2.3.6)
210
+ unicode-display_width (2.4.2)
211
+ webmock (3.17.1)
212
+ addressable (>= 2.8.0)
189
213
  crack (>= 0.3.2)
190
214
  hashdiff (>= 0.4.0, < 2.0.0)
191
- yajl-ruby (1.4.1)
215
+ webrick (1.7.0)
216
+ yajl-ruby (1.4.3)
192
217
 
193
218
  PLATFORMS
194
219
  ruby
@@ -198,10 +223,10 @@ DEPENDENCIES
198
223
  fluent-plugin-google-cloud!
199
224
  mocha (= 1.9.0)
200
225
  prometheus-client (< 0.10)
201
- rake (= 10.5.0)
202
- rubocop (= 0.39.0)
226
+ rake (= 13.0.6)
227
+ rubocop (= 1.48.1)
203
228
  test-unit (= 3.3.3)
204
- webmock (= 3.6.2)
229
+ webmock (= 3.17.1)
205
230
 
206
231
  BUNDLED WITH
207
232
  2.1.4
data/Rakefile CHANGED
@@ -28,15 +28,16 @@ task :fix_perms do
28
28
  end
29
29
 
30
30
  files.each do |file|
31
- mode = File.stat(file).mode & 0777
32
- next unless mode & 0444 != 0444
31
+ mode = File.stat(file).mode & 0o777
32
+ next unless mode & 0o444 != 0o444
33
+
33
34
  puts "Changing mode of #{file} from #{mode.to_s(8)} to "\
34
- "#{(mode | 0444).to_s(8)}"
35
- chmod mode | 0444, file
35
+ "#{(mode | 0o444).to_s(8)}"
36
+ chmod mode | 0o444, file
36
37
  end
37
38
  end
38
39
 
39
40
  desc 'Run unit tests and RuboCop to check for style violations'
40
- task all: [:rubocop, :test, :fix_perms]
41
+ task all: %i[rubocop test fix_perms]
41
42
 
42
43
  task default: :all
@@ -1,47 +1,46 @@
1
1
  Gem::Specification.new do |gem|
2
2
  gem.name = 'fluent-plugin-google-cloud'
3
- gem.description = <<-eos
3
+ gem.description = <<-DESCRIPTION
4
4
  Fluentd plugins for the Stackdriver Logging API, which will make logs
5
5
  viewable in the Stackdriver Logs Viewer and can optionally store them
6
6
  in Google Cloud Storage and/or BigQuery.
7
7
  This is an official Google Ruby gem.
8
- eos
8
+ DESCRIPTION
9
9
  gem.summary = 'fluentd plugins for the Stackdriver Logging API'
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.10.9'
13
+ gem.version = '0.13.1'
14
14
  gem.authors = ['Stackdriver Agents Team']
15
15
  gem.email = ['stackdriver-agents@google.com']
16
- gem.required_ruby_version = Gem::Requirement.new('>= 2.2')
16
+ gem.required_ruby_version = Gem::Requirement.new('>= 2.6')
17
17
 
18
18
  gem.files = Dir['**/*'].keep_if { |file| File.file?(file) }
19
19
  gem.test_files = gem.files.grep(/^(test)/)
20
20
  gem.require_paths = ['lib']
21
21
 
22
- gem.add_runtime_dependency 'fluentd', '1.11.2'
23
- gem.add_runtime_dependency 'googleapis-common-protos', '1.3.10'
24
- gem.add_runtime_dependency 'googleauth', '0.9.0'
25
- gem.add_runtime_dependency 'google-api-client', '0.30.8'
26
- gem.add_runtime_dependency 'google-cloud-logging', '1.6.6'
27
- gem.add_runtime_dependency 'google-protobuf', '3.15.8'
28
- gem.add_runtime_dependency 'grpc', '1.31.1'
29
- gem.add_runtime_dependency 'json', '2.2.0'
22
+ # NOTE: In order to update the Fluentd version, please update both here and
23
+ # also the fluentd version in
24
+ # https://github.com/GoogleCloudPlatform/google-fluentd/blob/master/config/software/fluentd.rb.
25
+ gem.add_runtime_dependency 'fluentd', '1.13.3'
26
+ gem.add_runtime_dependency 'google-api-client', '0.53.0'
27
+ gem.add_runtime_dependency 'googleapis-common-protos', '1.4.0'
28
+ gem.add_runtime_dependency 'googleauth', '1.3.0'
29
+ gem.add_runtime_dependency 'google-cloud-logging', '2.3.2'
30
+ gem.add_runtime_dependency 'google-cloud-monitoring-v3', '0.10.0'
31
+ gem.add_runtime_dependency 'google-protobuf', '3.22.1'
32
+ gem.add_runtime_dependency 'grpc', '1.53.0'
33
+ gem.add_runtime_dependency 'json', '2.6.3'
30
34
  gem.add_runtime_dependency 'opencensus', '0.5.0'
31
- gem.add_runtime_dependency 'opencensus-stackdriver', '0.3.2'
35
+ gem.add_runtime_dependency 'opencensus-stackdriver', '0.4.1'
32
36
 
33
37
  gem.add_development_dependency 'mocha', '1.9.0'
34
38
  # Keep this the same as in
35
39
  # https://github.com/fluent/fluent-plugin-prometheus/blob/master/fluent-plugin-prometheus.gemspec
40
+ gem.add_development_dependency 'coveralls', '0.8.23'
36
41
  gem.add_development_dependency 'prometheus-client', '< 0.10'
37
- # TODO(qingling128): Upgrade rake to 11.0+ after the following issues are
38
- # fixed because rake (11.0+) requires ALL variables to be explicitly
39
- # initialized.
40
- # https://github.com/googleapis/google-auth-library-ruby/issues/227
41
- # https://github.com/farcaller/rly/issues/2
42
- gem.add_development_dependency 'rake', '10.5.0'
43
- gem.add_development_dependency 'rubocop', '0.39.0'
42
+ gem.add_development_dependency 'rake', '13.0.6'
43
+ gem.add_development_dependency 'rubocop', '1.48.1'
44
44
  gem.add_development_dependency 'test-unit', '3.3.3'
45
- gem.add_development_dependency 'webmock', '3.6.2'
46
- gem.add_development_dependency 'coveralls', '0.8.23'
45
+ gem.add_development_dependency 'webmock', '3.17.1'
47
46
  end
@@ -12,13 +12,15 @@
12
12
  # See the License for the specific language governing permissions and
13
13
  # limitations under the License.
14
14
 
15
+ require 'uri'
16
+
15
17
  module Common
16
18
  # Constants for service names, resource types and etc.
17
19
  module ServiceConstants
18
20
  APPENGINE_CONSTANTS = {
19
21
  service: 'appengine.googleapis.com',
20
22
  resource_type: 'gae_app',
21
- metadata_attributes: %w(gae_backend_name gae_backend_version)
23
+ metadata_attributes: %w[gae_backend_name gae_backend_version]
22
24
  }.freeze
23
25
  COMPUTE_CONSTANTS = {
24
26
  service: 'compute.googleapis.com',
@@ -27,9 +29,9 @@ module Common
27
29
  GKE_CONSTANTS = {
28
30
  service: 'container.googleapis.com',
29
31
  resource_type: 'gke_container',
30
- extra_resource_labels: %w(namespace_id pod_id container_name),
31
- extra_common_labels: %w(namespace_name pod_name),
32
- metadata_attributes: %w(cluster-name cluster-location),
32
+ extra_resource_labels: %w[namespace_id pod_id container_name],
33
+ extra_common_labels: %w[namespace_name pod_name],
34
+ metadata_attributes: %w[cluster-name cluster-location],
33
35
  stream_severity_map: {
34
36
  'stdout' => 'INFO',
35
37
  'stderr' => 'ERROR'
@@ -47,12 +49,12 @@ module Common
47
49
  DATAFLOW_CONSTANTS = {
48
50
  service: 'dataflow.googleapis.com',
49
51
  resource_type: 'dataflow_step',
50
- extra_resource_labels: %w(region job_name job_id step_id)
52
+ extra_resource_labels: %w[region job_name job_id step_id]
51
53
  }.freeze
52
54
  DATAPROC_CONSTANTS = {
53
55
  service: 'cluster.dataproc.googleapis.com',
54
56
  resource_type: 'cloud_dataproc_cluster',
55
- metadata_attributes: %w(dataproc-cluster-uuid dataproc-cluster-name)
57
+ metadata_attributes: %w[dataproc-cluster-uuid dataproc-cluster-name]
56
58
  }.freeze
57
59
  EC2_CONSTANTS = {
58
60
  service: 'ec2.amazonaws.com',
@@ -61,7 +63,7 @@ module Common
61
63
  ML_CONSTANTS = {
62
64
  service: 'ml.googleapis.com',
63
65
  resource_type: 'ml_job',
64
- extra_resource_labels: %w(job_id task_name)
66
+ extra_resource_labels: %w[job_id task_name]
65
67
  }.freeze
66
68
 
67
69
  # The map between a subservice name and a resource type.
@@ -111,7 +113,7 @@ module Common
111
113
  end
112
114
 
113
115
  begin
114
- open('http://' + METADATA_SERVICE_ADDR, proxy: false) do |f|
116
+ URI.open("http://#{METADATA_SERVICE_ADDR}", proxy: false) do |f|
115
117
  if f.meta['metadata-flavor'] == 'Google'
116
118
  @log.info 'Detected GCE platform'
117
119
  return Platform::GCE
@@ -132,10 +134,10 @@ module Common
132
134
  def fetch_gce_metadata(platform, metadata_path)
133
135
  raise "Called fetch_gce_metadata with platform=#{platform}" unless
134
136
  platform == Platform::GCE
137
+
135
138
  # See https://cloud.google.com/compute/docs/metadata
136
- open('http://' + METADATA_SERVICE_ADDR + '/computeMetadata/v1/' +
137
- metadata_path, 'Metadata-Flavor' => 'Google', :proxy => false,
138
- &:read)
139
+ URI.open("http://#{METADATA_SERVICE_ADDR}/computeMetadata/v1/#{metadata_path}",
140
+ 'Metadata-Flavor' => 'Google', :proxy => false, &:read)
139
141
  end
140
142
 
141
143
  # EC2 Metadata server returns everything in one call. Store it after the
@@ -143,10 +145,10 @@ module Common
143
145
  def ec2_metadata(platform)
144
146
  raise "Called ec2_metadata with platform=#{platform}" unless
145
147
  platform == Platform::EC2
148
+
146
149
  unless @ec2_metadata
147
150
  # See http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-instance-metadata.html
148
- open('http://' + METADATA_SERVICE_ADDR +
149
- '/latest/dynamic/instance-identity/document', proxy: false) do |f|
151
+ URI.open("http://#{METADATA_SERVICE_ADDR}/latest/dynamic/instance-identity/document", proxy: false) do |f|
150
152
  contents = f.read
151
153
  @ec2_metadata = JSON.parse(contents)
152
154
  end
@@ -164,6 +166,7 @@ module Common
164
166
  missing << 'vm_id' unless vm_id
165
167
  end
166
168
  return if missing.empty?
169
+
167
170
  raise Fluent::ConfigError,
168
171
  "Unable to obtain metadata parameters: #{missing.join(' ')}"
169
172
  end
@@ -203,15 +206,16 @@ module Common
203
206
  # 2. If not, try to retrieve it locally.
204
207
  def get_location(platform, zone, use_aws_availability_zone)
205
208
  # Response format: "projects/<number>/zones/<zone>"
206
- zone ||= fetch_gce_metadata(platform,
207
- 'instance/zone').rpartition('/')[2] if
208
- platform == Platform::GCE
209
+ if platform == Platform::GCE
210
+ zone ||= fetch_gce_metadata(platform,
211
+ 'instance/zone').rpartition('/')[2]
212
+ end
209
213
  aws_location_key = if use_aws_availability_zone
210
214
  'availabilityZone'
211
215
  else
212
216
  'region'
213
217
  end
214
- zone ||= 'aws:' + ec2_metadata(platform)[aws_location_key] if
218
+ zone ||= "aws:#{ec2_metadata(platform)[aws_location_key]}" if
215
219
  platform == Platform::EC2 &&
216
220
  ec2_metadata(platform).key?(aws_location_key)
217
221
  zone
@@ -222,7 +226,8 @@ module Common
222
226
  # Create a monitored resource from type and labels.
223
227
  def create_monitored_resource(type, labels)
224
228
  Google::Apis::LoggingV2::MonitoredResource.new(
225
- type: type, labels: labels.to_h)
229
+ type: type, labels: labels.to_h
230
+ )
226
231
  end
227
232
 
228
233
  # Retrieve monitored resource via the legacy way.
@@ -231,25 +236,30 @@ module Common
231
236
  # Metadata Agent. Thus it should be equivalent to what Metadata Agent
232
237
  # returns.
233
238
  def determine_agent_level_monitored_resource_via_legacy(
234
- platform, subservice_name, detect_subservice, vm_id, zone)
239
+ platform, subservice_name, detect_subservice, vm_id, zone
240
+ )
235
241
  resource_type = determine_agent_level_monitored_resource_type(
236
- platform, subservice_name, detect_subservice)
242
+ platform, subservice_name, detect_subservice
243
+ )
237
244
  create_monitored_resource(
238
245
  resource_type,
239
246
  determine_agent_level_monitored_resource_labels(
240
- platform, resource_type, vm_id, zone))
247
+ platform, resource_type, vm_id, zone
248
+ )
249
+ )
241
250
  end
242
251
 
243
252
  # Determine agent level monitored resource type.
244
253
  def determine_agent_level_monitored_resource_type(
245
- platform, subservice_name, detect_subservice)
254
+ platform, subservice_name, detect_subservice
255
+ )
246
256
  case platform
247
257
  when Platform::OTHER
248
258
  # Unknown platform will be defaulted to GCE instance.
249
- return COMPUTE_CONSTANTS[:resource_type]
259
+ COMPUTE_CONSTANTS[:resource_type]
250
260
 
251
261
  when Platform::EC2
252
- return EC2_CONSTANTS[:resource_type]
262
+ EC2_CONSTANTS[:resource_type]
253
263
 
254
264
  when Platform::GCE
255
265
  # Resource types determined by subservice_name config.
@@ -269,14 +279,15 @@ module Common
269
279
  end
270
280
 
271
281
  # GCE instance.
272
- return COMPUTE_CONSTANTS[:resource_type]
282
+ COMPUTE_CONSTANTS[:resource_type]
273
283
  end
274
284
  end
275
285
 
276
286
  # Determine agent level monitored resource labels based on the resource
277
287
  # type. Each resource type has its own labels that need to be filled in.
278
288
  def determine_agent_level_monitored_resource_labels(
279
- platform, type, vm_id, zone)
289
+ platform, type, vm_id, zone
290
+ )
280
291
  case type
281
292
  # GAE app.
282
293
  when APPENGINE_CONSTANTS[:resource_type]
@@ -293,6 +304,7 @@ module Common
293
304
  when COMPUTE_CONSTANTS[:resource_type]
294
305
  raise "Cannot construct a #{type} resource without vm_id and zone" \
295
306
  unless vm_id && zone
307
+
296
308
  return {
297
309
  'instance_id' => vm_id,
298
310
  'zone' => zone
@@ -302,6 +314,7 @@ module Common
302
314
  when GKE_CONSTANTS[:resource_type]
303
315
  raise "Cannot construct a #{type} resource without vm_id and zone" \
304
316
  unless vm_id && zone
317
+
305
318
  return {
306
319
  'instance_id' => vm_id,
307
320
  'zone' => zone,
@@ -327,6 +340,7 @@ module Common
327
340
  when EC2_CONSTANTS[:resource_type]
328
341
  raise "Cannot construct a #{type} resource without vm_id and zone" \
329
342
  unless vm_id && zone
343
+
330
344
  labels = {
331
345
  'instance_id' => vm_id,
332
346
  'region' => zone
@@ -352,9 +366,8 @@ module Common
352
366
  # Returns the project ID (as a string) on success, or nil on failure.
353
367
  def self.project_id
354
368
  creds = Google::Auth.get_application_default(LOGGING_SCOPE)
355
- if creds.respond_to?(:project_id)
356
- return creds.project_id if creds.project_id
357
- end
369
+ return creds.project_id if creds.respond_to?(:project_id) && creds.project_id
370
+
358
371
  if creds.issuer
359
372
  id = extract_project_id(creds.issuer)
360
373
  return id unless id.nil?