google-cloud-env 2.0.1 → 2.1.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: 5ac62dcc3131def7be6bf69813f79c3d23b6d6ce5199d0250ffad596cf3b7fcb
4
- data.tar.gz: d9eadf5f767d8225022ed9551ea3a5a2ee37e8ad5b68da9eea7c94f416333f4f
3
+ metadata.gz: 874603cbcc635840a5fa275335b574f242b5abe3100217d561189cd8c30ab12d
4
+ data.tar.gz: f8756d74ac146f9a3148d5149e29fd1b718e1ab5be177aecd81cbac3507212d9
5
5
  SHA512:
6
- metadata.gz: def8ccefb5d889744cb562a85cc78a9d3b718f80f2d48eab409c6fcdbcbe2dfe9adae14393f06aab3b6a6db83b6fc6d631902d11c1a932e2a77ee2f93a5ca82f
7
- data.tar.gz: 5faabdeb543a4237dd19a69a9963237e4b843f93aeeaa1f002cc08bd0269ba005da6a89baee20989076330b97de9551a41a50e658febd173847166fc29013bcb
6
+ metadata.gz: 6ad688117a2b8cc86596be5d2e0ec5f592f5734927756112a0cd82116d52cc0be6c24b8e8594d9d3ea010977e88275c5916cea676b2d50016973b58a7fd52649
7
+ data.tar.gz: c347078193dd1cc9cab88f1222327f57d928cf246fad899dca010ad4481f4de7d15a3df924df1dcb42bb7860139d98952b222b53f91cde0c1985319f7d18b832
data/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # Release History
2
2
 
3
+ ### 2.1.1 (2024-02-01)
4
+
5
+ #### Bug Fixes
6
+
7
+ * Setting non-empty overrides simulates metadata server existence setting ([#64](https://github.com/googleapis/ruby-cloud-env/issues/64))
8
+
9
+ ### 2.1.0 (2023-12-12)
10
+
11
+ #### Features
12
+
13
+ * Provide retrieval_monotonic_time on compute metadata response objects ([#62](https://github.com/googleapis/ruby-cloud-env/issues/62))
14
+
3
15
  ### 2.0.1 (2023-12-01)
4
16
 
5
17
  #### Bug Fixes
@@ -89,7 +89,8 @@ module Google
89
89
  # {ComputeMetadata#lookup_response}.
90
90
  #
91
91
  # This object duck-types the `status`, `body`, and `headers` fields of
92
- # `Faraday::Response`.
92
+ # `Faraday::Response`. It also includes the CLOCK_MONOTONIC time when
93
+ # the data was retrieved.
93
94
  #
94
95
  class Response
95
96
  ##
@@ -105,6 +106,7 @@ module Google
105
106
  @status = status
106
107
  @body = body
107
108
  @headers = headers
109
+ @retrieval_monotonic_time = Process.clock_gettime Process::CLOCK_MONOTONIC
108
110
  end
109
111
 
110
112
  ##
@@ -125,6 +127,11 @@ module Google
125
127
  #
126
128
  attr_reader :headers
127
129
 
130
+ # The CLOCK_MONOTONIC time at which this response was retrieved.
131
+ # @return [Numeric]
132
+ #
133
+ attr_reader :retrieval_monotonic_time
134
+
128
135
  ##
129
136
  # Returns true if the metadata-flavor is correct for Google Cloud
130
137
  # @return [boolean]
@@ -382,12 +389,12 @@ module Google
382
389
  retry_count: :default,
383
390
  retry_timeout: :default
384
391
  query = canonicalize_query query
385
- raise MetadataServerNotResponding unless gce_check
386
392
  if @overrides
387
393
  @mutex.synchronize do
388
394
  return lookup_override path, query if @overrides
389
395
  end
390
396
  end
397
+ raise MetadataServerNotResponding unless gce_check
391
398
  retry_count = self.retry_count if retry_count == :default
392
399
  retry_count += 1 if retry_count
393
400
  retry_timeout = self.retry_timeout if retry_timeout == :default
@@ -752,9 +759,9 @@ module Google
752
759
  end
753
760
  response = Response.new http_response.status, http_response.body, http_response.headers
754
761
  if path.nil?
755
- post_update_existence(response.status == 200 && response.google_flavor?)
762
+ post_update_existence(response.status == 200 && response.google_flavor?, response.retrieval_monotonic_time)
756
763
  elsif response.google_flavor?
757
- post_update_existence true
764
+ post_update_existence true, response.retrieval_monotonic_time
758
765
  end
759
766
  lifetime = determine_data_lifetime path, response.body.strip
760
767
  LazyValue.expiring_value lifetime, response
@@ -767,14 +774,14 @@ module Google
767
774
  # @private
768
775
  # Update existence based on a received result
769
776
  #
770
- def post_update_existence success
777
+ def post_update_existence success, current_time = nil
771
778
  return if @existence == :confirmed
772
779
  @mutex.synchronize do
773
780
  if success
774
781
  @existence = :confirmed
775
- elsif @existence != :confirmed &&
776
- Process.clock_gettime(Process::CLOCK_MONOTONIC) > @startup_time + warmup_time
777
- @existence = :no
782
+ elsif @existence != :confirmed
783
+ current_time ||= Process.clock_gettime Process::CLOCK_MONOTONIC
784
+ @existence = :no if current_time > @startup_time + warmup_time
778
785
  end
779
786
  end
780
787
  end
@@ -838,6 +845,7 @@ module Google
838
845
  @existence = :no
839
846
  raise MetadataServerNotResponding
840
847
  end
848
+ @existence = :confirmed
841
849
  result = @overrides.lookup path, query: query
842
850
  result ||= Response.new 404, "Not found", FLAVOR_HEADER
843
851
  result
@@ -20,7 +20,7 @@ module Google
20
20
  # Library version
21
21
  # @return [String]
22
22
  #
23
- VERSION = "2.0.1".freeze
23
+ VERSION = "2.1.1".freeze
24
24
  end
25
25
  end
26
26
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: google-cloud-env
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.1
4
+ version: 2.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Azuma
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-12-01 00:00:00.000000000 Z
11
+ date: 2024-02-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -59,10 +59,10 @@ homepage: https://github.com/googleapis/ruby-cloud-env
59
59
  licenses:
60
60
  - Apache-2.0
61
61
  metadata:
62
- changelog_uri: https://rubydoc.info/gems/google-cloud-env/2.0.1/CHANGELOG.md
62
+ changelog_uri: https://rubydoc.info/gems/google-cloud-env/2.1.1/CHANGELOG.md
63
63
  source_code_uri: https://github.com/googleapis/ruby-cloud-env
64
64
  bug_tracker_uri: https://github.com/googleapis/ruby-cloud-env/issues
65
- documentation_uri: https://rubydoc.info/gems/google-cloud-env/2.0.1
65
+ documentation_uri: https://rubydoc.info/gems/google-cloud-env/2.1.1
66
66
  post_install_message:
67
67
  rdoc_options: []
68
68
  require_paths:
@@ -78,7 +78,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
78
78
  - !ruby/object:Gem::Version
79
79
  version: '0'
80
80
  requirements: []
81
- rubygems_version: 3.4.19
81
+ rubygems_version: 3.5.3
82
82
  signing_key:
83
83
  specification_version: 4
84
84
  summary: Google Cloud Platform hosting environment information.