gitlab-labkit 2.8.0 → 2.8.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: a0038ac3c9b17772bb517d4e2fc9e61ca26d05647e3de991c4899dfc867f4d88
4
- data.tar.gz: 041f4b6ee0f7257738b0bb7663adcbca06c9f520152cd7f7b8397b31ed280d7c
3
+ metadata.gz: 7ad3bb9ba369010544041c2ab2d2ec2d8610c535c5b2c5e592fe0e8313c56a66
4
+ data.tar.gz: 4fa90bdb331f44920cc9969603db7189e42dec21c7fab1d7593e91455de323c3
5
5
  SHA512:
6
- metadata.gz: ee2a000a091c0eb8433911f6a0e17d7921c1477204ed9f5e5fb54a3b8d625c8361b7653134cb5231c7b78e4fdc6df74c1b3c9d92424b1a17533f35257b913115
7
- data.tar.gz: dd0a54427b6a2181bfad09efda0536ca4c0b703e2ee8182214a0ce02079f7ee207423f4e7f7d4f40f564a98d2e2d6eaeac8b4e312cf288450c2c0d8e6d146c4f
6
+ metadata.gz: 21c914360a54bb30e914e7b6771781657463b3febd83b81634b88513f2986d7d9f25016bae84781b69918429a49c13fdfdf7da8581d385bc13adb698c8728f1d
7
+ data.tar.gz: e8b1b9f46c438e2608a1f12e55d2fd3f518586795dfb0327b08fed8bcd6496525fb0fba71c5212fdab45b45a3ca1b3b9c792dc212a838a98124be37d698fd823
@@ -48,15 +48,68 @@ module Labkit
48
48
  begin
49
49
  super
50
50
  ensure
51
- payload[:duration] = (::Labkit::System.monotonic_time - start_time).to_f
51
+ # Fold in any connection-establishment time (DNS/TCP/TLS) measured by
52
+ # `#do_start`, so a slow connect is attributed to the request instead
53
+ # of vanishing. Counted once, on the first request of the connection.
54
+ payload[:duration] = (::Labkit::System.monotonic_time - start_time).to_f + take_connect_duration
52
55
  end
53
56
  payload[:code] = response.code
54
57
  response
55
58
  end
56
59
  end
57
60
 
61
+ # Net::HTTP establishes the connection (DNS resolution, TCP connect, TLS
62
+ # handshake) here, before any `#request` runs. With the explicit-start
63
+ # pattern (`Net::HTTP.start(host) { |http| http.request(...) }`) this happens
64
+ # entirely outside `#request`, so without instrumenting it a connection that
65
+ # hangs -- or fails with e.g. Net::OpenTimeout before any request is sent --
66
+ # would contribute nothing to external_http timing or counts.
67
+ def do_start
68
+ start_time = ::Labkit::System.monotonic_time
69
+
70
+ begin
71
+ super
72
+ rescue StandardError
73
+ # The connection failed before any request could be sent, so `#request`
74
+ # will never run to attribute this time. Emit a standalone event so the
75
+ # failure and the time spent are still visible.
76
+ ActiveSupport::Notifications.instrument(
77
+ ::Labkit::EXTERNAL_HTTP_NOTIFICATION_TOPIC, create_connect_payload
78
+ ) do |payload|
79
+ payload[:duration] = (::Labkit::System.monotonic_time - start_time).to_f
80
+ raise
81
+ end
82
+ end
83
+
84
+ @labkit_connect_duration = (::Labkit::System.monotonic_time - start_time).to_f
85
+ end
86
+ private :do_start
87
+
58
88
  private
59
89
 
90
+ def take_connect_duration
91
+ duration = @labkit_connect_duration || 0.0
92
+ @labkit_connect_duration = nil
93
+ duration
94
+ end
95
+
96
+ def create_connect_payload
97
+ {
98
+ method: nil,
99
+ host: address,
100
+ port: port,
101
+ scheme: use_ssl? ? "https" : "http",
102
+ path: nil,
103
+ query: nil,
104
+ fragment: nil
105
+ }.tap do |payload|
106
+ if proxy?
107
+ payload[:proxy_host] = proxy_address
108
+ payload[:proxy_port] = proxy_port
109
+ end
110
+ end
111
+ end
112
+
60
113
  def create_request_payload(request)
61
114
  payload = {
62
115
  method: request.method
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gitlab-labkit
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.8.0
4
+ version: 2.8.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Newdigate