lib/google/cloud/logging/middleware.rb in google-cloud-logging-0.24.2 vs lib/google/cloud/logging/middleware.rb in google-cloud-logging-1.0.0
- old
+ new
@@ -106,10 +106,20 @@
##
# Construct a monitored resource based on the given type and label if
# both are provided. Otherwise, construct a default monitored resource
# based on the current environment.
#
+ # @param [String] type Type of Google::Cloud::Logging::Resource
+ # @param [Hash<String, String>] labels Metadata lebels of
+ # Google::Cloud::Logging::Resource
+ #
+ # @return [Google::Cloud::Logging::Resource] An Resource object with
+ # type and labels
+ #
+ # @see https://cloud.google.com/logging/docs/api/v2/resource-list
+ # Monitored Resources and Services
+ #
# @example If both type and labels are provided, it returns resource:
# rc = Google::Cloud::Logging::Middleware.build_monitored_resource(
# "aws_ec2_instance",
# {
# instance_id: "ec2-id",
@@ -140,19 +150,10 @@
# @example Otherwise default to generic "global" type:
# rc = Google::Cloud::Logging::Middleware.build_monitored_resource
# rc.type #=> "global"
# rc.labels #=> {}
#
- # Reference https://cloud.google.com/logging/docs/api/ref_v2beta1/rest/v2beta1/MonitoredResource
- # for a full list of monitoring resources
- #
- # @param [String] type Type of Google::Cloud::Logging::Resource
- # @param [Hash<String, String>] labels Metadata lebels of
- # Google::Cloud::Logging::Resource
- #
- # @return [Google::Cloud::Logging::Resource] An Resource object with
- # type and labels
def self.build_monitored_resource type = nil, labels = nil
if type && labels
Google::Cloud::Logging::Resource.new.tap do |r|
r.type = type
r.labels = labels
@@ -164,10 +165,16 @@
##
# @private Extract information from current environment and construct
# the correct monitoring resource types and labels.
#
+ # @return [Google::Cloud::Logging::Resource] An Resource object with
+ # correct type and labels
+ #
+ # @see https://cloud.google.com/logging/docs/api/v2/resource-list
+ # Monitored Resources and Services
+ #
# @example If running from GAE, returns default resource:
# rc = Google::Cloud::Logging::Middleware.send \
# :default_monitored_resource
# rc.type #=> "gae_app"
# rc.labels # { module_id: [GAE module name],
@@ -191,28 +198,25 @@
# rc = Google::Cloud::Logging::Middleware.send \
# :default_monitored_resource
# rc.type #=> "global"
# rc.labels #=> {}
#
- # Reference https://cloud.google.com/logging/docs/api/ref_v2beta1/rest/v2beta1/MonitoredResource
- # for a full list of monitoring resources
- #
- # @return [Google::Cloud::Logging::Resource] An Resource object with
- # correct type and labels
def self.default_monitored_resource
type, labels =
- if Core::Environment.gae?
+ if Google::Cloud.env.app_engine?
["gae_app", {
- module_id: Core::Environment.gae_module_id,
- version_id: Core::Environment.gae_module_version }]
- elsif Core::Environment.gke?
+ module_id: Google::Cloud.env.app_engine_service_id,
+ version_id: Google::Cloud.env.app_engine_service_version }]
+ elsif Google::Cloud.env.container_engine?
["container", {
- cluster_name: Core::Environment.gke_cluster_name,
- namespace_id: Core::Environment.gke_namespace_id || "default" }]
- elsif Core::Environment.gce?
+ cluster_name: Google::Cloud.env.container_engine_cluster_name,
+ namespace_id: \
+ Google::Cloud.env.container_engine_namespace_id || "default"
+ }]
+ elsif Google::Cloud.env.compute_engine?
["gce_instance", {
- instance_id: Core::Environment.instance_id,
- zone: Core::Environment.instance_zone }]
+ instance_id: Google::Cloud.env.instance_name,
+ zone: Google::Cloud.env.instance_zone }]
else
["global", {}]
end
Google::Cloud::Logging::Resource.new.tap do |r|