Skip to content
This repository was archived by the owner on Jun 2, 2021. It is now read-only.

Commit 95f7465

Browse files
authored
Merge pull request cloudfoundry#1921 from cloudfoundry/honeeycomb-pr
Add basic Honeycomb instrumentation
2 parents 2871d5c + 0c85f52 commit 95f7465

File tree

5 files changed

+51
-1
lines changed

5 files changed

+51
-1
lines changed

Gemfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ gem 'eventmachine', '~> 1.0.9'
1010
gem 'fluent-logger'
1111
gem 'googleapis-common-protos'
1212
gem 'hashdiff'
13+
gem 'honeycomb-beeline'
1314
gem 'httpclient'
1415
gem 'json-diff'
1516
gem 'json-schema'

Gemfile.lock

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,8 @@ GEM
227227
google-protobuf (~> 3.1)
228228
googleapis-common-protos-types (~> 1.0.0)
229229
hashdiff (0.3.8)
230+
honeycomb-beeline (2.2.0)
231+
libhoney (~> 1.14, >= 1.14.2)
230232
http (4.4.1)
231233
addressable (~> 2.3)
232234
http-cookie (~> 1.0)
@@ -258,6 +260,9 @@ GEM
258260
jsonpath (~> 1.0)
259261
recursive-open-struct (~> 1.1, >= 1.1.1)
260262
rest-client (~> 2.0)
263+
libhoney (1.14.6)
264+
addressable (~> 2.0)
265+
http (>= 2.0, < 5.0)
261266
listen (3.2.1)
262267
rb-fsevent (~> 0.10, >= 0.10.3)
263268
rb-inotify (~> 0.9, >= 0.9.10)
@@ -530,6 +535,7 @@ DEPENDENCIES
530535
fog-openstack
531536
googleapis-common-protos
532537
hashdiff
538+
honeycomb-beeline
533539
httpclient
534540
json-diff
535541
json-schema

config/initializers/honeycomb.rb

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
require 'honeycomb-beeline'
2+
3+
module CCInitializers
4+
def self.honeycomb(cc_config)
5+
if cc_config[:honeycomb]
6+
Honeycomb.configure do |hc|
7+
hc.write_key = cc_config[:honeycomb][:write_key]
8+
hc.dataset = cc_config[:honeycomb][:dataset]
9+
hc.sample_hook do |fields|
10+
CustomSampler.sample(fields)
11+
end
12+
end
13+
end
14+
end
15+
end
16+
17+
class CustomSampler
18+
extend Honeycomb::DeterministicSampler
19+
def self.sample(fields)
20+
sample_rate = 1
21+
# Remove this if you want a closer look at our DB calls
22+
if fields['meta.package'] == 'sequel'
23+
return [false, 0]
24+
end
25+
26+
# These calls will dominate the dataset if you don't filter them
27+
if fields['request.path'] == '/healthz' && fields['response.status_code'] == 200
28+
return [false, 0]
29+
end
30+
31+
if should_sample(sample_rate, fields['trace.trace_id'])
32+
return [true, sample_rate]
33+
end
34+
35+
return [false, 0]
36+
end
37+
end

lib/cloud_controller/config_schemas/api_schema.rb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,11 @@ class ApiSchema < VCAP::Config
343343
default_app_lifecycle: String,
344344
custom_metric_tag_prefix_list: Array,
345345

346+
optional(:honeycomb) => {
347+
write_key: String,
348+
dataset: String,
349+
},
350+
346351
optional(:kubernetes) => {
347352
host_url: String,
348353
service_account: {
@@ -388,7 +393,7 @@ class ApiSchema < VCAP::Config
388393
auth_user: String,
389394
auth_password: String,
390395
},
391-
),
396+
),
392397

393398
}
394399
end

lib/cloud_controller/rack_app_builder.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ def build(config, request_metrics)
2121
use CloudFoundry::Middleware::Cors, config.get(:allowed_cors_domains)
2222
use CloudFoundry::Middleware::VcapRequestId
2323
use CloudFoundry::Middleware::NewRelicCustomAttributes if config.get(:newrelic_enabled)
24+
use Honeycomb::Rack::Middleware, client: Honeycomb.client if config.get(:honeycomb)
2425
use CloudFoundry::Middleware::SecurityContextSetter, configurer
2526
use CloudFoundry::Middleware::RequestLogs, Steno.logger('cc.api')
2627
if config.get(:rate_limiter, :enabled)

0 commit comments

Comments
 (0)