Class: Gcloud::Logging::Service
- Inherits:
-
Object
- Object
- Gcloud::Logging::Service
- Defined in:
- lib/gcloud/logging/service.rb
Overview
methods.
Instance Attribute Summary collapse
-
#credentials ⇒ Object
Returns the value of attribute credentials.
-
#host ⇒ Object
Returns the value of attribute host.
-
#mocked_logging ⇒ Object
Returns the value of attribute mocked_logging.
-
#mocked_metrics ⇒ Object
Returns the value of attribute mocked_metrics.
-
#mocked_sinks ⇒ Object
Returns the value of attribute mocked_sinks.
-
#project ⇒ Object
Returns the value of attribute project.
-
#retries ⇒ Object
Returns the value of attribute retries.
-
#timeout ⇒ Object
Returns the value of attribute timeout.
Instance Method Summary collapse
- #create_metric(name, filter, description) ⇒ Object
- #create_sink(name, destination, filter, version) ⇒ Object
- #creds ⇒ Object
- #delete_log(name) ⇒ Object
- #delete_metric(name) ⇒ Object
- #delete_sink(name) ⇒ Object
- #get_metric(name) ⇒ Object
- #get_sink(name) ⇒ Object
-
#initialize(project, credentials, host: nil, retries: nil, timeout: nil) ⇒ Service
constructor
Creates a new Service instance.
- #inspect ⇒ Object
- #list_entries(projects: nil, filter: nil, order: nil, token: nil, max: nil) ⇒ Object
- #list_metrics(token: nil, max: nil) ⇒ Object
- #list_resource_descriptors(token: nil, max: nil) ⇒ Object
- #list_sinks(token: nil, max: nil) ⇒ Object
- #logging ⇒ Object
- #metrics ⇒ Object
- #sinks ⇒ Object
- #update_metric(name, description, filter) ⇒ Object
- #update_sink(name, destination, filter, version) ⇒ Object
- #write_entries(entries, log_name: nil, resource: nil, labels: nil) ⇒ Object
Constructor Details
#initialize(project, credentials, host: nil, retries: nil, timeout: nil) ⇒ Service
Creates a new Service instance.
33 34 35 36 37 38 39 |
# File 'lib/gcloud/logging/service.rb', line 33 def initialize project, credentials, host: nil, retries: nil, timeout: nil @project = project @credentials = credentials @host = host || "logging.googleapis.com" @retries = retries @timeout = timeout end |
Instance Attribute Details
#credentials ⇒ Object
Returns the value of attribute credentials.
29 30 31 |
# File 'lib/gcloud/logging/service.rb', line 29 def credentials @credentials end |
#host ⇒ Object
Returns the value of attribute host.
29 30 31 |
# File 'lib/gcloud/logging/service.rb', line 29 def host @host end |
#mocked_logging ⇒ Object
Returns the value of attribute mocked_logging.
51 52 53 |
# File 'lib/gcloud/logging/service.rb', line 51 def mocked_logging @mocked_logging end |
#mocked_metrics ⇒ Object
Returns the value of attribute mocked_metrics.
65 66 67 |
# File 'lib/gcloud/logging/service.rb', line 65 def mocked_metrics @mocked_metrics end |
#mocked_sinks ⇒ Object
Returns the value of attribute mocked_sinks.
58 59 60 |
# File 'lib/gcloud/logging/service.rb', line 58 def mocked_sinks @mocked_sinks end |
#project ⇒ Object
Returns the value of attribute project.
29 30 31 |
# File 'lib/gcloud/logging/service.rb', line 29 def project @project end |
#retries ⇒ Object
Returns the value of attribute retries.
29 30 31 |
# File 'lib/gcloud/logging/service.rb', line 29 def retries @retries end |
#timeout ⇒ Object
Returns the value of attribute timeout.
29 30 31 |
# File 'lib/gcloud/logging/service.rb', line 29 def timeout @timeout end |
Instance Method Details
#create_metric(name, filter, description) ⇒ Object
185 186 187 188 189 190 191 192 193 194 195 196 197 198 |
# File 'lib/gcloud/logging/service.rb', line 185 def create_metric name, filter, description metric_params = { name: name, description: description, filter: filter }.delete_if { |_, v| v.nil? } create_req = Google::Logging::V2::CreateLogMetricRequest.new( project_name: project_path, metric: Google::Logging::V2::LogMetric.new(metric_params) ) execute { metrics.create_log_metric create_req } end |
#create_sink(name, destination, filter, version) ⇒ Object
130 131 132 133 134 135 136 137 138 139 140 141 142 |
# File 'lib/gcloud/logging/service.rb', line 130 def create_sink name, destination, filter, version sink_params = { name: name, destination: destination, filter: filter, output_version_format: version }.delete_if { |_, v| v.nil? } create_req = Google::Logging::V2::CreateSinkRequest.new( project_name: project_path, sink: Google::Logging::V2::LogSink.new(sink_params) ) execute { sinks.create_sink create_req } end |
#creds ⇒ Object
41 42 43 44 |
# File 'lib/gcloud/logging/service.rb', line 41 def creds GRPC::Core::ChannelCredentials.new.compose \ GRPC::Core::CallCredentials.new credentials.client.updater_proc end |
#delete_log(name) ⇒ Object
99 100 101 102 103 104 105 |
# File 'lib/gcloud/logging/service.rb', line 99 def delete_log name delete_req = Google::Logging::V2::DeleteLogRequest.new( log_name: log_path(name) ) execute { logging.delete_log delete_req } end |
#delete_metric(name) ⇒ Object
223 224 225 226 227 228 229 |
# File 'lib/gcloud/logging/service.rb', line 223 def delete_metric name delete_req = Google::Logging::V2::DeleteLogMetricRequest.new( metric_name: metric_path(name) ) execute { metrics.delete_log_metric delete_req } end |
#delete_sink(name) ⇒ Object
166 167 168 169 170 171 172 |
# File 'lib/gcloud/logging/service.rb', line 166 def delete_sink name delete_req = Google::Logging::V2::DeleteSinkRequest.new( sink_name: sink_path(name) ) execute { sinks.delete_sink delete_req } end |
#get_metric(name) ⇒ Object
200 201 202 203 204 205 206 |
# File 'lib/gcloud/logging/service.rb', line 200 def get_metric name get_req = Google::Logging::V2::GetLogMetricRequest.new( metric_name: metric_path(name) ) execute { metrics.get_log_metric get_req } end |
#get_sink(name) ⇒ Object
144 145 146 147 148 149 150 |
# File 'lib/gcloud/logging/service.rb', line 144 def get_sink name get_req = Google::Logging::V2::GetSinkRequest.new( sink_name: sink_path(name) ) execute { sinks.get_sink get_req } end |
#inspect ⇒ Object
231 232 233 |
# File 'lib/gcloud/logging/service.rb', line 231 def inspect "#{self.class}(#{@project})" end |
#list_entries(projects: nil, filter: nil, order: nil, token: nil, max: nil) ⇒ Object
67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/gcloud/logging/service.rb', line 67 def list_entries projects: nil, filter: nil, order: nil, token: nil, max: nil list_params = { project_ids: Array(projects || @project), filter: filter, order_by: order, page_token: token, page_size: max }.delete_if { |_, v| v.nil? } list_req = Google::Logging::V2::ListLogEntriesRequest.new(list_params) execute { logging.list_log_entries list_req } end |
#list_metrics(token: nil, max: nil) ⇒ Object
174 175 176 177 178 179 180 181 182 183 |
# File 'lib/gcloud/logging/service.rb', line 174 def list_metrics token: nil, max: nil list_params = { project_name: project_path, page_token: token, page_size: max }.delete_if { |_, v| v.nil? } list_req = Google::Logging::V2::ListLogMetricsRequest.new(list_params) execute { metrics.list_log_metrics list_req } end |
#list_resource_descriptors(token: nil, max: nil) ⇒ Object
107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/gcloud/logging/service.rb', line 107 def list_resource_descriptors token: nil, max: nil list_params = { page_token: token, page_size: max }.delete_if { |_, v| v.nil? } list_req = \ Google::Logging::V2::ListMonitoredResourceDescriptorsRequest.new( list_params) execute { logging.list_monitored_resource_descriptors list_req } end |
#list_sinks(token: nil, max: nil) ⇒ Object
119 120 121 122 123 124 125 126 127 128 |
# File 'lib/gcloud/logging/service.rb', line 119 def list_sinks token: nil, max: nil list_params = { project_name: project_path, page_token: token, page_size: max }.delete_if { |_, v| v.nil? } list_req = Google::Logging::V2::ListSinksRequest.new(list_params) execute { sinks.list_sinks list_req } end |
#logging ⇒ Object
46 47 48 49 50 |
# File 'lib/gcloud/logging/service.rb', line 46 def logging return mocked_logging if mocked_logging @logging ||= Google::Logging::V2::LoggingServiceV2::Stub.new( host, creds, timeout: timeout) end |
#metrics ⇒ Object
60 61 62 63 64 |
# File 'lib/gcloud/logging/service.rb', line 60 def metrics return mocked_metrics if mocked_metrics @metrics ||= Google::Logging::V2::MetricsServiceV2::Stub.new( host, creds, timeout: timeout) end |
#sinks ⇒ Object
53 54 55 56 57 |
# File 'lib/gcloud/logging/service.rb', line 53 def sinks return mocked_sinks if mocked_sinks @sinks ||= Google::Logging::V2::ConfigServiceV2::Stub.new( host, creds, timeout: timeout) end |
#update_metric(name, description, filter) ⇒ Object
208 209 210 211 212 213 214 215 216 217 218 219 220 221 |
# File 'lib/gcloud/logging/service.rb', line 208 def update_metric name, description, filter metric_params = { name: name, description: description, filter: filter }.delete_if { |_, v| v.nil? } update_req = Google::Logging::V2::UpdateLogMetricRequest.new( metric_name: metric_path(name), metric: Google::Logging::V2::LogMetric.new(metric_params) ) execute { metrics.update_log_metric update_req } end |
#update_sink(name, destination, filter, version) ⇒ Object
152 153 154 155 156 157 158 159 160 161 162 163 164 |
# File 'lib/gcloud/logging/service.rb', line 152 def update_sink name, destination, filter, version sink_params = { name: name, destination: destination, filter: filter, output_version_format: version }.delete_if { |_, v| v.nil? } update_req = Google::Logging::V2::UpdateSinkRequest.new( sink_name: sink_path(name), sink: Google::Logging::V2::LogSink.new(sink_params) ) execute { sinks.update_sink update_req } end |
#write_entries(entries, log_name: nil, resource: nil, labels: nil) ⇒ Object
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/gcloud/logging/service.rb', line 81 def write_entries entries, log_name: nil, resource: nil, labels: nil # Fix log names so they are the full path entries = Array(entries).each do |entry| entry.log_name = log_path(entry.log_name) end resource = resource.to_grpc if resource labels = Hash[labels.map { |k, v| [String(k), String(v)] }] if labels write_params = { entries: entries, log_name: log_path(log_name), resource: resource, labels: labels }.delete_if { |_, v| v.nil? } write_req = Google::Logging::V2::WriteLogEntriesRequest.new write_params execute { logging.write_log_entries write_req } end |