diff --git a/app/services/metrics/dashboard/pod_dashboard_service.rb b/app/services/metrics/dashboard/pod_dashboard_service.rb new file mode 100644 index 0000000000000000000000000000000000000000..16b87d2d587d81b88e5fa9be81d729b3c6a394c0 --- /dev/null +++ b/app/services/metrics/dashboard/pod_dashboard_service.rb @@ -0,0 +1,10 @@ +# frozen_string_literal: true + +module Metrics + module Dashboard + class PodDashboardService < ::Metrics::Dashboard::PredefinedDashboardService + DASHBOARD_PATH = 'config/prometheus/pod_metrics.yml' + DASHBOARD_NAME = 'Pod Health' + end + end +end diff --git a/config/prometheus/pod_metrics.yml b/config/prometheus/pod_metrics.yml new file mode 100644 index 0000000000000000000000000000000000000000..29575ec543e631b521033a912fb7784572f563e3 --- /dev/null +++ b/config/prometheus/pod_metrics.yml @@ -0,0 +1,59 @@ +dashboard: 'Pod metrics' +priority: 10 +panel_groups: +- group: CPU metrics + panels: + - title: "CPU usage" + type: "line-chart" + y_label: "Cores per pod" + metrics: + - id: pod_cpu_usage_seconds_total + query_range: 'rate(container_cpu_usage_seconds_total{pod_name="{{pod_name}}",container_name="POD"}[5m])' + unit: "cores" + label: pod_name +- group: Memory metrics + panels: + - title: "Memory usage working set" + type: "line-chart" + y_label: "Working set memory (MiB)" + metrics: + - id: pod_memory_working_set + query_range: 'container_memory_working_set_bytes{pod_name="{{pod_name}}",container_name="POD"}/1024/1024' + unit: "MiB" + label: pod_name +- group: Network metrics + panels: + - title: "Network Receive (In)" + type: "line-chart" + y_label: "Received (KiB/sec)" + metrics: + - id: pod_network_receive + query_range: 'rate(container_network_receive_bytes_total{pod_name="{{pod_name}}",container_name="POD"}[5m])/1024' + unit: "KiB / sec" + label: pod_name + - title: "Network Transmit (Out)" + type: "line-chart" + y_label: "Transmitted (KiB/sec)" + metrics: + - id: pod_network_transmit + query_range: 'rate(container_network_transmit_bytes_total{pod_name="{{pod_name}}",container_name="POD"}[5m])/1024' + unit: "KiB / sec" + label: pod_name +- group: Disk metrics + panels: + - title: "Disk Reads" + type: "line-chart" + y_label: "Disk reads (KiB/sec)" + metrics: + - id: pod_disk_reads + query_range: 'rate(container_fs_reads_bytes_total{container_name="POD",pod_name="{{pod_name}}"}[5m])/1024' + unit: "KiB / sec" + label: pod_name + - title: "Disk Writes" + type: "line-chart" + y_label: "Disk writes (KiB/sec)" + metrics: + - id: pod_disk_writes + query_range: 'rate(container_fs_writes_bytes_total{container_name="POD",pod_name="{{pod_name}}"}[5m])/1024' + unit: "KiB / sec" + label: pod_name diff --git a/lib/gitlab/metrics/dashboard/service_selector.rb b/lib/gitlab/metrics/dashboard/service_selector.rb index 22314c2a0ee34b156e0e18efb5adc17d18c2a5ff..5b6f25420e09d497d7fd319f285131c8cdf7e29d 100644 --- a/lib/gitlab/metrics/dashboard/service_selector.rb +++ b/lib/gitlab/metrics/dashboard/service_selector.rb @@ -22,6 +22,7 @@ def call(params) return SERVICES::DynamicEmbedService if dynamic_embed?(params) return SERVICES::DefaultEmbedService if params[:embedded] return SERVICES::SystemDashboardService if system_dashboard?(params[:dashboard_path]) + return SERVICES::PodDashboardService if pod_dashboard?(params[:dashboard_path]) return SERVICES::ProjectDashboardService if params[:dashboard_path] default_service @@ -37,6 +38,10 @@ def system_dashboard?(filepath) SERVICES::SystemDashboardService.matching_dashboard?(filepath) end + def pod_dashboard?(filepath) + SERVICES::PodDashboardService.matching_dashboard?(filepath) + end + def custom_metric_embed?(params) SERVICES::CustomMetricEmbedService.valid_params?(params) end diff --git a/spec/fixtures/lib/gitlab/metrics/dashboard/schemas/panel_groups.json b/spec/fixtures/lib/gitlab/metrics/dashboard/schemas/panel_groups.json index d7a390adcdc4fdbc4f31a5db38208f0928257e3a..f4afb4cbffc90d66e0553d1d09433475120948b9 100644 --- a/spec/fixtures/lib/gitlab/metrics/dashboard/schemas/panel_groups.json +++ b/spec/fixtures/lib/gitlab/metrics/dashboard/schemas/panel_groups.json @@ -2,7 +2,6 @@ "type": "object", "required": [ "group", - "priority", "panels" ], "properties": { diff --git a/spec/lib/gitlab/metrics/dashboard/service_selector_spec.rb b/spec/lib/gitlab/metrics/dashboard/service_selector_spec.rb index 0d4562f78f169e6e4869f2ca1c8bfb4e6bf6bd67..e0c8133994b9b80c1f98c6f0d21af1283beb0ddc 100644 --- a/spec/lib/gitlab/metrics/dashboard/service_selector_spec.rb +++ b/spec/lib/gitlab/metrics/dashboard/service_selector_spec.rb @@ -22,6 +22,12 @@ it { is_expected.to be Metrics::Dashboard::SystemDashboardService } end + + context 'when the path is for the pod dashboard' do + let(:arguments) { { dashboard_path: pod_dashboard_path } } + + it { is_expected.to be Metrics::Dashboard::PodDashboardService } + end end context 'when the embedded flag is provided' do diff --git a/spec/services/metrics/dashboard/pod_dashboard_service_spec.rb b/spec/services/metrics/dashboard/pod_dashboard_service_spec.rb new file mode 100644 index 0000000000000000000000000000000000000000..c3993bf71ea3ed1a4173d6dc7252c9db90ae54e0 --- /dev/null +++ b/spec/services/metrics/dashboard/pod_dashboard_service_spec.rb @@ -0,0 +1,24 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe Metrics::Dashboard::PodDashboardService, :use_clean_rails_memory_store_caching do + include MetricsDashboardHelpers + + let_it_be(:user) { create(:user) } + let_it_be(:project) { create(:project) } + let_it_be(:environment) { create(:environment, project: project) } + + before do + project.add_maintainer(user) + end + + describe 'get_dashboard' do + let(:dashboard_path) { described_class::DASHBOARD_PATH } + let(:service_params) { [project, user, { environment: environment, dashboard_path: dashboard_path }] } + let(:service_call) { described_class.new(*service_params).get_dashboard } + + it_behaves_like 'valid dashboard service response' + it_behaves_like 'caches the unprocessed dashboard for subsequent calls' + end +end diff --git a/spec/support/helpers/metrics_dashboard_helpers.rb b/spec/support/helpers/metrics_dashboard_helpers.rb index 98f235bdac41d77680ffdc154a9ec0db697084cb..5b425d0964d4eef525888d3a9c93db878f0c2d5c 100644 --- a/spec/support/helpers/metrics_dashboard_helpers.rb +++ b/spec/support/helpers/metrics_dashboard_helpers.rb @@ -22,6 +22,10 @@ def system_dashboard_path Metrics::Dashboard::SystemDashboardService::DASHBOARD_PATH end + def pod_dashboard_path + Metrics::Dashboard::PodDashboardService::DASHBOARD_PATH + end + def business_metric_title PrometheusMetricEnums.group_details[:business][:group_title] end