Class: OpenCensus::Stats::Exporters::Stackdriver
- Inherits:
-
Object
- Object
- OpenCensus::Stats::Exporters::Stackdriver
- Defined in:
- lib/opencensus/stats/exporters/stackdriver.rb,
lib/opencensus/stats/exporters/stackdriver/converter.rb
Overview
The Stackdriver exporter for OpenCensus Stats exports captured stats to a Google Monitoring project. It calls the Monitoring API in a background thread pool.
Constant Summary collapse
- CUSTOM_OPENCENSUS_DOMAIN =
Default custom opencensus domain name
"custom.googleapis.com/opencensus".freeze
- GLOBAL_RESOURCE_TYPE =
Default metric resouce type.
"global".freeze
Instance Attribute Summary collapse
-
#metric_prefix ⇒ String
readonly
Metric prefix.
-
#project_id ⇒ String
readonly
The project ID.
-
#resource_labels ⇒ Hash<String,String>
readonly
Metric resource labels.
-
#resource_type ⇒ String
readonly
Metric resource type.
Instance Method Summary collapse
-
#create_metric_descriptor(view) ⇒ Google::Api::MetricDescriptor
Create a metric descriptor.
-
#export(views_data) ⇒ Object
Export stats to Monitoring service asynchronously.
-
#initialize(project_id: nil, credentials: nil, scope: nil, timeout: nil, client_config: nil, max_queue: 1000, max_threads: 1, auto_terminate_time: 10, mock_client: nil, metric_prefix: nil, resource_type: nil, resource_labels: nil) ⇒ Stackdriver
constructor
Create a Stackdriver exporter.
-
#kill ⇒ Object
Begin shutting down the exporter forcefully.
-
#running? ⇒ boolean
Returns true if this exporter is running and will accept further export requests.
-
#shutdown ⇒ Object
Begin shutting down the exporter gracefully.
-
#shutdown? ⇒ boolean
Returns true if this exporter has finished shutting down and all pending stats have been sent.
-
#shuttingdown? ⇒ boolean
Returns true if this exporter has begun shutting down and is no longer accepting export requests, but is still running queued requests in the background.
-
#wait_for_termination(timeout = nil) ⇒ boolean
Wait for the exporter to finish shutting down.
Constructor Details
#initialize(project_id: nil, credentials: nil, scope: nil, timeout: nil, client_config: nil, max_queue: 1000, max_threads: 1, auto_terminate_time: 10, mock_client: nil, metric_prefix: nil, resource_type: nil, resource_labels: nil) ⇒ Stackdriver
Create a Stackdriver exporter.
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 |
# File 'lib/opencensus/stats/exporters/stackdriver.rb', line 107 def initialize \ project_id: nil, credentials: nil, scope: nil, timeout: nil, client_config: nil, max_queue: 1000, max_threads: 1, auto_terminate_time: 10, mock_client: nil, metric_prefix: nil, resource_type: nil, resource_labels: nil @project_id = final_project_id project_id @metric_prefix = metric_prefix || CUSTOM_OPENCENSUS_DOMAIN @resource_type = resource_type || GLOBAL_RESOURCE_TYPE @resource_labels = resource_labels || { "project_id" => @project_id } @executor = create_executor max_threads, max_queue if auto_terminate_time terminate_at_exit! @executor, auto_terminate_time end if mock_client @client_promise = Concurrent::Promise.fulfill mock_client, executor: @executor else credentials = final_credentials credentials, scope @client_promise = create_client_promise \ @executor, credentials, scope, client_config, timeout end @converter = Converter.new @project_id @project_path = Google::Cloud::Monitoring::V3:: \ MetricServiceClient.project_path @project_id end |
Instance Attribute Details
#metric_prefix ⇒ String (readonly)
Metric prefix
56 57 58 |
# File 'lib/opencensus/stats/exporters/stackdriver.rb', line 56 def metric_prefix @metric_prefix end |
#project_id ⇒ String (readonly)
The project ID
52 53 54 |
# File 'lib/opencensus/stats/exporters/stackdriver.rb', line 52 def project_id @project_id end |
#resource_labels ⇒ Hash<String,String> (readonly)
Metric resource labels
64 65 66 |
# File 'lib/opencensus/stats/exporters/stackdriver.rb', line 64 def resource_labels @resource_labels end |
#resource_type ⇒ String (readonly)
Metric resource type
60 61 62 |
# File 'lib/opencensus/stats/exporters/stackdriver.rb', line 60 def resource_type @resource_type end |
Instance Method Details
#create_metric_descriptor(view) ⇒ Google::Api::MetricDescriptor
Create a metric descriptor
An error will be raised if there is already a metric descriptor created with the same name but it has a different aggregation or keys.
240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 |
# File 'lib/opencensus/stats/exporters/stackdriver.rb', line 240 def create_metric_descriptor view metric_descriptor = @converter.convert_metric_descriptor( view, metric_prefix ) metric_name = Google::Cloud::Monitoring::V3:: \ MetricServiceClient.metric_descriptor_path( project_id, metric_descriptor.type ) @client_promise.execute descriptor_create_promise = @client_promise.then do |client| client.create_metric_descriptor metric_name, metric_descriptor end descriptor_create_promise.value! end |
#export(views_data) ⇒ Object
Export stats to Monitoring service asynchronously.
151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 |
# File 'lib/opencensus/stats/exporters/stackdriver.rb', line 151 def export views_data raise "Exporter is no longer running" unless @executor.running? return if views_data.nil? || views_data.empty? @client_promise.execute export_promise = @client_promise.then do |client| export_as_batch(client, views_data) end export_promise.on_error do |reason| warn "Unable to export to Monitering service because: #{reason}" end nil end |
#kill ⇒ Object
Begin shutting down the exporter forcefully. After this operation is performed, the exporter will no longer accept export requests, and will finish any currently running export requests, but will cancel all requests that are still pending in the queue.
214 215 216 217 |
# File 'lib/opencensus/stats/exporters/stackdriver.rb', line 214 def kill @executor.kill self end |
#running? ⇒ boolean
Returns true if this exporter is running and will accept further export requests. Returns false once the exporter begins shutting down.
173 174 175 |
# File 'lib/opencensus/stats/exporters/stackdriver.rb', line 173 def running? @executor.running? end |
#shutdown ⇒ Object
Begin shutting down the exporter gracefully. After this operation is performed, the exporter will no longer accept export requests, but will finish any pending requests in the background.
203 204 205 206 |
# File 'lib/opencensus/stats/exporters/stackdriver.rb', line 203 def shutdown @executor.shutdown self end |
#shutdown? ⇒ boolean
Returns true if this exporter has finished shutting down and all pending stats have been sent.
183 184 185 |
# File 'lib/opencensus/stats/exporters/stackdriver.rb', line 183 def shutdown? @executor.shutdown? end |
#shuttingdown? ⇒ boolean
Returns true if this exporter has begun shutting down and is no longer accepting export requests, but is still running queued requests in the background.
194 195 196 |
# File 'lib/opencensus/stats/exporters/stackdriver.rb', line 194 def shuttingdown? @executor.shuttingdown? end |
#wait_for_termination(timeout = nil) ⇒ boolean
Wait for the exporter to finish shutting down.
227 228 229 |
# File 'lib/opencensus/stats/exporters/stackdriver.rb', line 227 def wait_for_termination timeout = nil @executor.wait_for_termination timeout end |