diff options
| author | Douwe Maan <douwe@gitlab.com> | 2017-05-12 17:15:31 +0000 |
|---|---|---|
| committer | Douwe Maan <douwe@gitlab.com> | 2017-05-12 17:15:31 +0000 |
| commit | bec9ec9a6e8980d4354f2b577cfd2a96a83a73b7 (patch) | |
| tree | 4a5c6ddb0915de712628e48dfdf7c8cbea7a17fa /spec/lib | |
| parent | 4024200314144cd7aa0bda35f38817c8b198142a (diff) | |
| parent | f38779c6f521e0d554303db0619bafb07ffeda29 (diff) | |
| download | gitlab-ce-bec9ec9a6e8980d4354f2b577cfd2a96a83a73b7.tar.gz | |
Merge branch '27439-performance-deltas' into 'master'
Expose memory deltas between app deployments and refactor prometheus queries to support more custom queries
See merge request !10981
Diffstat (limited to 'spec/lib')
| -rw-r--r-- | spec/lib/gitlab/prometheus/queries/deployment_query_spec.rb | 36 | ||||
| -rw-r--r-- | spec/lib/gitlab/prometheus_client_spec.rb (renamed from spec/lib/gitlab/prometheus_spec.rb) | 2 |
2 files changed, 37 insertions, 1 deletions
diff --git a/spec/lib/gitlab/prometheus/queries/deployment_query_spec.rb b/spec/lib/gitlab/prometheus/queries/deployment_query_spec.rb new file mode 100644 index 00000000000..cc7d7e57f06 --- /dev/null +++ b/spec/lib/gitlab/prometheus/queries/deployment_query_spec.rb @@ -0,0 +1,36 @@ +require 'spec_helper' + +describe Gitlab::Prometheus::Queries::DeploymentQuery, lib: true do + let(:environment) { create(:environment, slug: 'environment-slug') } + let(:deployment) { create(:deployment, environment: environment) } + + let(:client) { double('prometheus_client') } + subject { described_class.new(client) } + + around do |example| + Timecop.freeze { example.run } + end + + it 'sends appropriate queries to prometheus' do + start_time_matcher = be_within(0.5).of((deployment.created_at - 30.minutes).to_f) + stop_time_matcher = be_within(0.5).of((deployment.created_at + 30.minutes).to_f) + created_at_matcher = be_within(0.5).of(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', + start: start_time_matcher, stop: stop_time_matcher) + expect(client).to receive(:query).with('avg(avg_over_time(container_memory_usage_bytes{container_name!="POD",environment="environment-slug"}[30m]))', + time: created_at_matcher) + expect(client).to receive(:query).with('avg(avg_over_time(container_memory_usage_bytes{container_name!="POD",environment="environment-slug"}[30m]))', + time: stop_time_matcher) + + expect(client).to receive(:query_range).with('avg(rate(container_cpu_usage_seconds_total{container_name!="POD",environment="environment-slug"}[2m])) * 100', + start: start_time_matcher, stop: stop_time_matcher) + expect(client).to receive(:query).with('avg(rate(container_cpu_usage_seconds_total{container_name!="POD",environment="environment-slug"}[30m])) * 100', + time: created_at_matcher) + expect(client).to receive(:query).with('avg(rate(container_cpu_usage_seconds_total{container_name!="POD",environment="environment-slug"}[30m])) * 100', + time: stop_time_matcher) + + 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) + end +end diff --git a/spec/lib/gitlab/prometheus_spec.rb b/spec/lib/gitlab/prometheus_client_spec.rb index 9d67e3d2f37..2d8bd2f6b97 100644 --- a/spec/lib/gitlab/prometheus_spec.rb +++ b/spec/lib/gitlab/prometheus_client_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -describe Gitlab::Prometheus, lib: true do +describe Gitlab::PrometheusClient, lib: true do include PrometheusHelpers subject { described_class.new(api_url: 'https://prometheus.example.com') } |
