fog-google 1.25.0 → 1.26.0
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/.github/workflows/integration-compute-core.yml +2 -2
- data/.github/workflows/integration-compute-instance_groups.yml +2 -2
- data/.github/workflows/integration-compute-loadbalancing.yml +2 -2
- data/.github/workflows/integration-compute-networking.yml +2 -2
- data/.github/workflows/integration-monitoring.yml +2 -2
- data/.github/workflows/integration-pubsub.yml +2 -2
- data/.github/workflows/integration-sql.yml +2 -2
- data/.github/workflows/integration-storage.yml +2 -2
- data/.github/workflows/unit.yml +2 -2
- data/CHANGELOG.md +46 -27
- data/SECURITY.md +3 -14
- data/fog-google.gemspec +2 -3
- data/lib/fog/google/compute/models/server.rb +1 -1
- data/lib/fog/google/storage/storage_json/real.rb +4 -2
- data/lib/fog/google/storage/storage_json/utils.rb +4 -2
- data/lib/fog/google/storage/storage_xml/real.rb +4 -2
- data/lib/fog/google/storage/storage_xml/requests/get_bucket.rb +1 -1
- data/lib/fog/google/storage/storage_xml/utils.rb +4 -2
- data/lib/fog/google/version.rb +1 -1
- metadata +5 -198
- data/.github/workflows/stale.yml +0 -23
- data/test/helpers/client_helper.rb +0 -63
- data/test/helpers/integration_test_helper.rb +0 -108
- data/test/helpers/test_collection.rb +0 -60
- data/test/helpers/test_helper.rb +0 -28
- data/test/integration/compute/core_compute/test_client_options.rb +0 -12
- data/test/integration/compute/core_compute/test_coverage.rb +0 -6
- data/test/integration/compute/core_compute/test_disk_types.rb +0 -43
- data/test/integration/compute/core_compute/test_disks.rb +0 -53
- data/test/integration/compute/core_compute/test_images.rb +0 -32
- data/test/integration/compute/core_compute/test_machine_types.rb +0 -55
- data/test/integration/compute/core_compute/test_operations.rb +0 -45
- data/test/integration/compute/core_compute/test_projects.rb +0 -19
- data/test/integration/compute/core_compute/test_regions.rb +0 -33
- data/test/integration/compute/core_compute/test_servers.rb +0 -235
- data/test/integration/compute/core_compute/test_snapshots.rb +0 -21
- data/test/integration/compute/core_compute/test_zones.rb +0 -35
- data/test/integration/compute/core_networking/test_addresses.rb +0 -107
- data/test/integration/compute/core_networking/test_coverage.rb +0 -6
- data/test/integration/compute/core_networking/test_firewalls.rb +0 -11
- data/test/integration/compute/core_networking/test_networks.rb +0 -30
- data/test/integration/compute/core_networking/test_routes.rb +0 -26
- data/test/integration/compute/core_networking/test_subnetworks.rb +0 -11
- data/test/integration/compute/instance_groups/test_coverage.rb +0 -6
- data/test/integration/compute/instance_groups/test_instance_group_managers.rb +0 -11
- data/test/integration/compute/instance_groups/test_instance_groups.rb +0 -11
- data/test/integration/compute/instance_groups/test_instance_templates.rb +0 -11
- data/test/integration/compute/loadbalancing/test_backend_services.rb +0 -11
- data/test/integration/compute/loadbalancing/test_coverage.rb +0 -6
- data/test/integration/compute/loadbalancing/test_forwarding_rules.rb +0 -11
- data/test/integration/compute/loadbalancing/test_global_addresses.rb +0 -11
- data/test/integration/compute/loadbalancing/test_global_forwarding_rules.rb +0 -11
- data/test/integration/compute/loadbalancing/test_http_health_checks.rb +0 -11
- data/test/integration/compute/loadbalancing/test_ssl_certificates.rb +0 -11
- data/test/integration/compute/loadbalancing/test_target_http_proxies.rb +0 -11
- data/test/integration/compute/loadbalancing/test_target_https_proxies.rb +0 -11
- data/test/integration/compute/loadbalancing/test_target_instances.rb +0 -11
- data/test/integration/compute/loadbalancing/test_target_pools.rb +0 -55
- data/test/integration/compute/loadbalancing/test_url_maps.rb +0 -11
- data/test/integration/factories/addresses_factory.rb +0 -20
- data/test/integration/factories/backend_services_factory.rb +0 -19
- data/test/integration/factories/collection_factory.rb +0 -52
- data/test/integration/factories/disks_factory.rb +0 -22
- data/test/integration/factories/firewalls_factory.rb +0 -13
- data/test/integration/factories/forwarding_rules_factory.rb +0 -25
- data/test/integration/factories/global_addresses_factory.rb +0 -15
- data/test/integration/factories/global_forwarding_rules_factory.rb +0 -20
- data/test/integration/factories/http_health_checks_factory.rb +0 -11
- data/test/integration/factories/images_factory.rb +0 -16
- data/test/integration/factories/instance_group_manager_factory.rb +0 -30
- data/test/integration/factories/instance_groups_factory.rb +0 -20
- data/test/integration/factories/instance_template_factory.rb +0 -24
- data/test/integration/factories/networks_factory.rb +0 -14
- data/test/integration/factories/servers_factory.rb +0 -30
- data/test/integration/factories/sql_certs_factory.rb +0 -20
- data/test/integration/factories/sql_instances_factory.rb +0 -19
- data/test/integration/factories/sql_users_factory.rb +0 -23
- data/test/integration/factories/ssl_certificates_factory.rb +0 -13
- data/test/integration/factories/subnetworks_factory.rb +0 -26
- data/test/integration/factories/target_http_proxies_factory.rb +0 -19
- data/test/integration/factories/target_https_proxies_factory.rb +0 -26
- data/test/integration/factories/target_instances_factory.rb +0 -24
- data/test/integration/factories/target_pools_factory.rb +0 -28
- data/test/integration/factories/url_maps_factory.rb +0 -19
- data/test/integration/monitoring/test_coverage.rb +0 -6
- data/test/integration/monitoring/test_metric_descriptors.rb +0 -131
- data/test/integration/monitoring/test_monitored_resource_descriptors.rb +0 -37
- data/test/integration/monitoring/test_timeseries.rb +0 -253
- data/test/integration/pubsub/pubsub_shared.rb +0 -75
- data/test/integration/pubsub/test_coverage.rb +0 -6
- data/test/integration/pubsub/test_pubsub_models.rb +0 -135
- data/test/integration/pubsub/test_pubsub_requests.rb +0 -105
- data/test/integration/sql/test_certs.rb +0 -50
- data/test/integration/sql/test_common_flags.rb +0 -31
- data/test/integration/sql/test_common_tiers.rb +0 -26
- data/test/integration/sql/test_coverage.rb +0 -6
- data/test/integration/sql/test_instances.rb +0 -101
- data/test/integration/sql/test_users.rb +0 -37
- data/test/integration/storage/storage_shared.rb +0 -101
- data/test/integration/storage/test_buckets.rb +0 -112
- data/test/integration/storage/test_coverage.rb +0 -6
- data/test/integration/storage/test_directories.rb +0 -67
- data/test/integration/storage/test_files.rb +0 -168
- data/test/integration/storage/test_objects.rb +0 -226
- data/test/integration/test_authentication.rb +0 -38
- data/test/unit/compute/test_common_collections.rb +0 -42
- data/test/unit/compute/test_common_models.rb +0 -35
- data/test/unit/compute/test_disk.rb +0 -26
- data/test/unit/compute/test_server.rb +0 -29
- data/test/unit/dns/test_common_collections.rb +0 -43
- data/test/unit/monitoring/test_comon_collections.rb +0 -44
- data/test/unit/pubsub/test_common_collections.rb +0 -35
- data/test/unit/sql/test_common_collections.rb +0 -46
- data/test/unit/storage/test_common_json_collections.rb +0 -38
- data/test/unit/storage/test_common_xml_collections.rb +0 -50
- data/test/unit/storage/test_json_requests.rb +0 -60
- data/test/unit/storage/test_xml_requests.rb +0 -60
@@ -1,26 +0,0 @@
|
|
1
|
-
require "integration/factories/collection_factory"
|
2
|
-
|
3
|
-
class SubnetworksFactory < CollectionFactory
|
4
|
-
def initialize(example)
|
5
|
-
# We cannot have 2 subnetworks with the same CIDR range so instantiating a
|
6
|
-
# class variable holding a generator, ensuring that the factory gives us a
|
7
|
-
# new subnet every time it's called
|
8
|
-
@octet_generator = (0..255).each
|
9
|
-
super(Fog::Compute[:google].subnetworks, example)
|
10
|
-
end
|
11
|
-
|
12
|
-
def get(identity)
|
13
|
-
@subject.get(identity, TEST_REGION)
|
14
|
-
end
|
15
|
-
|
16
|
-
def all
|
17
|
-
@subject.all(region: TEST_REGION)
|
18
|
-
end
|
19
|
-
|
20
|
-
def params
|
21
|
-
{ :name => resource_name,
|
22
|
-
:network => "default",
|
23
|
-
:region => TEST_REGION,
|
24
|
-
:ip_cidr_range => "192.168.#{@octet_generator.next}.0/24" }
|
25
|
-
end
|
26
|
-
end
|
@@ -1,19 +0,0 @@
|
|
1
|
-
require "integration/factories/collection_factory"
|
2
|
-
require "integration/factories/url_maps_factory"
|
3
|
-
|
4
|
-
class TargetHttpProxiesFactory < CollectionFactory
|
5
|
-
def initialize(example)
|
6
|
-
@url_maps = UrlMapsFactory.new(example)
|
7
|
-
super(Fog::Compute[:google].target_http_proxies, example)
|
8
|
-
end
|
9
|
-
|
10
|
-
def cleanup
|
11
|
-
super
|
12
|
-
@url_maps.cleanup
|
13
|
-
end
|
14
|
-
|
15
|
-
def params
|
16
|
-
{ :name => resource_name,
|
17
|
-
:url_map => @url_maps.create.self_link }
|
18
|
-
end
|
19
|
-
end
|
@@ -1,26 +0,0 @@
|
|
1
|
-
require "integration/factories/collection_factory"
|
2
|
-
require "integration/factories/url_maps_factory"
|
3
|
-
require "integration/factories/ssl_certificates_factory"
|
4
|
-
|
5
|
-
class TargetHttpsProxiesFactory < CollectionFactory
|
6
|
-
def initialize(example)
|
7
|
-
@ssl_certificates = SslCertificatesFactory.new(example)
|
8
|
-
@url_maps = UrlMapsFactory.new(example)
|
9
|
-
super(Fog::Compute[:google].target_https_proxies, example)
|
10
|
-
end
|
11
|
-
|
12
|
-
def cleanup
|
13
|
-
# Calling CollectionFactory#cleanup with forced async as
|
14
|
-
# Url Maps need the Https Proxy to be deleted before they
|
15
|
-
# can be destroyed
|
16
|
-
super(false)
|
17
|
-
@ssl_certificates.cleanup
|
18
|
-
@url_maps.cleanup
|
19
|
-
end
|
20
|
-
|
21
|
-
def params
|
22
|
-
{ :name => resource_name,
|
23
|
-
:url_map => @url_maps.create.self_link,
|
24
|
-
:ssl_certificates => [@ssl_certificates.create.self_link] }
|
25
|
-
end
|
26
|
-
end
|
@@ -1,24 +0,0 @@
|
|
1
|
-
require "integration/factories/collection_factory"
|
2
|
-
require "integration/factories/servers_factory"
|
3
|
-
|
4
|
-
class TargetInstancesFactory < CollectionFactory
|
5
|
-
def initialize(example)
|
6
|
-
@servers = ServersFactory.new(example)
|
7
|
-
super(Fog::Compute[:google].target_instances, example)
|
8
|
-
end
|
9
|
-
|
10
|
-
def cleanup
|
11
|
-
super
|
12
|
-
@servers.cleanup
|
13
|
-
end
|
14
|
-
|
15
|
-
def all
|
16
|
-
@subject.all(zone: TEST_ZONE)
|
17
|
-
end
|
18
|
-
|
19
|
-
def params
|
20
|
-
{ :name => resource_name,
|
21
|
-
:zone => TEST_ZONE,
|
22
|
-
:instance => @servers.create.self_link }
|
23
|
-
end
|
24
|
-
end
|
@@ -1,28 +0,0 @@
|
|
1
|
-
require "integration/factories/collection_factory"
|
2
|
-
require "integration/factories/servers_factory"
|
3
|
-
require "integration/factories/http_health_checks_factory"
|
4
|
-
|
5
|
-
class TargetPoolsFactory < CollectionFactory
|
6
|
-
def initialize(example)
|
7
|
-
@http_health_checks = HttpHealthChecksFactory.new(example)
|
8
|
-
@servers = ServersFactory.new(example)
|
9
|
-
super(Fog::Compute[:google].target_pools, example)
|
10
|
-
end
|
11
|
-
|
12
|
-
def cleanup
|
13
|
-
super
|
14
|
-
@servers.cleanup
|
15
|
-
@http_health_checks.cleanup
|
16
|
-
end
|
17
|
-
|
18
|
-
def all
|
19
|
-
@subject.all(region: TEST_REGION)
|
20
|
-
end
|
21
|
-
|
22
|
-
def params
|
23
|
-
{ :name => resource_name,
|
24
|
-
:region => TEST_REGION,
|
25
|
-
:instances => [@servers.create.self_link, @servers.create.self_link],
|
26
|
-
:health_checks => [@http_health_checks.create.self_link] }
|
27
|
-
end
|
28
|
-
end
|
@@ -1,19 +0,0 @@
|
|
1
|
-
require "integration/factories/collection_factory"
|
2
|
-
require "integration/factories/backend_services_factory"
|
3
|
-
|
4
|
-
class UrlMapsFactory < CollectionFactory
|
5
|
-
def initialize(example)
|
6
|
-
@backend_services = BackendServicesFactory.new(example)
|
7
|
-
super(Fog::Compute[:google].url_maps, example)
|
8
|
-
end
|
9
|
-
|
10
|
-
def cleanup
|
11
|
-
super
|
12
|
-
@backend_services.cleanup
|
13
|
-
end
|
14
|
-
|
15
|
-
def params
|
16
|
-
{ :name => resource_name,
|
17
|
-
:default_service => @backend_services.create.self_link }
|
18
|
-
end
|
19
|
-
end
|
@@ -1,6 +0,0 @@
|
|
1
|
-
require "helpers/integration_test_helper"
|
2
|
-
|
3
|
-
# This is a simple coverage helper that helps differentiate
|
4
|
-
# the tests when run in parallel so the final coverage report
|
5
|
-
# can be properly combined together from multiple runners
|
6
|
-
SimpleCov.command_name "test:monitoring" if ENV["COVERAGE"]
|
@@ -1,131 +0,0 @@
|
|
1
|
-
require "helpers/integration_test_helper"
|
2
|
-
require "helpers/client_helper"
|
3
|
-
|
4
|
-
class TestMetricDescriptors < FogIntegrationTest
|
5
|
-
TEST_METRIC_TYPE_PREFIX = "custom.googleapis.com/fog-google-test/test-metric-descriptors".freeze
|
6
|
-
|
7
|
-
def setup
|
8
|
-
@client = Fog::Google::Monitoring.new
|
9
|
-
# Ensure any resources we create with test prefixes are removed
|
10
|
-
Minitest.after_run do
|
11
|
-
delete_test_resources
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
def delete_test_resources
|
16
|
-
test_resources = @client.monitoring.list_project_metric_descriptors(
|
17
|
-
"projects/#{@project}",
|
18
|
-
:filter => "metric.type = starts_with(\"#{TEST_METRIC_TYPE_PREFIX}\")"
|
19
|
-
)
|
20
|
-
unless test_resources.metric_descriptors.nil?
|
21
|
-
test_resources.metric_descriptors.each do |md|
|
22
|
-
@client.monitoring.delete_project_metric_descriptors(md.name)
|
23
|
-
end
|
24
|
-
end
|
25
|
-
rescue
|
26
|
-
# Do nothing
|
27
|
-
end
|
28
|
-
|
29
|
-
def test_list_metric_descriptors
|
30
|
-
list_resp = @client.list_metric_descriptors
|
31
|
-
assert_operator(list_resp.metric_descriptors.size, :>, 0,
|
32
|
-
"metric descriptor count should be positive")
|
33
|
-
|
34
|
-
resp = @client.list_metric_descriptors(
|
35
|
-
:filter => 'metric.type = starts_with("compute.googleapis.com")',
|
36
|
-
:page_size => 5
|
37
|
-
)
|
38
|
-
assert_operator(resp.metric_descriptors.size, :<=, 5,
|
39
|
-
"metric descriptor count should be <= page size 5")
|
40
|
-
|
41
|
-
resp = @client.list_metric_descriptors(:page_size => 1)
|
42
|
-
assert_equal(resp.metric_descriptors.size, 1,
|
43
|
-
"metric descriptor count should be page size 1")
|
44
|
-
|
45
|
-
next_resp = @client.list_metric_descriptors(
|
46
|
-
:page_size => 1,
|
47
|
-
:page_token => resp.next_page_token
|
48
|
-
)
|
49
|
-
assert_equal(next_resp.metric_descriptors.size, 1, "metric descriptor count should be page size 1")
|
50
|
-
assert(resp.metric_descriptors[0].name != next_resp.metric_descriptors[0].name,
|
51
|
-
"paginated result should not be the same value")
|
52
|
-
end
|
53
|
-
|
54
|
-
def test_create_custom_metric_descriptors
|
55
|
-
metric_type = "#{TEST_METRIC_TYPE_PREFIX}/test-create"
|
56
|
-
label = {
|
57
|
-
:key => "foo",
|
58
|
-
:value_type => "INT64",
|
59
|
-
:description => "test label for a metric descriptor"
|
60
|
-
}
|
61
|
-
options = {
|
62
|
-
:metric_type => metric_type,
|
63
|
-
:unit => "1",
|
64
|
-
:value_type => "INT64",
|
65
|
-
:description => "A custom metric descriptor for fog-google metric descriptor tests.",
|
66
|
-
:display_name => "fog-google/test-metric-descriptor",
|
67
|
-
:metric_kind => "GAUGE",
|
68
|
-
:labels => [label]
|
69
|
-
}
|
70
|
-
|
71
|
-
created = @client.create_metric_descriptor(**options)
|
72
|
-
|
73
|
-
# Check created metric descriptor
|
74
|
-
assert_equal(_full_name(metric_type), created.name)
|
75
|
-
assert_equal(metric_type, created.type)
|
76
|
-
assert_equal(options[:metric_kind], created.metric_kind)
|
77
|
-
assert_equal(options[:value_type], created.value_type)
|
78
|
-
assert_equal(options[:unit], created.unit)
|
79
|
-
assert_equal(options[:description], created.description)
|
80
|
-
assert_equal(options[:display_name], created.display_name)
|
81
|
-
|
82
|
-
assert_equal(created.labels.size, 1, "expected 1 label, got #{created.labels.size}")
|
83
|
-
label_descriptor = created.labels.first
|
84
|
-
assert_equal(label[:key], label_descriptor.key)
|
85
|
-
assert_equal(label[:value_type], label_descriptor.value_type)
|
86
|
-
assert_equal(label[:description], label_descriptor.description)
|
87
|
-
|
88
|
-
Fog.wait_for(30) do
|
89
|
-
begin
|
90
|
-
get_resp = @client.get_metric_descriptor(metric_type)
|
91
|
-
return !get_resp.nil?
|
92
|
-
rescue
|
93
|
-
return false
|
94
|
-
end
|
95
|
-
end
|
96
|
-
|
97
|
-
list_resp = @client.list_metric_descriptor(:filter => "metric.type = \"#{metric_type}\"", :page_size => 1)
|
98
|
-
assert(!list_resp.metric_descriptors.nil?, "expected non-empty list request for metric descriptors")
|
99
|
-
|
100
|
-
assert_empty(@client.delete_metric_descriptor(metric_type))
|
101
|
-
end
|
102
|
-
|
103
|
-
def test_metric_descriptors_all
|
104
|
-
descriptors = @client.metric_descriptors.all
|
105
|
-
assert_operator(descriptors.size, :>, 0,
|
106
|
-
"metric descriptor count should be positive")
|
107
|
-
end
|
108
|
-
|
109
|
-
def test_metric_descriptors_all_page_size
|
110
|
-
descriptors = @client.metric_descriptors.all(
|
111
|
-
:filter => 'metric.type = starts_with("compute.googleapis.com")',
|
112
|
-
:page_size => 5
|
113
|
-
)
|
114
|
-
assert_operator(descriptors.size, :<=, 5,
|
115
|
-
"metric descriptor count should be <= page size 5")
|
116
|
-
|
117
|
-
descriptors = @client.metric_descriptors.all(:page_size => 2)
|
118
|
-
assert_equal(descriptors.size, 2, "metric descriptor count should be page size 2")
|
119
|
-
end
|
120
|
-
|
121
|
-
def test_metric_descriptors_get
|
122
|
-
builtin_test_type = "compute.googleapis.com/instance/cpu/usage_time"
|
123
|
-
|
124
|
-
descriptor = @client.metric_descriptors.get("compute.googleapis.com/instance/cpu/usage_time")
|
125
|
-
assert_equal(descriptor.type, builtin_test_type)
|
126
|
-
end
|
127
|
-
|
128
|
-
def _full_name(metric_type)
|
129
|
-
"projects/#{@client.project}/metricDescriptors/#{metric_type}"
|
130
|
-
end
|
131
|
-
end
|
@@ -1,37 +0,0 @@
|
|
1
|
-
require "helpers/integration_test_helper"
|
2
|
-
|
3
|
-
class TestMetricDescriptors < FogIntegrationTest
|
4
|
-
def setup
|
5
|
-
@client = Fog::Google::Monitoring.new
|
6
|
-
end
|
7
|
-
|
8
|
-
def test_list_and_get
|
9
|
-
resp = @client.list_monitored_resource_descriptors
|
10
|
-
|
11
|
-
assert_operator(resp.resource_descriptors.size, :>, 0,
|
12
|
-
"resource descriptor count should be positive")
|
13
|
-
|
14
|
-
@client.get_monitored_resource_descriptor(
|
15
|
-
resp.resource_descriptors.first.type
|
16
|
-
)
|
17
|
-
end
|
18
|
-
|
19
|
-
def test_all
|
20
|
-
resp = @client.monitored_resource_descriptors.all
|
21
|
-
|
22
|
-
assert_operator(resp.size, :>, 0,
|
23
|
-
"resource descriptor count should be positive")
|
24
|
-
end
|
25
|
-
|
26
|
-
def test_get
|
27
|
-
resource = "global"
|
28
|
-
descriptor = @client.monitored_resource_descriptors.get(resource)
|
29
|
-
|
30
|
-
assert_equal(
|
31
|
-
descriptor.name,
|
32
|
-
"projects/#{@client.project}/monitoredResourceDescriptors/#{resource}"
|
33
|
-
)
|
34
|
-
assert_equal(descriptor.labels.size, 1)
|
35
|
-
assert_equal(descriptor.labels.first[:key], "project_id")
|
36
|
-
end
|
37
|
-
end
|
@@ -1,253 +0,0 @@
|
|
1
|
-
require "helpers/integration_test_helper"
|
2
|
-
|
3
|
-
class TestMetricDescriptors < FogIntegrationTest
|
4
|
-
# This module has a decent amount of retry wrappers as the Stackdriver API
|
5
|
-
# can be quite slow with metric propagation (sometimes 80+ seconds) and client
|
6
|
-
# returning errors, e.g. Google::Apis::ClientError: badRequest if the metric
|
7
|
-
# hasn't yet been created instead of a 404.
|
8
|
-
|
9
|
-
TEST_METRIC_PREFIX = "custom.googleapis.com/fog-google-test/timeseries".freeze
|
10
|
-
LABEL_DESCRIPTORS = [
|
11
|
-
{
|
12
|
-
:key => "test_string_label",
|
13
|
-
:value_type => "STRING",
|
14
|
-
:description => "test string label"
|
15
|
-
},
|
16
|
-
{
|
17
|
-
:key => "test_bool_label",
|
18
|
-
:value_type => "BOOL",
|
19
|
-
:description => "test boolean label"
|
20
|
-
},
|
21
|
-
{
|
22
|
-
:key => "test_int_label",
|
23
|
-
:value_type => "INT64",
|
24
|
-
:description => "test integer label"
|
25
|
-
}
|
26
|
-
].freeze
|
27
|
-
|
28
|
-
def setup
|
29
|
-
@client = Fog::Google::Monitoring.new
|
30
|
-
# Ensure any resources we create with test prefixes are removed
|
31
|
-
|
32
|
-
Minitest.after_run do
|
33
|
-
_delete_test_resources
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
def test_timeseries_collection
|
38
|
-
metric_type = "#{TEST_METRIC_PREFIX}/test_requests"
|
39
|
-
_some_custom_metric_descriptor(metric_type)
|
40
|
-
|
41
|
-
start_time = Time.now
|
42
|
-
labels = {
|
43
|
-
:test_string_label => "foo",
|
44
|
-
:test_bool_label => "false",
|
45
|
-
:test_int_label => "1"
|
46
|
-
}
|
47
|
-
|
48
|
-
expected = _some_timeseries(start_time, metric_type, labels)
|
49
|
-
# Retrying since this is prone to errors in test environment due to
|
50
|
-
# constant creation/deletion of resources
|
51
|
-
resp = retry_on(Google::Apis::ServerError) do
|
52
|
-
@client.create_timeseries(:timeseries => [expected])
|
53
|
-
end
|
54
|
-
assert_empty(resp.to_h)
|
55
|
-
|
56
|
-
# Wait for TimeSeries to be created
|
57
|
-
# Google Monitoring backend is not exactly designed for synchronous retrieval so this retry is necessary
|
58
|
-
Fog.wait_for(30) do
|
59
|
-
begin
|
60
|
-
test_ts = @client.list_timeseries(
|
61
|
-
:filter => "metric.type = \"#{metric_type}\"",
|
62
|
-
:interval => {
|
63
|
-
# Subtracting one second because timeSeries.list API
|
64
|
-
# doesn't return points that are exactly the same time
|
65
|
-
# as the interval for some reason.
|
66
|
-
:start_time => (start_time - 1).to_datetime.rfc3339,
|
67
|
-
:end_time => Time.now.to_datetime.rfc3339
|
68
|
-
}
|
69
|
-
).time_series
|
70
|
-
return !test_ts.nil?
|
71
|
-
rescue
|
72
|
-
return false
|
73
|
-
end
|
74
|
-
end
|
75
|
-
|
76
|
-
series = retry_on(Google::Apis::ClientError) do
|
77
|
-
@client.timeseries_collection.all(
|
78
|
-
:filter => "metric.type = \"#{metric_type}\"",
|
79
|
-
:interval => {
|
80
|
-
# Subtracting one second because timeSeries.list API
|
81
|
-
# doesn't return points that are exactly the same time
|
82
|
-
# as the interval for some reason.
|
83
|
-
:start_time => (start_time - 1).to_datetime.rfc3339,
|
84
|
-
:end_time => Time.now.to_datetime.rfc3339
|
85
|
-
}
|
86
|
-
)
|
87
|
-
end
|
88
|
-
|
89
|
-
assert_equal(1, series.size)
|
90
|
-
actual = series.first
|
91
|
-
assert_equal(expected[:metric], actual.metric)
|
92
|
-
assert_equal(expected[:metric_kind], actual.metric_kind)
|
93
|
-
|
94
|
-
assert_equal(expected[:resource], actual.resource)
|
95
|
-
assert_equal(expected[:value_type], actual.value_type)
|
96
|
-
assert_equal(1, actual.points.size)
|
97
|
-
assert_equal(expected[:points].first[:value], actual.points.first[:value])
|
98
|
-
end
|
99
|
-
|
100
|
-
def test_multiple_timeseries
|
101
|
-
metric_type = "#{TEST_METRIC_PREFIX}/test_multiple"
|
102
|
-
_some_custom_metric_descriptor(metric_type)
|
103
|
-
|
104
|
-
start_time = Time.now
|
105
|
-
metric_labels = [
|
106
|
-
{
|
107
|
-
:test_string_label => "first",
|
108
|
-
:test_bool_label => "true",
|
109
|
-
:test_int_label => "1"
|
110
|
-
},
|
111
|
-
{
|
112
|
-
:test_string_label => "second",
|
113
|
-
:test_bool_label => "false",
|
114
|
-
:test_int_label => "2"
|
115
|
-
}
|
116
|
-
]
|
117
|
-
|
118
|
-
timeseries = metric_labels.map do |labels|
|
119
|
-
_some_timeseries(start_time, metric_type, labels)
|
120
|
-
end
|
121
|
-
|
122
|
-
# Retrying since this is prone to errors in test environment due to
|
123
|
-
# constant creation/deletion of resources
|
124
|
-
retry_on(Google::Apis::ServerError) do
|
125
|
-
@client.create_timeseries(:timeseries => timeseries)
|
126
|
-
end
|
127
|
-
interval = {
|
128
|
-
# Subtracting one second because timeSeries.list API
|
129
|
-
# doesn't return points that are exactly the same time
|
130
|
-
# as the interval for some reason.
|
131
|
-
:start_time => (start_time - 1).to_datetime.rfc3339,
|
132
|
-
:end_time => Time.now.to_datetime.rfc3339
|
133
|
-
}
|
134
|
-
|
135
|
-
# Wait for TimeSeries to be created
|
136
|
-
# Google Monitoring backend is not exactly designed for synchronous retrieval so this retry is necessary
|
137
|
-
Fog.wait_for(30) do
|
138
|
-
begin
|
139
|
-
test_ts = @client.list_timeseries(
|
140
|
-
:filter => "metric.type = \"#{metric_type}\"",
|
141
|
-
:interval => interval
|
142
|
-
).time_series
|
143
|
-
return !test_ts.nil?
|
144
|
-
rescue
|
145
|
-
return false
|
146
|
-
end
|
147
|
-
end
|
148
|
-
|
149
|
-
# Test page size
|
150
|
-
resp = retry_on(Google::Apis::ClientError) do
|
151
|
-
@client.list_timeseries(
|
152
|
-
:filter => "metric.type = \"#{metric_type}\"",
|
153
|
-
:interval => interval,
|
154
|
-
:page_size => 1
|
155
|
-
)
|
156
|
-
end
|
157
|
-
|
158
|
-
refute_nil(resp.time_series, "expected timeseries to not be nil")
|
159
|
-
assert_equal(resp.time_series.size, 1,
|
160
|
-
"expected timeseries count to be equal to page size 1")
|
161
|
-
|
162
|
-
next_resp = @client.list_timeseries(
|
163
|
-
:filter => "metric.type = \"#{metric_type}\"",
|
164
|
-
:interval => interval,
|
165
|
-
:page_size => 1,
|
166
|
-
:page_token => resp.next_page_token
|
167
|
-
)
|
168
|
-
assert_equal(next_resp.time_series.size, 1,
|
169
|
-
"expected timeseries count to be equal to page size 1")
|
170
|
-
labels = resp.time_series.first.metric.labels
|
171
|
-
labels_next = next_resp.time_series.first.metric.labels
|
172
|
-
refute_equal(labels, labels_next,
|
173
|
-
"expected different timeseries when using page_token")
|
174
|
-
|
175
|
-
# Test filter
|
176
|
-
series = retry_on(Google::Apis::ClientError) do
|
177
|
-
@client.timeseries_collection.all(
|
178
|
-
:filter => %[
|
179
|
-
metric.type = "#{metric_type}" AND
|
180
|
-
metric.label.test_string_label = "first"
|
181
|
-
],
|
182
|
-
:interval => interval
|
183
|
-
)
|
184
|
-
end
|
185
|
-
assert_equal(series.size, 1,
|
186
|
-
"expected returned timeseries to be filtered to 1 value")
|
187
|
-
assert_equal("true", series.first.metric[:labels][:test_bool_label])
|
188
|
-
assert_equal("1", series.first.metric[:labels][:test_int_label])
|
189
|
-
end
|
190
|
-
|
191
|
-
def _delete_test_resources
|
192
|
-
list_resp = @client.monitoring.list_project_metric_descriptors(
|
193
|
-
"projects/#{@client.project}",
|
194
|
-
filter: "metric.type = starts_with(\"#{TEST_METRIC_PREFIX}\")"
|
195
|
-
)
|
196
|
-
unless list_resp.metric_descriptors.nil?
|
197
|
-
list_resp.metric_descriptors.each do |md|
|
198
|
-
@client.monitoring.delete_project_metric_descriptor(md.name)
|
199
|
-
end
|
200
|
-
end
|
201
|
-
rescue
|
202
|
-
# Do nothing
|
203
|
-
end
|
204
|
-
|
205
|
-
def _some_custom_metric_descriptor(metric_type)
|
206
|
-
# Create custom metric to write test timeseries for.
|
207
|
-
@client.create_metric_descriptor(
|
208
|
-
:labels => LABEL_DESCRIPTORS,
|
209
|
-
:metric_type => metric_type,
|
210
|
-
:unit => "1",
|
211
|
-
:value_type => "INT64",
|
212
|
-
:description => "A custom metric descriptor for fog-google timeseries test.",
|
213
|
-
:display_name => "fog-google-test/#{metric_type}",
|
214
|
-
:metric_kind => "GAUGE"
|
215
|
-
)
|
216
|
-
|
217
|
-
# Wait for metric descriptor to be created
|
218
|
-
Fog.wait_for(180, 2) do
|
219
|
-
begin
|
220
|
-
@client.get_metric_descriptor(metric_type)
|
221
|
-
true
|
222
|
-
rescue
|
223
|
-
false
|
224
|
-
end
|
225
|
-
end
|
226
|
-
end
|
227
|
-
|
228
|
-
def _some_timeseries(start_time, metric_type, labels)
|
229
|
-
{
|
230
|
-
:metric => {
|
231
|
-
:type => metric_type,
|
232
|
-
:labels => labels
|
233
|
-
},
|
234
|
-
:resource => {
|
235
|
-
:type => "global",
|
236
|
-
:labels => { :project_id => @client.project }
|
237
|
-
},
|
238
|
-
:metric_kind => "GAUGE",
|
239
|
-
:value_type => "INT64",
|
240
|
-
:points => [
|
241
|
-
{
|
242
|
-
:interval => {
|
243
|
-
:end_time => start_time.to_datetime.rfc3339,
|
244
|
-
:start_time => start_time.to_datetime.rfc3339
|
245
|
-
},
|
246
|
-
:value => {
|
247
|
-
:int64_value => rand(10)
|
248
|
-
}
|
249
|
-
}
|
250
|
-
]
|
251
|
-
}
|
252
|
-
end
|
253
|
-
end
|
@@ -1,75 +0,0 @@
|
|
1
|
-
require "helpers/integration_test_helper"
|
2
|
-
require "securerandom"
|
3
|
-
require "base64"
|
4
|
-
|
5
|
-
class PubSubShared < FogIntegrationTest
|
6
|
-
def setup
|
7
|
-
@client = Fog::Google::Pubsub.new
|
8
|
-
# Ensure any resources we create with test prefixes are removed
|
9
|
-
Minitest.after_run do
|
10
|
-
delete_test_resources
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
def delete_test_resources
|
15
|
-
topics_result = @client.list_topics
|
16
|
-
unless topics_result.topics.nil?
|
17
|
-
begin
|
18
|
-
topics_result.topics
|
19
|
-
.map(&:name)
|
20
|
-
.select { |t| t.start_with?(topic_resource_prefix) }
|
21
|
-
.each { |t| @client.delete_topic(t) }
|
22
|
-
# We ignore errors here as list operations may not represent changes applied recently.
|
23
|
-
# Hence, list operations can return a topic which has already been deleted but which we
|
24
|
-
# will attempt to delete again.
|
25
|
-
rescue Google::Apis::Error
|
26
|
-
Fog::Logger.warning("ignoring Google Api error during delete_test_resources")
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
subscriptions_result = @client.list_subscriptions
|
31
|
-
unless subscriptions_result.subscriptions.nil?
|
32
|
-
begin
|
33
|
-
subscriptions_result.subscriptions
|
34
|
-
.map(&:name)
|
35
|
-
.select { |s| s.start_with?(subscription_resource_prefix) }
|
36
|
-
.each { |s| @client.delete_subscription(s) }
|
37
|
-
# We ignore errors here as list operations may not represent changes applied recently.
|
38
|
-
# Hence, list operations can return a topic which has already been deleted but which we
|
39
|
-
# will attempt to delete again.
|
40
|
-
rescue Google::Apis::Error
|
41
|
-
Fog::Logger.warning("ignoring Google Api error during delete_test_resources")
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
def topic_resource_prefix
|
47
|
-
"projects/#{@client.project}/topics/fog-integration-test"
|
48
|
-
end
|
49
|
-
|
50
|
-
def subscription_resource_prefix
|
51
|
-
"projects/#{@client.project}/subscriptions/fog-integration-test"
|
52
|
-
end
|
53
|
-
|
54
|
-
def new_topic_name
|
55
|
-
"#{topic_resource_prefix}-#{SecureRandom.uuid}"
|
56
|
-
end
|
57
|
-
|
58
|
-
def new_subscription_name
|
59
|
-
"#{subscription_resource_prefix}-#{SecureRandom.uuid}"
|
60
|
-
end
|
61
|
-
|
62
|
-
def some_topic_name
|
63
|
-
# create lazily to speed tests up
|
64
|
-
@some_topic ||= new_topic_name.tap do |t|
|
65
|
-
@client.create_topic(t)
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
|
-
def some_subscription_name
|
70
|
-
# create lazily to speed tests up
|
71
|
-
@some_subscription ||= new_subscription_name.tap do |s|
|
72
|
-
@client.create_subscription(s, some_topic_name)
|
73
|
-
end
|
74
|
-
end
|
75
|
-
end
|
@@ -1,6 +0,0 @@
|
|
1
|
-
require "helpers/integration_test_helper"
|
2
|
-
|
3
|
-
# This is a simple coverage helper that helps differentiate
|
4
|
-
# the tests when run in parallel so the final coverage report
|
5
|
-
# can be properly combined together from multiple runners
|
6
|
-
SimpleCov.command_name "test:pubsub" if ENV["COVERAGE"]
|