debian-mirror-gitlab/spec/lib/gitlab/prometheus/queries/deployment_query_spec.rb

40 lines
2.2 KiB
Ruby
Raw Normal View History

2019-12-04 20:38:33 +05:30
# frozen_string_literal: true
2017-09-10 17:25:29 +05:30
require 'spec_helper'
2020-07-28 23:09:34 +05:30
RSpec.describe Gitlab::Prometheus::Queries::DeploymentQuery do
2017-09-10 17:25:29 +05:30
let(:environment) { create(:environment, slug: 'environment-slug') }
let(:deployment) { create(:deployment, environment: environment) }
let(:client) { double('prometheus_client') }
2020-01-01 13:55:28 +05:30
2017-09-10 17:25:29 +05:30
subject { described_class.new(client) }
around do |example|
time_without_subsecond_values = Time.local(2008, 9, 1, 12, 0, 0)
Timecop.freeze(time_without_subsecond_values) { example.run }
end
it 'sends appropriate queries to prometheus' do
start_time = (deployment.created_at - 30.minutes).to_f
2020-04-22 19:07:51 +05:30
end_time = (deployment.created_at + 30.minutes).to_f
2017-09-10 17:25:29 +05:30
created_at = deployment.created_at.to_f
expect(client).to receive(:query_range).with('avg(container_memory_usage_bytes{container_name!="POD",environment="environment-slug"}) / 2^20',
2020-04-22 19:07:51 +05:30
start_time: start_time, end_time: end_time)
2017-09-10 17:25:29 +05:30
expect(client).to receive(:query).with('avg(avg_over_time(container_memory_usage_bytes{container_name!="POD",environment="environment-slug"}[30m]))',
time: created_at)
expect(client).to receive(:query).with('avg(avg_over_time(container_memory_usage_bytes{container_name!="POD",environment="environment-slug"}[30m]))',
2020-04-22 19:07:51 +05:30
time: end_time)
2017-09-10 17:25:29 +05:30
expect(client).to receive(:query_range).with('avg(rate(container_cpu_usage_seconds_total{container_name!="POD",environment="environment-slug"}[2m])) * 100',
2020-04-22 19:07:51 +05:30
start_time: start_time, end_time: end_time)
2017-09-10 17:25:29 +05:30
expect(client).to receive(:query).with('avg(rate(container_cpu_usage_seconds_total{container_name!="POD",environment="environment-slug"}[30m])) * 100',
time: created_at)
expect(client).to receive(:query).with('avg(rate(container_cpu_usage_seconds_total{container_name!="POD",environment="environment-slug"}[30m])) * 100',
2020-04-22 19:07:51 +05:30
time: end_time)
2017-09-10 17:25:29 +05:30
2018-03-27 19:54:05 +05:30
expect(subject.query(deployment.id)).to eq(memory_values: nil, memory_before: nil, memory_after: nil,
cpu_values: nil, cpu_before: nil, cpu_after: nil)
2017-09-10 17:25:29 +05:30
end
end