Commit 608186d5 authored by Pawel Chojnacki's avatar Pawel Chojnacki

Add per deployment additional metrics

parent 4d8f3978
......@@ -22,6 +22,17 @@ class Projects::DeploymentsController < Projects::ApplicationController
render_404
end
def additional_metrics
return render_404 unless deployment.has_additional_metrics?
metrics = deployment.additional_metrics
if metrics&.any?
render json: metrics, status: :ok
else
head :no_content
end
end
private
def deployment
......
......@@ -103,12 +103,22 @@ class Deployment < ActiveRecord::Base
project.monitoring_service.present?
end
def has_additional_metrics?
has_metrics? && project.monitoring_service&.respond_to?(:reactive_query)
end
def metrics
return {} unless has_metrics?
project.monitoring_service.deployment_metrics(self)
end
def additional_metrics
return {} unless has_additional_metrics?
metrics = project.monitoring_service.reactive_query(Gitlab::Prometheus::Queries::AdditionalMetricsDeploymentQuery.name, id, &:itself)
metrics&.merge(deployment_time: created_at.to_i) || {}
end
private
def ref_path
......
......@@ -167,6 +167,7 @@ constraints(ProjectUrlConstrainer.new) do
resources :deployments, only: [:index] do
member do
get :metrics
get :additional_metrics
end
end
end
......
module Gitlab::Prometheus::Queries
class AdditionalMetricsDeploymentQuery < AdditionalMetricsQuery
def query(deployment_id)
deployment = Deployment.find_by(id: deployment_id)
query_context = {
environment_slug: deployment.environment.slug,
environment_filter: %{container_name!="POD",environment="#{deployment.environment.slug}"},
timeframe_start: (deployment.created_at - 30.minutes).to_f,
timeframe_end: (deployment.created_at + 30.minutes).to_f
}
query_metrics(query_context)
end
end
end
module Gitlab::Prometheus::Queries
class AdditionalMetricsQuery < BaseQuery
def query(environment_id)
query_processor = method(:process_query).curry[query_context(environment_id)]
environment = Environment.find_by(id: environment_id)
query_context = {
environment_slug: environment.slug,
environment_filter: %{container_name!="POD",environment="#{environment.slug}"},
timeframe_start: 8.hours.ago.to_f,
timeframe_end: Time.now.to_f
}
query_metrics(query_context)
end
protected
def query_metrics(query_context)
query_processor = method(:process_query).curry[query_context]
matched_metrics.map do |group|
metrics = group.metrics.map do |metric|
......@@ -22,16 +36,6 @@ module Gitlab::Prometheus::Queries
private
def query_context(environment_id)
environment = Environment.find_by(id: environment_id)
{
environment_slug: environment.slug,
environment_filter: %{container_name!="POD",environment="#{environment.slug}"},
timeframe_start: 8.hours.ago.to_f,
timeframe_end: Time.now.to_f
}
end
def process_query(context, query)
query_with_result = query.dup
query_with_result[:result] =
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment