fluent-plugin-google-cloud 0.10.4 → 0.10.9
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 +4 -4
 - data/Gemfile.lock +39 -37
 - data/fluent-plugin-google-cloud.gemspec +3 -3
 - data/lib/fluent/plugin/filter_analyze_config.rb +44 -12
 - data/lib/fluent/plugin/monitoring.rb +42 -11
 - data/lib/fluent/plugin/out_google_cloud.rb +6 -6
 - data/test/plugin/asserts.rb +22 -12
 - data/test/plugin/base_test.rb +148 -17
 - data/test/plugin/test_filter_analyze_config.rb +43 -1
 - data/test/plugin/test_out_google_cloud.rb +51 -75
 - data/test/plugin/test_out_google_cloud_grpc.rb +58 -89
 - metadata +6 -6
 
    
        data/test/plugin/asserts.rb
    CHANGED
    
    | 
         @@ -37,7 +37,10 @@ module Asserts 
     | 
|
| 
       37 
37 
     | 
    
         
             
                assert_in_delta expected_ts.tv_nsec, ts_nanos, 600, entry
         
     | 
| 
       38 
38 
     | 
    
         
             
              end
         
     | 
| 
       39 
39 
     | 
    
         | 
| 
       40 
     | 
    
         
            -
               
     | 
| 
      
 40 
     | 
    
         
            +
              # rubocop:disable Metrics/ParameterLists
         
     | 
| 
      
 41 
     | 
    
         
            +
              def assert_prometheus_metric_value(metric_name, expected_value, _prefix,
         
     | 
| 
      
 42 
     | 
    
         
            +
                                                 _aggregation, _test_driver, labels = {})
         
     | 
| 
      
 43 
     | 
    
         
            +
                # rubocop:enable Metrics/ParameterLists
         
     | 
| 
       41 
44 
     | 
    
         
             
                metric = Prometheus::Client.registry.get(metric_name)
         
     | 
| 
       42 
45 
     | 
    
         
             
                assert_not_nil(metric)
         
     | 
| 
       43 
46 
     | 
    
         
             
                metric_value = if labels == :aggregate
         
     | 
| 
         @@ -49,7 +52,10 @@ module Asserts 
     | 
|
| 
       49 
52 
     | 
    
         
             
                assert_equal(expected_value, metric_value)
         
     | 
| 
       50 
53 
     | 
    
         
             
              end
         
     | 
| 
       51 
54 
     | 
    
         | 
| 
       52 
     | 
    
         
            -
               
     | 
| 
      
 55 
     | 
    
         
            +
              # rubocop:disable Metrics/ParameterLists
         
     | 
| 
      
 56 
     | 
    
         
            +
              def assert_opencensus_metric_value(metric_name, expected_value, prefix,
         
     | 
| 
      
 57 
     | 
    
         
            +
                                                 aggregation, test_driver, labels = {})
         
     | 
| 
      
 58 
     | 
    
         
            +
                # rubocop:enable Metrics/ParameterLists
         
     | 
| 
       53 
59 
     | 
    
         
             
                translator = Monitoring::MetricTranslator.new(metric_name, labels)
         
     | 
| 
       54 
60 
     | 
    
         
             
                metric_name = translator.name
         
     | 
| 
       55 
61 
     | 
    
         
             
                labels = translator.translate_labels(labels)
         
     | 
| 
         @@ -60,18 +66,22 @@ module Asserts 
     | 
|
| 
       60 
66 
     | 
    
         
             
                # label that never changes during runtime.
         
     | 
| 
       61 
67 
     | 
    
         
             
                labels.select! { |k, _| translator.view_labels.include? k }
         
     | 
| 
       62 
68 
     | 
    
         
             
                labels = labels.map { |k, v| [k.to_s, v.to_s] }.to_h
         
     | 
| 
       63 
     | 
    
         
            -
             
     | 
| 
       64 
     | 
    
         
            -
                 
     | 
| 
       65 
     | 
    
         
            -
                 
     | 
| 
      
 69 
     | 
    
         
            +
             
     | 
| 
      
 70 
     | 
    
         
            +
                registry = test_driver.instance.instance_variable_get(:@registry)
         
     | 
| 
      
 71 
     | 
    
         
            +
                recorder = registry.instance_variable_get(:@recorders)[prefix]
         
     | 
| 
      
 72 
     | 
    
         
            +
                view_data = recorder.measure_views_data[metric_name][0].data
         
     | 
| 
      
 73 
     | 
    
         
            +
                view = recorder.instance_variable_get(:@views)[metric_name]
         
     | 
| 
      
 74 
     | 
    
         
            +
             
     | 
| 
      
 75 
     | 
    
         
            +
                # Assert values in the view.
         
     | 
| 
      
 76 
     | 
    
         
            +
                assert_kind_of(aggregation, view.aggregation)
         
     | 
| 
      
 77 
     | 
    
         
            +
                assert_equal(labels.keys, view.columns)
         
     | 
| 
      
 78 
     | 
    
         
            +
                assert_equal(metric_name, view.measure.name)
         
     | 
| 
      
 79 
     | 
    
         
            +
                assert_equal('INT64', view.measure.type)
         
     | 
| 
      
 80 
     | 
    
         
            +
             
     | 
| 
       66 
81 
     | 
    
         
             
                # For now assume all metrics are counters.
         
     | 
| 
       67 
     | 
    
         
            -
                 
     | 
| 
       68 
     | 
    
         
            -
                               view_data.view.aggregation)
         
     | 
| 
       69 
     | 
    
         
            -
                assert_true(view_data.view.measure.int64?)
         
     | 
| 
       70 
     | 
    
         
            -
                tag_values = view_data.view.columns.map { |column| labels[column] }
         
     | 
| 
      
 82 
     | 
    
         
            +
                tag_values = view.columns.map { |column| labels[column] }
         
     | 
| 
       71 
83 
     | 
    
         
             
                metric_value = 0
         
     | 
| 
       72 
     | 
    
         
            -
                if view_data. 
     | 
| 
       73 
     | 
    
         
            -
                  metric_value = view_data.data[tag_values].value
         
     | 
| 
       74 
     | 
    
         
            -
                end
         
     | 
| 
      
 84 
     | 
    
         
            +
                metric_value = view_data[tag_values].value if view_data.key? tag_values
         
     | 
| 
       75 
85 
     | 
    
         
             
                assert_equal(expected_value, metric_value)
         
     | 
| 
       76 
86 
     | 
    
         
             
              end
         
     | 
| 
       77 
87 
     | 
    
         
             
            end
         
     | 
    
        data/test/plugin/base_test.rb
    CHANGED
    
    | 
         @@ -943,22 +943,30 @@ module BaseTest 
     | 
|
| 
       943 
943 
     | 
    
         
             
                      d.emit("tag#{i}", 'message' => log_entry(i))
         
     | 
| 
       944 
944 
     | 
    
         
             
                    end
         
     | 
| 
       945 
945 
     | 
    
         
             
                    d.run
         
     | 
| 
      
 946 
     | 
    
         
            +
                    @logs_sent.zip(request_log_names).each do |request, log_name|
         
     | 
| 
      
 947 
     | 
    
         
            +
                      assert_equal log_name, request['logName']
         
     | 
| 
      
 948 
     | 
    
         
            +
                    end
         
     | 
| 
      
 949 
     | 
    
         
            +
                    verify_log_entries(log_entry_count, COMPUTE_PARAMS_NO_LOG_NAME,
         
     | 
| 
      
 950 
     | 
    
         
            +
                                       'textPayload') do |entry, entry_index|
         
     | 
| 
      
 951 
     | 
    
         
            +
                      verify_default_log_entry_text(entry['textPayload'], entry_index,
         
     | 
| 
      
 952 
     | 
    
         
            +
                                                    entry)
         
     | 
| 
      
 953 
     | 
    
         
            +
                      assert_equal entry_log_names[entry_index], entry['logName']
         
     | 
| 
      
 954 
     | 
    
         
            +
                    end
         
     | 
| 
      
 955 
     | 
    
         
            +
                    # Verify the number of requests is different based on whether the
         
     | 
| 
      
 956 
     | 
    
         
            +
                    # 'split_logs_by_tag' flag is enabled.
         
     | 
| 
      
 957 
     | 
    
         
            +
                    assert_prometheus_metric_value(
         
     | 
| 
      
 958 
     | 
    
         
            +
                      :stackdriver_successful_requests_count,
         
     | 
| 
      
 959 
     | 
    
         
            +
                      request_count,
         
     | 
| 
      
 960 
     | 
    
         
            +
                      'agent.googleapis.com/agent',
         
     | 
| 
      
 961 
     | 
    
         
            +
                      OpenCensus::Stats::Aggregation::Sum, d,
         
     | 
| 
      
 962 
     | 
    
         
            +
                      :aggregate)
         
     | 
| 
      
 963 
     | 
    
         
            +
                    assert_prometheus_metric_value(
         
     | 
| 
      
 964 
     | 
    
         
            +
                      :stackdriver_ingested_entries_count,
         
     | 
| 
      
 965 
     | 
    
         
            +
                      log_entry_count,
         
     | 
| 
      
 966 
     | 
    
         
            +
                      'agent.googleapis.com/agent',
         
     | 
| 
      
 967 
     | 
    
         
            +
                      OpenCensus::Stats::Aggregation::Sum, d,
         
     | 
| 
      
 968 
     | 
    
         
            +
                      :aggregate)
         
     | 
| 
       946 
969 
     | 
    
         
             
                  end
         
     | 
| 
       947 
     | 
    
         
            -
                  @logs_sent.zip(request_log_names).each do |request, log_name|
         
     | 
| 
       948 
     | 
    
         
            -
                    assert_equal log_name, request['logName']
         
     | 
| 
       949 
     | 
    
         
            -
                  end
         
     | 
| 
       950 
     | 
    
         
            -
                  verify_log_entries(log_entry_count, COMPUTE_PARAMS_NO_LOG_NAME,
         
     | 
| 
       951 
     | 
    
         
            -
                                     'textPayload') do |entry, entry_index|
         
     | 
| 
       952 
     | 
    
         
            -
                    verify_default_log_entry_text(entry['textPayload'], entry_index,
         
     | 
| 
       953 
     | 
    
         
            -
                                                  entry)
         
     | 
| 
       954 
     | 
    
         
            -
                    assert_equal entry_log_names[entry_index], entry['logName']
         
     | 
| 
       955 
     | 
    
         
            -
                  end
         
     | 
| 
       956 
     | 
    
         
            -
                  # Verify the number of requests is different based on whether the
         
     | 
| 
       957 
     | 
    
         
            -
                  # 'split_logs_by_tag' flag is enabled.
         
     | 
| 
       958 
     | 
    
         
            -
                  assert_prometheus_metric_value(:stackdriver_successful_requests_count,
         
     | 
| 
       959 
     | 
    
         
            -
                                                 request_count, :aggregate)
         
     | 
| 
       960 
     | 
    
         
            -
                  assert_prometheus_metric_value(:stackdriver_ingested_entries_count,
         
     | 
| 
       961 
     | 
    
         
            -
                                                 log_entry_count, :aggregate)
         
     | 
| 
       962 
970 
     | 
    
         
             
                end
         
     | 
| 
       963 
971 
     | 
    
         
             
              end
         
     | 
| 
       964 
972 
     | 
    
         | 
| 
         @@ -1968,7 +1976,9 @@ module BaseTest 
     | 
|
| 
       1968 
1976 
     | 
    
         
             
                    expected = Time.now.to_i - start_time
         
     | 
| 
       1969 
1977 
     | 
    
         
             
                    d.instance.update_uptime
         
     | 
| 
       1970 
1978 
     | 
    
         
             
                    assert_metric_value.call(
         
     | 
| 
       1971 
     | 
    
         
            -
                      :uptime, expected,  
     | 
| 
      
 1979 
     | 
    
         
            +
                      :uptime, expected, 'agent.googleapis.com/agent',
         
     | 
| 
      
 1980 
     | 
    
         
            +
                      OpenCensus::Stats::Aggregation::Sum, d,
         
     | 
| 
      
 1981 
     | 
    
         
            +
                      version: Fluent::GoogleCloudOutput.version_string)
         
     | 
| 
       1972 
1982 
     | 
    
         
             
                  rescue Test::Unit::AssertionFailedError
         
     | 
| 
       1973 
1983 
     | 
    
         
             
                    retry if (retries += 1) < 3
         
     | 
| 
       1974 
1984 
     | 
    
         
             
                  end
         
     | 
| 
         @@ -1976,6 +1986,102 @@ module BaseTest 
     | 
|
| 
       1976 
1986 
     | 
    
         
             
                end
         
     | 
| 
       1977 
1987 
     | 
    
         
             
              end
         
     | 
| 
       1978 
1988 
     | 
    
         | 
| 
      
 1989 
     | 
    
         
            +
              def test_metrics
         
     | 
| 
      
 1990 
     | 
    
         
            +
                setup_gce_metadata_stubs
         
     | 
| 
      
 1991 
     | 
    
         
            +
                [
         
     | 
| 
      
 1992 
     | 
    
         
            +
                  [ENABLE_PROMETHEUS_CONFIG, method(:assert_prometheus_metric_value)],
         
     | 
| 
      
 1993 
     | 
    
         
            +
                  [ENABLE_OPENCENSUS_CONFIG, method(:assert_opencensus_metric_value)]
         
     | 
| 
      
 1994 
     | 
    
         
            +
                ].each do |config, assert_metric_value|
         
     | 
| 
      
 1995 
     | 
    
         
            +
                  [
         
     | 
| 
      
 1996 
     | 
    
         
            +
                    # Single successful request.
         
     | 
| 
      
 1997 
     | 
    
         
            +
                    [ok_status_code, 1, 1, [0, 0, 0]],
         
     | 
| 
      
 1998 
     | 
    
         
            +
                    # Several successful requests.
         
     | 
| 
      
 1999 
     | 
    
         
            +
                    [ok_status_code, 2, 1, [0, 0, 0]],
         
     | 
| 
      
 2000 
     | 
    
         
            +
                    # Single successful request with several entries.
         
     | 
| 
      
 2001 
     | 
    
         
            +
                    [ok_status_code, 1, 2, [0, 0, 0]],
         
     | 
| 
      
 2002 
     | 
    
         
            +
                    # Single failed request that causes logs to be dropped.
         
     | 
| 
      
 2003 
     | 
    
         
            +
                    [client_error_status_code, 1, 1, [1, 1, 0]],
         
     | 
| 
      
 2004 
     | 
    
         
            +
                    # Single failed request that escalates without logs being dropped with
         
     | 
| 
      
 2005 
     | 
    
         
            +
                    # several entries.
         
     | 
| 
      
 2006 
     | 
    
         
            +
                    [server_error_status_code, 1, 2, [0, 0, 2]]
         
     | 
| 
      
 2007 
     | 
    
         
            +
                  ].each do |code, request_count, entry_count, metric_values|
         
     | 
| 
      
 2008 
     | 
    
         
            +
                    clear_metrics
         
     | 
| 
      
 2009 
     | 
    
         
            +
                    setup_logging_stubs(nil, code, 'SomeMessage') do
         
     | 
| 
      
 2010 
     | 
    
         
            +
                      (1..request_count).each do |request_index|
         
     | 
| 
      
 2011 
     | 
    
         
            +
                        d = create_driver(config)
         
     | 
| 
      
 2012 
     | 
    
         
            +
                        (1..entry_count).each do |entry_index|
         
     | 
| 
      
 2013 
     | 
    
         
            +
                          d.emit('message' => log_entry(entry_index.to_s))
         
     | 
| 
      
 2014 
     | 
    
         
            +
                        end
         
     | 
| 
      
 2015 
     | 
    
         
            +
                        # rubocop:disable Lint/HandleExceptions
         
     | 
| 
      
 2016 
     | 
    
         
            +
                        begin
         
     | 
| 
      
 2017 
     | 
    
         
            +
                          d.run
         
     | 
| 
      
 2018 
     | 
    
         
            +
                        rescue mock_error_type
         
     | 
| 
      
 2019 
     | 
    
         
            +
                        end
         
     | 
| 
      
 2020 
     | 
    
         
            +
                        # rubocop:enable Lint/HandleExceptions
         
     | 
| 
      
 2021 
     | 
    
         
            +
                        failed_requests_count, dropped_entries_count,
         
     | 
| 
      
 2022 
     | 
    
         
            +
                        retried_entries_count = metric_values
         
     | 
| 
      
 2023 
     | 
    
         
            +
             
     | 
| 
      
 2024 
     | 
    
         
            +
                        successful_requests_count = \
         
     | 
| 
      
 2025 
     | 
    
         
            +
                          if code != ok_status_code
         
     | 
| 
      
 2026 
     | 
    
         
            +
                            0
         
     | 
| 
      
 2027 
     | 
    
         
            +
                          elsif config == ENABLE_OPENCENSUS_CONFIG
         
     | 
| 
      
 2028 
     | 
    
         
            +
                            # TODO(b/173215689) Improve the Open Census side of testing.
         
     | 
| 
      
 2029 
     | 
    
         
            +
                            # The test driver instance variables can not survive between
         
     | 
| 
      
 2030 
     | 
    
         
            +
                            # test driver runs. So the open cencensus side counter gets
         
     | 
| 
      
 2031 
     | 
    
         
            +
                            # reset as expected.
         
     | 
| 
      
 2032 
     | 
    
         
            +
                            1
         
     | 
| 
      
 2033 
     | 
    
         
            +
                          else
         
     | 
| 
      
 2034 
     | 
    
         
            +
                            request_index
         
     | 
| 
      
 2035 
     | 
    
         
            +
                          end
         
     | 
| 
      
 2036 
     | 
    
         
            +
             
     | 
| 
      
 2037 
     | 
    
         
            +
                        ingested_entries_count = \
         
     | 
| 
      
 2038 
     | 
    
         
            +
                          if code != ok_status_code
         
     | 
| 
      
 2039 
     | 
    
         
            +
                            0
         
     | 
| 
      
 2040 
     | 
    
         
            +
                          elsif config == ENABLE_OPENCENSUS_CONFIG
         
     | 
| 
      
 2041 
     | 
    
         
            +
                            # TODO(b/173215689) Improve the Open Census side of testing.
         
     | 
| 
      
 2042 
     | 
    
         
            +
                            # The test driver instance variables can not survive between
         
     | 
| 
      
 2043 
     | 
    
         
            +
                            # test driver runs. So the open cencensus side counter gets
         
     | 
| 
      
 2044 
     | 
    
         
            +
                            # reset as expected.
         
     | 
| 
      
 2045 
     | 
    
         
            +
                            entry_count
         
     | 
| 
      
 2046 
     | 
    
         
            +
                          else
         
     | 
| 
      
 2047 
     | 
    
         
            +
                            request_index * entry_count
         
     | 
| 
      
 2048 
     | 
    
         
            +
                          end
         
     | 
| 
      
 2049 
     | 
    
         
            +
             
     | 
| 
      
 2050 
     | 
    
         
            +
                        assert_metric_value.call(:stackdriver_successful_requests_count,
         
     | 
| 
      
 2051 
     | 
    
         
            +
                                                 successful_requests_count,
         
     | 
| 
      
 2052 
     | 
    
         
            +
                                                 'agent.googleapis.com/agent',
         
     | 
| 
      
 2053 
     | 
    
         
            +
                                                 OpenCensus::Stats::Aggregation::Sum, d,
         
     | 
| 
      
 2054 
     | 
    
         
            +
                                                 grpc: use_grpc, code: ok_status_code)
         
     | 
| 
      
 2055 
     | 
    
         
            +
                        assert_metric_value.call(:stackdriver_ingested_entries_count,
         
     | 
| 
      
 2056 
     | 
    
         
            +
                                                 ingested_entries_count,
         
     | 
| 
      
 2057 
     | 
    
         
            +
                                                 'agent.googleapis.com/agent',
         
     | 
| 
      
 2058 
     | 
    
         
            +
                                                 OpenCensus::Stats::Aggregation::Sum, d,
         
     | 
| 
      
 2059 
     | 
    
         
            +
                                                 grpc: use_grpc, code: ok_status_code)
         
     | 
| 
      
 2060 
     | 
    
         
            +
                        assert_metric_value.call(:stackdriver_retried_entries_count,
         
     | 
| 
      
 2061 
     | 
    
         
            +
                                                 retried_entries_count,
         
     | 
| 
      
 2062 
     | 
    
         
            +
                                                 'agent.googleapis.com/agent',
         
     | 
| 
      
 2063 
     | 
    
         
            +
                                                 OpenCensus::Stats::Aggregation::Sum, d,
         
     | 
| 
      
 2064 
     | 
    
         
            +
                                                 grpc: use_grpc, code: code)
         
     | 
| 
      
 2065 
     | 
    
         
            +
                        # Skip failure assertions when code indicates success, because the
         
     | 
| 
      
 2066 
     | 
    
         
            +
                        # assertion will fail in the case when a single metric contains time
         
     | 
| 
      
 2067 
     | 
    
         
            +
                        # series with success and failure events.
         
     | 
| 
      
 2068 
     | 
    
         
            +
                        next if code == ok_status_code
         
     | 
| 
      
 2069 
     | 
    
         
            +
                        assert_metric_value.call(:stackdriver_failed_requests_count,
         
     | 
| 
      
 2070 
     | 
    
         
            +
                                                 failed_requests_count,
         
     | 
| 
      
 2071 
     | 
    
         
            +
                                                 'agent.googleapis.com/agent',
         
     | 
| 
      
 2072 
     | 
    
         
            +
                                                 OpenCensus::Stats::Aggregation::Sum, d,
         
     | 
| 
      
 2073 
     | 
    
         
            +
                                                 grpc: use_grpc, code: code)
         
     | 
| 
      
 2074 
     | 
    
         
            +
                        assert_metric_value.call(:stackdriver_dropped_entries_count,
         
     | 
| 
      
 2075 
     | 
    
         
            +
                                                 dropped_entries_count,
         
     | 
| 
      
 2076 
     | 
    
         
            +
                                                 'agent.googleapis.com/agent',
         
     | 
| 
      
 2077 
     | 
    
         
            +
                                                 OpenCensus::Stats::Aggregation::Sum, d,
         
     | 
| 
      
 2078 
     | 
    
         
            +
                                                 grpc: use_grpc, code: code)
         
     | 
| 
      
 2079 
     | 
    
         
            +
                      end
         
     | 
| 
      
 2080 
     | 
    
         
            +
                    end
         
     | 
| 
      
 2081 
     | 
    
         
            +
                  end
         
     | 
| 
      
 2082 
     | 
    
         
            +
                end
         
     | 
| 
      
 2083 
     | 
    
         
            +
              end
         
     | 
| 
      
 2084 
     | 
    
         
            +
             
     | 
| 
       1979 
2085 
     | 
    
         
             
              private
         
     | 
| 
       1980 
2086 
     | 
    
         | 
| 
       1981 
2087 
     | 
    
         
             
              # Provide a stub context that initializes @logs_sent, executes the block and
         
     | 
| 
         @@ -2456,7 +2562,32 @@ module BaseTest 
     | 
|
| 
       2456 
2562 
     | 
    
         
             
              end
         
     | 
| 
       2457 
2563 
     | 
    
         | 
| 
       2458 
2564 
     | 
    
         
             
              # Set up http or grpc stubs to mock the external calls.
         
     | 
| 
       2459 
     | 
    
         
            -
              def setup_logging_stubs
         
     | 
| 
      
 2565 
     | 
    
         
            +
              def setup_logging_stubs(_error = nil, _code = nil, _message = nil)
         
     | 
| 
      
 2566 
     | 
    
         
            +
                _undefined
         
     | 
| 
      
 2567 
     | 
    
         
            +
              end
         
     | 
| 
      
 2568 
     | 
    
         
            +
             
     | 
| 
      
 2569 
     | 
    
         
            +
              # Whether this is the grpc path
         
     | 
| 
      
 2570 
     | 
    
         
            +
              def use_grpc
         
     | 
| 
      
 2571 
     | 
    
         
            +
                _undefined
         
     | 
| 
      
 2572 
     | 
    
         
            +
              end
         
     | 
| 
      
 2573 
     | 
    
         
            +
             
     | 
| 
      
 2574 
     | 
    
         
            +
              # The OK status code.
         
     | 
| 
      
 2575 
     | 
    
         
            +
              def ok_status_code
         
     | 
| 
      
 2576 
     | 
    
         
            +
                _undefined
         
     | 
| 
      
 2577 
     | 
    
         
            +
              end
         
     | 
| 
      
 2578 
     | 
    
         
            +
             
     | 
| 
      
 2579 
     | 
    
         
            +
              # A client side error status code.
         
     | 
| 
      
 2580 
     | 
    
         
            +
              def client_error_status_code
         
     | 
| 
      
 2581 
     | 
    
         
            +
                _undefined
         
     | 
| 
      
 2582 
     | 
    
         
            +
              end
         
     | 
| 
      
 2583 
     | 
    
         
            +
             
     | 
| 
      
 2584 
     | 
    
         
            +
              # A server side error status code.
         
     | 
| 
      
 2585 
     | 
    
         
            +
              def server_error_status_code
         
     | 
| 
      
 2586 
     | 
    
         
            +
                _undefined
         
     | 
| 
      
 2587 
     | 
    
         
            +
              end
         
     | 
| 
      
 2588 
     | 
    
         
            +
             
     | 
| 
      
 2589 
     | 
    
         
            +
              # The parent error type to expect in the mock
         
     | 
| 
      
 2590 
     | 
    
         
            +
              def mock_error_type
         
     | 
| 
       2460 
2591 
     | 
    
         
             
                _undefined
         
     | 
| 
       2461 
2592 
     | 
    
         
             
              end
         
     | 
| 
       2462 
2593 
     | 
    
         | 
| 
         @@ -51,12 +51,15 @@ class FilterAnalyzeConfigTest < Test::Unit::TestCase 
     | 
|
| 
       51 
51 
     | 
    
         
             
                   method(:assert_opencensus_metric_value)]
         
     | 
| 
       52 
52 
     | 
    
         
             
                ].each do |config, assert_metric_value|
         
     | 
| 
       53 
53 
     | 
    
         
             
                  clear_metrics
         
     | 
| 
       54 
     | 
    
         
            -
                  create_driver(config)
         
     | 
| 
      
 54 
     | 
    
         
            +
                  d = create_driver(config)
         
     | 
| 
       55 
55 
     | 
    
         | 
| 
       56 
56 
     | 
    
         
             
                  # Default plugins, with default config.
         
     | 
| 
       57 
57 
     | 
    
         
             
                  assert_metric_value.call(
         
     | 
| 
       58 
58 
     | 
    
         
             
                    :enabled_plugins,
         
     | 
| 
       59 
59 
     | 
    
         
             
                    1,
         
     | 
| 
      
 60 
     | 
    
         
            +
                    'agent.googleapis.com/agent/internal/logging/config',
         
     | 
| 
      
 61 
     | 
    
         
            +
                    OpenCensus::Stats::Aggregation::LastValue,
         
     | 
| 
      
 62 
     | 
    
         
            +
                    d,
         
     | 
| 
       60 
63 
     | 
    
         
             
                    plugin_name: 'source/syslog/tcp',
         
     | 
| 
       61 
64 
     | 
    
         
             
                    is_default_plugin: true,
         
     | 
| 
       62 
65 
     | 
    
         
             
                    has_default_config: true,
         
     | 
| 
         @@ -64,6 +67,9 @@ class FilterAnalyzeConfigTest < Test::Unit::TestCase 
     | 
|
| 
       64 
67 
     | 
    
         
             
                  assert_metric_value.call(
         
     | 
| 
       65 
68 
     | 
    
         
             
                    :enabled_plugins,
         
     | 
| 
       66 
69 
     | 
    
         
             
                    1,
         
     | 
| 
      
 70 
     | 
    
         
            +
                    'agent.googleapis.com/agent/internal/logging/config',
         
     | 
| 
      
 71 
     | 
    
         
            +
                    OpenCensus::Stats::Aggregation::LastValue,
         
     | 
| 
      
 72 
     | 
    
         
            +
                    d,
         
     | 
| 
       67 
73 
     | 
    
         
             
                    plugin_name: 'source/tail/apache-access',
         
     | 
| 
       68 
74 
     | 
    
         
             
                    is_default_plugin: true,
         
     | 
| 
       69 
75 
     | 
    
         
             
                    has_default_config: true,
         
     | 
| 
         @@ -71,6 +77,9 @@ class FilterAnalyzeConfigTest < Test::Unit::TestCase 
     | 
|
| 
       71 
77 
     | 
    
         
             
                  assert_metric_value.call(
         
     | 
| 
       72 
78 
     | 
    
         
             
                    :enabled_plugins,
         
     | 
| 
       73 
79 
     | 
    
         
             
                    1,
         
     | 
| 
      
 80 
     | 
    
         
            +
                    'agent.googleapis.com/agent/internal/logging/config',
         
     | 
| 
      
 81 
     | 
    
         
            +
                    OpenCensus::Stats::Aggregation::LastValue,
         
     | 
| 
      
 82 
     | 
    
         
            +
                    d,
         
     | 
| 
       74 
83 
     | 
    
         
             
                    plugin_name: 'filter/add_insert_ids',
         
     | 
| 
       75 
84 
     | 
    
         
             
                    is_default_plugin: true,
         
     | 
| 
       76 
85 
     | 
    
         
             
                    has_default_config: true,
         
     | 
| 
         @@ -80,6 +89,9 @@ class FilterAnalyzeConfigTest < Test::Unit::TestCase 
     | 
|
| 
       80 
89 
     | 
    
         
             
                  assert_metric_value.call(
         
     | 
| 
       81 
90 
     | 
    
         
             
                    :enabled_plugins,
         
     | 
| 
       82 
91 
     | 
    
         
             
                    1,
         
     | 
| 
      
 92 
     | 
    
         
            +
                    'agent.googleapis.com/agent/internal/logging/config',
         
     | 
| 
      
 93 
     | 
    
         
            +
                    OpenCensus::Stats::Aggregation::LastValue,
         
     | 
| 
      
 94 
     | 
    
         
            +
                    d,
         
     | 
| 
       83 
95 
     | 
    
         
             
                    plugin_name: 'match/google_cloud',
         
     | 
| 
       84 
96 
     | 
    
         
             
                    is_default_plugin: true,
         
     | 
| 
       85 
97 
     | 
    
         
             
                    has_default_config: false,
         
     | 
| 
         @@ -89,6 +101,9 @@ class FilterAnalyzeConfigTest < Test::Unit::TestCase 
     | 
|
| 
       89 
101 
     | 
    
         
             
                  assert_metric_value.call(
         
     | 
| 
       90 
102 
     | 
    
         
             
                    :enabled_plugins,
         
     | 
| 
       91 
103 
     | 
    
         
             
                    1,
         
     | 
| 
      
 104 
     | 
    
         
            +
                    'agent.googleapis.com/agent/internal/logging/config',
         
     | 
| 
      
 105 
     | 
    
         
            +
                    OpenCensus::Stats::Aggregation::LastValue,
         
     | 
| 
      
 106 
     | 
    
         
            +
                    d,
         
     | 
| 
       92 
107 
     | 
    
         
             
                    plugin_name: 'filter',
         
     | 
| 
       93 
108 
     | 
    
         
             
                    is_default_plugin: false,
         
     | 
| 
       94 
109 
     | 
    
         
             
                    has_default_config: false,
         
     | 
| 
         @@ -96,6 +111,9 @@ class FilterAnalyzeConfigTest < Test::Unit::TestCase 
     | 
|
| 
       96 
111 
     | 
    
         
             
                  assert_metric_value.call(
         
     | 
| 
       97 
112 
     | 
    
         
             
                    :enabled_plugins,
         
     | 
| 
       98 
113 
     | 
    
         
             
                    1,
         
     | 
| 
      
 114 
     | 
    
         
            +
                    'agent.googleapis.com/agent/internal/logging/config',
         
     | 
| 
      
 115 
     | 
    
         
            +
                    OpenCensus::Stats::Aggregation::LastValue,
         
     | 
| 
      
 116 
     | 
    
         
            +
                    d,
         
     | 
| 
       99 
117 
     | 
    
         
             
                    plugin_name: 'filter/record_transformer',
         
     | 
| 
       100 
118 
     | 
    
         
             
                    is_default_plugin: false,
         
     | 
| 
       101 
119 
     | 
    
         
             
                    has_default_config: false,
         
     | 
| 
         @@ -103,6 +121,9 @@ class FilterAnalyzeConfigTest < Test::Unit::TestCase 
     | 
|
| 
       103 
121 
     | 
    
         
             
                  assert_metric_value.call(
         
     | 
| 
       104 
122 
     | 
    
         
             
                    :enabled_plugins,
         
     | 
| 
       105 
123 
     | 
    
         
             
                    1,
         
     | 
| 
      
 124 
     | 
    
         
            +
                    'agent.googleapis.com/agent/internal/logging/config',
         
     | 
| 
      
 125 
     | 
    
         
            +
                    OpenCensus::Stats::Aggregation::LastValue,
         
     | 
| 
      
 126 
     | 
    
         
            +
                    d,
         
     | 
| 
       106 
127 
     | 
    
         
             
                    plugin_name: 'match/stdout',
         
     | 
| 
       107 
128 
     | 
    
         
             
                    is_default_plugin: false,
         
     | 
| 
       108 
129 
     | 
    
         
             
                    has_default_config: false,
         
     | 
| 
         @@ -112,6 +133,9 @@ class FilterAnalyzeConfigTest < Test::Unit::TestCase 
     | 
|
| 
       112 
133 
     | 
    
         
             
                  assert_metric_value.call(
         
     | 
| 
       113 
134 
     | 
    
         
             
                    :plugin_config,
         
     | 
| 
       114 
135 
     | 
    
         
             
                    1,
         
     | 
| 
      
 136 
     | 
    
         
            +
                    'agent.googleapis.com/agent/internal/logging/config',
         
     | 
| 
      
 137 
     | 
    
         
            +
                    OpenCensus::Stats::Aggregation::LastValue,
         
     | 
| 
      
 138 
     | 
    
         
            +
                    d,
         
     | 
| 
       115 
139 
     | 
    
         
             
                    plugin_name: 'google_cloud',
         
     | 
| 
       116 
140 
     | 
    
         
             
                    param: 'adjust_invalid_timestamps',
         
     | 
| 
       117 
141 
     | 
    
         
             
                    is_present: true,
         
     | 
| 
         @@ -119,6 +143,9 @@ class FilterAnalyzeConfigTest < Test::Unit::TestCase 
     | 
|
| 
       119 
143 
     | 
    
         
             
                  assert_metric_value.call(
         
     | 
| 
       120 
144 
     | 
    
         
             
                    :plugin_config,
         
     | 
| 
       121 
145 
     | 
    
         
             
                    1,
         
     | 
| 
      
 146 
     | 
    
         
            +
                    'agent.googleapis.com/agent/internal/logging/config',
         
     | 
| 
      
 147 
     | 
    
         
            +
                    OpenCensus::Stats::Aggregation::LastValue,
         
     | 
| 
      
 148 
     | 
    
         
            +
                    d,
         
     | 
| 
       122 
149 
     | 
    
         
             
                    plugin_name: 'google_cloud',
         
     | 
| 
       123 
150 
     | 
    
         
             
                    param: 'autoformat_stackdriver_trace',
         
     | 
| 
       124 
151 
     | 
    
         
             
                    is_present: true,
         
     | 
| 
         @@ -126,6 +153,9 @@ class FilterAnalyzeConfigTest < Test::Unit::TestCase 
     | 
|
| 
       126 
153 
     | 
    
         
             
                  assert_metric_value.call(
         
     | 
| 
       127 
154 
     | 
    
         
             
                    :plugin_config,
         
     | 
| 
       128 
155 
     | 
    
         
             
                    1,
         
     | 
| 
      
 156 
     | 
    
         
            +
                    'agent.googleapis.com/agent/internal/logging/config',
         
     | 
| 
      
 157 
     | 
    
         
            +
                    OpenCensus::Stats::Aggregation::LastValue,
         
     | 
| 
      
 158 
     | 
    
         
            +
                    d,
         
     | 
| 
       129 
159 
     | 
    
         
             
                    plugin_name: 'google_cloud',
         
     | 
| 
       130 
160 
     | 
    
         
             
                    param: 'coerce_to_utf8',
         
     | 
| 
       131 
161 
     | 
    
         
             
                    is_present: true,
         
     | 
| 
         @@ -165,6 +195,9 @@ class FilterAnalyzeConfigTest < Test::Unit::TestCase 
     | 
|
| 
       165 
195 
     | 
    
         
             
                    assert_metric_value.call(
         
     | 
| 
       166 
196 
     | 
    
         
             
                      :plugin_config,
         
     | 
| 
       167 
197 
     | 
    
         
             
                      1,
         
     | 
| 
      
 198 
     | 
    
         
            +
                      'agent.googleapis.com/agent/internal/logging/config',
         
     | 
| 
      
 199 
     | 
    
         
            +
                      OpenCensus::Stats::Aggregation::LastValue,
         
     | 
| 
      
 200 
     | 
    
         
            +
                      d,
         
     | 
| 
       168 
201 
     | 
    
         
             
                      plugin_name: 'google_cloud',
         
     | 
| 
       169 
202 
     | 
    
         
             
                      param: p,
         
     | 
| 
       170 
203 
     | 
    
         
             
                      is_present: false,
         
     | 
| 
         @@ -175,18 +208,27 @@ class FilterAnalyzeConfigTest < Test::Unit::TestCase 
     | 
|
| 
       175 
208 
     | 
    
         
             
                  assert_metric_value.call(
         
     | 
| 
       176 
209 
     | 
    
         
             
                    :config_bool_values,
         
     | 
| 
       177 
210 
     | 
    
         
             
                    1,
         
     | 
| 
      
 211 
     | 
    
         
            +
                    'agent.googleapis.com/agent/internal/logging/config',
         
     | 
| 
      
 212 
     | 
    
         
            +
                    OpenCensus::Stats::Aggregation::LastValue,
         
     | 
| 
      
 213 
     | 
    
         
            +
                    d,
         
     | 
| 
       178 
214 
     | 
    
         
             
                    plugin_name: 'google_cloud',
         
     | 
| 
       179 
215 
     | 
    
         
             
                    param: 'adjust_invalid_timestamps',
         
     | 
| 
       180 
216 
     | 
    
         
             
                    value: true)
         
     | 
| 
       181 
217 
     | 
    
         
             
                  assert_metric_value.call(
         
     | 
| 
       182 
218 
     | 
    
         
             
                    :config_bool_values,
         
     | 
| 
       183 
219 
     | 
    
         
             
                    1,
         
     | 
| 
      
 220 
     | 
    
         
            +
                    'agent.googleapis.com/agent/internal/logging/config',
         
     | 
| 
      
 221 
     | 
    
         
            +
                    OpenCensus::Stats::Aggregation::LastValue,
         
     | 
| 
      
 222 
     | 
    
         
            +
                    d,
         
     | 
| 
       184 
223 
     | 
    
         
             
                    plugin_name: 'google_cloud',
         
     | 
| 
       185 
224 
     | 
    
         
             
                    param: 'autoformat_stackdriver_trace',
         
     | 
| 
       186 
225 
     | 
    
         
             
                    value: false)
         
     | 
| 
       187 
226 
     | 
    
         
             
                  assert_metric_value.call(
         
     | 
| 
       188 
227 
     | 
    
         
             
                    :config_bool_values,
         
     | 
| 
       189 
228 
     | 
    
         
             
                    1,
         
     | 
| 
      
 229 
     | 
    
         
            +
                    'agent.googleapis.com/agent/internal/logging/config',
         
     | 
| 
      
 230 
     | 
    
         
            +
                    OpenCensus::Stats::Aggregation::LastValue,
         
     | 
| 
      
 231 
     | 
    
         
            +
                    d,
         
     | 
| 
       190 
232 
     | 
    
         
             
                    plugin_name: 'google_cloud',
         
     | 
| 
       191 
233 
     | 
    
         
             
                    param: 'coerce_to_utf8',
         
     | 
| 
       192 
234 
     | 
    
         
             
                    value: true)
         
     | 
| 
         @@ -86,13 +86,21 @@ class GoogleCloudOutputTest < Test::Unit::TestCase 
     | 
|
| 
       86 
86 
     | 
    
         
             
                end
         
     | 
| 
       87 
87 
     | 
    
         
             
                d.run
         
     | 
| 
       88 
88 
     | 
    
         
             
                assert_prometheus_metric_value(
         
     | 
| 
       89 
     | 
    
         
            -
                  :stackdriver_successful_requests_count, 1, 
     | 
| 
      
 89 
     | 
    
         
            +
                  :stackdriver_successful_requests_count, 1,
         
     | 
| 
      
 90 
     | 
    
         
            +
                  'agent.googleapis.com/agent', OpenCensus::Stats::Aggregation::Sum, d,
         
     | 
| 
      
 91 
     | 
    
         
            +
                  grpc: false, code: 200)
         
     | 
| 
       90 
92 
     | 
    
         
             
                assert_prometheus_metric_value(
         
     | 
| 
       91 
     | 
    
         
            -
                  :stackdriver_ingested_entries_count, 1, 
     | 
| 
      
 93 
     | 
    
         
            +
                  :stackdriver_ingested_entries_count, 1,
         
     | 
| 
      
 94 
     | 
    
         
            +
                  'agent.googleapis.com/agent', OpenCensus::Stats::Aggregation::Sum, d,
         
     | 
| 
      
 95 
     | 
    
         
            +
                  grpc: false, code: 200)
         
     | 
| 
       92 
96 
     | 
    
         
             
                assert_prometheus_metric_value(
         
     | 
| 
       93 
     | 
    
         
            -
                  :stackdriver_dropped_entries_count, 2, 
     | 
| 
      
 97 
     | 
    
         
            +
                  :stackdriver_dropped_entries_count, 2,
         
     | 
| 
      
 98 
     | 
    
         
            +
                  'agent.googleapis.com/agent', OpenCensus::Stats::Aggregation::Sum, d,
         
     | 
| 
      
 99 
     | 
    
         
            +
                  grpc: false, code: 3)
         
     | 
| 
       94 
100 
     | 
    
         
             
                assert_prometheus_metric_value(
         
     | 
| 
       95 
     | 
    
         
            -
                  :stackdriver_dropped_entries_count, 1, 
     | 
| 
      
 101 
     | 
    
         
            +
                  :stackdriver_dropped_entries_count, 1,
         
     | 
| 
      
 102 
     | 
    
         
            +
                  'agent.googleapis.com/agent', OpenCensus::Stats::Aggregation::Sum, d,
         
     | 
| 
      
 103 
     | 
    
         
            +
                  grpc: false, code: 7)
         
     | 
| 
       96 
104 
     | 
    
         
             
                assert_requested(:post, WRITE_LOG_ENTRIES_URI, times: 1)
         
     | 
| 
       97 
105 
     | 
    
         
             
              end
         
     | 
| 
       98 
106 
     | 
    
         | 
| 
         @@ -109,13 +117,21 @@ class GoogleCloudOutputTest < Test::Unit::TestCase 
     | 
|
| 
       109 
117 
     | 
    
         
             
                d.emit('message' => log_entry(0))
         
     | 
| 
       110 
118 
     | 
    
         
             
                d.run
         
     | 
| 
       111 
119 
     | 
    
         
             
                assert_prometheus_metric_value(
         
     | 
| 
       112 
     | 
    
         
            -
                  :stackdriver_successful_requests_count, 0, 
     | 
| 
      
 120 
     | 
    
         
            +
                  :stackdriver_successful_requests_count, 0,
         
     | 
| 
      
 121 
     | 
    
         
            +
                  'agent.googleapis.com/agent', OpenCensus::Stats::Aggregation::Sum, d,
         
     | 
| 
      
 122 
     | 
    
         
            +
                  grpc: false, code: 200)
         
     | 
| 
       113 
123 
     | 
    
         
             
                assert_prometheus_metric_value(
         
     | 
| 
       114 
     | 
    
         
            -
                  :stackdriver_failed_requests_count, 1, 
     | 
| 
      
 124 
     | 
    
         
            +
                  :stackdriver_failed_requests_count, 1,
         
     | 
| 
      
 125 
     | 
    
         
            +
                  'agent.googleapis.com/agent', OpenCensus::Stats::Aggregation::Sum, d,
         
     | 
| 
      
 126 
     | 
    
         
            +
                  grpc: false, code: 400)
         
     | 
| 
       115 
127 
     | 
    
         
             
                assert_prometheus_metric_value(
         
     | 
| 
       116 
     | 
    
         
            -
                  :stackdriver_ingested_entries_count, 0, 
     | 
| 
      
 128 
     | 
    
         
            +
                  :stackdriver_ingested_entries_count, 0,
         
     | 
| 
      
 129 
     | 
    
         
            +
                  'agent.googleapis.com/agent', OpenCensus::Stats::Aggregation::Sum, d,
         
     | 
| 
      
 130 
     | 
    
         
            +
                  grpc: false, code: 200)
         
     | 
| 
       117 
131 
     | 
    
         
             
                assert_prometheus_metric_value(
         
     | 
| 
       118 
     | 
    
         
            -
                  :stackdriver_dropped_entries_count, 1, 
     | 
| 
      
 132 
     | 
    
         
            +
                  :stackdriver_dropped_entries_count, 1,
         
     | 
| 
      
 133 
     | 
    
         
            +
                  'agent.googleapis.com/agent', OpenCensus::Stats::Aggregation::Sum, d,
         
     | 
| 
      
 134 
     | 
    
         
            +
                  grpc: false, code: 400)
         
     | 
| 
       119 
135 
     | 
    
         
             
                assert_requested(:post, WRITE_LOG_ENTRIES_URI, times: 1)
         
     | 
| 
       120 
136 
     | 
    
         
             
              end
         
     | 
| 
       121 
137 
     | 
    
         | 
| 
         @@ -138,71 +154,6 @@ class GoogleCloudOutputTest < Test::Unit::TestCase 
     | 
|
| 
       138 
154 
     | 
    
         
             
                assert_equal 1, exception_count
         
     | 
| 
       139 
155 
     | 
    
         
             
              end
         
     | 
| 
       140 
156 
     | 
    
         | 
| 
       141 
     | 
    
         
            -
              # TODO: The code in the non-gRPC and gRPC tests is nearly identical.
         
     | 
| 
       142 
     | 
    
         
            -
              # Refactor and remove duplication.
         
     | 
| 
       143 
     | 
    
         
            -
              # TODO: Use status codes instead of int literals.
         
     | 
| 
       144 
     | 
    
         
            -
              def test_metrics
         
     | 
| 
       145 
     | 
    
         
            -
                setup_gce_metadata_stubs
         
     | 
| 
       146 
     | 
    
         
            -
                [
         
     | 
| 
       147 
     | 
    
         
            -
                  [ENABLE_PROMETHEUS_CONFIG, method(:assert_prometheus_metric_value)],
         
     | 
| 
       148 
     | 
    
         
            -
                  [ENABLE_OPENCENSUS_CONFIG, method(:assert_opencensus_metric_value)]
         
     | 
| 
       149 
     | 
    
         
            -
                ].each do |config, assert_metric_value|
         
     | 
| 
       150 
     | 
    
         
            -
                  [
         
     | 
| 
       151 
     | 
    
         
            -
                    # Single successful request.
         
     | 
| 
       152 
     | 
    
         
            -
                    [200, 1, 1, [1, 0, 1, 0, 0]],
         
     | 
| 
       153 
     | 
    
         
            -
                    # Several successful requests.
         
     | 
| 
       154 
     | 
    
         
            -
                    [200, 2, 1, [2, 0, 2, 0, 0]],
         
     | 
| 
       155 
     | 
    
         
            -
                    # Single successful request with several entries.
         
     | 
| 
       156 
     | 
    
         
            -
                    [200, 1, 2, [1, 0, 2, 0, 0]],
         
     | 
| 
       157 
     | 
    
         
            -
                    # Single failed request that causes logs to be dropped.
         
     | 
| 
       158 
     | 
    
         
            -
                    [401, 1, 1, [0, 1, 0, 1, 0]],
         
     | 
| 
       159 
     | 
    
         
            -
                    # Single failed request that escalates without logs being dropped with
         
     | 
| 
       160 
     | 
    
         
            -
                    # several entries.
         
     | 
| 
       161 
     | 
    
         
            -
                    [500, 1, 2, [0, 0, 0, 0, 2]]
         
     | 
| 
       162 
     | 
    
         
            -
                  ].each do |code, request_count, entry_count, metric_values|
         
     | 
| 
       163 
     | 
    
         
            -
                    clear_metrics
         
     | 
| 
       164 
     | 
    
         
            -
                    # TODO: Do this as part of setup_logging_stubs.
         
     | 
| 
       165 
     | 
    
         
            -
                    stub_request(:post, WRITE_LOG_ENTRIES_URI)
         
     | 
| 
       166 
     | 
    
         
            -
                      .to_return(status: code, body: 'Some Message')
         
     | 
| 
       167 
     | 
    
         
            -
                    (1..request_count).each do
         
     | 
| 
       168 
     | 
    
         
            -
                      d = create_driver(config)
         
     | 
| 
       169 
     | 
    
         
            -
                      (1..entry_count).each do |i|
         
     | 
| 
       170 
     | 
    
         
            -
                        d.emit('message' => log_entry(i.to_s))
         
     | 
| 
       171 
     | 
    
         
            -
                      end
         
     | 
| 
       172 
     | 
    
         
            -
                      # rubocop:disable Lint/HandleExceptions
         
     | 
| 
       173 
     | 
    
         
            -
                      begin
         
     | 
| 
       174 
     | 
    
         
            -
                        d.run
         
     | 
| 
       175 
     | 
    
         
            -
                      rescue Google::Apis::AuthorizationError
         
     | 
| 
       176 
     | 
    
         
            -
                      rescue Google::Apis::ServerError
         
     | 
| 
       177 
     | 
    
         
            -
                      end
         
     | 
| 
       178 
     | 
    
         
            -
                      # rubocop:enable Lint/HandleExceptions
         
     | 
| 
       179 
     | 
    
         
            -
                    end
         
     | 
| 
       180 
     | 
    
         
            -
                    successful_requests_count, failed_requests_count,
         
     | 
| 
       181 
     | 
    
         
            -
                    ingested_entries_count, dropped_entries_count,
         
     | 
| 
       182 
     | 
    
         
            -
                    retried_entries_count = metric_values
         
     | 
| 
       183 
     | 
    
         
            -
                    assert_metric_value.call(:stackdriver_successful_requests_count,
         
     | 
| 
       184 
     | 
    
         
            -
                                             successful_requests_count,
         
     | 
| 
       185 
     | 
    
         
            -
                                             grpc: false, code: 200)
         
     | 
| 
       186 
     | 
    
         
            -
                    assert_metric_value.call(:stackdriver_ingested_entries_count,
         
     | 
| 
       187 
     | 
    
         
            -
                                             ingested_entries_count,
         
     | 
| 
       188 
     | 
    
         
            -
                                             grpc: false, code: 200)
         
     | 
| 
       189 
     | 
    
         
            -
                    assert_metric_value.call(:stackdriver_retried_entries_count,
         
     | 
| 
       190 
     | 
    
         
            -
                                             retried_entries_count,
         
     | 
| 
       191 
     | 
    
         
            -
                                             grpc: false, code: code)
         
     | 
| 
       192 
     | 
    
         
            -
                    # Skip failure assertions when code indicates success, because the
         
     | 
| 
       193 
     | 
    
         
            -
                    # assertion will fail in the case when a single metric contains time
         
     | 
| 
       194 
     | 
    
         
            -
                    # series with success and failure events.
         
     | 
| 
       195 
     | 
    
         
            -
                    next if code == 200
         
     | 
| 
       196 
     | 
    
         
            -
                    assert_metric_value.call(:stackdriver_failed_requests_count,
         
     | 
| 
       197 
     | 
    
         
            -
                                             failed_requests_count,
         
     | 
| 
       198 
     | 
    
         
            -
                                             grpc: false, code: code)
         
     | 
| 
       199 
     | 
    
         
            -
                    assert_metric_value.call(:stackdriver_dropped_entries_count,
         
     | 
| 
       200 
     | 
    
         
            -
                                             dropped_entries_count,
         
     | 
| 
       201 
     | 
    
         
            -
                                             grpc: false, code: code)
         
     | 
| 
       202 
     | 
    
         
            -
                  end
         
     | 
| 
       203 
     | 
    
         
            -
                end
         
     | 
| 
       204 
     | 
    
         
            -
              end
         
     | 
| 
       205 
     | 
    
         
            -
             
     | 
| 
       206 
157 
     | 
    
         
             
              # This test looks similar between the grpc and non-grpc paths except that when
         
     | 
| 
       207 
158 
     | 
    
         
             
              # parsing "105", the grpc path responds with "DEBUG", while the non-grpc path
         
     | 
| 
       208 
159 
     | 
    
         
             
              # responds with "100".
         
     | 
| 
         @@ -400,14 +351,39 @@ class GoogleCloudOutputTest < Test::Unit::TestCase 
     | 
|
| 
       400 
351 
     | 
    
         
             
              end
         
     | 
| 
       401 
352 
     | 
    
         | 
| 
       402 
353 
     | 
    
         
             
              # Set up http stubs to mock the external calls.
         
     | 
| 
       403 
     | 
    
         
            -
              def setup_logging_stubs
         
     | 
| 
      
 354 
     | 
    
         
            +
              def setup_logging_stubs(_error = nil, code = nil, message = 'some message')
         
     | 
| 
       404 
355 
     | 
    
         
             
                stub_request(:post, WRITE_LOG_ENTRIES_URI).to_return do |request|
         
     | 
| 
       405 
356 
     | 
    
         
             
                  @logs_sent << JSON.parse(request.body)
         
     | 
| 
       406 
     | 
    
         
            -
                  { body:  
     | 
| 
      
 357 
     | 
    
         
            +
                  { status: code, body: message }
         
     | 
| 
       407 
358 
     | 
    
         
             
                end
         
     | 
| 
       408 
359 
     | 
    
         
             
                yield
         
     | 
| 
       409 
360 
     | 
    
         
             
              end
         
     | 
| 
       410 
361 
     | 
    
         | 
| 
      
 362 
     | 
    
         
            +
              # Whether this is the grpc path
         
     | 
| 
      
 363 
     | 
    
         
            +
              def use_grpc
         
     | 
| 
      
 364 
     | 
    
         
            +
                false
         
     | 
| 
      
 365 
     | 
    
         
            +
              end
         
     | 
| 
      
 366 
     | 
    
         
            +
             
     | 
| 
      
 367 
     | 
    
         
            +
              # The OK status code for the grpc path.
         
     | 
| 
      
 368 
     | 
    
         
            +
              def ok_status_code
         
     | 
| 
      
 369 
     | 
    
         
            +
                200
         
     | 
| 
      
 370 
     | 
    
         
            +
              end
         
     | 
| 
      
 371 
     | 
    
         
            +
             
     | 
| 
      
 372 
     | 
    
         
            +
              # A client side error status code for the grpc path.
         
     | 
| 
      
 373 
     | 
    
         
            +
              def client_error_status_code
         
     | 
| 
      
 374 
     | 
    
         
            +
                401
         
     | 
| 
      
 375 
     | 
    
         
            +
              end
         
     | 
| 
      
 376 
     | 
    
         
            +
             
     | 
| 
      
 377 
     | 
    
         
            +
              # A server side error status code for the grpc path.
         
     | 
| 
      
 378 
     | 
    
         
            +
              def server_error_status_code
         
     | 
| 
      
 379 
     | 
    
         
            +
                500
         
     | 
| 
      
 380 
     | 
    
         
            +
              end
         
     | 
| 
      
 381 
     | 
    
         
            +
             
     | 
| 
      
 382 
     | 
    
         
            +
              # The parent error type to expect in the mock
         
     | 
| 
      
 383 
     | 
    
         
            +
              def mock_error_type
         
     | 
| 
      
 384 
     | 
    
         
            +
                Google::Apis::Error
         
     | 
| 
      
 385 
     | 
    
         
            +
              end
         
     | 
| 
      
 386 
     | 
    
         
            +
             
     | 
| 
       411 
387 
     | 
    
         
             
              # The conversions from user input to output.
         
     | 
| 
       412 
388 
     | 
    
         
             
              def latency_conversion
         
     | 
| 
       413 
389 
     | 
    
         
             
                {
         
     |