Class: SolidEvents::TracesController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- SolidEvents::TracesController
- Defined in:
- app/controllers/solid_events/traces_controller.rb
Constant Summary collapse
- PER_PAGE_OPTIONS =
[25, 50, 100].freeze
- COMPARE_DIMENSIONS =
%w[source name deployment_id service_version environment_name entity_type].freeze
- COMPARE_METRICS =
%w[error_rate latency_avg].freeze
Instance Method Summary collapse
Instance Method Details
#hot_path ⇒ Object
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'app/controllers/solid_events/traces_controller.rb', line 72 def hot_path @name = params[:name].to_s @source = params[:source].to_s @window = params[:window].to_s.presence || "7d" scope = SolidEvents::Trace.recent.where(name: @name, source: @source) scope = case @window when "24h" then scope.where("solid_events_traces.started_at >= ?", 24.hours.ago) else scope.where("solid_events_traces.started_at >= ?", 7.days.ago) end @traces = scope.limit(200) durations = @traces.filter_map do |trace| next unless trace.started_at && trace.finished_at ((trace.finished_at - trace.started_at) * 1000.0).round(2) end.sort @latency_stats = { count: durations.size, p50_ms: percentile(durations, 0.50), p95_ms: percentile(durations, 0.95), p99_ms: percentile(durations, 0.99), error_rate_pct: if @traces.any? ((@traces.count { |trace| trace.status == "error" }.to_f / @traces.size) * 100.0).round(2) else 0.0 end } @hourly = @traces.group_by { |trace| trace.started_at&.beginning_of_hour }.sort_by { |hour, _| hour || Time.at(0) }.last(24).map do |hour, rows| bucket_durations = rows.filter_map do |trace| next unless trace.started_at && trace.finished_at ((trace.finished_at - trace.started_at) * 1000.0).round(2) end.sort { hour: hour, count: rows.size, error_count: rows.count { |trace| trace.status == "error" }, p95_ms: percentile(bucket_durations, 0.95) } end end |
#index ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'app/controllers/solid_events/traces_controller.rb', line 12 def index apply_shared_view! apply_saved_view! @query = params[:q].to_s.strip @status = params[:status].to_s @trace_type = params[:trace_type].to_s @source = params[:source].to_s.strip @context_key = params[:context_key].to_s.strip @context_id = params[:context_id].to_s.strip @entity_type = params[:entity_type].to_s.strip @entity_id = params[:entity_id].to_s.strip @error_fingerprint = params[:error_fingerprint].to_s.strip @request_id = params[:request_id].to_s.strip @feature_key = params[:feature_key].to_s.strip @feature_value = params[:feature_value].to_s.strip @min_duration_ms = params[:min_duration_ms].to_s.strip @window = params[:window].to_s.presence || "24h" @page = [params[:page].to_i, 1].max @per_page = sanitize_per_page(params[:per_page]) = SolidEvents::Trace.distinct.order(:trace_type).pluck(:trace_type) scope = SolidEvents::Trace.recent scope = scope.where(status: @status) if @status.in?(%w[ok error]) scope = scope.where(trace_type: @trace_type) if @trace_type.present? scope = scope.where("solid_events_traces.source ILIKE ?", "%#{@source}%") if @source.present? scope = apply_time_window(scope) scope = apply_context_id_filters(scope) scope = apply_entity_filters(scope) scope = apply_error_fingerprint_filter(scope) scope = apply_request_id_filter(scope) scope = apply_feature_slice_filter(scope) scope = apply_min_duration_filter(scope) if @query.present? scope = scope.left_outer_joins(:record_links).where( "solid_events_traces.name ILIKE :q OR solid_events_traces.source ILIKE :q OR " \ "solid_events_record_links.record_type ILIKE :q OR CAST(solid_events_record_links.record_id AS TEXT) ILIKE :q", q: "%#{@query}%" ).distinct end @total_count = scope.except(:limit, :offset, :order).count("DISTINCT solid_events_traces.id") @error_count = scope.where(status: "error").count("DISTINCT solid_events_traces.id") @page_count = (@total_count.to_f / @per_page).ceil @traces = scope .includes(:events, :record_links, :error_links, :summary) .offset((@page - 1) * @per_page) .limit(@per_page) SolidEvents::IncidentEvaluator.evaluate! if SolidEvents.evaluate_incidents_on_request? load_slo_panel(scope) load_index_insights load_compare_panel load_journey_panel load_incidents load_saved_views end |
#show ⇒ Object
170 171 172 173 174 175 176 177 |
# File 'app/controllers/solid_events/traces_controller.rb', line 170 def show @events = @trace.events.order(:occurred_at) @record_links = @trace.record_links @error_links = @trace.error_links @event_counts = @events.reorder(nil).group(:event_type).count load_correlation_pivots end |
#timeline ⇒ Object
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 |
# File 'app/controllers/solid_events/traces_controller.rb', line 114 def timeline @request_id = params[:request_id].to_s.strip @entity_type = params[:entity_type].to_s.strip @entity_id = params[:entity_id].to_s.strip @window = params[:window].to_s.presence || "24h" @timeline_rows = [] summaries = SolidEvents::Summary.where(started_at: journey_window_start..Time.current).order(started_at: :asc) if @request_id.present? summaries = summaries.where(request_id: @request_id) elsif @entity_type.present? && @entity_id.present? summaries = summaries.where(entity_type: @entity_type, entity_id: @entity_id.to_i) else summaries = summaries.none end traces = SolidEvents::Trace.includes(:events, :summary).where(id: summaries.limit(100).pluck(:trace_id)).order(started_at: :asc) @timeline_rows = traces.flat_map do |trace| base = [{ at: trace.started_at, kind: "trace", label: "#{trace.name} (#{trace.status})", trace_id: trace.id, details: [ trace.source, ("caused_by_trace_id=#{trace.caused_by_trace_id}" if trace.caused_by_trace_id.present?), ("caused_by_event_id=#{trace.caused_by_event_id}" if trace.caused_by_event_id.present?) ].compact.join(" | "), explain: { trace_id: trace.id, source: trace.source, status: trace.status, caused_by_trace_id: trace.caused_by_trace_id, caused_by_event_id: trace.caused_by_event_id } }] events = trace.events.order(:occurred_at).map do |event| { at: event.occurred_at, kind: event.event_type, label: event.name, trace_id: trace.id, details: event.duration_ms ? "#{event.duration_ms} ms" : nil, explain: { trace_id: trace.id, event_type: event.event_type, duration_ms: event.duration_ms, payload: event.payload.to_h } } end base + events end.sort_by { |row| row[:at] || Time.at(0) } append_incident_lifecycle_rows!(summaries) end |