Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix ruby metrics #549

Merged
merged 1 commit into from
Jun 3, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/services/metrics/send_metrics.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def call

def prometheus_client
@prometheus_client ||= PrometheusExporter::Client.new(
host: Rails.configuration.x.service_host,
host: Rails.configuration.x.metrics_service_host,
thread_sleep: PROMETHEUS_THREAD_SLEEP
)
end
Expand Down
2 changes: 1 addition & 1 deletion config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class Application < Rails::Application
config.x.admin_portal.allow_create_test_applications = ENV['ADMIN_ALLOW_CREATE_TEST_APPLICATIONS'] == 'true'
config.x.admin_portal.password = ENV['ADMIN_PASSWORD']

config.x.service_host = ENV.fetch('SERVICE_HOST', 'localhost')
config.x.metrics_service_host = ENV.fetch('METRICS_SERVICE_HOST', 'localhost')

require Rails.root.join 'app/lib/govuk_elements_form_builder/form_builder'
ActionView::Base.default_form_builder = GovukElementsFormBuilder::FormBuilder
Expand Down
2 changes: 1 addition & 1 deletion config/initializers/prometheus_metrics.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
require 'prometheus_exporter/middleware'

PrometheusExporter::Client.default = PrometheusExporter::Client.new(
host: Rails.configuration.x.service_host
host: Rails.configuration.x.metrics_service_host
)

PrometheusExporter::Instrumentation::Process.start(type: 'master')
Expand Down
4 changes: 2 additions & 2 deletions helm_deploy/apply-for-legal-aid/templates/_envs.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,6 @@ env:
key: googleAnalyticsTrackingID
- name: KUBERNETES_DEPLOYMENT
value: "true"
- name: SERVICE_HOST
value: {{ .Release.Name }}
- name: METRICS_SERVICE_HOST
value: {{ template "apply-for-legal-aid.fullname" . }}-metrics
{{- end }}
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ spec:
replicas: 1
selector:
matchLabels:
app: {{ template "apply-for-legal-aid.name" . }}
release: {{ .Release.Name }}
service: {{ template "apply-for-legal-aid.fullname" . }}-metrics
template:
metadata:
labels:
app: {{ template "apply-for-legal-aid.name" . }}
release: {{ .Release.Name }}
service: {{ template "apply-for-legal-aid.fullname" . }}-metrics
spec:
containers:
- name: metrics
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ spec:
protocol: TCP
resources:
{{ toYaml .Values.clamav.resources | indent 12 }}
- name: {{ .Chart.Name }}
- name: web
image: '{{ .Values.image.repository }}:{{ .Values.image.tag }}'
imagePullPolicy: IfNotPresent
{{ include "apply-for-legal-aid.envs" . | nindent 10 }}
Expand Down
17 changes: 17 additions & 0 deletions helm_deploy/apply-for-legal-aid/templates/service-metrics.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
apiVersion: v1
kind: Service
metadata:
name: {{ template "apply-for-legal-aid.fullname" . }}-metrics
labels:
service: {{ template "apply-for-legal-aid.fullname" . }}-metrics
app: {{ template "apply-for-legal-aid.name" . }}
chart: {{ template "apply-for-legal-aid.chart" . }}
release: {{ .Release.Name }}
heritage: {{ .Release.Service }}
spec:
ports:
- port: 9394
protocol: TCP
name: metrics
selector:
service: {{ template "apply-for-legal-aid.fullname" . }}-metrics
3 changes: 0 additions & 3 deletions helm_deploy/apply-for-legal-aid/templates/service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@ spec:
targetPort: http
protocol: TCP
name: http
- port: 9394
targetPort: 9394
name: metrics
selector:
app: {{ template "apply-for-legal-aid.name" . }}
release: {{ .Release.Name }}
6 changes: 3 additions & 3 deletions spec/services/metrics/send_metrics_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,21 @@

RSpec.describe Metrics::SendMetrics do
describe '#call' do
let(:service_host) { Faker::Internet.domain_word }
let(:metrics_service_host) { Faker::Internet.domain_word }
let(:prometheus_client) { spy(PrometheusExporter::Client) }
let(:prometheus_thread_sleep) { rand(1..10).to_f / 1000 }
subject { described_class.call }

before do
stub_const('Metrics::SendMetrics::PROMETHEUS_THREAD_SLEEP', prometheus_thread_sleep)
allow(PrometheusExporter::Client).to receive(:new).and_return(prometheus_client)
allow(Rails.configuration.x).to receive(:service_host).and_return(service_host)
allow(Rails.configuration.x).to receive(:metrics_service_host).and_return(metrics_service_host)
end

it 'creates a prometheus client with the right settings' do
expect(PrometheusExporter::Client)
.to receive(:new)
.with(host: service_host, thread_sleep: prometheus_thread_sleep)
.with(host: metrics_service_host, thread_sleep: prometheus_thread_sleep)
.and_return(prometheus_client)
subject
end
Expand Down