BigW Consortium Gitlab

Commit 608186d5 by Pawel Chojnacki

Add per deployment additional metrics

parent 4d8f3978
...@@ -22,6 +22,17 @@ class Projects::DeploymentsController < Projects::ApplicationController ...@@ -22,6 +22,17 @@ class Projects::DeploymentsController < Projects::ApplicationController
render_404 render_404
end 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 private
def deployment def deployment
......
...@@ -103,12 +103,22 @@ class Deployment < ActiveRecord::Base ...@@ -103,12 +103,22 @@ class Deployment < ActiveRecord::Base
project.monitoring_service.present? project.monitoring_service.present?
end end
def has_additional_metrics?
has_metrics? && project.monitoring_service&.respond_to?(:reactive_query)
end
def metrics def metrics
return {} unless has_metrics? return {} unless has_metrics?
project.monitoring_service.deployment_metrics(self) project.monitoring_service.deployment_metrics(self)
end 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 private
def ref_path def ref_path
......
...@@ -167,6 +167,7 @@ constraints(ProjectUrlConstrainer.new) do ...@@ -167,6 +167,7 @@ constraints(ProjectUrlConstrainer.new) do
resources :deployments, only: [:index] do resources :deployments, only: [:index] do
member do member do
get :metrics get :metrics
get :additional_metrics
end end
end 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 module Gitlab::Prometheus::Queries
class AdditionalMetricsQuery < BaseQuery class AdditionalMetricsQuery < BaseQuery
def query(environment_id) 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| matched_metrics.map do |group|
metrics = group.metrics.map do |metric| metrics = group.metrics.map do |metric|
...@@ -22,16 +36,6 @@ module Gitlab::Prometheus::Queries ...@@ -22,16 +36,6 @@ module Gitlab::Prometheus::Queries
private 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) def process_query(context, query)
query_with_result = query.dup query_with_result = query.dup
query_with_result[:result] = 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