debian-mirror-gitlab/app/models/deployment_metrics.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

45 lines
1 KiB
Ruby
Raw Normal View History

2019-09-30 21:07:59 +05:30
# frozen_string_literal: true
class DeploymentMetrics
include Gitlab::Utils::StrongMemoize
attr_reader :project, :deployment
delegate :cluster, to: :deployment
def initialize(project, deployment)
@project = project
@deployment = deployment
end
def has_metrics?
2020-03-09 13:42:32 +05:30
deployment.success? && prometheus_adapter&.configured?
2019-09-30 21:07:59 +05:30
end
def metrics
2020-03-09 13:42:32 +05:30
return {} unless has_metrics_and_can_query?
2019-09-30 21:07:59 +05:30
metrics = prometheus_adapter.query(:deployment, deployment)
metrics&.merge(deployment_time: deployment.finished_at.to_i) || {}
end
def additional_metrics
2020-03-09 13:42:32 +05:30
return {} unless has_metrics_and_can_query?
2019-09-30 21:07:59 +05:30
metrics = prometheus_adapter.query(:additional_metrics_deployment, deployment)
metrics&.merge(deployment_time: deployment.finished_at.to_i) || {}
end
private
def prometheus_adapter
strong_memoize(:prometheus_adapter) do
2020-03-09 13:42:32 +05:30
Gitlab::Prometheus::Adapter.new(project, cluster).prometheus_adapter
2019-09-30 21:07:59 +05:30
end
end
2020-03-09 13:42:32 +05:30
def has_metrics_and_can_query?
has_metrics? && prometheus_adapter.can_query?
2019-09-30 21:07:59 +05:30
end
end