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

alert_shared_context.rb « prometheus « shared_contexts « support « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 330d2c4515fbacc5260ff1f4ddb5cea8a9a59ab1 (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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# frozen_string_literal: true

# These contexts expect a `project` to be defined.
# It is expected that these contexts are used to create an
# alert.
RSpec.shared_context 'self-managed prometheus alert attributes' do
  let_it_be(:environment) { create(:environment, project: project, name: 'production') }

  let(:starts_at) { '2018-03-12T09:06:00Z' }
  let(:title) { 'title' }
  let(:y_label) { 'y_label' }
  let(:query) { 'avg(metric) > 1.0' }

  let(:embed_content) do
    {
      panel_groups: [{
        panels: [{
          type: 'line-graph',
          title: title,
          y_label: y_label,
          metrics: [{ query_range: query }]
        }]
      }]
    }.to_json
  end

  let(:payload) do
    {
      'startsAt' => starts_at,
      'generatorURL' => "http://host?g0.expr=#{CGI.escape(query)}",
      'labels' => {
        'gitlab_environment_name' => 'production'
      },
      'annotations' => {
        'title' => title,
        'gitlab_y_label' => y_label
      }
    }
  end

  let(:dashboard_url_for_alert) do
    Gitlab::Routing.url_helpers.metrics_dashboard_project_environment_url(
      project,
      environment,
      embed_json: embed_content,
      embedded: true,
      end: '2018-03-12T09:36:00Z',
      start: '2018-03-12T08:36:00Z'
    )
  end
end

RSpec.shared_context 'gitlab-managed prometheus alert attributes' do
  let_it_be(:prometheus_alert) { create(:prometheus_alert, project: project) }
  let(:prometheus_metric_id) { prometheus_alert.prometheus_metric_id }

  let(:payload) do
    {
      'startsAt' => '2018-03-12T09:06:00Z',
      'labels' => {
        'gitlab_alert_id' => prometheus_metric_id
      }
    }
  end

  let(:dashboard_url_for_alert) do
    Gitlab::Routing.url_helpers.metrics_dashboard_project_prometheus_alert_url(
      project,
      prometheus_metric_id,
      environment_id: prometheus_alert.environment_id,
      embedded: true,
      end: '2018-03-12T09:36:00Z',
      start: '2018-03-12T08:36:00Z'
    )
  end
end