Commit 600abf54 authored by GitLab Bot's avatar GitLab Bot

Automatic merge of gitlab-org/gitlab-ce master

parents 452a7db1 74abc775
...@@ -33,6 +33,11 @@ export default { ...@@ -33,6 +33,11 @@ export default {
type: Number, type: Number,
required: true, required: true,
}, },
deploymentData: {
type: Array,
required: false,
default: () => [],
},
alertData: { alertData: {
type: Object, type: Object,
required: false, required: false,
...@@ -79,6 +84,43 @@ export default { ...@@ -79,6 +84,43 @@ export default {
legend: { legend: {
formatter: this.xAxisLabel, formatter: this.xAxisLabel,
}, },
series: this.scatterSeries,
};
},
earliestDatapoint() {
return Object.values(this.chartData).reduce((acc, data) => {
const [[timestamp]] = data.sort(([a], [b]) => {
if (a < b) {
return -1;
}
return a > b ? 1 : 0;
});
return timestamp < acc || acc === null ? timestamp : acc;
}, null);
},
recentDeployments() {
return this.deploymentData.reduce((acc, deployment) => {
if (deployment.created_at >= this.earliestDatapoint) {
acc.push({
id: deployment.id,
createdAt: deployment.created_at,
sha: deployment.sha,
commitUrl: `${this.projectPath}/commit/${deployment.sha}`,
tag: deployment.tag,
tagUrl: deployment.tag ? `${this.tagsPath}/${deployment.ref.name}` : null,
ref: deployment.ref.name,
showDeploymentFlag: false,
});
}
return acc;
}, []);
},
scatterSeries() {
return {
type: 'scatter',
data: this.recentDeployments.map(deployment => [deployment.createdAt, 0]),
}; };
}, },
xAxisLabel() { xAxisLabel() {
......
...@@ -212,6 +212,7 @@ export default { ...@@ -212,6 +212,7 @@ export default {
v-for="(graphData, graphIndex) in groupData.metrics" v-for="(graphData, graphIndex) in groupData.metrics"
:key="graphIndex" :key="graphIndex"
:graph-data="graphData" :graph-data="graphData"
:deployment-data="store.deploymentData"
:alert-data="getGraphAlerts(graphData.id)" :alert-data="getGraphAlerts(graphData.id)"
:container-width="elWidth" :container-width="elWidth"
group-id="monitor-area-chart" group-id="monitor-area-chart"
......
...@@ -2,6 +2,8 @@ ...@@ -2,6 +2,8 @@
module Projects module Projects
class UpdatePagesConfigurationService < BaseService class UpdatePagesConfigurationService < BaseService
include Gitlab::Utils::StrongMemoize
attr_reader :project attr_reader :project
def initialize(project) def initialize(project)
...@@ -9,15 +11,25 @@ module Projects ...@@ -9,15 +11,25 @@ module Projects
end end
def execute def execute
update_file(pages_config_file, pages_config.to_json) if file_equals?(pages_config_file, pages_config_json)
return success(reload: false)
end
update_file(pages_config_file, pages_config_json)
reload_daemon reload_daemon
success success(reload: true)
rescue => e rescue => e
error(e.message) error(e.message)
end end
private private
def pages_config_json
strong_memoize(:pages_config_json) do
pages_config.to_json
end
end
def pages_config def pages_config
{ {
domains: pages_domains_config, domains: pages_domains_config,
...@@ -67,11 +79,6 @@ module Projects ...@@ -67,11 +79,6 @@ module Projects
end end
def update_file(file, data) def update_file(file, data)
unless data
FileUtils.remove(file, force: true)
return
end
temp_file = "#{file}.#{SecureRandom.hex(16)}" temp_file = "#{file}.#{SecureRandom.hex(16)}"
File.open(temp_file, 'w') do |f| File.open(temp_file, 'w') do |f|
f.write(data) f.write(data)
...@@ -81,5 +88,18 @@ module Projects ...@@ -81,5 +88,18 @@ module Projects
# In case if the updating fails # In case if the updating fails
FileUtils.remove(temp_file, force: true) FileUtils.remove(temp_file, force: true)
end end
def file_equals?(file, data)
existing_data = read_file(file)
data == existing_data.to_s
end
def read_file(file)
File.open(file, 'r') do |f|
f.read
end
rescue
nil
end
end end
end end
---
title: Do not reload daemon if configuration file of pages does not change
merge_request:
author:
type: performance
...@@ -2,23 +2,41 @@ require 'spec_helper' ...@@ -2,23 +2,41 @@ require 'spec_helper'
describe Projects::UpdatePagesConfigurationService do describe Projects::UpdatePagesConfigurationService do
let(:project) { create(:project) } let(:project) { create(:project) }
subject { described_class.new(project) } let(:service) { described_class.new(project) }
describe "#update" do describe "#update" do
let(:file) { Tempfile.new('pages-test') } let(:file) { Tempfile.new('pages-test') }
subject { service.execute }
after do after do
file.close file.close
file.unlink file.unlink
end end
before do
allow(service).to receive(:pages_config_file).and_return(file.path)
end
context 'when configuration changes' do
it 'updates the .update file' do it 'updates the .update file' do
# Access this reference to ensure scoping works expect(service).to receive(:reload_daemon).and_call_original
Projects::Settings # rubocop:disable Lint/Void
expect(subject).to receive(:pages_config_file).and_return(file.path) expect(subject).to include(status: :success, reload: true)
expect(subject).to receive(:reload_daemon).and_call_original end
end
context 'when configuration does not change' do
before do
# we set the configuration
service.execute
end
expect(subject.execute).to eq({ status: :success }) it 'does not update the .update file' do
expect(service).not_to receive(:reload_daemon)
expect(subject).to include(status: :success, reload: false)
end
end end
end end
end end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment