Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'app/finders/metrics/dashboards/annotations_finder.rb')
-rw-r--r--app/finders/metrics/dashboards/annotations_finder.rb42
1 files changed, 42 insertions, 0 deletions
diff --git a/app/finders/metrics/dashboards/annotations_finder.rb b/app/finders/metrics/dashboards/annotations_finder.rb
new file mode 100644
index 00000000000..c42b8bf40e5
--- /dev/null
+++ b/app/finders/metrics/dashboards/annotations_finder.rb
@@ -0,0 +1,42 @@
+# frozen_string_literal: true
+
+module Metrics
+ module Dashboards
+ class AnnotationsFinder
+ def initialize(dashboard:, params:)
+ @dashboard, @params = dashboard, params
+ end
+
+ def execute
+ if dashboard.environment
+ apply_filters_to(annotations_for_environment)
+ else
+ Metrics::Dashboard::Annotation.none
+ end
+ end
+
+ private
+
+ attr_reader :dashboard, :params
+
+ def apply_filters_to(annotations)
+ annotations = annotations.after(params[:from]) if params[:from].present?
+ annotations = annotations.before(params[:to]) if params[:to].present? && valid_timespan_boundaries?
+
+ by_dashboard(annotations)
+ end
+
+ def annotations_for_environment
+ dashboard.environment.metrics_dashboard_annotations
+ end
+
+ def by_dashboard(annotations)
+ annotations.for_dashboard(dashboard.path)
+ end
+
+ def valid_timespan_boundaries?
+ params[:from].blank? || params[:to] >= params[:from]
+ end
+ end
+ end
+end