# Copyright 2019 Google Inc. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. require 'erb' # Module for collecting diagnostic information and formatting it as an # HTML page to serve on the /statusz endpoint. module Statusz module_function def response(plugin) uptime = Time.now - SERVER_START uptime_str = format('%d hr %02d min %02d sec', hours: uptime / 3600, minutes: (uptime / 60) % 60, seconds: uptime % 60) ERB.new(STATUSZ_TMPL).result_with_hash( plugin: plugin, uptime_str: uptime_str ) end end SERVER_START = Time.now # Does not include the following deprecated config params: # auth_method, private_key_email, private_key_passphrase, private_key_path CONFIG_KEYS = %w[ adjust_invalid_timestamps autoformat_stackdriver_trace coerce_to_utf8 detect_json detect_subservice enable_monitoring http_request_key insert_id_key k8s_cluster_location k8s_cluster_name kubernetes_tag_regexp label_map labels_key labels logging_api_url monitoring_type non_utf8_replacement_string operation_key project_id require_valid_tags source_location_key span_id_key split_logs_by_tag statusz_port subservice_name trace_key trace_sampled_key use_aws_availability_zone use_grpc use_metadata_service vm_id vm_name zone ].freeze STATUSZ_TMPL = %(\ Status for <%= File.basename($PROGRAM_NAME) %>

Status for <%= File.basename($PROGRAM_NAME) %>

Started: <%= SERVER_START %>
Up <%= uptime_str %>

Parsed configuration

#{CONFIG_KEYS.map { |k| " " }.join("\n")}
#{k}<%= plugin.#{k} %>
).freeze