Class: SolidApm::TransactionsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/solid_apm/transactions_controller.rb

Instance Method Summary collapse

Instance Method Details

#indexObject



8
9
10
11
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
# File 'app/controllers/solid_apm/transactions_controller.rb', line 8

def index
  if from_to_range.end < from_to_range.begin
    flash[:error] = 'Invalid time range'
    redirect_to transactions_path
    return
  end

  @transactions_scope = Transaction.where(timestamp: from_to_range)
  @transactions_scope = @transactions_scope.where(name: params[:name]) if params[:name].present?
  transaction_names = @transactions_scope.distinct.pluck(:name)
  latency_95p = @transactions_scope.group(:name).percentile(:duration, 0.95)
  latency_median = @transactions_scope.group(:name).median(:duration)
  tmp_dict = @transactions_scope.group(:name).group_by_minute(:timestamp,
                                                              series: false).count.each_with_object({}) do |(k, v), h|
    current_value = h[k.first] ||= 0
    h[k.first] = v if v > current_value
  end

  @aggregated_transactions = transaction_names.each_with_object({}) do |transaction_name, h|
    latency = latency_median[transaction_name]
    tmp = tmp_dict[transaction_name]
    impact = latency * tmp
    h[transaction_name] = TransactionAggregation.new(
      transaction_name,
      tmp,
      latency,
      latency_95p[transaction_name],
      impact
    )
  end

  return if @aggregated_transactions.empty?

  # Find the maximum and minimum impact values
  max_impact = @aggregated_transactions.values.max_by(&:impact).impact
  min_impact = @aggregated_transactions.values.min_by(&:impact).impact

  # Normalize impact 0-100
  @aggregated_transactions.each do |_, aggregation|
    normalized_impact = ((aggregation.impact - min_impact) / (max_impact - min_impact)) * 100
    normalized_impact = 0 if normalized_impact.nan?
    aggregation.impact = normalized_impact.to_i || 0
  end
  @aggregated_transactions = @aggregated_transactions.sort_by { |_, v| -v.impact }.to_h

  grouping_method, grouping_options = smart_time_grouping(from_to_range)
  scope = @transactions_scope.public_send(grouping_method, :timestamp, range: from_to_range, **grouping_options)
  @throughput_data = scope.count
  @latency_data = scope.median(:duration).transform_values(&:to_i)

  # Pass browser timezone info to view for chart rendering
  @browser_timezone = params[:browser_timezone]
end

#spansObject



62
63
64
65
# File 'app/controllers/solid_apm/transactions_controller.rb', line 62

def spans
  @transaction = Transaction.find_by!(uuid: params[:uuid])
  @transaction.spans.to_a
end