Skip to content

Commit

Permalink
fixed zipkin-web to actually return values from servers
Browse files Browse the repository at this point in the history
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: #68
  • Loading branch information
Franklin Hu committed Jul 16, 2012
1 parent a3327f0 commit 1bf66d5
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 19 deletions.
10 changes: 6 additions & 4 deletions zipkin-web/app/controllers/traces_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 10 additions & 4 deletions zipkin-web/app/models/index.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -52,4 +58,4 @@ def self.secondsToMicroseconds(end_time)
return end_time.to_i * 1000 * 1000
end

end
end
10 changes: 7 additions & 3 deletions zipkin-web/app/models/names.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
end
6 changes: 4 additions & 2 deletions zipkin-web/app/models/trace_combo.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
end
6 changes: 4 additions & 2 deletions zipkin-web/app/models/trace_summary.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -108,4 +110,4 @@ def as_json(opts={})
}
end

end
end
6 changes: 4 additions & 2 deletions zipkin-web/app/models/trace_timeline.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -132,4 +134,4 @@ def as_json(opts={})
}
end
end
end
end
6 changes: 4 additions & 2 deletions zipkin-web/app/models/ztrace.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down Expand Up @@ -156,4 +158,4 @@ def span_depth_rc(all_spans, depth, id)
end
rv
end
end
end

0 comments on commit 1bf66d5

Please sign in to comment.