File: instructions_fetcher.rb

package info (click to toggle)
ruby-jaeger-client 1.3.0-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 624 kB
  • sloc: ruby: 3,381; makefile: 6; sh: 4
file content (34 lines) | stat: -rw-r--r-- 859 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# frozen_string_literal: true

module Jaeger
  module Samplers
    class RemoteControlled
      class InstructionsFetcher
        FetchFailed = Class.new(StandardError)

        def initialize(host:, port:, service_name:)
          @host = host
          @port = port
          @service_name = service_name
        end

        def fetch
          http = Net::HTTP.new(@host, @port)
          path = "/sampling?service=#{CGI.escape(@service_name)}"
          response =
            begin
              http.request(Net::HTTP::Get.new(path))
            rescue StandardError => e
              raise FetchFailed, e.inspect
            end

          unless response.is_a?(Net::HTTPSuccess)
            raise FetchFailed, "Unsuccessful response (code=#{response.code})"
          end

          JSON.parse(response.body)
        end
      end
    end
  end
end