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

logger.rb « artifacts « ci « gitlab « lib - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 628f4129df4069a5c3c198575f525932821a2cd9 (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
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
# frozen_string_literal: true

module Gitlab
  module Ci
    module Artifacts
      module Logger
        def log_artifacts_filesize(artifact_file)
          return if artifact_file.nil?

          unless artifact_file.is_a?(::Ci::Artifactable)
            raise ArgumentError, "unknown artifact file class `#{artifact_file.class}`"
          end

          ::Gitlab::ApplicationContext.push(artifact: artifact_file)
        end

        def log_artifacts_context(job)
          ::Gitlab::ApplicationContext.push(
            namespace: job&.project&.namespace,
            project: job&.project,
            job: job
          )
        end

        def log_build_dependencies(size:, count: 0)
          ::Gitlab::ApplicationContext.push(
            artifacts_dependencies_size: size,
            artifacts_dependencies_count: count
          )
        end

        def self.log_created(artifact)
          payload = Gitlab::ApplicationContext.current.merge(
            message: 'Artifact created',
            job_artifact_id: artifact.id,
            size: artifact.size,
            type: artifact.file_type,
            build_id: artifact.job_id,
            project_id: artifact.project_id
          )

          Gitlab::AppLogger.info(payload)
        end

        def self.log_deleted(job_artifacts, method)
          Array(job_artifacts).each do |artifact|
            payload = Gitlab::ApplicationContext.current.merge(
              message: 'Artifact deleted',
              job_artifact_id: artifact.id,
              expire_at: artifact.expire_at,
              size: artifact.size,
              type: artifact.file_type,
              build_id: artifact.job_id,
              project_id: artifact.project_id,
              method: method
            )

            Gitlab::AppLogger.info(payload)
          end
        end
      end
    end
  end
end