Welcome to mirror list, hosted at ThFree Co, Russian Federation.

uploads.rb « instrumentation « gitlab « lib - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 02e457453cd79354f480570b684252e029914798 (plain)
1
2
3
4
5
6
7
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
# frozen_string_literal: true

module Gitlab
  module Instrumentation
    class Uploads
      UPLOAD_DURATION = :uploaded_file_upload_duration_s
      UPLOADED_FILE_SIZE = :uploaded_file_size_bytes

      def self.track(uploaded_file)
        if ::Gitlab::SafeRequestStore.active?
          ::Gitlab::SafeRequestStore[UPLOAD_DURATION] = uploaded_file.upload_duration
          ::Gitlab::SafeRequestStore[UPLOADED_FILE_SIZE] = uploaded_file.size
        end
      end

      def self.get_upload_duration
        ::Gitlab::SafeRequestStore[UPLOAD_DURATION]
      end

      def self.get_uploaded_file_size
        ::Gitlab::SafeRequestStore[UPLOADED_FILE_SIZE]
      end

      def self.payload
        {
          UPLOAD_DURATION => get_upload_duration,
          UPLOADED_FILE_SIZE => get_uploaded_file_size
        }.compact
      end
    end
  end
end