1# Copyright 2016 gRPC authors. 2# 3# Licensed under the Apache License, Version 2.0 (the "License"); 4# you may not use this file except in compliance with the License. 5# You may obtain a copy of the License at 6# 7# http://www.apache.org/licenses/LICENSE-2.0 8# 9# Unless required by applicable law or agreed to in writing, software 10# distributed under the License is distributed on an "AS IS" BASIS, 11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12# See the License for the specific language governing permissions and 13# limitations under the License. 14 15require_relative '../pb/grpc/testing/metrics_pb.rb' 16require_relative '../pb/grpc/testing/metrics_services_pb.rb' 17 18class Gauge 19 def get_name 20 raise NoMethodError.new 21 end 22 23 def get_type 24 raise NoMethodError.new 25 end 26 27 def get_value 28 raise NoMethodError.new 29 end 30end 31 32class MetricsServiceImpl < Grpc::Testing::MetricsService::Service 33 include Grpc::Testing 34 @gauges 35 36 def initialize 37 @gauges = {} 38 end 39 40 def register_gauge(gauge) 41 @gauges[gauge.get_name] = gauge 42 end 43 44 def make_gauge_response(gauge) 45 response = GaugeResponse.new(:name => gauge.get_name) 46 value = gauge.get_value 47 case gauge.get_type 48 when 'long' 49 response.long_value = value 50 when 'double' 51 response.double_value = value 52 when 'string' 53 response.string_value = value 54 end 55 response 56 end 57 58 def get_all_gauges(_empty, _call) 59 @gauges.values.map do |gauge| 60 make_gauge_response gauge 61 end 62 end 63 64 def get_gauge(gauge_req, _call) 65 gauge = @gauges[gauge_req.name] 66 make_gauge_response gauge 67 end 68end 69