Class: DeploymentMetrics

Inherits:
Object
  • Object
show all
Includes:
Gitlab::Utils::StrongMemoize
Defined in:
app/models/deployment_metrics.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Gitlab::Utils::StrongMemoize

#clear_memoization, #strong_memoize, #strong_memoized?

Constructor Details

#initialize(project, deployment) ⇒ DeploymentMetrics

Returns a new instance of DeploymentMetrics.


10
11
12
13
# File 'app/models/deployment_metrics.rb', line 10

def initialize(project, deployment)
  @project = project
  @deployment = deployment
end

Instance Attribute Details

#deploymentObject (readonly)

Returns the value of attribute deployment


6
7
8
# File 'app/models/deployment_metrics.rb', line 6

def deployment
  @deployment
end

#projectObject (readonly)

Returns the value of attribute project


6
7
8
# File 'app/models/deployment_metrics.rb', line 6

def project
  @project
end

Instance Method Details

#additional_metricsObject


26
27
28
29
30
31
# File 'app/models/deployment_metrics.rb', line 26

def additional_metrics
  return {} unless has_metrics_and_can_query?

  metrics = prometheus_adapter.query(:additional_metrics_deployment, deployment)
  metrics&.merge(deployment_time: deployment.finished_at.to_i) || {}
end

#has_metrics?Boolean

Returns:

  • (Boolean)

15
16
17
# File 'app/models/deployment_metrics.rb', line 15

def has_metrics?
  deployment.success? && prometheus_adapter&.configured?
end

#metricsObject


19
20
21
22
23
24
# File 'app/models/deployment_metrics.rb', line 19

def metrics
  return {} unless has_metrics_and_can_query?

  metrics = prometheus_adapter.query(:deployment, deployment)
  metrics&.merge(deployment_time: deployment.finished_at.to_i) || {}
end