Commit 325a2cc0 authored by Miguel Rincon's avatar Miguel Rincon

Remove duplicate data in metric_id

`metricId` has replaced `metric_id` in most monitoring components.

This is the last step to remove `metric_id` from the frontend
view models.
parent 6149be16
...@@ -67,7 +67,7 @@ export default { ...@@ -67,7 +67,7 @@ export default {
'setShowErrorBanner', 'setShowErrorBanner',
]), ]),
chartHasData(chart) { chartHasData(chart) {
return chart.metrics.some(metric => this.metricsWithData().includes(metric.metric_id)); return chart.metrics.some(metric => this.metricsWithData().includes(metric.metricId));
}, },
onSidebarMutation() { onSidebarMutation() {
setTimeout(() => { setTimeout(() => {
......
...@@ -13,11 +13,12 @@ export const gqClient = createGqClient( ...@@ -13,11 +13,12 @@ export const gqClient = createGqClient(
/** /**
* Metrics loaded from project-defined dashboards do not have a metric_id. * Metrics loaded from project-defined dashboards do not have a metric_id.
* This method creates a unique ID combining metric_id and id, if either is present. * This method creates a unique ID combining metric_id and id, if either is present.
* This is hopefully a temporary solution until BE processes metrics before passing to fE * This is hopefully a temporary solution until BE processes metrics before passing to FE
* @param {Object} metric - metric * @param {Object} metric - metric
* @returns {Object} - normalized metric with a uniqueID * @returns {Object} - normalized metric with a uniqueID
*/ */
export const uniqMetricsId = metric => `${metric.metric_id}_${metric.id}`; // eslint-disable-next-line babel/camelcase
export const uniqMetricsId = ({ metric_id, id }) => `${metric_id}_${id}`;
/** /**
* Project path has a leading slash that doesn't work well * Project path has a leading slash that doesn't work well
...@@ -68,10 +69,6 @@ const mapToMetricsViewModel = (metrics, defaultLabel) => ...@@ -68,10 +69,6 @@ const mapToMetricsViewModel = (metrics, defaultLabel) =>
queryRange: query_range, queryRange: query_range,
prometheusEndpointPath: prometheus_endpoint_path, prometheusEndpointPath: prometheus_endpoint_path,
metricId: uniqMetricsId({ metric_id, id }), metricId: uniqMetricsId({ metric_id, id }),
// `metric_id` is used by embed.vue, keeping this duplicated.
// https://gitlab.com/gitlab-org/gitlab/issues/37492
metric_id: uniqMetricsId({ metric_id, id }),
...metric, ...metric,
})); }));
......
export const metricsWithData = [15, 16]; export const metricsWithData = ['15_metric_a', '16_metric_b'];
export const groups = [ export const groups = [
{ {
...@@ -7,39 +7,10 @@ export const groups = [ ...@@ -7,39 +7,10 @@ export const groups = [
title: 'Memory Usage (Total)', title: 'Memory Usage (Total)',
type: 'area-chart', type: 'area-chart',
y_label: 'Total Memory Used', y_label: 'Total Memory Used',
weight: 4, metrics: null,
metrics: [
{
id: 'system_metrics_kubernetes_container_memory_total',
metric_id: 15,
},
],
},
{
title: 'Core Usage (Total)',
type: 'area-chart',
y_label: 'Total Cores',
weight: 3,
metrics: [
{
id: 'system_metrics_kubernetes_container_cores_total',
metric_id: 16,
}, },
], ],
}, },
],
},
];
export const metrics = [
{
id: 'system_metrics_kubernetes_container_memory_total',
metric_id: 15,
},
{
id: 'system_metrics_kubernetes_container_cores_total',
metric_id: 16,
},
]; ];
const result = [ const result = [
...@@ -60,7 +31,7 @@ export const metricsData = [ ...@@ -60,7 +31,7 @@ export const metricsData = [
{ {
metrics: [ metrics: [
{ {
metric_id: 15, metricId: '15_metric_a',
result, result,
}, },
], ],
...@@ -68,7 +39,7 @@ export const metricsData = [ ...@@ -68,7 +39,7 @@ export const metricsData = [
{ {
metrics: [ metrics: [
{ {
metric_id: 16, metricId: '16_metric_b',
result, result,
}, },
], ],
......
...@@ -213,20 +213,16 @@ describe('mapToDashboardViewModel', () => { ...@@ -213,20 +213,16 @@ describe('mapToDashboardViewModel', () => {
expect(getMappedMetric(dashboard)).toEqual({ expect(getMappedMetric(dashboard)).toEqual({
label: expect.any(String), label: expect.any(String),
metricId: expect.any(String), metricId: expect.any(String),
metric_id: expect.any(String),
}); });
}); });
it('creates a metric with a correct ids', () => { it('creates a metric with a correct id', () => {
const dashboard = dashboardWithMetric({ const dashboard = dashboardWithMetric({
id: 'http_responses', id: 'http_responses',
metric_id: 1, metric_id: 1,
}); });
expect(getMappedMetric(dashboard)).toMatchObject({ expect(getMappedMetric(dashboard).metricId).toEqual('1_http_responses');
metricId: '1_http_responses',
metric_id: '1_http_responses',
});
}); });
it('creates a metric with a default label', () => { it('creates a metric with a default label', () => {
......
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