diff options
Diffstat (limited to 'app')
-rw-r--r-- | app/controllers/projects/environments_controller.rb | 12 | ||||
-rw-r--r-- | app/models/concerns/prometheus_adapter.rb | 2 | ||||
-rw-r--r-- | app/models/environment.rb | 6 |
3 files changed, 16 insertions, 4 deletions
diff --git a/app/controllers/projects/environments_controller.rb b/app/controllers/projects/environments_controller.rb index e9cd475a199..4fa6cd94ae5 100644 --- a/app/controllers/projects/environments_controller.rb +++ b/app/controllers/projects/environments_controller.rb @@ -10,6 +10,9 @@ class Projects::EnvironmentsController < Projects::ApplicationController before_action :environment, only: [:show, :edit, :update, :stop, :terminal, :terminal_websocket_authorize, :metrics] before_action :verify_api_request!, only: :terminal_websocket_authorize before_action :expire_etag_cache, only: [:index] + before_action only: [:metrics, :additional_metrics] do + push_frontend_feature_flag(:metrics_time_window) + end def index @environments = project.environments @@ -146,7 +149,7 @@ class Projects::EnvironmentsController < Projects::ApplicationController def additional_metrics respond_to do |format| format.json do - additional_metrics = environment.additional_metrics || {} + additional_metrics = environment.additional_metrics(*metrics_params) || {} render json: additional_metrics, status: additional_metrics.any? ? :ok : :no_content end @@ -186,6 +189,13 @@ class Projects::EnvironmentsController < Projects::ApplicationController @environment ||= project.environments.find(params[:id]) end + def metrics_params + return unless Feature.enabled?(:metrics_time_window, project) + return unless params[:start].present? || params[:end].present? + + params.require([:start, :end]).values_at(:start, :end) + end + def search_environment_names return [] unless params[:query] diff --git a/app/models/concerns/prometheus_adapter.rb b/app/models/concerns/prometheus_adapter.rb index a29e80fe0c1..decbbbd87f2 100644 --- a/app/models/concerns/prometheus_adapter.rb +++ b/app/models/concerns/prometheus_adapter.rb @@ -51,7 +51,7 @@ module PrometheusAdapter end def build_query_args(*args) - args.map(&:id) + args.map { |arg| arg.respond_to?(:id) ? arg.id : arg } end end end diff --git a/app/models/environment.rb b/app/models/environment.rb index 25373c7a1f7..fa29a83e517 100644 --- a/app/models/environment.rb +++ b/app/models/environment.rb @@ -170,8 +170,10 @@ class Environment < ApplicationRecord prometheus_adapter.query(:environment, self) if has_metrics? end - def additional_metrics - prometheus_adapter.query(:additional_metrics_environment, self) if has_metrics? + def additional_metrics(*args) + return unless has_metrics? + + prometheus_adapter.query(:additional_metrics_environment, self, *args.map(&:to_f)) end # rubocop: disable CodeReuse/ServiceClass |