gitlab-labkit 0.26.0 → 0.27.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 67d751c41c569f082517aca92fb16a5671d9b82693a6a02065ad349ad648c4ab
4
- data.tar.gz: 94ac25bcad3f2cdb07626e882866b232e75328d5ad458d99dd7feeb81d656852
3
+ metadata.gz: 79846c3feb1b3287ef00d0f55b81ee788745bd5e9834849686061d3ec533cd8a
4
+ data.tar.gz: 527270e43d3a430155932fa3fd133be491ae572196f830e1f3464ff3fe0d4144
5
5
  SHA512:
6
- metadata.gz: 11754a10140341571519d42e999240c3f580b32e7313852c361ba93c42f9b9d0b18599d019d07217566440e128d8f8a00490ab39938e1dec7f813f1d45c03806
7
- data.tar.gz: 7b993168a160a5beacf9757893b424f3da57eeb4fa71600d7ed41e99841a92d0bc7cb4a95fefa572697957c5e7081a672cbe570897db08e5d78e55d6bac3cedb
6
+ metadata.gz: bdf9d4b68fa887ddaf7763a21637cdafe0937dd6f6aef355c71178e8f52c960b7726f9060364c4d254e75e83014764baddfa8545a27818b92fb0409fb422dabd
7
+ data.tar.gz: 1926fbefa4446482eb4a9ed7af240eecb2c6b5af6a8e6cc444d67ca7c95bb252853729b771bf29984437e0843396bfac9e188031a29f29913cf61d9f97f6a183
data/.env.example.sh ADDED
@@ -0,0 +1,7 @@
1
+ export CI_PROJECT_ID=10947578
2
+ export CI_API_V4_URL="https://gitlab.com/api/v4"
3
+ export CI_PROJECT_URL="https://gitlab.com/gitlab-org/ruby/gems/labkit-ruby"
4
+ # Don't keep secrets in plaintext files. Use a keyring or 1password to load
5
+ # it instead and export it as an env var.
6
+ token=$(load-your-token)
7
+ export GITLAB_TOKEN=$token
data/.gitignore CHANGED
@@ -2,3 +2,4 @@ Gemfile.lock
2
2
  *.gem
3
3
  node_modules
4
4
  .bundle
5
+ /.env.sh
data/README.md CHANGED
@@ -44,6 +44,20 @@ Note that LabKit-Ruby uses the [`rufo`](https://github.com/ruby-formatter/rufo)
44
44
 
45
45
  Please also review the [development section of the LabKit (go) README](https://gitlab.com/gitlab-org/labkit#developing-labkit) for details of the LabKit architectural philosophy.
46
46
 
47
+ To work on some of the scripts we use for releasing a new version,
48
+ make sure to add a new `.env.sh`.
49
+
50
+ ```console
51
+ cp .env.example.sh .env.sh`
52
+ ```
53
+
54
+ Inside `.env.sh`, add a personal acccess token for the `GITLAB_TOKEN`
55
+ environment variable. Next source the file:
56
+
57
+ ```console
58
+ . .env.sh
59
+ ```
60
+
47
61
  ### Releasing a new version
48
62
 
49
63
  Releasing a new version can be done by pushing a new tag, or creating
@@ -1,5 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "active_support"
4
+ require "active_support/core_ext"
5
+
3
6
  require "jaeger/client"
4
7
 
5
8
  module Labkit
@@ -22,10 +25,13 @@ module Labkit
22
25
  # The service_name parameter from GITLAB_TRACING takes precedence over the application one
23
26
  service_name = options[:service_name] if options[:service_name]
24
27
 
28
+ # parse reporter headers as necessary
29
+ headers = build_headers(options)
30
+
25
31
  kwargs = {
26
32
  service_name: service_name,
27
33
  sampler: get_sampler(options[:sampler], options[:sampler_param]),
28
- reporter: get_reporter(service_name, options[:http_endpoint], options[:udp_endpoint]),
34
+ reporter: get_reporter(service_name, options[:http_endpoint], options[:udp_endpoint], headers),
29
35
  }.compact
30
36
 
31
37
  extra_params = options.except(:sampler, :sampler_param, :http_endpoint, :udp_endpoint, :strict_parsing, :debug)
@@ -40,6 +46,24 @@ module Labkit
40
46
  Jaeger::Client.build(**kwargs)
41
47
  end
42
48
 
49
+ def self.build_headers(options)
50
+ return unless options&.key?(:http_endpoint)
51
+
52
+ http_endpoint = options[:http_endpoint]
53
+ parsed = URI.parse(http_endpoint)
54
+
55
+ headers = {}
56
+ # add basic auth header only when both user and password are setup correctly
57
+ user = parsed.user
58
+ password = parsed.password
59
+ if user.present? && password.present?
60
+ headers["Authorization"] = "Basic " + Base64.strict_encode64("#{user}:#{password}")
61
+ end
62
+
63
+ return headers
64
+ end
65
+ private_class_method :build_headers
66
+
43
67
  def self.get_sampler(sampler_type, sampler_param)
44
68
  case sampler_type
45
69
  when "probabilistic"
@@ -52,11 +76,11 @@ module Labkit
52
76
  end
53
77
  private_class_method :get_sampler
54
78
 
55
- def self.get_reporter(service_name, http_endpoint, udp_endpoint)
79
+ def self.get_reporter(service_name, http_endpoint, udp_endpoint, headers)
56
80
  encoder = Jaeger::Encoders::ThriftEncoder.new(service_name: service_name)
57
81
 
58
82
  if http_endpoint.present?
59
- sender = get_http_sender(encoder, http_endpoint)
83
+ sender = get_http_sender(encoder, http_endpoint, headers)
60
84
  elsif udp_endpoint.present?
61
85
  sender = get_udp_sender(encoder, udp_endpoint)
62
86
  else
@@ -67,8 +91,8 @@ module Labkit
67
91
  end
68
92
  private_class_method :get_reporter
69
93
 
70
- def self.get_http_sender(encoder, address)
71
- Jaeger::HttpSender.new(url: address, encoder: encoder, logger: Logger.new(STDOUT))
94
+ def self.get_http_sender(encoder, address, headers)
95
+ Jaeger::HttpSender.new(url: address, headers: headers, encoder: encoder, logger: Logger.new(STDOUT))
72
96
  end
73
97
  private_class_method :get_http_sender
74
98
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gitlab-labkit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.26.0
4
+ version: 0.27.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Newdigate
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-10-25 00:00:00.000000000 Z
11
+ date: 2022-10-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: actionpack
@@ -357,6 +357,7 @@ executables: []
357
357
  extensions: []
358
358
  extra_rdoc_files: []
359
359
  files:
360
+ - ".env.example.sh"
360
361
  - ".gitignore"
361
362
  - ".gitlab-ci.yml"
362
363
  - ".gitlab/CODEOWNERS"