fluent-plugin-google-cloud 0.8.6 → 0.10.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +46 -34
- data/fluent-plugin-google-cloud.gemspec +4 -4
- data/lib/fluent/plugin/common.rb +386 -0
- data/lib/fluent/plugin/filter_analyze_config.rb +42 -4
- data/lib/fluent/plugin/out_google_cloud.rb +81 -360
- data/test/plugin/asserts.rb +2 -0
- data/test/plugin/base_test.rb +69 -139
- data/test/plugin/constants.rb +60 -2
- data/test/plugin/test_driver.rb +1 -14
- data/test/plugin/test_filter_analyze_config.rb +143 -130
- data/test/plugin/utils.rb +147 -0
- metadata +11 -8
@@ -0,0 +1,147 @@
|
|
1
|
+
# Copyright 2020 Google Inc. All rights reserved.
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
# you may not use this file except in compliance with the License.
|
5
|
+
# You may obtain a copy of the License at
|
6
|
+
#
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
# See the License for the specific language governing permissions and
|
13
|
+
# limitations under the License.
|
14
|
+
|
15
|
+
require_relative 'constants'
|
16
|
+
|
17
|
+
require 'prometheus/client'
|
18
|
+
require 'webmock/test_unit'
|
19
|
+
|
20
|
+
module Utils
|
21
|
+
include Constants
|
22
|
+
|
23
|
+
def delete_env_vars
|
24
|
+
# delete environment variables that googleauth uses to find credentials.
|
25
|
+
ENV.delete(CREDENTIALS_PATH_ENV_VAR)
|
26
|
+
# service account env.
|
27
|
+
ENV.delete(PRIVATE_KEY_VAR)
|
28
|
+
ENV.delete(CLIENT_EMAIL_VAR)
|
29
|
+
ENV.delete(PROJECT_ID_VAR)
|
30
|
+
# authorized_user env.
|
31
|
+
ENV.delete(CLIENT_ID_VAR)
|
32
|
+
ENV.delete(CLIENT_SECRET_VAR)
|
33
|
+
ENV.delete(REFRESH_TOKEN_VAR)
|
34
|
+
# home var, which is used to find $HOME/.gcloud/...
|
35
|
+
ENV.delete('HOME')
|
36
|
+
end
|
37
|
+
|
38
|
+
def stub_metadata_request(metadata_path, response_body)
|
39
|
+
stub_request(:get, 'http://169.254.169.254/computeMetadata/v1/' +
|
40
|
+
metadata_path)
|
41
|
+
.to_return(body: response_body, status: 200,
|
42
|
+
headers: { 'Content-Length' => response_body.length })
|
43
|
+
end
|
44
|
+
|
45
|
+
def setup_no_metadata_service_stubs
|
46
|
+
# Simulate a machine with no metadata service present
|
47
|
+
stub_request(:any, %r{http://169.254.169.254/.*})
|
48
|
+
.to_raise(Errno::EHOSTUNREACH)
|
49
|
+
end
|
50
|
+
|
51
|
+
def setup_gce_metadata_stubs
|
52
|
+
# Stub the root, used for platform detection by the plugin and 'googleauth'.
|
53
|
+
stub_request(:get, 'http://169.254.169.254')
|
54
|
+
.to_return(status: 200, headers: { 'Metadata-Flavor' => 'Google' })
|
55
|
+
|
56
|
+
# Create stubs for all the GCE metadata lookups the agent needs to make.
|
57
|
+
stub_metadata_request('project/project-id', PROJECT_ID)
|
58
|
+
stub_metadata_request('instance/zone', FULLY_QUALIFIED_ZONE)
|
59
|
+
stub_metadata_request('instance/id', VM_ID)
|
60
|
+
stub_metadata_request('instance/attributes/',
|
61
|
+
"attribute1\nattribute2\nattribute3")
|
62
|
+
|
63
|
+
# Used by 'googleauth' to fetch the default service account credentials.
|
64
|
+
stub_request(:get, 'http://169.254.169.254/computeMetadata/v1/' \
|
65
|
+
'instance/service-accounts/default/token')
|
66
|
+
.to_return(body: %({"access_token": "#{FAKE_AUTH_TOKEN}"}),
|
67
|
+
status: 200,
|
68
|
+
headers: { 'Content-Length' => FAKE_AUTH_TOKEN.length,
|
69
|
+
'Content-Type' => 'application/json' })
|
70
|
+
end
|
71
|
+
|
72
|
+
def setup_ec2_metadata_stubs
|
73
|
+
# Stub the root, used for platform detection.
|
74
|
+
stub_request(:get, 'http://169.254.169.254')
|
75
|
+
.to_return(status: 200, headers: { 'Server' => 'EC2ws' })
|
76
|
+
|
77
|
+
# Stub the identity document lookup made by the agent.
|
78
|
+
stub_request(:get, 'http://169.254.169.254/latest/dynamic/' \
|
79
|
+
'instance-identity/document')
|
80
|
+
.to_return(body: EC2_IDENTITY_DOCUMENT, status: 200,
|
81
|
+
headers: { 'Content-Length' => EC2_IDENTITY_DOCUMENT.length })
|
82
|
+
end
|
83
|
+
|
84
|
+
def setup_auth_stubs(base_url)
|
85
|
+
# Used when loading credentials from a JSON file.
|
86
|
+
stub_request(:post, base_url)
|
87
|
+
.with(body: hash_including(grant_type: AUTH_GRANT_TYPE))
|
88
|
+
.to_return(body: %({"access_token": "#{FAKE_AUTH_TOKEN}"}),
|
89
|
+
status: 200,
|
90
|
+
headers: { 'Content-Length' => FAKE_AUTH_TOKEN.length,
|
91
|
+
'Content-Type' => 'application/json' })
|
92
|
+
|
93
|
+
stub_request(:post, base_url)
|
94
|
+
.with(body: hash_including(grant_type: 'refresh_token'))
|
95
|
+
.to_return(body: %({"access_token": "#{FAKE_AUTH_TOKEN}"}),
|
96
|
+
status: 200,
|
97
|
+
headers: { 'Content-Length' => FAKE_AUTH_TOKEN.length,
|
98
|
+
'Content-Type' => 'application/json' })
|
99
|
+
end
|
100
|
+
|
101
|
+
def setup_managed_vm_metadata_stubs
|
102
|
+
stub_metadata_request(
|
103
|
+
'instance/attributes/',
|
104
|
+
"attribute1\ngae_backend_name\ngae_backend_version\nlast_attribute")
|
105
|
+
stub_metadata_request('instance/attributes/gae_backend_name',
|
106
|
+
MANAGED_VM_BACKEND_NAME)
|
107
|
+
stub_metadata_request('instance/attributes/gae_backend_version',
|
108
|
+
MANAGED_VM_BACKEND_VERSION)
|
109
|
+
end
|
110
|
+
|
111
|
+
def setup_k8s_metadata_stubs(should_respond = true)
|
112
|
+
if should_respond
|
113
|
+
stub_metadata_request(
|
114
|
+
'instance/attributes/',
|
115
|
+
"attribute1\ncluster-location\ncluster-name\nlast_attribute")
|
116
|
+
stub_metadata_request('instance/attributes/cluster-location',
|
117
|
+
K8S_LOCATION2)
|
118
|
+
stub_metadata_request('instance/attributes/cluster-name',
|
119
|
+
K8S_CLUSTER_NAME)
|
120
|
+
else
|
121
|
+
['cluster-location', 'cluster-name'].each do |metadata_name|
|
122
|
+
stub_request(:get, %r{.*instance/attributes/#{metadata_name}.*})
|
123
|
+
.to_return(status: 404,
|
124
|
+
body: 'The requested URL /computeMetadata/v1/instance/' \
|
125
|
+
"attributes/#{metadata_name} was not found on this" \
|
126
|
+
' server.')
|
127
|
+
end
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
def setup_dataproc_metadata_stubs
|
132
|
+
stub_metadata_request(
|
133
|
+
'instance/attributes/',
|
134
|
+
"attribute1\ndataproc-cluster-uuid\ndataproc-cluster-name")
|
135
|
+
stub_metadata_request('instance/attributes/dataproc-cluster-name',
|
136
|
+
DATAPROC_CLUSTER_NAME)
|
137
|
+
stub_metadata_request('instance/attributes/dataproc-cluster-uuid',
|
138
|
+
DATAPROC_CLUSTER_UUID)
|
139
|
+
stub_metadata_request('instance/attributes/dataproc-region',
|
140
|
+
DATAPROC_REGION)
|
141
|
+
end
|
142
|
+
|
143
|
+
def clear_metrics
|
144
|
+
Prometheus::Client.registry.instance_variable_set('@metrics', {})
|
145
|
+
OpenCensus::Stats.ensure_recorder.clear_stats
|
146
|
+
end
|
147
|
+
end
|
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.
|
4
|
+
version: 0.10.1
|
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: 2020-
|
11
|
+
date: 2020-08-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: fluentd
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - '='
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 1.
|
19
|
+
version: 1.11.2
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - '='
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 1.
|
26
|
+
version: 1.11.2
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: googleapis-common-protos
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -86,28 +86,28 @@ dependencies:
|
|
86
86
|
requirements:
|
87
87
|
- - '='
|
88
88
|
- !ruby/object:Gem::Version
|
89
|
-
version: 3.
|
89
|
+
version: 3.12.2
|
90
90
|
type: :runtime
|
91
91
|
prerelease: false
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
94
94
|
- - '='
|
95
95
|
- !ruby/object:Gem::Version
|
96
|
-
version: 3.
|
96
|
+
version: 3.12.2
|
97
97
|
- !ruby/object:Gem::Dependency
|
98
98
|
name: grpc
|
99
99
|
requirement: !ruby/object:Gem::Requirement
|
100
100
|
requirements:
|
101
101
|
- - '='
|
102
102
|
- !ruby/object:Gem::Version
|
103
|
-
version: 1.
|
103
|
+
version: 1.31.1
|
104
104
|
type: :runtime
|
105
105
|
prerelease: false
|
106
106
|
version_requirements: !ruby/object:Gem::Requirement
|
107
107
|
requirements:
|
108
108
|
- - '='
|
109
109
|
- !ruby/object:Gem::Version
|
110
|
-
version: 1.
|
110
|
+
version: 1.31.1
|
111
111
|
- !ruby/object:Gem::Dependency
|
112
112
|
name: json
|
113
113
|
requirement: !ruby/object:Gem::Requirement
|
@@ -266,6 +266,7 @@ files:
|
|
266
266
|
- README.rdoc
|
267
267
|
- Rakefile
|
268
268
|
- fluent-plugin-google-cloud.gemspec
|
269
|
+
- lib/fluent/plugin/common.rb
|
269
270
|
- lib/fluent/plugin/filter_add_insert_ids.rb
|
270
271
|
- lib/fluent/plugin/filter_analyze_config.rb
|
271
272
|
- lib/fluent/plugin/in_object_space_dump.rb
|
@@ -288,6 +289,7 @@ files:
|
|
288
289
|
- test/plugin/test_filter_analyze_config.rb
|
289
290
|
- test/plugin/test_out_google_cloud.rb
|
290
291
|
- test/plugin/test_out_google_cloud_grpc.rb
|
292
|
+
- test/plugin/utils.rb
|
291
293
|
homepage: https://github.com/GoogleCloudPlatform/fluent-plugin-google-cloud
|
292
294
|
licenses:
|
293
295
|
- Apache-2.0
|
@@ -328,3 +330,4 @@ test_files:
|
|
328
330
|
- test/plugin/test_filter_analyze_config.rb
|
329
331
|
- test/plugin/test_out_google_cloud.rb
|
330
332
|
- test/plugin/test_out_google_cloud_grpc.rb
|
333
|
+
- test/plugin/utils.rb
|