From 1bf66d5aa07d36940f3f5970b543714600fb30b4 Mon Sep 17 00:00:00 2001 From: Franklin Hu Date: Mon, 16 Jul 2012 11:00:17 -0700 Subject: [PATCH] fixed zipkin-web to actually return values from servers Ruby 1.9.3 fixed a problem where do loops were sometimes not returning their last value. However, for compatibility with 1.9.2, the with_transport do loops need their last value to be assigned to a variable with a greater scope than the do loop, ie to be initialized outside of the do loop and then assigned within. Either the necessary ruby version should be specified in the documentation, or this fix needs to be pulled in. Author: @mosesn Fixes #68 URL: https://github.com/twitter/zipkin/pull/68 --- zipkin-web/app/controllers/traces_controller.rb | 10 ++++++---- zipkin-web/app/models/index.rb | 14 ++++++++++---- zipkin-web/app/models/names.rb | 10 +++++++--- zipkin-web/app/models/trace_combo.rb | 6 ++++-- zipkin-web/app/models/trace_summary.rb | 6 ++++-- zipkin-web/app/models/trace_timeline.rb | 6 ++++-- zipkin-web/app/models/ztrace.rb | 6 ++++-- 7 files changed, 39 insertions(+), 19 deletions(-) diff --git a/zipkin-web/app/controllers/traces_controller.rb b/zipkin-web/app/controllers/traces_controller.rb index 1c05211c934..0de86243604 100644 --- a/zipkin-web/app/controllers/traces_controller.rb +++ b/zipkin-web/app/controllers/traces_controller.rb @@ -119,16 +119,18 @@ def spans_json def top_annotations service_name = params[:service_name] || "" - top_annotations = ZipkinQuery::Client.with_transport(Rails.configuration.zookeeper) do |client| - client.getTopAnnotations(service_name) + top_annotations = nil + ZipkinQuery::Client.with_transport(Rails.configuration.zookeeper) do |client| + top_annotations = client.getTopAnnotations(service_name) end render :json => top_annotations || [] end def top_kv_annotations service_name = params[:service_name] || "" - top_annotations = ZipkinQuery::Client.with_transport(Rails.configuration.zookeeper) do |client| - client.getTopKeyValueAnnotations(service_name) + top_annotations = nil + ZipkinQuery::Client.with_transport(Rails.configuration.zookeeper) do |client| + top_annotations = client.getTopKeyValueAnnotations(service_name) end render :json => top_annotations || [] end diff --git a/zipkin-web/app/models/index.rb b/zipkin-web/app/models/index.rb index c894592da05..784cbd53723 100644 --- a/zipkin-web/app/models/index.rb +++ b/zipkin-web/app/models/index.rb @@ -23,27 +23,33 @@ 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 + tmp = nil ZipkinQuery::Client.with_transport(Rails.configuration.zookeeper) do |client| - client.getTraceIdsBySpanName(service_name, span_name, end_ts, limit, order) + tmp = client.getTraceIdsBySpanName(service_name, span_name, end_ts, limit, order) end + tmp end def self.get_trace_ids_by_service_name(service_name, end_ts, limit, opts = {}) end_ts = secondsToMicroseconds(end_ts) order = opts[:order] || ORDER_DEFAULT + tmp = nil ZipkinQuery::Client.with_transport(Rails.configuration.zookeeper) do |client| - client.getTraceIdsByServiceName(service_name, end_ts, limit, order) + tmp = client.getTraceIdsByServiceName(service_name, end_ts, limit, order) end + tmp end def self.get_trace_ids_by_annotation(service_name, annotation, value, end_ts, limit, opts = {}) end_ts = secondsToMicroseconds(end_ts) order = opts[:order] || ORDER_DEFAULT + tmp = nil ZipkinQuery::Client.with_transport(Rails.configuration.zookeeper) do |client| - client.getTraceIdsByAnnotation(service_name, annotation, value, end_ts, limit, order) + tmp = client.getTraceIdsByAnnotation(service_name, annotation, value, end_ts, limit, order) end + tmp end private @@ -52,4 +58,4 @@ def self.secondsToMicroseconds(end_time) return end_time.to_i * 1000 * 1000 end -end \ No newline at end of file +end diff --git a/zipkin-web/app/models/names.rb b/zipkin-web/app/models/names.rb index 538ce88b291..66051bcefe6 100644 --- a/zipkin-web/app/models/names.rb +++ b/zipkin-web/app/models/names.rb @@ -17,15 +17,19 @@ class Names def self.get_service_names + tmp = nil ZipkinQuery::Client.with_transport(Rails.configuration.zookeeper) do |client| - client.getServiceNames().sort + tmp = client.getServiceNames().sort end + tmp end def self.get_span_names(service_name) + tmp = nil ZipkinQuery::Client.with_transport(Rails.configuration.zookeeper) do |client| - client.getSpanNames(service_name).sort + tmp = client.getSpanNames(service_name).sort end + tmp end -end \ No newline at end of file +end diff --git a/zipkin-web/app/models/trace_combo.rb b/zipkin-web/app/models/trace_combo.rb index d81d0d2b8bd..c3862223412 100644 --- a/zipkin-web/app/models/trace_combo.rb +++ b/zipkin-web/app/models/trace_combo.rb @@ -42,10 +42,12 @@ def initialize(trace, summary, timeline, span_depths) end def self.get_trace_combos_by_ids(trace_ids, adjusters, opts = {}) + tmp = nil 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) } + tmp = combos.collect { |combo| TraceCombo.from_thrift(combo) } end + tmp end -end \ No newline at end of file +end diff --git a/zipkin-web/app/models/trace_summary.rb b/zipkin-web/app/models/trace_summary.rb index f96eb0a4fd0..aafe0068645 100644 --- a/zipkin-web/app/models/trace_summary.rb +++ b/zipkin-web/app/models/trace_summary.rb @@ -60,11 +60,13 @@ def initialize(trace_id, start_timestamp, end_timestamp, duration_micro, service end def self.get_trace_summaries_by_ids(trace_ids, adjusters, opts={}) + tmp = nil 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) } + tmp = summaries.collect { |summary| TraceSummary.from_thrift(summary) } end + tmp end def start_timestamp_ms @@ -108,4 +110,4 @@ def as_json(opts={}) } end -end \ No newline at end of file +end diff --git a/zipkin-web/app/models/trace_timeline.rb b/zipkin-web/app/models/trace_timeline.rb index e1eecf53b5d..63c906dc8e7 100644 --- a/zipkin-web/app/models/trace_timeline.rb +++ b/zipkin-web/app/models/trace_timeline.rb @@ -44,12 +44,14 @@ def initialize(trace_id, root_most_span_id, annotations, binary_annotations) end def self.get_trace_timelines_by_ids(trace_ids, opts = {}) + tmp = nil 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) - timelines.collect { |timeline| TraceTimeline.from_thrift(timeline) } + tmp = timelines.collect { |timeline| TraceTimeline.from_thrift(timeline) } end + tmp end def start_timestamp @@ -132,4 +134,4 @@ def as_json(opts={}) } end end -end \ No newline at end of file +end diff --git a/zipkin-web/app/models/ztrace.rb b/zipkin-web/app/models/ztrace.rb index c704e8990fa..0c6c1d5bba7 100644 --- a/zipkin-web/app/models/ztrace.rb +++ b/zipkin-web/app/models/ztrace.rb @@ -121,11 +121,13 @@ def as_json(opts={}) end def self.get_traces_by_ids(trace_ids, opts = {}) + tmp = nil 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) } + tmp = traces.collect { |trace| ZTrace.from_thrift(trace) } end + tmp end # what is the default ttl we set traces to? @@ -156,4 +158,4 @@ def span_depth_rc(all_spans, depth, id) end rv end -end \ No newline at end of file +end