|
| 1 | +require File.dirname(__FILE__) + "/../spec_helper" |
| 2 | + |
| 3 | +RSpec.describe "BlockInstrumentation metrics", type: :request do |
| 4 | + let(:tags_middleware) do |
| 5 | + lambda do |tags| |
| 6 | + tags.merge(tags_middleware: :tags_middleware) |
| 7 | + end |
| 8 | + end |
| 9 | + before do |
| 10 | + allow_any_instance_of(ActionDispatch::Request).to receive(:request_id).and_return(:request_id) |
| 11 | + allow_any_instance_of(InfluxDB::Rails::Configuration).to receive(:application_name).and_return(:app_name) |
| 12 | + allow_any_instance_of(InfluxDB::Rails::Configuration).to receive(:tags_middleware).and_return(tags_middleware) |
| 13 | + end |
| 14 | + |
| 15 | + it "writes metric" do |
| 16 | + get "/metrics" |
| 17 | + |
| 18 | + expect_metric( |
| 19 | + tags: a_hash_including( |
| 20 | + location: "MetricsController#index", |
| 21 | + hook: "block_instrumentation", |
| 22 | + additional_tag: :value, |
| 23 | + server: Socket.gethostname, |
| 24 | + app_name: :app_name, |
| 25 | + tags_middleware: :tags_middleware, |
| 26 | + block_tag: :block_tag, |
| 27 | + name: "name" |
| 28 | + ), |
| 29 | + values: a_hash_including( |
| 30 | + additional_value: :value, |
| 31 | + request_id: :request_id, |
| 32 | + block_value: :block_value, |
| 33 | + value: be_between(1, 30) |
| 34 | + ) |
| 35 | + ) |
| 36 | + end |
| 37 | + |
| 38 | + it "includes correct timestamps" do |
| 39 | + travel_to Time.zone.local(2018, 1, 1, 9, 0, 0) |
| 40 | + |
| 41 | + get "/metrics" |
| 42 | + |
| 43 | + expect_metric( |
| 44 | + tags: a_hash_including( |
| 45 | + location: "MetricsController#index", |
| 46 | + hook: "block_instrumentation" |
| 47 | + ), |
| 48 | + timestamp: 1_514_797_200 |
| 49 | + ) |
| 50 | + end |
| 51 | + |
| 52 | + it "does not write metric when hook is ignored" do |
| 53 | + allow_any_instance_of(InfluxDB::Rails::Configuration).to receive(:ignored_hooks).and_return(["block_instrumentation.influxdb_rails"]) |
| 54 | + |
| 55 | + get "/metrics" |
| 56 | + |
| 57 | + expect_no_metric( |
| 58 | + tags: a_hash_including( |
| 59 | + location: "MetricsController#index", |
| 60 | + hook: "block_instrumentation" |
| 61 | + ) |
| 62 | + ) |
| 63 | + end |
| 64 | +end |
0 commit comments