summaryrefslogtreecommitdiff
path: root/spec/migrations/20200511145545_change_variable_interpolation_format_in_common_metrics_spec.rb
blob: e712e555b70af52e3729c0a6c7ed3a6b7024050f (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
# frozen_string_literal: true

require 'spec_helper'
require_migration!('change_variable_interpolation_format_in_common_metrics')

RSpec.describe ChangeVariableInterpolationFormatInCommonMetrics, :migration do
  let(:prometheus_metrics) { table(:prometheus_metrics) }

  let!(:common_metric) do
    prometheus_metrics.create!(
      identifier: 'system_metrics_kubernetes_container_memory_total',
      query: 'avg(sum(container_memory_usage_bytes{container_name!="POD",' \
      'pod_name=~"^%{ci_environment_slug}-(.*)",namespace="%{kube_namespace}"})' \
      ' by (job)) without (job)  /1024/1024/1024',
      project_id: nil,
      title: 'Memory Usage (Total)',
      y_label: 'Total Memory Used (GB)',
      unit: 'GB',
      legend: 'Total (GB)',
      group: -5,
      common: true
    )
  end

  it 'updates query to use {{}}' do
    expected_query = <<~EOS.chomp
    avg(sum(container_memory_usage_bytes{container!="POD",\
    pod=~"^{{ci_environment_slug}}-(.*)",namespace="{{kube_namespace}}"}) \
    by (job)) without (job)  /1024/1024/1024     OR      \
    avg(sum(container_memory_usage_bytes{container_name!="POD",\
    pod_name=~"^{{ci_environment_slug}}-(.*)",namespace="{{kube_namespace}}"}) \
    by (job)) without (job)  /1024/1024/1024
    EOS

    migrate!

    expect(common_metric.reload.query).to eq(expected_query)
  end
end