test/plugin/constants.rb in fluent-plugin-google-cloud-0.6.7 vs test/plugin/constants.rb in fluent-plugin-google-cloud-0.6.8.pre.1

- old
+ new

@@ -12,11 +12,13 @@ # See the License for the specific language governing permissions and # limitations under the License. # Constants used by unit tests for Google Cloud Logging plugin. module Constants - include Fluent::GoogleCloudOutput::Constants + include Fluent::GoogleCloudOutput::ServiceConstants + include Fluent::GoogleCloudOutput::ConfigConstants + include Fluent::GoogleCloudOutput::InternalConstants # Generic attributes. HOSTNAME = Socket.gethostname # TODO(qingling128) Separate constants into different submodules. @@ -24,10 +26,14 @@ PROJECT_ID = 'test-project-id' ZONE = 'us-central1-b' FULLY_QUALIFIED_ZONE = 'projects/' + PROJECT_ID + '/zones/' + ZONE VM_ID = '9876543210' + # Attributes used for the Metadata Agent resources. + METADATA_ZONE = 'us-central1-c' + METADATA_VM_ID = '0123456789' + # Attributes used for custom (overridden) configs. CUSTOM_PROJECT_ID = 'test-custom-project-id' CUSTOM_ZONE = 'us-custom-central1-b' CUSTOM_FULLY_QUALIFIED_ZONE = 'projects/' + PROJECT_ID + '/zones/' + ZONE CUSTOM_VM_ID = 'C9876543210' @@ -49,10 +55,20 @@ # Managed VMs specific labels. MANAGED_VM_BACKEND_NAME = 'default' MANAGED_VM_BACKEND_VERSION = 'guestbook2.0' + # Docker Container labels. + DOCKER_CONTAINER_ID = '0d0f03ff8d3c42688692536d1af77a28cd135c0a5c531f25a31' + DOCKER_CONTAINER_NAME = 'happy_hippo' + DOCKER_CONTAINER_STREAM_STDOUT = 'stdout' + DOCKER_CONTAINER_STREAM_STDERR = 'stderr' + # Timestamp for 1234567890 seconds and 987654321 nanoseconds since epoch. + DOCKER_CONTAINER_TIMESTAMP = '2009-02-13T23:31:30.987654321Z' + DOCKER_CONTAINER_SECONDS_EPOCH = 1_234_567_890 + DOCKER_CONTAINER_NANOS = 987_654_321 + # Container Engine / Kubernetes specific labels. CONTAINER_CLUSTER_NAME = 'cluster-1' CONTAINER_NAMESPACE_ID = '898268c8-4a36-11e5-9d81-42010af0194c' CONTAINER_NAMESPACE_NAME = 'kube-system' CONTAINER_POD_ID = 'cad3c3c4-4b9c-11e5-9d81-42010af0194c' @@ -147,10 +163,24 @@ PROMETHEUS_ENABLE_CONFIG = %( enable_monitoring true monitoring_type prometheus ) + ENABLE_METADATA_AGENT_CONFIG = %( + enable_metadata_agent true + ) + + DISABLE_METADATA_AGENT_CONFIG = %( + enable_metadata_agent false + ) + + DOCKER_CONTAINER_CONFIG = %( + enable_metadata_agent true + label_map { "source": "#{DOCKER_CONSTANTS[:service]}/stream" } + detect_json true + ) + CUSTOM_METADATA_CONFIG = %( project_id #{CUSTOM_PROJECT_ID} zone #{CUSTOM_ZONE} vm_id #{CUSTOM_VM_ID} vm_name #{CUSTOM_HOSTNAME} @@ -203,10 +233,12 @@ CONFIG_CUSTOM_TRACE_KEY_SPECIFIED = %( trace_key custom_trace_key ) # Service configurations for various services. + + # GCE. COMPUTE_PARAMS = { resource: { type: COMPUTE_CONSTANTS[:resource_type], labels: { 'instance_id' => VM_ID, @@ -217,11 +249,20 @@ project_id: PROJECT_ID, labels: { "#{COMPUTE_CONSTANTS[:service]}/resource_name" => HOSTNAME } } + COMPUTE_PARAMS_WITH_METADATA_VM_ID_AND_ZONE = COMPUTE_PARAMS.merge( + resource: COMPUTE_PARAMS[:resource].merge( + labels: { + 'instance_id' => METADATA_VM_ID, + 'zone' => METADATA_ZONE + } + ) + ) + # GAE. VMENGINE_PARAMS = { resource: { type: APPENGINE_CONSTANTS[:resource_type], labels: { 'module_id' => MANAGED_VM_BACKEND_NAME, @@ -235,16 +276,17 @@ "#{COMPUTE_CONSTANTS[:service]}/resource_name" => HOSTNAME, "#{COMPUTE_CONSTANTS[:service]}/zone" => ZONE } } + # GKE Container. CONTAINER_TAG = "kubernetes.#{CONTAINER_POD_NAME}_" \ "#{CONTAINER_NAMESPACE_NAME}_#{CONTAINER_CONTAINER_NAME}" CONTAINER_FROM_METADATA_PARAMS = { resource: { - type: CONTAINER_CONSTANTS[:resource_type], + type: GKE_CONSTANTS[:resource_type], labels: { 'cluster_name' => CONTAINER_CLUSTER_NAME, 'namespace_id' => CONTAINER_NAMESPACE_ID, 'instance_id' => VM_ID, 'pod_id' => CONTAINER_POD_ID, @@ -253,24 +295,24 @@ } }, log_name: CONTAINER_CONTAINER_NAME, project_id: PROJECT_ID, labels: { - "#{CONTAINER_CONSTANTS[:service]}/namespace_name" => + "#{GKE_CONSTANTS[:service]}/namespace_name" => CONTAINER_NAMESPACE_NAME, - "#{CONTAINER_CONSTANTS[:service]}/pod_name" => CONTAINER_POD_NAME, - "#{CONTAINER_CONSTANTS[:service]}/stream" => CONTAINER_STREAM, + "#{GKE_CONSTANTS[:service]}/pod_name" => CONTAINER_POD_NAME, + "#{GKE_CONSTANTS[:service]}/stream" => CONTAINER_STREAM, "label/#{CONTAINER_LABEL_KEY}" => CONTAINER_LABEL_VALUE, "#{COMPUTE_CONSTANTS[:service]}/resource_name" => HOSTNAME } } # Almost the same as from metadata, but namespace_id and pod_id come from # namespace and pod names. CONTAINER_FROM_TAG_PARAMS = { resource: { - type: CONTAINER_CONSTANTS[:resource_type], + type: GKE_CONSTANTS[:resource_type], labels: { 'cluster_name' => CONTAINER_CLUSTER_NAME, 'namespace_id' => CONTAINER_NAMESPACE_NAME, 'instance_id' => VM_ID, 'pod_id' => CONTAINER_POD_NAME, @@ -279,18 +321,60 @@ } }, log_name: CONTAINER_CONTAINER_NAME, project_id: PROJECT_ID, labels: { - "#{CONTAINER_CONSTANTS[:service]}/namespace_name" => + "#{GKE_CONSTANTS[:service]}/namespace_name" => CONTAINER_NAMESPACE_NAME, - "#{CONTAINER_CONSTANTS[:service]}/pod_name" => CONTAINER_POD_NAME, - "#{CONTAINER_CONSTANTS[:service]}/stream" => CONTAINER_STREAM, + "#{GKE_CONSTANTS[:service]}/pod_name" => CONTAINER_POD_NAME, + "#{GKE_CONSTANTS[:service]}/stream" => CONTAINER_STREAM, "#{COMPUTE_CONSTANTS[:service]}/resource_name" => HOSTNAME } } + CONTAINER_FROM_APPLICATION_PARAMS = { + resource: { + type: GKE_CONSTANTS[:resource_type], + labels: { + 'cluster_name' => CONTAINER_CLUSTER_NAME, + 'namespace_id' => CONTAINER_NAMESPACE_ID, + 'instance_id' => VM_ID, + 'pod_id' => CONTAINER_POD_ID, + 'container_name' => CONTAINER_CONTAINER_NAME, + 'zone' => ZONE + } + }, + log_name: 'redis', + project_id: PROJECT_ID, + labels: { + "#{COMPUTE_CONSTANTS[:service]}/resource_name" => HOSTNAME + } + } + + # Docker Container. + DOCKER_CONTAINER_PARAMS = { + resource: { + type: DOCKER_CONSTANTS[:resource_type], + labels: { + 'container_id' => DOCKER_CONTAINER_ID, + 'location' => ZONE + } + }, + log_name: 'test', + project_id: PROJECT_ID, + labels: { + "#{DOCKER_CONSTANTS[:service]}/stream" => DOCKER_CONTAINER_STREAM_STDOUT + } + } + DOCKER_CONTAINER_PARAMS_STREAM_STDERR = DOCKER_CONTAINER_PARAMS.merge( + labels: DOCKER_CONTAINER_PARAMS[:labels].merge( + "#{DOCKER_CONSTANTS[:service]}/stream" => DOCKER_CONTAINER_STREAM_STDERR + ) + ) + DOCKER_CONTAINER_PARAMS_NO_STREAM = DOCKER_CONTAINER_PARAMS.merge(labels: {}) + + # Cloud Functions. CLOUDFUNCTIONS_TAG = "kubernetes.#{CLOUDFUNCTIONS_POD_NAME}_" \ "#{CLOUDFUNCTIONS_NAMESPACE_NAME}_" \ "#{CLOUDFUNCTIONS_CONTAINER_NAME}" CLOUDFUNCTIONS_PARAMS = { @@ -303,12 +387,12 @@ }, log_name: 'cloud-functions', project_id: PROJECT_ID, labels: { 'execution_id' => CLOUDFUNCTIONS_EXECUTION_ID, - "#{CONTAINER_CONSTANTS[:service]}/instance_id" => VM_ID, - "#{CONTAINER_CONSTANTS[:service]}/cluster_name" => + "#{GKE_CONSTANTS[:service]}/instance_id" => VM_ID, + "#{GKE_CONSTANTS[:service]}/cluster_name" => CLOUDFUNCTIONS_CLUSTER_NAME, "#{COMPUTE_CONSTANTS[:service]}/resource_id" => VM_ID, "#{COMPUTE_CONSTANTS[:service]}/resource_name" => HOSTNAME, "#{COMPUTE_CONSTANTS[:service]}/zone" => ZONE } @@ -323,19 +407,20 @@ } }, log_name: 'cloud-functions', project_id: PROJECT_ID, labels: { - "#{CONTAINER_CONSTANTS[:service]}/instance_id" => VM_ID, - "#{CONTAINER_CONSTANTS[:service]}/cluster_name" => + "#{GKE_CONSTANTS[:service]}/instance_id" => VM_ID, + "#{GKE_CONSTANTS[:service]}/cluster_name" => CLOUDFUNCTIONS_CLUSTER_NAME, "#{COMPUTE_CONSTANTS[:service]}/resource_id" => VM_ID, "#{COMPUTE_CONSTANTS[:service]}/resource_name" => HOSTNAME, "#{COMPUTE_CONSTANTS[:service]}/zone" => ZONE } } + # Cloud Dataflow. DATAFLOW_PARAMS = { resource: { type: DATAFLOW_CONSTANTS[:resource_type], labels: { 'job_name' => DATAFLOW_JOB_NAME, @@ -351,10 +436,11 @@ "#{COMPUTE_CONSTANTS[:service]}/resource_name" => HOSTNAME, "#{COMPUTE_CONSTANTS[:service]}/zone" => ZONE } } + # Cloud Dataproc. DATAPROC_PARAMS = { resource: { type: DATAPROC_CONSTANTS[:resource_type], labels: { 'cluster_name' => DATAPROC_CLUSTER_NAME, @@ -369,10 +455,11 @@ "#{COMPUTE_CONSTANTS[:service]}/resource_id" => VM_ID, "#{COMPUTE_CONSTANTS[:service]}/zone" => ZONE } } + # Cloud ML. ML_PARAMS = { resource: { type: ML_CONSTANTS[:resource_type], labels: { 'job_id' => ML_JOB_ID, @@ -479,6 +566,52 @@ "#{[0x92].pack('C*')}" => '%20', # Empty string tag. '' => '_' } ALL_TAGS = VALID_TAGS.merge(INVALID_TAGS) + + # Stub value for Monitored resources from Metadata Agent. + # Map from the local_resource_id to the retrieved monitored resource. + MONITORED_RESOURCE_STUBS = { + # Implicit GCE instance. + IMPLICIT_LOCAL_RESOURCE_ID => + { + 'type' => COMPUTE_CONSTANTS[:resource_type], + 'labels' => { + 'zone' => METADATA_ZONE, + 'instance_id' => METADATA_VM_ID + } + }.to_json, + # Docker container stderr / stdout logs. + "container.#{DOCKER_CONTAINER_ID}" => + { + 'type' => DOCKER_CONSTANTS[:resource_type], + 'labels' => { + 'location' => ZONE, + 'container_id' => DOCKER_CONTAINER_ID + } + }.to_json, + # Docker container application logs. + "containerName.#{DOCKER_CONTAINER_NAME}" => + { + 'type' => DOCKER_CONSTANTS[:resource_type], + 'labels' => { + 'location' => ZONE, + 'container_id' => DOCKER_CONTAINER_ID + } + }.to_json, + # GKE container logs. + "gke_containerName.#{CONTAINER_NAMESPACE_ID}.#{CONTAINER_POD_NAME}." \ + "#{CONTAINER_CONTAINER_NAME}" => + { + 'type' => GKE_CONSTANTS[:resource_type], + 'labels' => { + 'cluster_name' => CONTAINER_CLUSTER_NAME, + 'container_name' => CONTAINER_CONTAINER_NAME, + 'instance_id' => VM_ID, + 'namespace_id' => CONTAINER_NAMESPACE_ID, + 'pod_id' => CONTAINER_POD_ID, + 'zone' => ZONE + } + }.to_json + } end