Commit 911c4841 authored by Adam Hegyi's avatar Adam Hegyi

Merge branch '215563-migration-to-import-common-metrics' into 'master'

Add migration to import common metrics into DB

See merge request gitlab-org/gitlab!31618
parents a1484cb6 1009c21f
---
title: Add migration to import changes to the system dashboard Prometheus queries
into DB
merge_request: 31618
author:
type: changed
# frozen_string_literal: true
class ChangeVariableInterpolationFormatInCommonMetrics < ActiveRecord::Migration[6.0]
DOWNTIME = false
def up
::Gitlab::DatabaseImporters::CommonMetrics::Importer.new.execute
end
def down
# no-op
# The import cannot be reversed since we do not know the state that the
# common metrics in the PrometheusMetric table were in before the import.
end
end
......@@ -13765,5 +13765,6 @@ COPY "schema_migrations" (version) FROM STDIN;
20200506085748
20200506125731
20200507221434
20200511145545
\.
# frozen_string_literal: true
require 'spec_helper'
require Rails.root.join('db', 'post_migrate', '20200511145545_change_variable_interpolation_format_in_common_metrics')
describe ChangeVariableInterpolationFormatInCommonMetrics, :migration do
let(:prometheus_metrics) { table(:prometheus_metrics) }
let!(:common_metric) do
prometheus_metrics.create!(
identifier: 'system_metrics_kubernetes_container_memory_total',
query: 'avg(sum(container_memory_usage_bytes{container_name!="POD",' \
'pod_name=~"^%{ci_environment_slug}-(.*)",namespace="%{kube_namespace}"})' \
' by (job)) without (job) /1024/1024/1024',
project_id: nil,
title: 'Memory Usage (Total)',
y_label: 'Total Memory Used (GB)',
unit: 'GB',
legend: 'Total (GB)',
group: -5,
common: true
)
end
it 'updates query to use {{}}' do
expected_query = 'avg(sum(container_memory_usage_bytes{container_name!="POD",' \
'pod_name=~"^{{ci_environment_slug}}-(.*)",namespace="{{kube_namespace}}"})' \
' by (job)) without (job) /1024/1024/1024'
migrate!
expect(common_metric.reload.query).to eq(expected_query)
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