Class: Tasker::AnalyticsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/tasker/analytics_controller.rb

Overview

Analytics controller providing performance and bottleneck analysis endpoints.

This controller provides analytics endpoints:

  • /analytics/performance - System-wide performance metrics with caching
  • /analytics/bottlenecks - Bottleneck analysis scoped by task/version/namespace

All endpoints use the authorization system with appropriate permissions. If authorization is disabled, access is allowed. If enabled, users need the corresponding analytics permissions.

Analytics calculations are handled by Tasker::AnalyticsService for better separation of concerns.

Instance Method Summary collapse

Instance Method Details

#bottlenecksJSON

Bottleneck analysis endpoint scoped by task parameters Provides bottleneck analysis for specific task contexts

Query parameters:

  • namespace: Filter by task namespace (optional)
  • name: Filter by task name (optional)
  • version: Filter by task version (optional)
  • period: Analysis period in hours (default: 24)

Returns:

  • (JSON)

    Bottleneck analysis for specified scope



64
65
66
67
68
69
70
71
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
# File 'app/controllers/tasker/analytics_controller.rb', line 64

def bottlenecks
  # Extract and validate scope parameters
  scope_params = extract_scope_parameters
  analysis_period = params[:period]&.to_i || 24

  # Generate cache key based on scope and period
  cache_key = "tasker:analytics:bottlenecks:#{bottlenecks_cache_version(scope_params, analysis_period)}"

  cached_result = @intelligent_cache.intelligent_fetch(cache_key, base_ttl: 2.minutes) do
    bottleneck_analytics = Tasker::AnalyticsService.calculate_bottleneck_analytics(
      scope_params,
      analysis_period
    )

    {
      **bottleneck_analytics.to_h,
      cache_info: {
        cached: true,
        cache_key: cache_key,
        ttl_base: '2 minutes'
      }
    }
  end

  render json: cached_result, status: :ok
rescue StandardError => e
  render json: {
    error: 'Bottleneck analysis failed',
    message: e.message,
    scope: extract_scope_parameters,
    timestamp: Time.current.iso8601
  }, status: :service_unavailable
end

#performanceJSON

Performance analytics endpoint with intelligent caching Provides system-wide performance metrics and trends

Returns:

  • (JSON)

    Performance metrics and analytics



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'app/controllers/tasker/analytics_controller.rb', line 29

def performance
  cache_key = "tasker:analytics:performance:#{performance_cache_version}"

  cached_result = @intelligent_cache.intelligent_fetch(cache_key, base_ttl: 90.seconds) do
    performance_analytics = Tasker::AnalyticsService.calculate_performance_analytics

    {
      **performance_analytics.to_h,
      cache_info: {
        cached: true,
        cache_key: cache_key,
        ttl_base: '90 seconds'
      }
    }
  end

  render json: cached_result, status: :ok
rescue StandardError => e
  render json: {
    error: 'Performance analytics failed',
    message: e.message,
    timestamp: Time.current.iso8601
  }, status: :service_unavailable
end