From 287ba77abff0c9ba46fea36b7dfd883181022fd8 Mon Sep 17 00:00:00 2001 From: Mitsuhiro Tanda Date: Thu, 18 Oct 2018 14:28:41 +0900 Subject: [PATCH 1/6] don't overwrite unit if user set --- public/app/plugins/panel/graph/module.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/public/app/plugins/panel/graph/module.ts b/public/app/plugins/panel/graph/module.ts index bc0d0c0c630..0701f1ddbbb 100644 --- a/public/app/plugins/panel/graph/module.ts +++ b/public/app/plugins/panel/graph/module.ts @@ -238,7 +238,7 @@ class GraphCtrl extends MetricsPanelCtrl { for (const series of this.seriesList) { series.applySeriesOverrides(this.panel.seriesOverrides); - if (series.unit) { + if (this.panel.yaxes[series.yaxis - 1].format === 'none' && series.unit) { this.panel.yaxes[series.yaxis - 1].format = series.unit; } } From e465b2d53ab59f8a004db580fdd3902d76536878 Mon Sep 17 00:00:00 2001 From: Mitsuhiro Tanda Date: Thu, 18 Oct 2018 20:45:03 +0900 Subject: [PATCH 2/6] Revert "don't overwrite unit if user set" This reverts commit 9dd33b79e037fc75ddc5f3a6b294edba99e99b94. --- public/app/plugins/panel/graph/module.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/public/app/plugins/panel/graph/module.ts b/public/app/plugins/panel/graph/module.ts index 0701f1ddbbb..bc0d0c0c630 100644 --- a/public/app/plugins/panel/graph/module.ts +++ b/public/app/plugins/panel/graph/module.ts @@ -238,7 +238,7 @@ class GraphCtrl extends MetricsPanelCtrl { for (const series of this.seriesList) { series.applySeriesOverrides(this.panel.seriesOverrides); - if (this.panel.yaxes[series.yaxis - 1].format === 'none' && series.unit) { + if (series.unit) { this.panel.yaxes[series.yaxis - 1].format = series.unit; } } From 4687ce2f7b884fd87f23a6d11bb9d3d0d64dcdc6 Mon Sep 17 00:00:00 2001 From: Mitsuhiro Tanda Date: Thu, 18 Oct 2018 20:51:36 +0900 Subject: [PATCH 3/6] allow unit override if cloudwatch response unit is none --- public/app/plugins/datasource/cloudwatch/datasource.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/public/app/plugins/datasource/cloudwatch/datasource.ts b/public/app/plugins/datasource/cloudwatch/datasource.ts index 7821c5dcb2c..b4f739f934c 100644 --- a/public/app/plugins/datasource/cloudwatch/datasource.ts +++ b/public/app/plugins/datasource/cloudwatch/datasource.ts @@ -137,7 +137,11 @@ export default class CloudWatchDatasource { if (res.results) { _.forEach(res.results, queryRes => { _.forEach(queryRes.series, series => { - data.push({ target: series.name, datapoints: series.points, unit: queryRes.meta.unit || 'none' }); + const s = { target: series.name, datapoints: series.points } as any; + if (queryRes.meta.unit) { + s.unit = queryRes.meta.unit; + } + data.push(s); }); }); } From d1740f090a0a0479a9e4999d7225c0a5c4ba8faf Mon Sep 17 00:00:00 2001 From: Erik Sundell Date: Thu, 18 Oct 2018 16:42:08 +0200 Subject: [PATCH 4/6] stackdriver: make sure unit is not returned to the panel if mapping from stackdriver unit to grafana unit can't be made --- .../app/plugins/datasource/stackdriver/datasource.ts | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/public/app/plugins/datasource/stackdriver/datasource.ts b/public/app/plugins/datasource/stackdriver/datasource.ts index 7ea748e1082..581c4f5002c 100644 --- a/public/app/plugins/datasource/stackdriver/datasource.ts +++ b/public/app/plugins/datasource/stackdriver/datasource.ts @@ -89,7 +89,7 @@ export default class StackdriverDatasource { } resolvePanelUnitFromTargets(targets: any[]) { - let unit = 'none'; + let unit; if (targets.length > 0 && targets.every(t => t.unit === targets[0].unit)) { if (stackdriverUnitMappings.hasOwnProperty(targets[0].unit)) { unit = stackdriverUnitMappings[targets[0].unit]; @@ -109,13 +109,17 @@ export default class StackdriverDatasource { const unit = this.resolvePanelUnitFromTargets(options.targets); queryRes.series.forEach(series => { - result.push({ + let timeSerie = { target: series.name, datapoints: series.points, refId: queryRes.refId, meta: queryRes.meta, unit, - }); + }; + if (unit) { + timeSerie = { ...timeSerie, unit }; + } + result.push(timeSerie); }); }); } From 0f0763b6b8cc3036d7f19f185c3be1778bbfe607 Mon Sep 17 00:00:00 2001 From: Erik Sundell Date: Thu, 18 Oct 2018 16:45:46 +0200 Subject: [PATCH 5/6] stackdriver: fix failing tests --- .../datasource/stackdriver/specs/datasource.test.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/public/app/plugins/datasource/stackdriver/specs/datasource.test.ts b/public/app/plugins/datasource/stackdriver/specs/datasource.test.ts index 3117be402a9..ab0c0653816 100644 --- a/public/app/plugins/datasource/stackdriver/specs/datasource.test.ts +++ b/public/app/plugins/datasource/stackdriver/specs/datasource.test.ts @@ -235,8 +235,8 @@ describe('StackdriverDataSource', () => { beforeEach(() => { res = ds.resolvePanelUnitFromTargets([{ unit: 'megaseconds' }]); }); - it('should return none', () => { - expect(res).toEqual('none'); + it('should return undefined', () => { + expect(res).toBeUndefined(); }); }); describe('and the stackdriver unit has a corresponding grafana unit', () => { @@ -262,16 +262,16 @@ describe('StackdriverDataSource', () => { beforeEach(() => { res = ds.resolvePanelUnitFromTargets([{ unit: 'megaseconds' }, { unit: 'megaseconds' }]); }); - it('should return the default value - none', () => { - expect(res).toEqual('none'); + it('should return the default value of undefined', () => { + expect(res).toBeUndefined(); }); }); describe('and all target units are not the same', () => { beforeEach(() => { res = ds.resolvePanelUnitFromTargets([{ unit: 'bit' }, { unit: 'min' }]); }); - it('should return the default value - none', () => { - expect(res).toEqual('none'); + it('should return the default value of undefined', () => { + expect(res).toBeUndefined(); }); }); }); From b2932058c7988e350d687fb60926e26519db41bb Mon Sep 17 00:00:00 2001 From: Erik Sundell Date: Fri, 19 Oct 2018 10:42:57 +0200 Subject: [PATCH 6/6] stackdriver: only add unit to resonse obj if it has a value --- public/app/plugins/datasource/stackdriver/datasource.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/public/app/plugins/datasource/stackdriver/datasource.ts b/public/app/plugins/datasource/stackdriver/datasource.ts index 581c4f5002c..b77abdbdab3 100644 --- a/public/app/plugins/datasource/stackdriver/datasource.ts +++ b/public/app/plugins/datasource/stackdriver/datasource.ts @@ -109,12 +109,11 @@ export default class StackdriverDatasource { const unit = this.resolvePanelUnitFromTargets(options.targets); queryRes.series.forEach(series => { - let timeSerie = { + let timeSerie: any = { target: series.name, datapoints: series.points, refId: queryRes.refId, meta: queryRes.meta, - unit, }; if (unit) { timeSerie = { ...timeSerie, unit };