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

annotations_finder.rb « dashboards « metrics « finders « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: e97704738ea1cc7c8e4fa5db204b818e18762b54 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# frozen_string_literal: true

module Metrics
  module Dashboards
    class AnnotationsFinder
      def initialize(dashboard:, params:)
        @dashboard = dashboard
        @params = 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