fog-google 0.5.5 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (29) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +6 -1
  3. data/examples/monitoring/metric_descriptors.rb +1 -1
  4. data/examples/monitoring/monitored_resource_descriptors.rb +24 -0
  5. data/examples/monitoring/timeseries_collection.rb +13 -8
  6. data/lib/fog/google/models/monitoring/metric_descriptor.rb +7 -4
  7. data/lib/fog/google/models/monitoring/metric_descriptors.rb +4 -6
  8. data/lib/fog/google/models/monitoring/monitored_resource_descriptor.rb +20 -0
  9. data/lib/fog/google/models/monitoring/monitored_resource_descriptors.rb +26 -0
  10. data/lib/fog/google/models/monitoring/timeseries.rb +5 -3
  11. data/lib/fog/google/models/monitoring/timeseries_collection.rb +19 -12
  12. data/lib/fog/google/monitoring.rb +10 -10
  13. data/lib/fog/google/monitoring/mock.rb +1 -1
  14. data/lib/fog/google/monitoring/real.rb +1 -1
  15. data/lib/fog/google/requests/monitoring/list_metric_descriptors.rb +181 -124
  16. data/lib/fog/google/requests/monitoring/list_monitored_resource_descriptors.rb +63 -0
  17. data/lib/fog/google/requests/monitoring/list_timeseries.rb +50 -31
  18. data/lib/fog/google/version.rb +1 -1
  19. metadata +7 -13
  20. data/examples/monitoring/timeseries_descriptors.rb +0 -27
  21. data/lib/fog/google/models/monitoring/timeseries_descriptor.rb +0 -20
  22. data/lib/fog/google/models/monitoring/timeseries_descriptors.rb +0 -31
  23. data/lib/fog/google/requests/monitoring/list_timeseries_descriptors.rb +0 -87
  24. data/tests/models/monitoring/metric_descriptors_tests.rb +0 -9
  25. data/tests/models/monitoring/timeseries_collection_tests.rb +0 -9
  26. data/tests/models/monitoring/timeseries_descriptors_tests.rb +0 -10
  27. data/tests/requests/monitoring/metric_descriptor_tests.rb +0 -22
  28. data/tests/requests/monitoring/timeseries_collection_tests.rb +0 -22
  29. data/tests/requests/monitoring/timeseries_descriptor_tests.rb +0 -23
@@ -0,0 +1,63 @@
1
+ module Fog
2
+ module Google
3
+ class Monitoring
4
+ ##
5
+ # Describes the schema of a MonitoredResource (a resource object that can be used for monitoring, logging,
6
+ # billing, or other purposes) using a type name and a set of labels.
7
+ #
8
+ # @see https://cloud.google.com/monitoring/api/ref_v3/rest/v3/projects.monitoredResourceDescriptors/list
9
+ class Real
10
+ def list_monitored_resource_descriptors(options = {})
11
+ api_method = @monitoring.projects.monitored_resource_descriptors.list
12
+ parameters = {
13
+ "name" => "projects/#{@project}"
14
+ }
15
+
16
+ parameters["filter"] = options[:filter] if options.key?(:filter)
17
+ parameters["pageSize"] = options[:page_size] if options.key?(:page_size)
18
+ parameters["pageToken"] = options[:page_token] if options.key?(:page_token)
19
+
20
+ request(api_method, parameters)
21
+ end
22
+ end
23
+
24
+ class Mock
25
+ def list_monitored_resource_descriptors(_options = {})
26
+ body = {
27
+ "resourceDescriptors" => [
28
+ {
29
+ "type" => "api",
30
+ "displayName" => "Produced API",
31
+ "description" => "An API provided by the producer.",
32
+ "labels" => [
33
+ {
34
+ "key" => "project_id",
35
+ "description" => "The identifier of the GCP project associated with this resource (e.g., my-project)."
36
+ },
37
+ {
38
+ "key" => "service",
39
+ "description" => "API service name e.g. \"cloudsql.googleapis.com\"."
40
+ },
41
+ {
42
+ "key" => "method",
43
+ "description" => "API method e.g. \"disks.list\"."
44
+ },
45
+ {
46
+ "key" => "version",
47
+ "description" => "API version e.g. \"v1\"."
48
+ },
49
+ {
50
+ "key" => "location",
51
+ "description" => "The service specific notion of location. This can be a name of a zone, region, or \"global."
52
+ }
53
+ ],
54
+ "name" => "projects/#{@project}/monitoredResourceDescriptors/api"
55
+ }
56
+ ]
57
+ }
58
+ build_excon_response(body)
59
+ end
60
+ end
61
+ end
62
+ end
63
+ end
@@ -5,55 +5,74 @@ module Fog
5
5
  # List the data points of the time series that match the metric and labels values and that have data points
6
6
  # in the interval
7
7
  #
8
- # https://developers.google.com/cloud-monitoring/v2beta1/timeseries
8
+ # @see https://cloud.google.com/monitoring/api/ref_v3/rest/v3/projects.timeSeries/list
9
9
  class Real
10
- def list_timeseries(metric, youngest, options = {})
11
- api_method = @monitoring.timeseries.list
10
+ def list_timeseries(options = {})
11
+ api_method = @monitoring.projects.time_series.list
12
12
  parameters = {
13
- "project" => @project,
14
- "metric" => metric,
15
- "youngest" => youngest
13
+ "name" => "projects/#{@project}"
16
14
  }
15
+ if options.key?(:interval)
16
+ interval = options[:interval]
17
+ parameters["interval.endTime"] = interval[:end_time] if interval.key?(:end_time)
18
+ parameters["interval.startTime"] = interval[:start_time] if interval.key?(:start_time)
19
+ end
17
20
 
18
- parameters["count"] = options[:count] if options.key?(:count)
19
- parameters["labels"] = options[:labels] if options.key?(:labels)
20
- parameters["oldest"] = options[:oldest] if options.key?(:oldest)
21
+ if options.key?(:aggregation)
22
+ aggregation = options[:aggregation]
23
+ parameters["aggregation.alignmentPeriod"] = aggregation[:alignment_period] if aggregation.key?(:alignment_period)
24
+ parameters["aggregation.crossSeriesReducer"] = aggregation[:cross_series_reducer] if aggregation.key?(:cross_series_reducer)
25
+ parameters["aggregation.groupByFields"] = aggregation[:group_by_fields] if aggregation.key?(:group_by_fields)
26
+ parameters["aggregation.perSeriesAligner"] = aggregation[:per_series_aligner] if aggregation.key?(:per_series_aligner)
27
+ end
28
+
29
+ parameters["filter"] = options[:filter] if options.key?(:filter)
30
+ parameters["orderBy"] = options[:order_by] if options.key?(:order_by)
31
+ parameters["pageSize"] = options[:page_size] if options.key?(:page_size)
21
32
  parameters["pageToken"] = options[:page_token] if options.key?(:page_token)
22
- parameters["timespan"] = options[:timespan] if options.key?(:timespan)
33
+ parameters["view"] = options[:view] if options.key?(:view)
34
+
35
+ unless parameters.key?("interval.startTime")
36
+ raise ArgumentError.new("option :interval must have :start_time value for listing timeseries")
37
+ end
38
+
39
+ unless parameters.key?("interval.endTime")
40
+ raise ArgumentError.new("option :interval must have :end_time value for listing timeseries")
41
+ end
42
+
43
+ unless parameters.key?("filter")
44
+ raise ArgumentError.new("options[:filter] value is required to list timeseries")
45
+ end
23
46
 
24
47
  request(api_method, parameters)
25
48
  end
26
49
  end
27
50
 
28
51
  class Mock
29
- def list_timeseries(metric, youngest, _options = {})
52
+ def list_timeseries(interval, _options = {})
30
53
  body = {
31
- "kind" => 'cloudmonitoring#listTimeseriesResponse',
32
- "youngest" => youngest,
33
- "oldest" => youngest,
34
- "timeseries" => [
54
+ "timeSeries" => [
35
55
  {
36
- "timeseriesDesc" => {
37
- "project" => @project,
38
- "metric" => metric,
56
+ "metric" => {
57
+ "labels" => { "instance_name" => "emilyye-dev" },
58
+ "type" => "compute.googleapis.com/instance/cpu/usage_time"
59
+ },
60
+ "resource" => {
61
+ "type" => "gce_instance",
39
62
  "labels" => {
40
- "cloud.googleapis.com/service" => "compute.googleapis.com",
41
- "compute.googleapis.com/resource_type" => "instance",
42
- "cloud.googleapis.com/location" => "us-central1-a",
43
- "compute.googleapis.com/resource_id" => Fog::Mock.random_numbers(20).to_s,
44
- "compute.googleapis.com/instance_name" => Fog::Mock.random_hex(40)
63
+ "instance_id" => "3959348537894302241",
64
+ "zone" => "us-central1-c",
65
+ "project_id" => @project
45
66
  }
46
67
  },
68
+ "metricKind" => "DELTA",
69
+ "valueType" => "DOUBLE",
47
70
  "points" => [
48
71
  {
49
- "start" => "2014-07-17T20:06:58.000Z",
50
- "end" => "2014-07-17T20:07:58.000Z",
51
- "doubleValue" => 60.0
52
- },
53
- {
54
- "start" => "2014-07-17T20:05:58.000Z",
55
- "end" => "2014-07-17T20:06:58.000Z",
56
- "doubleValue" => 60.0
72
+ "interval" => interval,
73
+ "value" => {
74
+ "doubleValue" => 1.8277230720141233
75
+ }
57
76
  }
58
77
  ]
59
78
  }
@@ -1,5 +1,5 @@
1
1
  module Fog
2
2
  module Google
3
- VERSION = "0.5.5".freeze
3
+ VERSION = "0.6.0".freeze
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fog-google
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.5
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nat Welch
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2017-08-29 00:00:00.000000000 Z
14
+ date: 2017-09-27 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: fog-core
@@ -232,8 +232,8 @@ files:
232
232
  - examples/load-balance.rb
233
233
  - examples/metadata.rb
234
234
  - examples/monitoring/metric_descriptors.rb
235
+ - examples/monitoring/monitored_resource_descriptors.rb
235
236
  - examples/monitoring/timeseries_collection.rb
236
- - examples/monitoring/timeseries_descriptors.rb
237
237
  - examples/network.rb
238
238
  - examples/precreated_client.rb
239
239
  - examples/pubsub/subscriptions.rb
@@ -486,10 +486,10 @@ files:
486
486
  - lib/fog/google/mock.rb
487
487
  - lib/fog/google/models/monitoring/metric_descriptor.rb
488
488
  - lib/fog/google/models/monitoring/metric_descriptors.rb
489
+ - lib/fog/google/models/monitoring/monitored_resource_descriptor.rb
490
+ - lib/fog/google/models/monitoring/monitored_resource_descriptors.rb
489
491
  - lib/fog/google/models/monitoring/timeseries.rb
490
492
  - lib/fog/google/models/monitoring/timeseries_collection.rb
491
- - lib/fog/google/models/monitoring/timeseries_descriptor.rb
492
- - lib/fog/google/models/monitoring/timeseries_descriptors.rb
493
493
  - lib/fog/google/models/pubsub/received_message.rb
494
494
  - lib/fog/google/models/pubsub/subscription.rb
495
495
  - lib/fog/google/models/pubsub/subscriptions.rb
@@ -514,8 +514,8 @@ files:
514
514
  - lib/fog/google/pubsub/mock.rb
515
515
  - lib/fog/google/pubsub/real.rb
516
516
  - lib/fog/google/requests/monitoring/list_metric_descriptors.rb
517
+ - lib/fog/google/requests/monitoring/list_monitored_resource_descriptors.rb
517
518
  - lib/fog/google/requests/monitoring/list_timeseries.rb
518
- - lib/fog/google/requests/monitoring/list_timeseries_descriptors.rb
519
519
  - lib/fog/google/requests/pubsub/acknowledge_subscription.rb
520
520
  - lib/fog/google/requests/pubsub/create_subscription.rb
521
521
  - lib/fog/google/requests/pubsub/create_topic.rb
@@ -679,9 +679,6 @@ files:
679
679
  - tests/models/dns/records_tests.rb
680
680
  - tests/models/dns/zone_tests.rb
681
681
  - tests/models/dns/zones_tests.rb
682
- - tests/models/monitoring/metric_descriptors_tests.rb
683
- - tests/models/monitoring/timeseries_collection_tests.rb
684
- - tests/models/monitoring/timeseries_descriptors_tests.rb
685
682
  - tests/models/pubsub/received_message_tests.rb
686
683
  - tests/models/pubsub/subscription_tests.rb
687
684
  - tests/models/pubsub/subscriptions_tests.rb
@@ -716,9 +713,6 @@ files:
716
713
  - tests/requests/dns/managed_zone_tests.rb
717
714
  - tests/requests/dns/project_tests.rb
718
715
  - tests/requests/dns/record_tests.rb
719
- - tests/requests/monitoring/metric_descriptor_tests.rb
720
- - tests/requests/monitoring/timeseries_collection_tests.rb
721
- - tests/requests/monitoring/timeseries_descriptor_tests.rb
722
716
  - tests/requests/sql/flag_tests.rb
723
717
  - tests/requests/sql/instance_tests.rb
724
718
  - tests/requests/sql/operation_tests.rb
@@ -746,7 +740,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
746
740
  version: '0'
747
741
  requirements: []
748
742
  rubyforge_project:
749
- rubygems_version: 2.6.10
743
+ rubygems_version: 2.6.13
750
744
  signing_key:
751
745
  specification_version: 4
752
746
  summary: Module for the 'fog' gem to support Google.
@@ -1,27 +0,0 @@
1
- # All examples presume that you have a ~/.fog credentials file set up.
2
- # # More info on it can be found here: http://fog.io/about/getting_started.html
3
- #
4
- require "bundler"
5
- Bundler.require(:default, :development)
6
- # Uncomment this if you want to make real requests to GCE (you _will_ be billed!)
7
- # WebMock.disable!
8
-
9
- def test
10
- connection = Fog::Google::Monitoring.new
11
-
12
- puts "Listing all TimeseriesDescriptors for the metric compute.googleapis.com/instance/uptime..."
13
- puts "------------------------------------------------------------------------------------------"
14
- td = connection.timeseries_descriptors.all("compute.googleapis.com/instance/uptime",
15
- DateTime.now.rfc3339)
16
- puts "Number of matches: #{td.length}"
17
-
18
- puts "Listing all TimeseriesDescriptors for the metric compute.googleapis.com/instance/uptime &"
19
- puts "the region us-central1..."
20
- puts "-----------------------------------------------------------------------------------------"
21
- td = connection.timeseries_descriptors.all("compute.googleapis.com/instance/uptime",
22
- DateTime.now.rfc3339,
23
- :labels => "cloud.googleapis.com/location=~us-central1.*")
24
- puts "Number of matches: #{td.length}"
25
- end
26
-
27
- test
@@ -1,20 +0,0 @@
1
- require "fog/core/model"
2
-
3
- module Fog
4
- module Google
5
- class Monitoring
6
- ##
7
- # A time series is a collection of data points that represents the value of a metric of a project over time.
8
- # The metric is described by the time-series descriptor. Each time-series descriptor is uniquely identified by
9
- # its metric name and a set of labels.
10
- #
11
- # @see https://developers.google.com/cloud-monitoring/v2beta1/timeseriesDescriptors
12
- class TimeseriesDescriptor < Fog::Model
13
- identity :metric
14
-
15
- attribute :labels
16
- attribute :project
17
- end
18
- end
19
- end
20
- end
@@ -1,31 +0,0 @@
1
- require "fog/core/collection"
2
- require "fog/google/models/monitoring/timeseries_descriptor"
3
-
4
- module Fog
5
- module Google
6
- class Monitoring
7
- class TimeseriesDescriptors < Fog::Collection
8
- model Fog::Google::Monitoring::TimeseriesDescriptor
9
-
10
- ##
11
- # Lists all Timeseries Descriptors.
12
- #
13
- # @param [String] metric The name of the metric (Metric names are protocol-free URLs).
14
- # @param [String] youngest End of the time interval (inclusive), which is expressed as an RFC 3339 timestamp.
15
- # @param [Hash] options Optional query parameters.
16
- # @option options [String] count Maximum number of time series descriptors per page. Used for pagination.
17
- # @option options [String] labels A collection of labels for the matching time series.
18
- # @option options [String] oldest Start of the time interval (exclusive), which is expressed as an RFC 3339
19
- # timestamp.
20
- # @options options [String] page_token The pagination token, which is used to page through large result sets.
21
- # @options options [String] timespan Length of the time interval to query, which is an alternative way to
22
- # declare the interval.
23
- # @return [Array<Fog::Google::Monitoring::TimeseriesDescriptor>] List of Timeseries Descriptors.
24
- def all(metric, youngest, options = {})
25
- data = service.list_timeseries_descriptors(metric, youngest, options).body["timeseries"] || []
26
- load(data)
27
- end
28
- end
29
- end
30
- end
31
- end
@@ -1,87 +0,0 @@
1
- module Fog
2
- module Google
3
- class Monitoring
4
- ##
5
- # List the descriptors of the time series that match the metric and labels values and that have data points
6
- # in the interval.
7
- #
8
- # @see https://developers.google.com/cloud-monitoring/v2beta1/timeseriesDescriptors/list
9
- class Real
10
- def list_timeseries_descriptors(metric, youngest, options = {})
11
- api_method = @monitoring.timeseries_descriptors.list
12
- parameters = {
13
- "project" => @project,
14
- "metric" => metric,
15
- "youngest" => youngest
16
- }
17
-
18
- parameters["count"] = options[:count] if options.key?(:count)
19
- parameters["labels"] = options[:labels] if options.key?(:labels)
20
- parameters["oldest"] = options[:oldest] if options.key?(:oldest)
21
- parameters["pageToken"] = options[:page_token] if options.key?(:page_token)
22
- parameters["timespan"] = options[:timespan] if options.key?(:timespan)
23
-
24
- request(api_method, parameters)
25
- end
26
- end
27
-
28
- class Mock
29
- def list_timeseries_descriptors(metric, youngest, _options = {})
30
- body = {
31
- "kind" => 'cloudmonitoring#listTimeseriesDescriptorsResponse',
32
- "youngest" => youngest,
33
- "oldest" => youngest,
34
- "timeseries" => [
35
- {
36
- "project" => @project,
37
- "metric" => metric,
38
- "labels" => {
39
- "cloud.googleapis.com/service" => "compute.googleapis.com",
40
- "compute.googleapis.com/resource_type" => "instance",
41
- "cloud.googleapis.com/location" => "us-central1-a",
42
- "compute.googleapis.com/resource_id" => Fog::Mock.random_numbers(20).to_s,
43
- "compute.googleapis.com/instance_name" => Fog::Mock.random_hex(40)
44
- }
45
- },
46
- {
47
- "project" => @project,
48
- "metric" => metric,
49
- "labels" => {
50
- "cloud.googleapis.com/service" => "compute.googleapis.com",
51
- "compute.googleapis.com/resource_type" => "instance",
52
- "cloud.googleapis.com/location" => "us-central1-a",
53
- "compute.googleapis.com/resource_id" => Fog::Mock.random_numbers(20).to_s,
54
- "compute.googleapis.com/instance_name" => Fog::Mock.random_hex(40)
55
- }
56
- },
57
- {
58
- "project" => @project,
59
- "metric" => metric,
60
- "labels" => {
61
- "cloud.googleapis.com/service" => "compute.googleapis.com",
62
- "compute.googleapis.com/resource_type" => "instance",
63
- "cloud.googleapis.com/location" => "us-central1-a",
64
- "compute.googleapis.com/resource_id" => Fog::Mock.random_numbers(20).to_s,
65
- "compute.googleapis.com/instance_name" => Fog::Mock.random_hex(40)
66
- }
67
- },
68
- {
69
- "project" => @project,
70
- "metric" => metric,
71
- "labels" => {
72
- "cloud.googleapis.com/service" => "compute.googleapis.com",
73
- "compute.googleapis.com/resource_type" => "instance",
74
- "cloud.googleapis.com/location" => "us-central1-a",
75
- "compute.googleapis.com/resource_id" => Fog::Mock.random_numbers(20).to_s,
76
- "compute.googleapis.com/instance_name" => Fog::Mock.random_hex(40)
77
- }
78
- }
79
- ]
80
- }
81
-
82
- build_excon_response(body)
83
- end
84
- end
85
- end
86
- end
87
- end
@@ -1,9 +0,0 @@
1
- Shindo.tests("Fog::Google[:monitoring] | metric_descriptors model", ["google"]) do
2
- @metric_descriptors = Fog::Google[:monitoring].metric_descriptors
3
-
4
- tests("success") do
5
- tests('#all').succeeds do
6
- @metric_descriptors.all
7
- end
8
- end
9
- end
@@ -1,9 +0,0 @@
1
- Shindo.tests("Fog::Google[:monitoring] | timeseries_collection model", ["google"]) do
2
- @timeseries_collection = Fog::Google[:monitoring].timeseries_collection
3
-
4
- tests("success") do
5
- tests('#all').succeeds do
6
- @timeseries_collection.all("compute.googleapis.com/instance/uptime", Time.now.strftime("%Y-%m-%dT%H:%M:%S%:z"))
7
- end
8
- end
9
- end