From 6071c7cb729f10ab80c1cb76ca464ae1bc1c8d4c Mon Sep 17 00:00:00 2001 From: Franklin Hu Date: Tue, 12 Jun 2012 13:45:10 -0700 Subject: [PATCH] zipkin-query gem Split access to Zipkin Query service out into separate gem - Fix generated ruby namespacing in `zipkin-thrift` - Thrift files are symlinked in `zipkin-gems/zipkin-query/thrift`, and the generated code is in `zipkin-gems/zipkin-query/vendor` Author: franklinhu Pull Request: #19 URL: https://github.com/twitter/zipkin/pull/19 --- zipkin-gems/zipkin-query/Rakefile | 19 ++ zipkin-gems/zipkin-query/lib/zipkin-query.rb | 107 ++++++ .../zipkin-query/lib/zipkin-query/version.rb | 16 + .../zipkin-query/thrift/zipkinCore.thrift | 1 + .../zipkin-query/thrift/zipkinQuery.thrift | 1 + .../vendor/gen-rb/zipkin-query.rb | 19 ++ .../zipkin-query/zipkin_core_constants.rb | 4 +- .../gen-rb/zipkin-query/zipkin_core_types.rb | 112 ++++++ .../gen-rb/zipkin-query}/zipkin_query.rb | 62 +--- .../zipkin-query/zipkin_query_constants.rb | 10 + .../gen-rb/zipkin-query/zipkin_query_types.rb | 155 +-------- zipkin-gems/zipkin-query/zipkin-query.gemspec | 35 ++ .../src/main/thrift/zipkinCollector.thrift | 1 + .../src/main/thrift/zipkinQuery.thrift | 1 + zipkin-web/Gemfile | 1 + zipkin-web/Gemfile.lock | 2 + .../app/controllers/traces_controller.rb | 3 - zipkin-web/app/models/endpoint.rb | 7 +- zipkin-web/app/models/index.rb | 14 +- zipkin-web/app/models/names.rb | 12 +- zipkin-web/app/models/span.rb | 13 +- zipkin-web/app/models/trace_combo.rb | 10 +- zipkin-web/app/models/trace_summary.rb | 10 +- zipkin-web/app/models/trace_timeline.rb | 4 +- zipkin-web/app/models/ztrace.rb | 16 +- zipkin-web/lib/zipkin.thrift | 287 ---------------- zipkin-web/lib/zipkin_client.rb | 109 ------ zipkin-web/lib/zipkin_collector.rb | 319 ------------------ 28 files changed, 368 insertions(+), 982 deletions(-) create mode 100644 zipkin-gems/zipkin-query/Rakefile create mode 100644 zipkin-gems/zipkin-query/lib/zipkin-query.rb create mode 100644 zipkin-gems/zipkin-query/lib/zipkin-query/version.rb create mode 120000 zipkin-gems/zipkin-query/thrift/zipkinCore.thrift create mode 120000 zipkin-gems/zipkin-query/thrift/zipkinQuery.thrift create mode 100644 zipkin-gems/zipkin-query/vendor/gen-rb/zipkin-query.rb rename zipkin-web/lib/zipkin_constants.rb => zipkin-gems/zipkin-query/vendor/gen-rb/zipkin-query/zipkin_core_constants.rb (73%) create mode 100644 zipkin-gems/zipkin-query/vendor/gen-rb/zipkin-query/zipkin_core_types.rb rename {zipkin-web/lib => zipkin-gems/zipkin-query/vendor/gen-rb/zipkin-query}/zipkin_query.rb (93%) create mode 100644 zipkin-gems/zipkin-query/vendor/gen-rb/zipkin-query/zipkin_query_constants.rb rename zipkin-web/lib/zipkin_types.rb => zipkin-gems/zipkin-query/vendor/gen-rb/zipkin-query/zipkin_query_types.rb (55%) create mode 100644 zipkin-gems/zipkin-query/zipkin-query.gemspec delete mode 100755 zipkin-web/lib/zipkin.thrift delete mode 100644 zipkin-web/lib/zipkin_client.rb delete mode 100644 zipkin-web/lib/zipkin_collector.rb diff --git a/zipkin-gems/zipkin-query/Rakefile b/zipkin-gems/zipkin-query/Rakefile new file mode 100644 index 00000000000..0527b5a2052 --- /dev/null +++ b/zipkin-gems/zipkin-query/Rakefile @@ -0,0 +1,19 @@ +# Copyright 2012 Twitter Inc. +# +# 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 'rubygems' + +desc 'Build the gem' +task :build do + system "gem build zipkin-query.gemspec" +end diff --git a/zipkin-gems/zipkin-query/lib/zipkin-query.rb b/zipkin-gems/zipkin-query/lib/zipkin-query.rb new file mode 100644 index 00000000000..0430e475eac --- /dev/null +++ b/zipkin-gems/zipkin-query/lib/zipkin-query.rb @@ -0,0 +1,107 @@ +# Copyright 2012 Twitter Inc. +# +# 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. + +gen_rb_path = File.expand_path(File.dirname(__FILE__) + "/../vendor/gen-rb") +$LOAD_PATH.unshift gen_rb_path +$LOAD_PATH.unshift "#{gen_rb_path}/zipkin-query" + +require "#{gen_rb_path}/zipkin-query" + +module ZipkinQuery extend self + + module Client + # The node location in zookeeper that stores the cassandra location + NODE_PATH = "/twitter/service/zipkin/query" + + def self.with_transport(opts = {}) + # Open a connection to a thrift server, do something, and close the connection + + begin + + if opts[:use_local_server] + # If we're running local (development mode) return a set value + host = "localhost" + port = 9149 + + # Create the connection to the local b3 query_daemon which uses different + # transport mechanism + socket = Thrift::Socket.new(host, port) + transport = Thrift::BufferedTransport.new(socket) + else + # Get the host and port of the location of the query service from zookeeper + zk_host = opts[:zk_host] || "localhost" + zk_port = opts[:zk_port] || 2181 + + host, port = Client::get_query_service(zk_host, zk_port, opts) + + # Create the connection to the b3 query_daemon + socket = Thrift::Socket.new(host, port) + buffered_tp = Thrift::BufferedTransport.new(socket) + transport = Thrift::FramedTransport.new(buffered_tp) + end + + protocol = Thrift::BinaryProtocol.new(transport) + client = ThriftClient.new(Zipkin::ZipkinQuery::Client, host + ':' + port.to_s, :retries => 0, :timeout => 60) + + # set up tracing for the client we use to talk to the query daemon + client_id = FinagleThrift::ClientId.new(:name => "zipkin.prod") + FinagleThrift.enable_tracing!(client, client_id, "zipkin") + + begin + transport.open + yield(client) + ensure + transport.close + end + rescue ZookeeperExceptions::ZookeeperException::ConnectionClosed => ze + "Could not connect to zookeeper at #{opts[:zk_host]}:#{opts[:zk_port]}" + end + + end + + def self.get_query_service(zk_host, zk_port, opts={}) + # Takes either: + # - ZooKeeper config options that map to a Zipkin Query server set OR + # - Direct host/port of a Query daemon + + if opts[:skip_zookeeper] + return [ opts[:zipkin_query_host], opts[:zipkin_query_port] ] + end + + node_path = opts[:node_path] || NODE_PATH + + # TODO: throw error if it fails + zk = Zookeeper.new("#{zk_host}:#{zk_port}") + + begin + # TODO: handle errors here + children = zk.get_children(:path => node_path) + node_key = children[:children][0] + + # TODO: throw errors + node = zk.get(:path => "#{node_path}/#{node_key}") + ensure + zk.close() if zk + end + + # Deserialize the result + d = Thrift::Deserializer.new + si = d.deserialize(Twitter::Thrift::ServiceInstance.new, node[:data]) + + # Return the host and port + [si.serviceEndpoint.host, si.serviceEndpoint.port] + end + end + +end diff --git a/zipkin-gems/zipkin-query/lib/zipkin-query/version.rb b/zipkin-gems/zipkin-query/lib/zipkin-query/version.rb new file mode 100644 index 00000000000..1541cbce765 --- /dev/null +++ b/zipkin-gems/zipkin-query/lib/zipkin-query/version.rb @@ -0,0 +1,16 @@ +# Copyright 2012 Twitter Inc. +# +# 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. +module ZipkinQuery + VERSION = "0.0.1" +end diff --git a/zipkin-gems/zipkin-query/thrift/zipkinCore.thrift b/zipkin-gems/zipkin-query/thrift/zipkinCore.thrift new file mode 120000 index 00000000000..38f8a92ebb9 --- /dev/null +++ b/zipkin-gems/zipkin-query/thrift/zipkinCore.thrift @@ -0,0 +1 @@ +../../../zipkin-thrift/src/main/thrift/zipkinCore.thrift \ No newline at end of file diff --git a/zipkin-gems/zipkin-query/thrift/zipkinQuery.thrift b/zipkin-gems/zipkin-query/thrift/zipkinQuery.thrift new file mode 120000 index 00000000000..3388f4c1da2 --- /dev/null +++ b/zipkin-gems/zipkin-query/thrift/zipkinQuery.thrift @@ -0,0 +1 @@ +../../../zipkin-thrift/src/main/thrift/zipkinQuery.thrift \ No newline at end of file diff --git a/zipkin-gems/zipkin-query/vendor/gen-rb/zipkin-query.rb b/zipkin-gems/zipkin-query/vendor/gen-rb/zipkin-query.rb new file mode 100644 index 00000000000..4dc4c35eb2a --- /dev/null +++ b/zipkin-gems/zipkin-query/vendor/gen-rb/zipkin-query.rb @@ -0,0 +1,19 @@ +# Copyright 2012 Twitter Inc. +# +# 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 'set' +require 'thrift' + +module ZipkinQuery + require 'zipkin-query/zipkin_query' +end diff --git a/zipkin-web/lib/zipkin_constants.rb b/zipkin-gems/zipkin-query/vendor/gen-rb/zipkin-query/zipkin_core_constants.rb similarity index 73% rename from zipkin-web/lib/zipkin_constants.rb rename to zipkin-gems/zipkin-query/vendor/gen-rb/zipkin-query/zipkin_core_constants.rb index cfcdfa0c020..a438a0169a1 100644 --- a/zipkin-web/lib/zipkin_constants.rb +++ b/zipkin-gems/zipkin-query/vendor/gen-rb/zipkin-query/zipkin_core_constants.rb @@ -1,10 +1,10 @@ # -# Autogenerated by Thrift +# Autogenerated by Thrift Compiler (0.8.0) # # DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING # -require 'zipkin_types' +require 'zipkin_core_types' module Zipkin CLIENT_SEND = %q"cs" diff --git a/zipkin-gems/zipkin-query/vendor/gen-rb/zipkin-query/zipkin_core_types.rb b/zipkin-gems/zipkin-query/vendor/gen-rb/zipkin-query/zipkin_core_types.rb new file mode 100644 index 00000000000..c8535b56c7d --- /dev/null +++ b/zipkin-gems/zipkin-query/vendor/gen-rb/zipkin-query/zipkin_core_types.rb @@ -0,0 +1,112 @@ +# +# Autogenerated by Thrift Compiler (0.8.0) +# +# DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING +# + + +module Zipkin + module AnnotationType + BOOL = 0 + BYTES = 1 + I16 = 2 + I32 = 3 + I64 = 4 + DOUBLE = 5 + STRING = 6 + VALUE_MAP = {0 => "BOOL", 1 => "BYTES", 2 => "I16", 3 => "I32", 4 => "I64", 5 => "DOUBLE", 6 => "STRING"} + VALID_VALUES = Set.new([BOOL, BYTES, I16, I32, I64, DOUBLE, STRING]).freeze + end + + class Endpoint + include ::Thrift::Struct, ::Thrift::Struct_Union + IPV4 = 1 + PORT = 2 + SERVICE_NAME = 3 + + FIELDS = { + IPV4 => {:type => ::Thrift::Types::I32, :name => 'ipv4'}, + PORT => {:type => ::Thrift::Types::I16, :name => 'port'}, + SERVICE_NAME => {:type => ::Thrift::Types::STRING, :name => 'service_name'} + } + + def struct_fields; FIELDS; end + + def validate + end + + ::Thrift::Struct.generate_accessors self + end + + class Annotation + include ::Thrift::Struct, ::Thrift::Struct_Union + TIMESTAMP = 1 + VALUE = 2 + HOST = 3 + + FIELDS = { + TIMESTAMP => {:type => ::Thrift::Types::I64, :name => 'timestamp'}, + VALUE => {:type => ::Thrift::Types::STRING, :name => 'value'}, + HOST => {:type => ::Thrift::Types::STRUCT, :name => 'host', :class => Zipkin::Endpoint, :optional => true} + } + + def struct_fields; FIELDS; end + + def validate + end + + ::Thrift::Struct.generate_accessors self + end + + class BinaryAnnotation + include ::Thrift::Struct, ::Thrift::Struct_Union + KEY = 1 + VALUE = 2 + ANNOTATION_TYPE = 3 + HOST = 4 + + FIELDS = { + KEY => {:type => ::Thrift::Types::STRING, :name => 'key'}, + VALUE => {:type => ::Thrift::Types::STRING, :name => 'value', :binary => true}, + ANNOTATION_TYPE => {:type => ::Thrift::Types::I32, :name => 'annotation_type', :enum_class => Zipkin::AnnotationType}, + HOST => {:type => ::Thrift::Types::STRUCT, :name => 'host', :class => Zipkin::Endpoint, :optional => true} + } + + def struct_fields; FIELDS; end + + def validate + unless @annotation_type.nil? || Zipkin::AnnotationType::VALID_VALUES.include?(@annotation_type) + raise ::Thrift::ProtocolException.new(::Thrift::ProtocolException::UNKNOWN, 'Invalid value of field annotation_type!') + end + end + + ::Thrift::Struct.generate_accessors self + end + + class Span + include ::Thrift::Struct, ::Thrift::Struct_Union + TRACE_ID = 1 + NAME = 3 + ID = 4 + PARENT_ID = 5 + ANNOTATIONS = 6 + BINARY_ANNOTATIONS = 8 + + FIELDS = { + TRACE_ID => {:type => ::Thrift::Types::I64, :name => 'trace_id'}, + NAME => {:type => ::Thrift::Types::STRING, :name => 'name'}, + ID => {:type => ::Thrift::Types::I64, :name => 'id'}, + PARENT_ID => {:type => ::Thrift::Types::I64, :name => 'parent_id', :optional => true}, + ANNOTATIONS => {:type => ::Thrift::Types::LIST, :name => 'annotations', :element => {:type => ::Thrift::Types::STRUCT, :class => Zipkin::Annotation}}, + BINARY_ANNOTATIONS => {:type => ::Thrift::Types::LIST, :name => 'binary_annotations', :element => {:type => ::Thrift::Types::STRUCT, :class => Zipkin::BinaryAnnotation}} + } + + def struct_fields; FIELDS; end + + def validate + end + + ::Thrift::Struct.generate_accessors self + end + + end diff --git a/zipkin-web/lib/zipkin_query.rb b/zipkin-gems/zipkin-query/vendor/gen-rb/zipkin-query/zipkin_query.rb similarity index 93% rename from zipkin-web/lib/zipkin_query.rb rename to zipkin-gems/zipkin-query/vendor/gen-rb/zipkin-query/zipkin_query.rb index f09dc382779..a03a53e1646 100644 --- a/zipkin-web/lib/zipkin_query.rb +++ b/zipkin-gems/zipkin-query/vendor/gen-rb/zipkin-query/zipkin_query.rb @@ -1,11 +1,11 @@ # -# Autogenerated by Thrift +# Autogenerated by Thrift Compiler (0.8.0) # # DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING # require 'thrift' -require 'zipkin_types' +require 'zipkin_query_types' module Zipkin module ZipkinQuery @@ -124,21 +124,6 @@ def recv_getTraceCombosByIds() raise ::Thrift::ApplicationException.new(::Thrift::ApplicationException::MISSING_RESULT, 'getTraceCombosByIds failed: unknown result') end - def getThriftToString(trace_id, key, thrift_idl) - send_getThriftToString(trace_id, key, thrift_idl) - return recv_getThriftToString() - end - - def send_getThriftToString(trace_id, key, thrift_idl) - send_message('getThriftToString', GetThriftToString_args, :trace_id => trace_id, :key => key, :thrift_idl => thrift_idl) - end - - def recv_getThriftToString() - result = receive_message(GetThriftToString_result) - return result.success unless result.success.nil? - raise ::Thrift::ApplicationException.new(::Thrift::ApplicationException::MISSING_RESULT, 'getThriftToString failed: unknown result') - end - def getServiceNames() send_getServiceNames() return recv_getServiceNames() @@ -300,13 +285,6 @@ def process_getTraceCombosByIds(seqid, iprot, oprot) write_result(result, oprot, 'getTraceCombosByIds', seqid) end - def process_getThriftToString(seqid, iprot, oprot) - args = read_args(iprot, GetThriftToString_args) - result = GetThriftToString_result.new() - result.success = @handler.getThriftToString(args.trace_id, args.key, args.thrift_idl) - write_result(result, oprot, 'getThriftToString', seqid) - end - def process_getServiceNames(seqid, iprot, oprot) args = read_args(iprot, GetServiceNames_args) result = GetServiceNames_result.new() @@ -645,42 +623,6 @@ def validate ::Thrift::Struct.generate_accessors self end - class GetThriftToString_args - include ::Thrift::Struct, ::Thrift::Struct_Union - TRACE_ID = 1 - KEY = 2 - THRIFT_IDL = 3 - - FIELDS = { - TRACE_ID => {:type => ::Thrift::Types::I64, :name => 'trace_id'}, - KEY => {:type => ::Thrift::Types::STRING, :name => 'key'}, - THRIFT_IDL => {:type => ::Thrift::Types::STRING, :name => 'thrift_idl'} - } - - def struct_fields; FIELDS; end - - def validate - end - - ::Thrift::Struct.generate_accessors self - end - - class GetThriftToString_result - include ::Thrift::Struct, ::Thrift::Struct_Union - SUCCESS = 0 - - FIELDS = { - SUCCESS => {:type => ::Thrift::Types::LIST, :name => 'success', :element => {:type => ::Thrift::Types::STRING}} - } - - def struct_fields; FIELDS; end - - def validate - end - - ::Thrift::Struct.generate_accessors self - end - class GetServiceNames_args include ::Thrift::Struct, ::Thrift::Struct_Union diff --git a/zipkin-gems/zipkin-query/vendor/gen-rb/zipkin-query/zipkin_query_constants.rb b/zipkin-gems/zipkin-query/vendor/gen-rb/zipkin-query/zipkin_query_constants.rb new file mode 100644 index 00000000000..09a952c8ba1 --- /dev/null +++ b/zipkin-gems/zipkin-query/vendor/gen-rb/zipkin-query/zipkin_query_constants.rb @@ -0,0 +1,10 @@ +# +# Autogenerated by Thrift Compiler (0.8.0) +# +# DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING +# + +require 'zipkin_query_types' + + module Zipkin +end diff --git a/zipkin-web/lib/zipkin_types.rb b/zipkin-gems/zipkin-query/vendor/gen-rb/zipkin-query/zipkin_query_types.rb similarity index 55% rename from zipkin-web/lib/zipkin_types.rb rename to zipkin-gems/zipkin-query/vendor/gen-rb/zipkin-query/zipkin_query_types.rb index f92338e555c..18d92e72fa8 100644 --- a/zipkin-web/lib/zipkin_types.rb +++ b/zipkin-gems/zipkin-query/vendor/gen-rb/zipkin-query/zipkin_query_types.rb @@ -1,23 +1,13 @@ # -# Autogenerated by Thrift +# Autogenerated by Thrift Compiler (0.8.0) # # DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING # +require 'zipkin_core_types' -module Zipkin - module AnnotationType - BOOL = 0 - BYTES = 1 - I16 = 2 - I32 = 3 - I64 = 4 - DOUBLE = 5 - STRING = 6 - VALUE_MAP = {0 => "BOOL", 1 => "BYTES", 2 => "I16", 3 => "I32", 4 => "I64", 5 => "DOUBLE", 6 => "STRING"} - VALID_VALUES = Set.new([BOOL, BYTES, I16, I32, I64, DOUBLE, STRING]).freeze - end +module Zipkin module Order TIMESTAMP_DESC = 0 TIMESTAMP_ASC = 1 @@ -35,104 +25,6 @@ module Adjust VALID_VALUES = Set.new([NOTHING, TIME_SKEW]).freeze end - module ResultCode - OK = 0 - TRY_LATER = 1 - VALUE_MAP = {0 => "OK", 1 => "TRY_LATER"} - VALID_VALUES = Set.new([OK, TRY_LATER]).freeze - end - - class Endpoint - include ::Thrift::Struct, ::Thrift::Struct_Union - IPV4 = 1 - PORT = 2 - SERVICE_NAME = 3 - - FIELDS = { - IPV4 => {:type => ::Thrift::Types::I32, :name => 'ipv4'}, - PORT => {:type => ::Thrift::Types::I16, :name => 'port'}, - SERVICE_NAME => {:type => ::Thrift::Types::STRING, :name => 'service_name'} - } - - def struct_fields; FIELDS; end - - def validate - end - - ::Thrift::Struct.generate_accessors self - end - - class Annotation - include ::Thrift::Struct, ::Thrift::Struct_Union - TIMESTAMP = 1 - VALUE = 2 - HOST = 3 - - FIELDS = { - TIMESTAMP => {:type => ::Thrift::Types::I64, :name => 'timestamp'}, - VALUE => {:type => ::Thrift::Types::STRING, :name => 'value'}, - HOST => {:type => ::Thrift::Types::STRUCT, :name => 'host', :class => Zipkin::Endpoint, :optional => true} - } - - def struct_fields; FIELDS; end - - def validate - end - - ::Thrift::Struct.generate_accessors self - end - - class BinaryAnnotation - include ::Thrift::Struct, ::Thrift::Struct_Union - KEY = 1 - VALUE = 2 - ANNOTATION_TYPE = 3 - HOST = 4 - - FIELDS = { - KEY => {:type => ::Thrift::Types::STRING, :name => 'key'}, - VALUE => {:type => ::Thrift::Types::STRING, :name => 'value', :binary => true}, - ANNOTATION_TYPE => {:type => ::Thrift::Types::I32, :name => 'annotation_type', :enum_class => Zipkin::AnnotationType}, - HOST => {:type => ::Thrift::Types::STRUCT, :name => 'host', :class => Zipkin::Endpoint, :optional => true} - } - - def struct_fields; FIELDS; end - - def validate - unless @annotation_type.nil? || Zipkin::AnnotationType::VALID_VALUES.include?(@annotation_type) - raise ::Thrift::ProtocolException.new(::Thrift::ProtocolException::UNKNOWN, 'Invalid value of field annotation_type!') - end - end - - ::Thrift::Struct.generate_accessors self - end - - class Span - include ::Thrift::Struct, ::Thrift::Struct_Union - TRACE_ID = 1 - NAME = 3 - ID = 4 - PARENT_ID = 5 - ANNOTATIONS = 6 - BINARY_ANNOTATIONS = 8 - - FIELDS = { - TRACE_ID => {:type => ::Thrift::Types::I64, :name => 'trace_id'}, - NAME => {:type => ::Thrift::Types::STRING, :name => 'name'}, - ID => {:type => ::Thrift::Types::I64, :name => 'id'}, - PARENT_ID => {:type => ::Thrift::Types::I64, :name => 'parent_id', :optional => true}, - ANNOTATIONS => {:type => ::Thrift::Types::LIST, :name => 'annotations', :element => {:type => ::Thrift::Types::STRUCT, :class => Zipkin::Annotation}}, - BINARY_ANNOTATIONS => {:type => ::Thrift::Types::LIST, :name => 'binary_annotations', :element => {:type => ::Thrift::Types::STRUCT, :class => Zipkin::BinaryAnnotation}} - } - - def struct_fields; FIELDS; end - - def validate - end - - ::Thrift::Struct.generate_accessors self - end - class Trace include ::Thrift::Struct, ::Thrift::Struct_Union SPANS = 1 @@ -172,29 +64,6 @@ def validate ::Thrift::Struct.generate_accessors self end - class AdjustableRateException < ::Thrift::Exception - include ::Thrift::Struct, ::Thrift::Struct_Union - def initialize(message=nil) - super() - self.msg = message - end - - def message; msg end - - MSG = 1 - - FIELDS = { - MSG => {:type => ::Thrift::Types::STRING, :name => 'msg'} - } - - def struct_fields; FIELDS; end - - def validate - end - - ::Thrift::Struct.generate_accessors self - end - # This sums up a single Trace to make it easy for a client to get an overview of what happened. class TraceSummary include ::Thrift::Struct, ::Thrift::Struct_Union @@ -297,22 +166,4 @@ def validate ::Thrift::Struct.generate_accessors self end - class LogEntry - include ::Thrift::Struct, ::Thrift::Struct_Union - CATEGORY = 1 - MESSAGE = 2 - - FIELDS = { - CATEGORY => {:type => ::Thrift::Types::STRING, :name => 'category'}, - MESSAGE => {:type => ::Thrift::Types::STRING, :name => 'message'} - } - - def struct_fields; FIELDS; end - - def validate - end - - ::Thrift::Struct.generate_accessors self - end - end diff --git a/zipkin-gems/zipkin-query/zipkin-query.gemspec b/zipkin-gems/zipkin-query/zipkin-query.gemspec new file mode 100644 index 00000000000..255db881fa8 --- /dev/null +++ b/zipkin-gems/zipkin-query/zipkin-query.gemspec @@ -0,0 +1,35 @@ +# -*- encoding: utf-8 -*- +# Copyright 2012 Twitter Inc. +# +# 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. +lib = File.expand_path('../lib/', __FILE__) +$:.unshift lib unless $:.include?(lib) + +require 'zipkin-query/version' + +Gem::Specification.new do |s| + s.name = "zipkin-query" + s.version = ZipkinQuery::VERSION + s.authors = ["Franklin Hu"] + s.email = ["franklin@twitter.com"] + s.homepage = "https://github.com/twitter/zipkin" + s.summary = "Zipkin Query client" + s.description = "Client for accessing the Zipkin query service" + + s.required_rubygems_version = ">= 1.3.5" + + s.files = Dir.glob("{bin,lib,vendor}/**/*") + s.require_path = 'lib' + + s.add_dependency 'thrift', '0.6.0' +end diff --git a/zipkin-thrift/src/main/thrift/zipkinCollector.thrift b/zipkin-thrift/src/main/thrift/zipkinCollector.thrift index 7badf180f67..36cf8498e0f 100644 --- a/zipkin-thrift/src/main/thrift/zipkinCollector.thrift +++ b/zipkin-thrift/src/main/thrift/zipkinCollector.thrift @@ -12,6 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. namespace java com.twitter.zipkin.gen +namespace rb Zipkin include "scribe.thrift" diff --git a/zipkin-thrift/src/main/thrift/zipkinQuery.thrift b/zipkin-thrift/src/main/thrift/zipkinQuery.thrift index 8c2471fbf05..d52a52e1586 100644 --- a/zipkin-thrift/src/main/thrift/zipkinQuery.thrift +++ b/zipkin-thrift/src/main/thrift/zipkinQuery.thrift @@ -12,6 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. namespace java com.twitter.zipkin.gen +namespace rb Zipkin include "zipkinCore.thrift" diff --git a/zipkin-web/Gemfile b/zipkin-web/Gemfile index e085cb63408..66b193c6cd2 100644 --- a/zipkin-web/Gemfile +++ b/zipkin-web/Gemfile @@ -7,4 +7,5 @@ gem 'zookeeper', "1.2.4" gem 'finagle-thrift', '1.2.0' gem 'scribe', '0.2.4' gem 'zipkin-tracer', '0.0.1' +gem 'zipkin-query', '0.0.1' diff --git a/zipkin-web/Gemfile.lock b/zipkin-web/Gemfile.lock index b7f97c45133..ba4aba0f6d6 100644 --- a/zipkin-web/Gemfile.lock +++ b/zipkin-web/Gemfile.lock @@ -88,6 +88,7 @@ GEM polyglot polyglot (>= 0.3.1) tzinfo (0.3.33) + zipkin-query (0.0.1) zipkin-tracer (0.0.1) finagle-thrift (~> 1.2.0) scribe (~> 0.2.4) @@ -104,5 +105,6 @@ DEPENDENCIES scribe (= 0.2.4) thrift (= 0.6.0) thrift_client (= 0.6.3) + zipkin-query (= 0.0.1) zipkin-tracer (= 0.0.1) zookeeper (= 1.2.4) diff --git a/zipkin-web/app/controllers/traces_controller.rb b/zipkin-web/app/controllers/traces_controller.rb index 52b6a59aa45..718d45af68e 100644 --- a/zipkin-web/app/controllers/traces_controller.rb +++ b/zipkin-web/app/controllers/traces_controller.rb @@ -16,8 +16,6 @@ require 'base64' -require 'zipkin_client' - require 'endpoint' require 'annotation' require 'names' @@ -26,7 +24,6 @@ require 'index' require 'timeline_annotation' - class TracesController < ApplicationController respond_to :html, :json diff --git a/zipkin-web/app/models/endpoint.rb b/zipkin-web/app/models/endpoint.rb index 91698c472ca..676ffee1fb8 100644 --- a/zipkin-web/app/models/endpoint.rb +++ b/zipkin-web/app/models/endpoint.rb @@ -1,18 +1,17 @@ # Copyright 2012 Twitter Inc. -# +# # 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 'zipkin_types' require 'ipaddr' class Endpoint diff --git a/zipkin-web/app/models/index.rb b/zipkin-web/app/models/index.rb index 7a6d8093378..c894592da05 100644 --- a/zipkin-web/app/models/index.rb +++ b/zipkin-web/app/models/index.rb @@ -1,19 +1,17 @@ # Copyright 2012 Twitter Inc. -# +# # 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 'zipkin_client' -require 'zipkin_types' require 'ipaddr' # methods for fetching the trace ids the user is interested in from the index @@ -25,7 +23,7 @@ def self.get_trace_ids_by_span_name(service_name, span_name, end_ts, limit, opts end_ts = secondsToMicroseconds(end_ts) order = opts[:order] || ORDER_DEFAULT - ZipkinClient.with_transport(Rails.configuration.zookeeper) do |client| + ZipkinQuery::Client.with_transport(Rails.configuration.zookeeper) do |client| client.getTraceIdsBySpanName(service_name, span_name, end_ts, limit, order) end end @@ -34,7 +32,7 @@ def self.get_trace_ids_by_service_name(service_name, end_ts, limit, opts = {}) end_ts = secondsToMicroseconds(end_ts) order = opts[:order] || ORDER_DEFAULT - ZipkinClient.with_transport(Rails.configuration.zookeeper) do |client| + ZipkinQuery::Client.with_transport(Rails.configuration.zookeeper) do |client| client.getTraceIdsByServiceName(service_name, end_ts, limit, order) end end @@ -43,7 +41,7 @@ def self.get_trace_ids_by_annotation(service_name, annotation, value, end_ts, li end_ts = secondsToMicroseconds(end_ts) order = opts[:order] || ORDER_DEFAULT - ZipkinClient.with_transport(Rails.configuration.zookeeper) do |client| + ZipkinQuery::Client.with_transport(Rails.configuration.zookeeper) do |client| client.getTraceIdsByAnnotation(service_name, annotation, value, end_ts, limit, order) end end diff --git a/zipkin-web/app/models/names.rb b/zipkin-web/app/models/names.rb index 3a028238a8e..538ce88b291 100644 --- a/zipkin-web/app/models/names.rb +++ b/zipkin-web/app/models/names.rb @@ -1,31 +1,29 @@ # Copyright 2012 Twitter Inc. -# +# # 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 'zipkin_client' -require 'zipkin_types' require 'ipaddr' class Names def self.get_service_names - ZipkinClient.with_transport(Rails.configuration.zookeeper) do |client| + ZipkinQuery::Client.with_transport(Rails.configuration.zookeeper) do |client| client.getServiceNames().sort end end def self.get_span_names(service_name) - ZipkinClient.with_transport(Rails.configuration.zookeeper) do |client| + ZipkinQuery::Client.with_transport(Rails.configuration.zookeeper) do |client| client.getSpanNames(service_name).sort end end diff --git a/zipkin-web/app/models/span.rb b/zipkin-web/app/models/span.rb index 4dcdc3e10f6..4a646aea572 100644 --- a/zipkin-web/app/models/span.rb +++ b/zipkin-web/app/models/span.rb @@ -1,18 +1,17 @@ # Copyright 2012 Twitter Inc. -# +# # 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 'zipkin_types' require 'ipaddr' class Span @@ -63,15 +62,15 @@ def duration_ms # Convert from micro seconds to milliseconds (end_timestamp - start_timestamp) / 1000.00 end - + def service_names services = annotations.map do |a| - if (a.host) + if (a.host) a.host.service_name else nil end end services.compact.uniq - end + end end \ No newline at end of file diff --git a/zipkin-web/app/models/trace_combo.rb b/zipkin-web/app/models/trace_combo.rb index e548b5dbe2d..d81d0d2b8bd 100644 --- a/zipkin-web/app/models/trace_combo.rb +++ b/zipkin-web/app/models/trace_combo.rb @@ -1,19 +1,17 @@ # Copyright 2012 Twitter Inc. -# +# # 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 'zipkin_client' -require 'zipkin_types' require 'ipaddr' class TraceCombo @@ -44,7 +42,7 @@ def initialize(trace, summary, timeline, span_depths) end def self.get_trace_combos_by_ids(trace_ids, adjusters, opts = {}) - ZipkinClient.with_transport(Rails.configuration.zookeeper) do |client| + ZipkinQuery::Client.with_transport(Rails.configuration.zookeeper) do |client| combos = client.getTraceCombosByIds(trace_ids.collect { |id| id.to_i }, adjusters) combos.collect { |combo| TraceCombo.from_thrift(combo) } end diff --git a/zipkin-web/app/models/trace_summary.rb b/zipkin-web/app/models/trace_summary.rb index e9c0e8db10b..f96eb0a4fd0 100644 --- a/zipkin-web/app/models/trace_summary.rb +++ b/zipkin-web/app/models/trace_summary.rb @@ -1,19 +1,17 @@ # Copyright 2012 Twitter Inc. -# +# # 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 'zipkin_client' -require 'zipkin_types' require 'ipaddr' require 'endpoint' @@ -62,7 +60,7 @@ def initialize(trace_id, start_timestamp, end_timestamp, duration_micro, service end def self.get_trace_summaries_by_ids(trace_ids, adjusters, opts={}) - ZipkinClient.with_transport(Rails.configuration.zookeeper) do |client| + ZipkinQuery::Client.with_transport(Rails.configuration.zookeeper) do |client| ids = trace_ids.collect { |id| id.to_i } summaries = client.getTraceSummariesByIds(ids, adjusters) summaries.collect { |summary| TraceSummary.from_thrift(summary) } diff --git a/zipkin-web/app/models/trace_timeline.rb b/zipkin-web/app/models/trace_timeline.rb index 5340d908912..e1eecf53b5d 100644 --- a/zipkin-web/app/models/trace_timeline.rb +++ b/zipkin-web/app/models/trace_timeline.rb @@ -12,8 +12,6 @@ # See the License for the specific language governing permissions and # limitations under the License. -require 'zipkin_client' -require 'zipkin_types' require 'ipaddr' class TraceTimeline @@ -46,7 +44,7 @@ def initialize(trace_id, root_most_span_id, annotations, binary_annotations) end def self.get_trace_timelines_by_ids(trace_ids, opts = {}) - ZipkinClient.with_transport(Rails.configuration.zookeeper) do |client| + ZipkinQuery::Client.with_transport(Rails.configuration.zookeeper) do |client| adjusters = [] # [Zipkin::Adjust::TIME_SKEW] #TODO config ids = trace_ids.collect { |id| id.to_i } timelines = client.getTraceTimelinesByIds(ids, adjusters) diff --git a/zipkin-web/app/models/ztrace.rb b/zipkin-web/app/models/ztrace.rb index e459b120d07..752517226be 100644 --- a/zipkin-web/app/models/ztrace.rb +++ b/zipkin-web/app/models/ztrace.rb @@ -1,19 +1,17 @@ # Copyright 2012 Twitter Inc. -# +# # 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 'zipkin_client' -require 'zipkin_types' require 'ipaddr' class ZTrace @@ -125,7 +123,7 @@ def as_json(opts={}) end def self.get_traces_by_ids(trace_ids, opts = {}) - ZipkinClient.with_transport(Rails.configuration.zookeeper) do |client| + ZipkinQuery::Client.with_transport(Rails.configuration.zookeeper) do |client| adjusters = [] #[Zipkin::Adjust::TIME_SKEW] #TODO config traces = client.getTracesByIds(trace_ids.collect { |id| id.to_i }, adjusters) traces.collect { |trace| ZTrace.from_thrift(trace) } @@ -134,19 +132,19 @@ def self.get_traces_by_ids(trace_ids, opts = {}) # what is the default ttl we set traces to? def self.get_default_ttl_sec(opts = {}) - ZipkinClient.with_transport(Rails.configuration.zookeeper) do |client| + ZipkinQuery::Client.with_transport(Rails.configuration.zookeeper) do |client| client.getDataTimeToLive() end end def self.get_ttl(trace_id, opts = {}) - ZipkinClient.with_transport(Rails.configuration.zookeeper) do |client| + ZipkinQuery::Client.with_transport(Rails.configuration.zookeeper) do |client| client.getTraceTimeToLive(trace_id) # returns seconds end end def self.set_ttl(trace_id, ttl_seconds, opts = {}) - ZipkinClient.with_transport(Rails.configuration.zookeeper) do |client| + ZipkinQuery::Client.with_transport(Rails.configuration.zookeeper) do |client| client.setTraceTimeToLive(trace_id.to_i, ttl_seconds.to_i) end end diff --git a/zipkin-web/lib/zipkin.thrift b/zipkin-web/lib/zipkin.thrift deleted file mode 100755 index 2f34e552635..00000000000 --- a/zipkin-web/lib/zipkin.thrift +++ /dev/null @@ -1,287 +0,0 @@ -# Copyright 2012 Twitter Inc. -# -# 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. -namespace java com.twitter.zipkin.gen -namespace rb Zipkin - -//************** Collection related structs ************** - -// these are the annotations we always expect to find in a span -const string CLIENT_SEND = "cs" -const string CLIENT_RECV = "cr" -const string SERVER_SEND = "ss" -const string SERVER_RECV = "sr" - -// this represents a host and port in a network -struct Endpoint { - 1: i32 ipv4, - 2: i16 port // beware that this will give us negative ports. some conversion needed - 3: string service_name // which service did this operation happen on? -} - -// some event took place, either one by the framework or by the user -struct Annotation { - 1: i64 timestamp // microseconds from epoch - 2: string value // what happened at the timestamp? - 3: optional Endpoint host // host this happened on -} - -enum AnnotationType { BOOL, BYTES, I16, I32, I64, DOUBLE, STRING } - -struct BinaryAnnotation { - 1: string key, - 2: binary value, - 3: AnnotationType annotation_type, - 4: optional Endpoint host -} - -struct Span { - 1: i64 trace_id // unique trace id, use for all spans in trace - 3: string name, // span name, rpc method for example - 4: i64 id, // unique span id, only used for this span - 5: optional i64 parent_id, // parent span id - 6: list annotations, // list of all annotations/events that occured - 8: list binary_annotations // any binary annotations -} - - -//************** Query related structs ************** - -struct Trace { - 1: list spans -} - -exception QueryException { - 1: string msg -} - -exception AdjustableRateException { - 1: string msg -} - -/** - * This sums up a single Trace to make it easy for a client to get an overview of what happened. - */ -struct TraceSummary { - 1: i64 trace_id // the trace - 2: i64 start_timestamp // start timestamp of the trace, in microseconds - 3: i64 end_timestamp // end timestamp of the trace, in microseconds - 4: i32 duration_micro // how long did the entire trace take? in microseconds - 5: map service_counts // which services were involved? - 6: list endpoints // which endpoints were involved? -} - -/** - * A modified version of the Annotation struct that brings in more information - */ -struct TimelineAnnotation { - 1: i64 timestamp // microseconds from epoch - 2: string value // what happened at the timestamp? - 3: Endpoint host // host this happened on - 4: i64 span_id // which span does this annotation belong to? - 5: optional i64 parent_id // parent span id - 6: string service_name // which service did this annotation happen on? - 7: string span_name // span name, rpc method for example -} - -/** - * This sums up a single Trace to make it easy for a client to get an overview of what happened. - */ -struct TraceTimeline { - 1: i64 trace_id // the trace - 2: i64 root_most_span_id // either the true root span or the closest we can find - 6: list annotations // annotations as they happened - 7: list binary_annotations // all the binary annotations -} - -/** - * Returns a combination of trace, summary and timeline. - */ -struct TraceCombo { - 1: Trace trace - 2: optional TraceSummary summary // not set if no spans in trace - 3: optional TraceTimeline timeline // not set if no spans in trace - 4: optional map span_depths // not set if no spans in trace -} - -enum Order { TIMESTAMP_DESC, TIMESTAMP_ASC, DURATION_ASC, DURATION_DESC, NONE } - -/** - * The raw data in our storage might have various problems. How should we adjust it before - * returning it to the user? - * - * Time skew adjuster tries to make sure that even though servers might have slightly - * different clocks the annotations in the returned data are adjusted so that they are - * in the correct order. - */ -enum Adjust { NOTHING, TIME_SKEW } - - -//************** Collector and query services ************** - -// this is copied from scribe.thrift. once we get scrooge working as we want it to we'll split this out again -enum ResultCode -{ - OK, - TRY_LATER -} - -struct LogEntry -{ - 1: string category, - 2: string message -} - -service ZipkinCollector { - - // from scribe.thrift - ResultCode Log(1: list messages); - - //************** ZK config changes ************** - - /** - * Get the sample rate in ZooKeeper for the cluster - */ - double getSampleRate() throws (1: AdjustableRateException qe); - - /** - * Set sample rate in ZooKeeper for the cluster - */ - void setSampleRate(1: double sample_rate) throws (1: AdjustableRateException qe); - - /** - * Get the storage request rate in ZooKeeper for the cluster - * The storage request rate is used as the target number of storage requests - * per minute - */ - double getStorageRequestRate() throws (1: AdjustableRateException e); - - /** - * Set the storage request rate in ZooKeeper for the cluster - */ - void setStorageRequestRate(1: double storage_request_rate) throws (1: AdjustableRateException e); -} - -service ZipkinQuery { - - - //************** Index lookups ************** - - /** - * Fetch trace ids by service and span name. - * Gets "limit" number of entries from before the "end_ts". - * - * Span name is optional. - * Timestamps are in microseconds. - */ - list getTraceIdsBySpanName(1: string service_name, 2: string span_name, - 4: i64 end_ts, 5: i32 limit, 6: Order order) throws (1: QueryException qe); - - /** - * Fetch trace ids by service name. - * Gets "limit" number of entries from before the "end_ts". - * - * Timestamps are in microseconds. - */ - list getTraceIdsByServiceName(1: string service_name, - 3: i64 end_ts, 4: i32 limit, 5: Order order) throws (1: QueryException qe); - - /** - * Fetch trace ids with a particular annotation. - * Gets "limit" number of entries from before the "end_ts". - * - * When requesting based on time based annotations only pass in the first parameter, "annotation" and leave out - * the second "value". If looking for a key-value binary annotation provide both, "annotation" is then the - * key in the key-value. - * - * Timestamps are in microseconds. - */ - list getTraceIdsByAnnotation(1: string service_name, 2: string annotation, 3: binary value, - 5: i64 end_ts, 6: i32 limit, 7: Order order) throws (1: QueryException qe); - - - //************** Fetch traces from id ************** - - /** - * Get the full traces associated with the given trace ids. - * - * Second argument is a list of methods of adjusting the trace - * data before returning it. Can be empty. - */ - list getTracesByIds(1: list trace_ids, 2: list adjust) throws (1: QueryException qe); - - /** - * Get the trace timelines associated with the given trace ids. - * This is a convenience method for users that just want to know - * the annotations and the (assumed) order they happened in. - * - * Second argument is a list of methods of adjusting the trace - * data before returning it. Can be empty. - * - * Note that if one of the trace ids does not have any data associated with it, it will not be - * represented in the output list. - */ - list getTraceTimelinesByIds(1: list trace_ids, 2: list adjust) throws (1: QueryException qe); - - /** - * Fetch trace summaries for the given trace ids. - * - * Second argument is a list of methods of adjusting the trace - * data before returning it. Can be empty. - * - * Note that if one of the trace ids does not have any data associated with it, it will not be - * represented in the output list. - */ - list getTraceSummariesByIds(1: list trace_ids, 2: list adjust) throws (1: QueryException qe); - - /** - * Not content with just one of traces, summaries or timelines? Want it all? This is the method for you. - */ - list getTraceCombosByIds(1: list trace_ids, 2: list adjust) throws (1: QueryException qe); - - //************** Misc metadata ************** - - /** - * Fetch the value attached to this trace and key, deserialize using the provided idl - * and run toString on it - */ - list getThriftToString(1: i64 trace_id, 2: string key, 3: string thrift_idl); - - /** - * Fetch all the service names we have seen from now all the way back to the set ttl. - */ - set getServiceNames() throws (1: QueryException qe); - - /** - * Get all the seen span names for a particular service, from now back until the set ttl. - */ - set getSpanNames(1: string service_name) throws (1: QueryException qe); - - //************** TTL related ************** - - /** - * Change the TTL of a trace. If we find an interesting trace we want to keep around for further - * investigation. - */ - void setTraceTimeToLive(1: i64 trace_id, 2: i32 ttl_seconds) throws (1: QueryException qe); - - /** - * Get the TTL in seconds of a specific trace. - */ - i32 getTraceTimeToLive(1: i64 trace_id) throws (1: QueryException qe); - - /** - * Get the data ttl. This is the number of seconds we keep the data around before deleting it. - */ - i32 getDataTimeToLive() throws (1: QueryException qe); -} diff --git a/zipkin-web/lib/zipkin_client.rb b/zipkin-web/lib/zipkin_client.rb deleted file mode 100644 index 1d6d02b323b..00000000000 --- a/zipkin-web/lib/zipkin_client.rb +++ /dev/null @@ -1,109 +0,0 @@ -# Copyright 2012 Twitter Inc. -# -# 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. - -# This file is the Client For interacting with the Zipkin Thrift service. All of the ruby files -# related to using this code are generated using thrift from bbb.thrift and scribe.thrift -# I use a shortcut file to download and generate the ruby code. See script/update_thrifts for more info - -require 'zookeeper' -require 'thrift' -require 'endpoint_types' -require 'zipkin_query' -require 'finagle-thrift' - -module ZipkinClient - - # The node location in zookeeper that stores the cassandra location - NODE_PATH = "/twitter/service/zipkin/query" - - def self.with_transport(opts = {}) - # Open a connection to a thrift server, do something, and close the connection - - begin - - if opts[:use_local_server] - # If we're running local (development mode) return a set value - host = "localhost" - port = 9149 - - # Create the connection to the local b3 query_daemon which uses different - # transport mechanism - socket = Thrift::Socket.new(host, port) - transport = Thrift::BufferedTransport.new(socket) - else - # Get the host and port of the location of the query service from zookeeper - zk_host = opts[:zk_host] || "localhost" - zk_port = opts[:zk_port] || 2181 - - host, port = ZipkinClient::get_query_service(zk_host, zk_port, opts) - - # Create the connection to the b3 query_daemon - socket = Thrift::Socket.new(host, port) - buffered_tp = Thrift::BufferedTransport.new(socket) - transport = Thrift::FramedTransport.new(buffered_tp) - end - - protocol = Thrift::BinaryProtocol.new(transport) - client = ThriftClient.new(Zipkin::ZipkinQuery::Client, host + ':' + port.to_s, :retries => 0, :timeout => 60) - - # set up tracing for the client we use to talk to the query daemon - client_id = FinagleThrift::ClientId.new(:name => "zipkin.prod") - FinagleThrift.enable_tracing!(client, client_id, "zipkin") - - begin - transport.open - yield(client) - ensure - transport.close - end - rescue ZookeeperExceptions::ZookeeperException::ConnectionClosed => ze - "Could not connect to zookeeper at #{opts[:zk_host]}:#{opts[:zk_port]}" - end - - end - - def self.get_query_service(zk_host, zk_port, opts={}) - # Takes either: - # - ZooKeeper config options that map to a Zipkin Query server set OR - # - Direct host/port of a Query daemon - - if opts[:skip_zookeeper] - return [ opts[:zipkin_query_host], opts[:zipkin_query_port] ] - end - - node_path = opts[:node_path] || NODE_PATH - - # TODO: throw error if it fails - zk = Zookeeper.new("#{zk_host}:#{zk_port}") - - begin - # TODO: handle errors here - children = zk.get_children(:path => node_path) - node_key = children[:children][0] - - # TODO: throw errors - node = zk.get(:path => "#{node_path}/#{node_key}") - ensure - zk.close() if zk - end - - # Deserialize the result - d = Thrift::Deserializer.new - si = d.deserialize(Twitter::Thrift::ServiceInstance.new, node[:data]) - - # Return the host and port - [si.serviceEndpoint.host, si.serviceEndpoint.port] - end - -end \ No newline at end of file diff --git a/zipkin-web/lib/zipkin_collector.rb b/zipkin-web/lib/zipkin_collector.rb deleted file mode 100644 index e07f59f1de2..00000000000 --- a/zipkin-web/lib/zipkin_collector.rb +++ /dev/null @@ -1,319 +0,0 @@ -# -# Autogenerated by Thrift -# -# DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING -# - -require 'thrift' -require 'zipkin_types' - - module Zipkin - module ZipkinCollector - class Client - include ::Thrift::Client - - def Log(messages) - send_Log(messages) - return recv_Log() - end - - def send_Log(messages) - send_message('Log', Log_args, :messages => messages) - end - - def recv_Log() - result = receive_message(Log_result) - return result.success unless result.success.nil? - raise ::Thrift::ApplicationException.new(::Thrift::ApplicationException::MISSING_RESULT, 'Log failed: unknown result') - end - - def getSampleRate() - send_getSampleRate() - return recv_getSampleRate() - end - - def send_getSampleRate() - send_message('getSampleRate', GetSampleRate_args) - end - - def recv_getSampleRate() - result = receive_message(GetSampleRate_result) - return result.success unless result.success.nil? - raise result.qe unless result.qe.nil? - raise ::Thrift::ApplicationException.new(::Thrift::ApplicationException::MISSING_RESULT, 'getSampleRate failed: unknown result') - end - - def setSampleRate(sample_rate) - send_setSampleRate(sample_rate) - recv_setSampleRate() - end - - def send_setSampleRate(sample_rate) - send_message('setSampleRate', SetSampleRate_args, :sample_rate => sample_rate) - end - - def recv_setSampleRate() - result = receive_message(SetSampleRate_result) - raise result.qe unless result.qe.nil? - return - end - - def getStorageRequestRate() - send_getStorageRequestRate() - return recv_getStorageRequestRate() - end - - def send_getStorageRequestRate() - send_message('getStorageRequestRate', GetStorageRequestRate_args) - end - - def recv_getStorageRequestRate() - result = receive_message(GetStorageRequestRate_result) - return result.success unless result.success.nil? - raise result.e unless result.e.nil? - raise ::Thrift::ApplicationException.new(::Thrift::ApplicationException::MISSING_RESULT, 'getStorageRequestRate failed: unknown result') - end - - def setStorageRequestRate(storage_request_rate) - send_setStorageRequestRate(storage_request_rate) - recv_setStorageRequestRate() - end - - def send_setStorageRequestRate(storage_request_rate) - send_message('setStorageRequestRate', SetStorageRequestRate_args, :storage_request_rate => storage_request_rate) - end - - def recv_setStorageRequestRate() - result = receive_message(SetStorageRequestRate_result) - raise result.e unless result.e.nil? - return - end - - end - - class Processor - include ::Thrift::Processor - - def process_Log(seqid, iprot, oprot) - args = read_args(iprot, Log_args) - result = Log_result.new() - result.success = @handler.Log(args.messages) - write_result(result, oprot, 'Log', seqid) - end - - def process_getSampleRate(seqid, iprot, oprot) - args = read_args(iprot, GetSampleRate_args) - result = GetSampleRate_result.new() - begin - result.success = @handler.getSampleRate() - rescue Zipkin::AdjustableRateException => qe - result.qe = qe - end - write_result(result, oprot, 'getSampleRate', seqid) - end - - def process_setSampleRate(seqid, iprot, oprot) - args = read_args(iprot, SetSampleRate_args) - result = SetSampleRate_result.new() - begin - @handler.setSampleRate(args.sample_rate) - rescue Zipkin::AdjustableRateException => qe - result.qe = qe - end - write_result(result, oprot, 'setSampleRate', seqid) - end - - def process_getStorageRequestRate(seqid, iprot, oprot) - args = read_args(iprot, GetStorageRequestRate_args) - result = GetStorageRequestRate_result.new() - begin - result.success = @handler.getStorageRequestRate() - rescue Zipkin::AdjustableRateException => e - result.e = e - end - write_result(result, oprot, 'getStorageRequestRate', seqid) - end - - def process_setStorageRequestRate(seqid, iprot, oprot) - args = read_args(iprot, SetStorageRequestRate_args) - result = SetStorageRequestRate_result.new() - begin - @handler.setStorageRequestRate(args.storage_request_rate) - rescue Zipkin::AdjustableRateException => e - result.e = e - end - write_result(result, oprot, 'setStorageRequestRate', seqid) - end - - end - - # HELPER FUNCTIONS AND STRUCTURES - - class Log_args - include ::Thrift::Struct, ::Thrift::Struct_Union - MESSAGES = 1 - - FIELDS = { - MESSAGES => {:type => ::Thrift::Types::LIST, :name => 'messages', :element => {:type => ::Thrift::Types::STRUCT, :class => Zipkin::LogEntry}} - } - - def struct_fields; FIELDS; end - - def validate - end - - ::Thrift::Struct.generate_accessors self - end - - class Log_result - include ::Thrift::Struct, ::Thrift::Struct_Union - SUCCESS = 0 - - FIELDS = { - SUCCESS => {:type => ::Thrift::Types::I32, :name => 'success', :enum_class => Zipkin::ResultCode} - } - - def struct_fields; FIELDS; end - - def validate - unless @success.nil? || Zipkin::ResultCode::VALID_VALUES.include?(@success) - raise ::Thrift::ProtocolException.new(::Thrift::ProtocolException::UNKNOWN, 'Invalid value of field success!') - end - end - - ::Thrift::Struct.generate_accessors self - end - - class GetSampleRate_args - include ::Thrift::Struct, ::Thrift::Struct_Union - - FIELDS = { - - } - - def struct_fields; FIELDS; end - - def validate - end - - ::Thrift::Struct.generate_accessors self - end - - class GetSampleRate_result - include ::Thrift::Struct, ::Thrift::Struct_Union - SUCCESS = 0 - QE = 1 - - FIELDS = { - SUCCESS => {:type => ::Thrift::Types::DOUBLE, :name => 'success'}, - QE => {:type => ::Thrift::Types::STRUCT, :name => 'qe', :class => Zipkin::AdjustableRateException} - } - - def struct_fields; FIELDS; end - - def validate - end - - ::Thrift::Struct.generate_accessors self - end - - class SetSampleRate_args - include ::Thrift::Struct, ::Thrift::Struct_Union - SAMPLE_RATE = 1 - - FIELDS = { - SAMPLE_RATE => {:type => ::Thrift::Types::DOUBLE, :name => 'sample_rate'} - } - - def struct_fields; FIELDS; end - - def validate - end - - ::Thrift::Struct.generate_accessors self - end - - class SetSampleRate_result - include ::Thrift::Struct, ::Thrift::Struct_Union - QE = 1 - - FIELDS = { - QE => {:type => ::Thrift::Types::STRUCT, :name => 'qe', :class => Zipkin::AdjustableRateException} - } - - def struct_fields; FIELDS; end - - def validate - end - - ::Thrift::Struct.generate_accessors self - end - - class GetStorageRequestRate_args - include ::Thrift::Struct, ::Thrift::Struct_Union - - FIELDS = { - - } - - def struct_fields; FIELDS; end - - def validate - end - - ::Thrift::Struct.generate_accessors self - end - - class GetStorageRequestRate_result - include ::Thrift::Struct, ::Thrift::Struct_Union - SUCCESS = 0 - E = 1 - - FIELDS = { - SUCCESS => {:type => ::Thrift::Types::DOUBLE, :name => 'success'}, - E => {:type => ::Thrift::Types::STRUCT, :name => 'e', :class => Zipkin::AdjustableRateException} - } - - def struct_fields; FIELDS; end - - def validate - end - - ::Thrift::Struct.generate_accessors self - end - - class SetStorageRequestRate_args - include ::Thrift::Struct, ::Thrift::Struct_Union - STORAGE_REQUEST_RATE = 1 - - FIELDS = { - STORAGE_REQUEST_RATE => {:type => ::Thrift::Types::DOUBLE, :name => 'storage_request_rate'} - } - - def struct_fields; FIELDS; end - - def validate - end - - ::Thrift::Struct.generate_accessors self - end - - class SetStorageRequestRate_result - include ::Thrift::Struct, ::Thrift::Struct_Union - E = 1 - - FIELDS = { - E => {:type => ::Thrift::Types::STRUCT, :name => 'e', :class => Zipkin::AdjustableRateException} - } - - def struct_fields; FIELDS; end - - def validate - end - - ::Thrift::Struct.generate_accessors self - end - - end - - end