Commit ed1b6129 authored by Reuben Pereira's avatar Reuben Pereira Committed by Sean McGivern

Handle :9090 and 0.0.0.0:9090 listen_address formats

Prometheus listen_address can be in formats of :9090 and 0.0.0.0:9090.
But before these can be used to connect a project to Prometheus, they
have to converted into absolute URIs.
parent 33da820c
...@@ -45,20 +45,20 @@ module Gitlab ...@@ -45,20 +45,20 @@ module Gitlab
def validate_application_settings def validate_application_settings
return success if application_settings return success if application_settings
log_error(_('No application_settings found')) log_error('No application_settings found')
error(_('No application_settings found')) error(_('No application_settings found'))
end end
def validate_project_created def validate_project_created
return success unless project_created? return success unless project_created?
log_error(_('Project already created')) log_error('Project already created')
error(_('Project already created')) error(_('Project already created'))
end end
def validate_admins def validate_admins
unless instance_admins.any? unless instance_admins.any?
log_error(_('No active admin user found')) log_error('No active admin user found')
return error(_('No active admin user found')) return error(_('No active admin user found'))
end end
...@@ -83,7 +83,7 @@ module Gitlab ...@@ -83,7 +83,7 @@ module Gitlab
def create_project def create_project
if project_created? if project_created?
log_info(_('Instance administration project already exists')) log_info('Instance administration project already exists')
@project = application_settings.instance_administration_project @project = application_settings.instance_administration_project
return success(project: project) return success(project: project)
end end
...@@ -93,7 +93,7 @@ module Gitlab ...@@ -93,7 +93,7 @@ module Gitlab
if project.persisted? if project.persisted?
success(project: project) success(project: project)
else else
log_error(_("Could not create instance administration project. Errors: %{errors}") % { errors: project.errors.full_messages }) log_error("Could not create instance administration project. Errors: %{errors}" % { errors: project.errors.full_messages })
error(_('Could not create project')) error(_('Could not create project'))
end end
end end
...@@ -106,7 +106,7 @@ module Gitlab ...@@ -106,7 +106,7 @@ module Gitlab
if result if result
success success
else else
log_error(_("Could not save instance administration project ID, errors: %{errors}") % { errors: application_settings.errors.full_messages }) log_error("Could not save instance administration project ID, errors: %{errors}" % { errors: application_settings.errors.full_messages })
error(_('Could not save project ID')) error(_('Could not save project ID'))
end end
end end
...@@ -116,7 +116,7 @@ module Gitlab ...@@ -116,7 +116,7 @@ module Gitlab
errors = members.flat_map { |member| member.errors.full_messages } errors = members.flat_map { |member| member.errors.full_messages }
if errors.any? if errors.any?
log_error(_('Could not add admins as members to self-monitoring project. Errors: %{errors}') % { errors: errors }) log_error('Could not add admins as members to self-monitoring project. Errors: %{errors}' % { errors: errors })
error(_('Could not add admins as members')) error(_('Could not add admins as members'))
else else
success success
...@@ -128,7 +128,7 @@ module Gitlab ...@@ -128,7 +128,7 @@ module Gitlab
return success unless prometheus_listen_address.present? return success unless prometheus_listen_address.present?
uri = parse_url(internal_prometheus_listen_address_uri) uri = parse_url(internal_prometheus_listen_address_uri)
return error(_('Prometheus listen_address is not a valid URI')) unless uri return error(_('Prometheus listen_address in config/gitlab.yml is not a valid URI')) unless uri
application_settings.add_to_outbound_local_requests_whitelist([uri.normalized_host]) application_settings.add_to_outbound_local_requests_whitelist([uri.normalized_host])
result = application_settings.save result = application_settings.save
...@@ -140,7 +140,7 @@ module Gitlab ...@@ -140,7 +140,7 @@ module Gitlab
Gitlab::CurrentSettings.expire_current_application_settings Gitlab::CurrentSettings.expire_current_application_settings
success success
else else
log_error(_("Could not add prometheus URL to whitelist, errors: %{errors}") % { errors: application_settings.errors.full_messages }) log_error("Could not add prometheus URL to whitelist, errors: %{errors}" % { errors: application_settings.errors.full_messages })
error(_('Could not add prometheus URL to whitelist')) error(_('Could not add prometheus URL to whitelist'))
end end
end end
...@@ -152,7 +152,7 @@ module Gitlab ...@@ -152,7 +152,7 @@ module Gitlab
service = project.find_or_initialize_service('prometheus') service = project.find_or_initialize_service('prometheus')
unless service.update(prometheus_service_attributes) unless service.update(prometheus_service_attributes)
log_error(_('Could not save prometheus manual configuration for self-monitoring project. Errors: %{errors}') % { errors: service.errors.full_messages }) log_error('Could not save prometheus manual configuration for self-monitoring project. Errors: %{errors}' % { errors: service.errors.full_messages })
return error(_('Could not save prometheus manual configuration')) return error(_('Could not save prometheus manual configuration'))
end end
...@@ -175,15 +175,15 @@ module Gitlab ...@@ -175,15 +175,15 @@ module Gitlab
def prometheus_enabled? def prometheus_enabled?
Gitlab.config.prometheus.enable if Gitlab.config.prometheus Gitlab.config.prometheus.enable if Gitlab.config.prometheus
rescue Settingslogic::MissingSetting rescue Settingslogic::MissingSetting
log_error(_('prometheus.enable is not present in gitlab.yml')) log_error('prometheus.enable is not present in config/gitlab.yml')
false false
end end
def prometheus_listen_address def prometheus_listen_address
Gitlab.config.prometheus.listen_address if Gitlab.config.prometheus Gitlab.config.prometheus.listen_address.to_s if Gitlab.config.prometheus
rescue Settingslogic::MissingSetting rescue Settingslogic::MissingSetting
log_error(_('prometheus.listen_address is not present in gitlab.yml')) log_error('Prometheus listen_address is not present in config/gitlab.yml')
nil nil
end end
...@@ -228,9 +228,21 @@ module Gitlab ...@@ -228,9 +228,21 @@ module Gitlab
end end
def internal_prometheus_listen_address_uri def internal_prometheus_listen_address_uri
if prometheus_listen_address.starts_with?('http') if prometheus_listen_address.starts_with?('0.0.0.0:')
# 0.0.0.0:9090
port = ':' + prometheus_listen_address.split(':').second
'http://localhost' + port
elsif prometheus_listen_address.starts_with?(':')
# :9090
'http://localhost' + prometheus_listen_address
elsif prometheus_listen_address.starts_with?('http')
# https://localhost:9090
prometheus_listen_address prometheus_listen_address
else else
# localhost:9090
'http://' + prometheus_listen_address 'http://' + prometheus_listen_address
end end
end end
......
...@@ -4151,15 +4151,9 @@ msgstr "" ...@@ -4151,15 +4151,9 @@ msgstr ""
msgid "Could not add admins as members" msgid "Could not add admins as members"
msgstr "" msgstr ""
msgid "Could not add admins as members to self-monitoring project. Errors: %{errors}"
msgstr ""
msgid "Could not add prometheus URL to whitelist" msgid "Could not add prometheus URL to whitelist"
msgstr "" msgstr ""
msgid "Could not add prometheus URL to whitelist, errors: %{errors}"
msgstr ""
msgid "Could not authorize chat nickname. Try again!" msgid "Could not authorize chat nickname. Try again!"
msgstr "" msgstr ""
...@@ -4178,9 +4172,6 @@ msgstr "" ...@@ -4178,9 +4172,6 @@ msgstr ""
msgid "Could not create group" msgid "Could not create group"
msgstr "" msgstr ""
msgid "Could not create instance administration project. Errors: %{errors}"
msgstr ""
msgid "Could not create project" msgid "Could not create project"
msgstr "" msgstr ""
...@@ -4199,18 +4190,12 @@ msgstr "" ...@@ -4199,18 +4190,12 @@ msgstr ""
msgid "Could not revoke personal access token %{personal_access_token_name}." msgid "Could not revoke personal access token %{personal_access_token_name}."
msgstr "" msgstr ""
msgid "Could not save instance administration project ID, errors: %{errors}"
msgstr ""
msgid "Could not save project ID" msgid "Could not save project ID"
msgstr "" msgstr ""
msgid "Could not save prometheus manual configuration" msgid "Could not save prometheus manual configuration"
msgstr "" msgstr ""
msgid "Could not save prometheus manual configuration for self-monitoring project. Errors: %{errors}"
msgstr ""
msgid "Coverage" msgid "Coverage"
msgstr "" msgstr ""
...@@ -8233,9 +8218,6 @@ msgstr "" ...@@ -8233,9 +8218,6 @@ msgstr ""
msgid "Instance Statistics visibility" msgid "Instance Statistics visibility"
msgstr "" msgstr ""
msgid "Instance administration project already exists"
msgstr ""
msgid "Instance administrators group already exists" msgid "Instance administrators group already exists"
msgstr "" msgstr ""
...@@ -12043,7 +12025,7 @@ msgstr "" ...@@ -12043,7 +12025,7 @@ msgstr ""
msgid "ProjectsNew|Want to house several dependent projects under the same namespace? %{link_start}Create a group.%{link_end}" msgid "ProjectsNew|Want to house several dependent projects under the same namespace? %{link_start}Create a group.%{link_end}"
msgstr "" msgstr ""
msgid "Prometheus listen_address is not a valid URI" msgid "Prometheus listen_address in config/gitlab.yml is not a valid URI"
msgstr "" msgstr ""
msgid "PrometheusAlerts|Add alert" msgid "PrometheusAlerts|Add alert"
...@@ -18859,12 +18841,6 @@ msgstr[1] "" ...@@ -18859,12 +18841,6 @@ msgstr[1] ""
msgid "project avatar" msgid "project avatar"
msgstr "" msgstr ""
msgid "prometheus.enable is not present in gitlab.yml"
msgstr ""
msgid "prometheus.listen_address is not present in gitlab.yml"
msgstr ""
msgid "quick actions" msgid "quick actions"
msgstr "" msgstr ""
......
...@@ -176,14 +176,28 @@ describe Gitlab::DatabaseImporters::SelfMonitoring::Project::CreateService do ...@@ -176,14 +176,28 @@ describe Gitlab::DatabaseImporters::SelfMonitoring::Project::CreateService do
end end
context 'with non default prometheus address' do context 'with non default prometheus address' do
let(:listen_address) { 'https://localhost:9090' }
let(:prometheus_settings) do let(:prometheus_settings) do
{ {
enable: true, enable: true,
listen_address: 'https://localhost:9090' listen_address: listen_address
} }
end end
it_behaves_like 'has prometheus service', 'https://localhost:9090' it_behaves_like 'has prometheus service', 'https://localhost:9090'
context 'with :9090 symbol' do
let(:listen_address) { :':9090' }
it_behaves_like 'has prometheus service', 'http://localhost:9090'
end
context 'with 0.0.0.0:9090' do
let(:listen_address) { '0.0.0.0:9090' }
it_behaves_like 'has prometheus service', 'http://localhost:9090'
end
end end
context 'when prometheus setting is not present in gitlab.yml' do context 'when prometheus setting is not present in gitlab.yml' do
......
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